$(document).ready(function(){
	$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
		$(".slideDiv").hide();
		var mainDivs = jQuery(".mainDiv");
		for (var loopCounter = 0; loopCounter < mainDivs.length; loopCounter++){
			setChildrenDivs(mainDivs[loopCounter]);
		}


		$(".our-work-button").click(function(){
			
			if($(this).hasClass('button-on')){
				showAll=true;
			}else{
				showAll=false;
			}
			
			$(".our-work-button").removeClass('button-on');
			
			if(showAll){
				$(".our-work-thumbs").removeClass('thumbs-on');
				$("#thumbs-all").addClass('thumbs-on');
				$("#slide-show-all").anythingSlider(1);	
				$("#thumbs-all .anythingSlider").addClass('activeSlider');

			}else{
				$(this).addClass('button-on');
				medium=$(this).attr('title').toLowerCase();
				$("#slide-show-"+medium).anythingSlider(1);	
				$(".our-work-thumbs").removeClass('thumbs-on');
				$("#thumbs-"+medium).addClass('thumbs-on');
				$("#thumbs-"+medium+" .anythingSlider").addClass('activeSlider');
			}
		});
		
		$('#slide-show-all').anythingSlider({
			width               : 800,   // if resizeContent is false, this is the default width if panel size is not defined
			height              : 300,   // if resizeContent is false, this is the default height if panel size is not defined
			resizeContents      : true, // If true, solitary images/objects in the panel will expand to fit the viewport
			startStopped        : true,  // If autoPlay is on, this can force it to start stopped
			hashTags            : false
		});		
		
		$('#slide-show-print').anythingSlider({
			width               : 800,   // if resizeContent is false, this is the default width if panel size is not defined
			height              : 300,   // if resizeContent is false, this is the default height if panel size is not defined
			resizeContents      : true, // If true, solitary images/objects in the panel will expand to fit the viewport
			startStopped        : true,  // If autoPlay is on, this can force it to start stopped
			hashTags            : false
		});		
		
		$('#slide-show-television').anythingSlider({
			width               : 800,   // if resizeContent is false, this is the default width if panel size is not defined
			height              : 300,   // if resizeContent is false, this is the default height if panel size is not defined
			resizeContents      : true, // If true, solitary images/objects in the panel will expand to fit the viewport
			startStopped        : true,  // If autoPlay is on, this can force it to start stopped
			hashTags            : false
		});
		
		
		$(".thumbnail-image-television").click(function(){
			fileName=$(this).attr('id');
			
			if (fileName === "tv-adcouncil-bird") {
				//alert('Bird');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Ad Council:Bird']);	
			}
			if (fileName === "tv-adcouncil-lunch") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Ad Council:Lunch']);	
			}
			if (fileName === "tv-bmw-changes") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'BMW:DieselSB']);	
			}
			if (fileName === "tv-bmw-overprotective") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'BMW:DTAD Ad']);	
			}
			if (fileName === "tv-homegoods-momcave") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'HG:Mom Cave']);	
			}
			if (fileName === "tv-homegoods-gifting") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'HG:Holiday']);	
			}
			if (fileName === "tv-sns-penguin") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'SnS:Penguins']);	
			}
			if (fileName === "tv-tecate-medias") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Tecate:Light Beer']);	
			}
			if (fileName === "tv-tecate-papas") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Tecate:Parents']);	
			}
			if (fileName === "tv-vanguard-drama") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Vanguard:Drama']);	
			}
			if (fileName === "tv-vanguard-client") {
				//alert('Lunch');
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Vanguard:Retire']);	
			}
			
			$('#modal-window').load('our-work-modals/'+fileName+'.php');

			$('#modal-window').modal({
				containerCss:{
					backgroundColor:"#fff",
					borderColor:"#fff",
					height:'auto',
					padding:0,
					width: '768',
					height: '432px'
				},
				overlayClose:true
			});
		});
		
		$(".thumbnail-image-digital").click(function(){
			_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Digital Showcase']);
			fileName=$(this).attr('id');
			$('#modal-window').load('our-work-modals/'+fileName+'.php');
			$('#modal-window').modal({
				containerCss:{
					backgroundColor:"#fff",
					borderColor:"#fff",
					height:'auto',
					padding:0,
					width: '768',
					height: '432px'
				},
				overlayClose:true
			});
		});
		
		$(".thumbnail-image-print").click(function(){
			$("body").css("cursor", "progress");
			fileName=$(this).attr('id');
			if(fileName=='print-bmw-deer' || fileName=='print-bmw-child'){
				
				if (fileName === "print-bmw-deer") {
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'BMW:Deer']);
				}
				if (fileName === "print-bmw-child") {
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'BMW:Child']);
				}
				
				thisHeight='694px';
				thisWidth='460px';
			}else if(fileName=='print-netjets-1' || fileName=='print-netjets-2'){
				
				if (fileName === "print-netjets-1") {
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'NetJets:First']);
				}
				if (fileName === "print-netjets-2") {
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'NetJets:Pilots']);
				}
				
				thisHeight='599px';
				thisWidth='460px';				
			}else if(fileName=='print-frieda-frizz'){
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Frieda:Frizz']);
				thisHeight='632px';
				thisWidth='460px';	
			}else if(fileName=='print-frieda-luxurious'){
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Frieda:Volume']);
				thisHeight='560px';
				thisWidth='460px';	
			}else if(fileName=='print-frieda-blonde'){
				_gaq.push(['_trackEvent', 'Our Work', 'Click', 'Frieda:Blonde']);
				thisHeight='624px';
				thisWidth='460px';					
			}else{
				thisHeight='690px';
				thisWidth='460px';				
			}
			$.ajax({
				  url: 'our-work-modals/'+fileName+'.php',
				  beforeSend: function() {
					 
				  },
				  success: function(data) {
					  $('#modal-window').html(data);
					  $('#modal-window').modal({
						  position: ["16px",],
							containerCss:{
								backgroundColor:"#fff",
								borderColor:"#fff",
								padding:0,
								width: thisWidth,
								height: thisHeight
						},
							overlayClose:true,
							onClose: function (dialog) {
								$.modal.close();
								$('#modal-window').html("<br>");
								$('#modal-window').css('display', 'none');
							}
					  });
				  },
				  complete: function(){
					$("body").css("cursor", "auto");
					
				  }
				});
		});
		
		$("#thumbs-all .anythingSlider").addClass('activeSlider');	
});




