//loader js by dada raneses caro

// menu
function pageload(hash) 
{
//	var dom = {};
//	dom.query = jQuery.noConflict(true);
	getPage();
}
//showreel
$.fn.jqvideobox = function (opt) 
{
	return this.each(function()
	{
		function init()
        {
        	if ($("#lbOverlay").length == 0)
        	{
	        	var _overlay = $(document.createElement("div")).attr({"id": "lbOverlay"}).click(closeMe);
	        	var _center = $(document.createElement("div")).attr({"id": "lbCenter"}).css({'width': options.initialWidth+'px', 'height': options.initialHeight+'px', 'display': 'none'});
	        	var _bottomContainer = $(document.createElement("div")).attr({"id": "lbBottomContainer"}).css('display', 'none');

	        	var _bottom = $(document.createElement("div")).attr('id', 'lbBottom');
				var _close = $(document.createElement("a")).attr({id: 'lbCloseLink', href: '#'}).click(closeMe);
				var _caption = $(document.createElement("div")).attr('id', 'lbCaption');
				var _number = $(document.createElement("div")).attr('id', 'lbNumber');
				var _clear = $(document.createElement("div")).css('clear', 'both');	
				
				var _prevlink = $(document.createElement("a")).attr({id: 'lbPrevLink', href: '#'}).click(prevVideo);
				var _nextlink = $(document.createElement("a")).attr({id: 'lbNextLink', href: '#'}).click(nextVideo);
				_bottom.append(_close).append(_caption).append(_number).append(_clear);
				_bottomContainer.append(_bottom);
	        	$("body").append(_overlay).append(_center).append(_bottomContainer).append(_prevlink).append(_nextlink);
        	}
        	
    		overlay = $("#lbOverlay");
    		center = $("#lbCenter");
    		caption = $("#lbCaption");
    		bottomContainer = $("#lbBottomContainer");
        	prevlink = $("#lbPrevLink");
        	nextlink = $("#lbNextLink");
        	
        	element.click(activate);
        }
        
        function prevVideo()
        {
        	return false;
        }
        
        function nextVideo()
        {
        	return false;
        }
        
        function closeMe()
		{
				overlay.fadeTo("fast",0,function(){$(this).css('display','none');});
				center.css('display','none');
				bottomContainer.css('display', 'none');
				prevlink.css('display','none');
				nextlink.css('display','none');
				center.html('');
				return false;
		}
        
        function activate()
        {
			setup(href);
			top = $(window).scrollTop() + (($(window).height() / 2) - (options.defaultHeight / 2));
			left= (($(window).width() / 2) - (options.defaultWidth / 2));
			center.css({'top': top + 'px', 'left':  left + 'px','display': 'none', 'background': '#fff url(css/loading.gif) no-repeat center', 'height': options.contentsHeight, 'width': options.contentsWidth});					
			overlay.css('display','block').fadeTo("fast",options.defaultOverLayFade);
			caption.html(title);
			center.fadeIn("slow",
				function()
				{
					insert();
				}
			);
			return false;
        }
        
        function insert()
        {
        	center.css('background','#fff');
			flash ? so.write(center.attr("id")) : center.html(other) ;					
			bottomContainer.css({'top': (top + center.height() + 10) + "px", 'left': center.css('left'), 'width': options.contentsWidth+'px'});
			if (options.animateCaption)
			{
				bottomContainer.slideDown('slow');
			}
			else
			{
				bottomContainer.css('display','block');
			}
			//prevlink.css({'top': (top + (options.defaultHeight /2 )) + "px", 'display': 'block', 'left':  (parseInt(center.css('left'),10) + options.defaultWidth) + 'px'});
			//nextlink.css({'top': (top + (options.defaultHeight /2 )) + "px", 'display': 'block', 'left':  (parseInt(center.css('left'),10) - 53) + 'px'});
        }
        
        function setup(sLinkHref)
        {
        	var aDim = rel.match(/[0-9]+/g);
        	overlay.css({'top': $(window).scrollTop()+'px', 'height': $(window).height()+'px'});
			options.contentsWidth = (aDim && (aDim[0] > 0)) ? aDim[0] : options.defaultWidth;
			options.contentsHeight = (aDim && (aDim[1] > 0)) ? aDim[1] : options.defaultHeight;
			
			if (sLinkHref.match(/youtube\.com\/watch/i)) 
			{
		    	flash = true;
				var hRef = sLinkHref;
				var videoId = hRef.split('=');
				videoID = videoId[1];
				so = new SWFObject("http://www.youtube.com/v/"+videoID, "flvvideo", options.contentsWidth, options.contentsHeight, "0");
				so.addParam("wmode", "transparent");
			}
			else if (sLinkHref.match(/metacafe\.com\/watch/i)) 
			{
		      	flash = true;
				var hRef = sLinkHref;
				var videoId = hRef.split('/');
				videoID = videoId[4];
				so = new SWFObject("http://www.metacafe.com/fplayer/"+videoID+"/.swf", "flvvideo", options.contentsWidth, options.contentsHeight, "0");
				so.addParam("wmode", "transparent");
			}
			else if (sLinkHref.match(/google\.com\/videoplay/i)) 
			{
	      		flash = true;
				var hRef = sLinkHref;
				var videoId = hRef.split('=');
				videoID = videoId[1];
				so = new SWFObject("http://video.google.com/googleplayer.swf?docId="+videoID+"&hl=en", "flvvideo", options.contentsWidth, options.contentsHeight, "0");
				so.addParam("wmode", "transparent");
			}
			else if (sLinkHref.match(/ifilm\.com\/video/i)) 
			{
			  	flash = true;
				var hRef = sLinkHref;
				var videoId = hRef.split('video/');
				videoID = videoId[1];
				so = new SWFObject("http://www.ifilm.com/efp", "flvvideo", options.contentsWidth, options.contentsHeight, "0", "#000");
				so.addVariable("flvbaseclip", videoID+"&");
				so.addParam("wmode", "transparent");
			}
			else if (sLinkHref.match(/\.mov/i)) 
			{
				flash = false;
				if (navigator.plugins && navigator.plugins.length) 
				{
	          		other ='<object id="qtboxMovie" type="video/quicktime" codebase="http://www.apple.com/qtactivex/qtplugin.cab" data="'+sLinkHref+'" width="'+options.contentsWidth+'" height="'+options.contentsHeight+'"><param name="src" value="'+sLinkHref+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
	      		} 
	      		else 
	      		{
	        		other = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="'+options.contentsWidth+'" height="'+options.contentsHeight+'" id="qtboxMovie"><param name="src" value="'+sLinkHref+'" /><param name="scale" value="aspect" /><param name="controller" value="true" /><param name="autoplay" value="true" /><param name="bgcolor" value="#000000" /><param name="enablejavascript" value="true" /></object>';
	      		}
			}
			else if (sLinkHref.match(/\.wmv/i) || sLinkHref.match(/\.asx/i)) 
			{
				flash = false;
			 	other = '<object NAME="Player" WIDTH="'+options.contentsWidth+'" HEIGHT="'+options.contentsHeight+'" align="left" hspace="0" type="application/x-oleobject" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"><param NAME="URL" VALUE="'+sLinkHref+'"><param><param NAME="AUTOSTART" VALUE="false"></param><param name="showControls" value="true"></param><embed WIDTH="'+options.contentsWidth+'" HEIGHT="'+options.contentsHeight+'" align="left" hspace="0" SRC="'+sLinkHref+'" TYPE="application/x-oleobject" AUTOSTART="false"></embed></object>';
			}
			else if (sLinkHref.match(/\.flv/i)) 
			{
			 	flash = true;
			 	so = new SWFObject(options.flvplayer+"?file="+sLinkHref, "flvvideo", options.contentsWidth, options.contentsHeight, "0", "#000");
			}
			else 
			{
			  	flash = true;
				videoID = sLinkHref;
				so = new SWFObject(videoID, "flvvideo", options.contentsWidth, options.contentsHeight, "0");
			}
		}

        var options = $.extend({				        
				initialWidth: 640,		// Initial width of the box (px)
				initialHeight: 430,		// Initial height of the box (px)
				defaultWidth: 640,		// Default width of the box (px)
				defaultHeight: 430,	// Default height of the box (px)
				animateCaption: true,	// Enable/Disable caption animation
				defaultOverLayFade: 0.5,	//Default overlay fade value
				flvplayer: './swf/flvplayer.swf'
	        }, opt);
	    
	    //system vars
	    var overlay, center, caption, bottomContainer, so, flash, videoID, other, top;
	    var element = $(this);
	    var href = element.attr("href");
		var title = element.attr("title");
		var rel = element.attr("rel");

		//lets start it
        init();
	});
};
//end showreel
//main slideshow function
var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
    Ready : function()
    {
      $('div.tmpSlideshowControl')
        .hover(
          function() {
            $(this).addClass('tmpSlideshowControlOn');
          },
          function() {
            $(this).removeClass('tmpSlideshowControlOn');
          }
        )
        .click(
          function() {
            $$.Slideshow.Interrupted = true;

            $('div.tmpSlide').hide();
            $('div.tmpSlideshowControl').removeClass('tmpSlideshowControlActive');

            $('div#tmpSlide-' + $(this).SplitID()).show()
            $(this).addClass('tmpSlideshowControlActive');
          }
        );

      this.Counter = 1;
      this.Interrupted = false;

      this.Transition();
    },

    Transition : function()
    {
      if (this.Interrupted) {
        return;
      }

      this.Last = this.Counter - 1;

      if (this.Last < 1) {
        this.Last = 3;
      }

      $('div#tmpSlide-' + this.Last).fadeOut(
        'slow',
        function() {
          $('div#tmpSlideshowControl-' + $$.Slideshow.Last).removeClass('tmpSlideshowControlActive');
          $('div#tmpSlideshowControl-' + $$.Slideshow.Counter).addClass('tmpSlideshowControlActive');
          $('div#tmpSlide-' + $$.Slideshow.Counter).fadeIn('slow');

          $$.Slideshow.Counter++;

          if ($$.Slideshow.Counter > 5) {
            $$.Slideshow.Counter = 1;
          }

          setTimeout('$$.Slideshow.Transition();', 3000);
        }
      );
    }
  }
});
//end slideshow function


