$(document).ready(function(){
	
	
	var flashvars = {};
	var params = {wmode:"transparent", json_url:"flash/json/video_variables"};
	var attributes = {};
	swfobject.embedSWF("/flash/video.swf", "video", "543", "324", "9.0.0", "/flash/expressInstall.swf", flashvars, params, attributes);
 
	// Showreel slide's and arrow change
	if(!$('body').hasClass('home')) {
		$('#video').fadeOut('fast', function() {
			$('.flashvideo').hide();
			$('.flashvideo').toggleClass('down');
		});
		
		$('#showreel-link').click(
			function() {
				if (!$('.flashvideo').hasClass('down')) {
					$('.flashvideo object').fadeOut('fast', function() {
						$('.flashvideo').slideToggle("fast");
						$('.flashvideo').toggleClass('down');
						$('li#showreel-nav').toggleClass('menu-down');
					});
				} else {
					$('.flashvideo').slideDown("fast", function() {
						$('.flashvideo object').fadeIn("slow");
						$('.flashvideo').toggleClass('down');
						$('li#showreel-nav').toggleClass('menu-down');
					});
				}

			return false;
			}
		);
	}
	
// Home page settings for showreel

		$(function() {
		  if ($('body').hasClass('home')) { 
			$('#flashvideo').show();
			$('#flashvideo').toggleClass('down');
			$('#showreel-nav').css('background-image', 'none');
			$('a#showreel-link').css('background-position', '-280px -35px' );
			$('a#showreel-link').css('cursor', 'default' );
			}
		});



// Clients Fading Images
if($("#slideshow")) {
	setInterval(
	function() {

		var $active = $('#slideshow li.active');

		if ( $active.length == 0 ) $active = $('#slideshow li:last');

		var $next =  $active.next().length ? $active.next() : $('#slideshow li:first');

		$active.addClass('last-active');

		$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() { $active.removeClass('active last-active'); });

	}	
	, 5000 );
}

// Bubble pops for team page 
	$(function () {
	  var is_msie = $.browser.msie;
	  if($.browser.mozilla && $.browser.version.substr(0,3) == "1.8" && navigator.userAgent.indexOf('Mac') != -1) {
		var is_ff_mac = true;
	  }
	  if(is_msie  || is_ff_mac ) {
			$('.bubbleInfo').each(function () {
				
				$('body.home .popup').css({
		          background: "url('/images/home-bubble-bg.png') no-repeat",
				  position: "absolute",
				  top: "-100px",
			      left: "-50px",
		          width: "249px",
				  height: "156px",
				  padding: "20px",
				  display: "none"
		        })
		
				$('body.home .popup').css("text-indent","0em");

		
				$('body.team .popup').css({
		          background: "url('/images/team-bubble-bg.png') no-repeat",
				  position: "absolute",
				  top: "-202px",
			      left: "-249px",
		          width: "279px",
				  height: "254px",
				  padding: "20px",
				  display: "none"
		        })
		
				$('.trigger').css({
		          display: "block",
		          width: "158px",
				  height: "114px"
		        })
		
				$('#the-team .blank').css({
		          display: 'block',
				  width: '158px',
				  height: '114px'
		        })
		
				$(this).mouseover(
					function() {
						$('.popup', $(this)).css("display", "block");
					}
				);
				$(this).mouseout(
					function() {
						$('.popup', $(this)).css("display", "none");
					}
				);
			});
	  } else {
			
	  $('.bubbleInfo').each(function () {
			// options
		    var distance = 30;
		    var time = 250;
		    var hideDelay = 500;

		    var hideDelayTimer = null;

		    // tracker
		    var beingShown = false;
		    var shown = false;

		    var trigger = $('.trigger', this);
		    var popup = $('.popup', this).css('opacity', 0);	
			popup.css('position', 'absolute');
		
			$('.trigger').css({
	          display: "block",
	          width: "158px",
			  height: "114px"
	        })


			$('body.home .trigger').css({
	          display: "block",
	          width: "162px",
			  height: "119px"
	        })
			
			$('body.home .popup').css({
	          background: "url('/images/home-bubble-bg.png') no-repeat",
	          width: "249px",
			  height: "156px",
			  padding: "20px"
	        })
			
			$('body.home .popup').css("text-indent","0em");

			$('#the-team .blank').css({
	          display: 'block',
			  width: '158px',
			  height: '114px'
	        })
		
			//set variables for alterations between home page here
			var top;
			var left;
			if($('body').hasClass('home')) {
				top = -100;
				left = -50;
			} else {
				top = -200;
				left = -230;
			}
		
		    // set the mouseover and mouseout on both element
		    $([trigger.get(0), popup.get(0)]).mouseover(function () {
			  popup.addClass('current');
		      // stops the hide event if we move from the trigger to the popup element
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);

		      // don't trigger the animation again if we're being shown, or already visible
		      if (beingShown || shown) {
		        return;
		      } else {
		        beingShown = true;
		        // reset position of popup box
		        popup.css({
		          top: top,
		          left: left,
		          display: 'block' // brings the popup back in to view
		        });
				
		        // (we're using chaining on the popup) now animate it's opacity and position
		        popup.animate({
		          top: '-=' + distance + 'px',
		          opacity: 1
		        }, time, 'swing', function() {
		          // once the animation is complete, set the tracker variables
		          beingShown = false;
		          shown = true;
		        });
		      }
		    }).mouseout(function () {
			  popup.removeClass('current');
		      // reset the timer if we get fired again - avoids double animations
		      if (hideDelayTimer) clearTimeout(hideDelayTimer);

		      // store the timer so that it can be cleared in the mouseover if required
		      hideDelayTimer = setTimeout(function () {
		        hideDelayTimer = null;
				// once the animate is complete, set the tracker variables
		          shown = false;
		          // hide the popup entirely after the effect (opacity alone doesn't do the job)
		          popup.css('display', 'none');
		
		        popup.animate({
		          top: '-=' + distance + 'px',
		          opacity: 0
		        }, time, 'swing', function () {
		          // once the animate is complete, set the tracker variables
		          shown = false;
		          // hide the popup entirely after the effect (opacity alone doesn't do the job)
		          popup.css('display', 'none');
		        });
		      }, hideDelay);
		    });
			
		  });
		}
	});


});