function setChildrenDivs(mainDiv){
	var mainChildrenStableDiv = jQuery(mainDiv).children(".showDiv");
	var mainChildrenSlide = jQuery(mainDiv).children(".slideDiv");
        
	for (var loopCounter = 0; loopCounter < mainChildrenStableDiv.length; loopCounter++) {
		var currentStableDiv = jQuery(mainChildrenStableDiv[loopCounter]);
		var currentSlideDiv = jQuery(mainChildrenSlide[loopCounter]); 
		var containerPosition = jQuery(currentStableDiv).position();
		$(currentSlideDiv).css({ left: containerPosition.left + currentStableDiv.width() }); 
		setHover(currentSlideDiv, currentStableDiv);
	}
}
        
function setHover(currentSlideDiv, currentStableDiv){
	currentStableDiv.hover(function(){
	if(currentSlideDiv.is(":hidden")){
		if(currentSlideDiv.is(".slideLeft")){
			currentSlideDiv.show("slide", { direction: "left" }, 400);
		}else{
             if(currentSlideDiv.is(".employeeSpecial")){
            	 currentSlideDiv.css('left', '370px');
            	 currentSlideDiv.show("slide", { direction: "right" }, 400);
             }else{
            	 currentSlideDiv.css('left', '502px');
            	 currentSlideDiv.show("slide", { direction: "right" }, 400);
             }
		}
	}
	},
	function(){
		if (currentSlideDiv.is(":visible")){
			currentSlideDiv.hide("slide", { direction: "left" }, 50);
		}
	}
);
};



function formatText(index, panel) {
 return index + "";
};

function showShareLike1() {	
	  $('.popUp1').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox1();
	});
	$('.popUp2').hide();
	$('.popUp3').hide();
	$('.popUp4').hide();
	$('.popUp5').hide();
	$('.popUp6').hide();
	$('.popUp7').hide();

}