// awards slideshow function
$.fn.simplestSlideShow = function(settings){
	var config = {
		'timeOut': 2000,
		'speed': 'normal'
	};
	if (settings) $.extend(config, settings);
		this.each(function(){
			var $elem = $(this);
	    	$elem.children(':gt(0)').hide();
	    	setInterval(function(){
	    	$elem.children().eq(0).fadeOut(config['speed'])
	    	.next().fadeIn(config['speed'])
	    	.end().appendTo($elem);
    	}, config['timeOut']);
	});
    return this;
};
// end awards slideshow function
function getPage() 
{
	var data = 'page=' + encodeURIComponent(document.location.hash);
	$.ajax(
	{
		url: "views/view_loader.php",	
		type: "GET",		
		data: data,
		cache: false,
		success: 
		function (html) 
		{
			
			//prevent hiding divs on DOM ready from 'flashing'
			$('.loading').hide();		
			
			$('#content').html(html);
			$('#body').fadeIn('slow');
			//additional jquery stuff add below. dada			
			//slideshow 5secs
			$$.Slideshow.Ready();
			//end slideshow
			
			//showreel
			$('.vidbox').jqvideobox();
			//end showreel
			//toggle testi
			$('#togglecontrol').click(function(){
	            $('p').toggle();
	        });
			//end toggle testi
			
			//inner clicks - testimonials
			var tabContainers = $('div.tabs > div');
            tabContainers.hide().filter(':first').show();
            $('div.tabs ul.tabNavigation a').click(function () {
                    tabContainers.hide();
                    tabContainers.filter(this.hash).show();
                    $('div.tabs ul.tabNavigation a').removeClass('selected');
                    $(this).addClass('selected');
                    return false;
            }).filter(':first').click();
            //end inner clicks - testimonials
            
            //slideshow - awards
            $(".fadein").simplestSlideShow({'timeOut': 5000, 'speed': 1000});
            //end slideshow - awards
            //lets start it
            //;$.init()
            //slideshow - mainpage
            $(".fadeinMain").simplestSlideShow({'timeOut': 5000, 'speed': 1500});
            //end slideshow - mainpage
            
            //slideshow - mainpage
            $(".fadeinVFX").simplestSlideShow({'timeOut': 3000, 'speed': 2000});
            //end slideshow - mainpage
            
            //show hide projs
            var tabProjs = $('div.projs > div');
            tabProjs.hide().filter(':first').show();
            $('div.projs ul.tabNavigations a').click(function () {
            	tabProjs.hide();
            	tabProjs.filter(this.hash).show();
                    $('div.projs ul.tabNavigations a').removeClass('selected');
                    $(this).addClass('selected');
                    return false;
            }).filter(':first').click();
            //end show hide projs
            
            //showreel lightbox
           // $("a[rel^='prettyPhoto']").prettyPhoto();
            //end showreel lightbox

            //show more qa
            // Get the width of the outermost container div.
            var getWidth = $('#contain').width();

            // Set a global variable to keep track of how far
            // the "shifter" should be moved.
            var setWidth = 0;

            // Subtract the pane width from the amount by which
            // the "shifter" has already been moved.
            // Don't forget to give back the changed setWidth variable!
            $('a.shiftleft').click(function(){
            	setWidth = setWidth - getWidth;
	            $('#shifter').animate({left: setWidth}, 500);
	            return false;
            });
            // Same thing in reverse.
            $('a.shiftright').click(function(){
            	setWidth = setWidth + getWidth;
            	$('#shifter').animate({left: setWidth}, 500);
            	return false;
            });
            
            //
            
            //
            
            //end show more qa
            
            //otv works
//			var tabOTVContainers = $('div.otvworks > div');
//			tabOTVContainers.hide().filter(':first').show();
//            $('div.otvworks ul.tabOTVNavigation a').click(function () {
//            		tabOTVContainers.hide();
//            		tabOTVContainers.filter(this.hash).show();
//                    $('div.otvworks ul.tabOTVNavigation a').removeClass('selected');
//                    $(this).addClass('selected');
//                    return false;
//            }).filter(':first').click();
            //end otv works
            
			//end of additional stuff
		}
		//end of function 
	});
}
//end menu