function hideBox1() {
	$(".popUp1").mouseleave(function () {                         
		$('.popUp1').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}    











function showShareLike2() {	
	  $('.popUp2').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox2();
	});
	$('.popUp1').hide();
	$('.popUp3').hide();
	$('.popUp4').hide();
	$('.popUp5').hide();
	$('.popUp6').hide();
	$('.popUp7').hide();
}


function hideBox2() {
	$(".popUp2").mouseleave(function () {                         
		$('.popUp2').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}    





function showShareLike3() {	
	  $('.popUp3').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox3();
	});
	$('.popUp1').hide();
	$('.popUp2').hide();
	$('.popUp4').hide();
	$('.popUp5').hide();
	$('.popUp6').hide();
	$('.popUp7').hide();
}


function hideBox3() {
	$(".popUp3").mouseleave(function () {                         
		$('.popUp3').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}   



function showShareLike4() {	
	  $('.popUp4').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox4();
	});
	$('.popUp1').hide();
	$('.popUp2').hide();
	$('.popUp3').hide();
	$('.popUp5').hide();
	$('.popUp6').hide();
	$('.popUp7').hide();
}


function hideBox4() {
	$(".popUp4").mouseleave(function () {                         
		$('.popUp4').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}   



function showShareLike5() {	
	  $('.popUp5').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox5();
	});
	$('.popUp1').hide();
	$('.popUp2').hide();
	$('.popUp3').hide();
	$('.popUp4').hide();
	$('.popUp6').hide();
	$('.popUp7').hide();
}


function hideBox5() {
	$(".popUp5").mouseleave(function () {                         
		$('.popUp5').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}   



function showShareLike6() {	
	  $('.popUp6').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox6();
	});
	$('.popUp1').hide();
	$('.popUp2').hide();
	$('.popUp3').hide();
	$('.popUp4').hide();
	$('.popUp5').hide();
	$('.popUp7').hide();
}


function hideBox6() {
	$(".popUp6").mouseleave(function () {                         
		$('.popUp6').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}   

function showShareLike7() {	
	  $('.popUp7').animate({
		width: ['show', 'swing'],
		height: ['show', 'swing'],
		opacity: 'show'
	  }, 10, 'linear', function() {
		  hideBox7();
	});
	$('.popUp1').hide();
	$('.popUp2').hide();
	$('.popUp3').hide();
	$('.popUp4').hide();
	$('.popUp5').hide();
	$('.popUp6').hide();
}


function hideBox7() {
	$(".popUp7").mouseleave(function () {                         
		$('.popUp7').animate({
		width: ['hide', 'swing'],
		height: ['hide', 'swing'],
		opacity: 'hide'
	  }, 10, 'linear', function() {
		 
	});
         
	});
}     

function currentYPosition() {
	if (self.pageYOffset)
		 return self.pageYOffset;
	if (document.documentElement && document.documentElement.scrollTop)
		return document.documentElement.scrollTop;
	if (document.body.scrollTop)
		 return document.body.scrollTop;
	return 0;
}
function elmYPosition(eID) {
	var elm  = document.getElementById(eID);
	var y    = elm.offsetTop;
	var node = elm;
	while (node.offsetParent && node.offsetParent != document.body) {
		node = node.offsetParent;
		y   += node.offsetTop;
	} return y;
}
function smoothScroll(eID) {
	var startY   = currentYPosition();
	var stopY    = elmYPosition(eID);
	var distance = stopY > startY ? stopY - startY : startY - stopY;
	if (distance < 100) {
		scrollTo(0, stopY); return;
	}
	var speed = Math.round(distance / 100);
	if (speed >= 20) speed = 20;
	var step  = Math.round(distance / 25);
	var leapY = stopY > startY ? startY + step : startY - step;
	var timer = 0;
	if (stopY > startY) {
		for ( var i=startY; i<stopY; i+=step ) {
			setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
			leapY += step; if (leapY > stopY) leapY = stopY; timer++;
		} return;
	}
	for ( var i=startY; i>stopY; i-=step ) {
		setTimeout("window.scrollTo(0, "+leapY+")", timer * speed);
		leapY -= step; if (leapY < stopY) leapY = stopY; timer++;
	}
}
