var prevExpertiseSlide;
var nextExpertiseSlide;
var expertiseSlideDirection;
var arrSlides
var countExpertiseSlide;
var pageLoadGroup;
var currentSlide; // added by MP

function animateExpertiseBodyHeight(slide){
		$('#contentExpertiseContainer').queue("fx", []);
		var finalHeight;
		finalHeight = $('#contentExpertise').innerHeight();
		if(finalHeight == 0){finalHeight = 503};
		$('#contentExpertiseContainer').animate({'height': finalHeight+'px'}, 600, 'easeOutBack');
		$('#contentExpertiseContainer').queue("fx", function(){$('#contentExpertiseContainer').css({'height':''});});
	}
	
// moves backgrounds by MP
function moveBackgroundsNext(){
		$('#expertiseBg').stop().animate({'backgroundPosition': '-=280px 0'}, 700);  //move back bg
		$('#expertiseBgMid').stop().animate({'backgroundPosition': '-=440px 100px'}, 700); //move front bg	
}
function moveBackgroundsPrev(){
		$('#expertiseBg').stop().animate({'backgroundPosition': '+=280px 0'}, 700);  //move back bg
		$('#expertiseBgMid').stop().animate({'backgroundPosition': '+=440px 100px'}, 700); //move front bg	
}
function moveBackgroundsNone(){
		$('#expertiseBg, #expertiseBgMid').stop().animate({'backgroundPosition': '+=0'}, 0);
}

// move through each slide by MP
function moveToExpertise(slide){
		$('#expertiseAnim').stop().animate({left: '0'}, 750);
}
function moveToDesign(slide){
		$('#expertiseAnim').stop().animate({left: '-808px'}, 750); 
}
function moveToDev(slide){
		$('#expertiseAnim').stop().animate({left: '-1616px'}, 750); 
}
function moveToCurate(slide){
		$('#expertiseAnim').stop().animate({left: '-2424px'}, 750);
}

// set the direction of content animation and call animation
function expertiseAnimateNext(group){
		expertiseSlideDirection = 'next';
		var g=group;
		expertiseAnimate(g);
	}
	
// set the direction of content animation and call animation
function expertiseAnimatePrev(group){
		expertiseSlideDirection = 'prev';
		var g=group;
		expertiseAnimate(g);
	}

function setPrevNextLinks(slide){
		prevExpertiseSlide = slide;
		nextExpertiseSlide = slide;
		if(slide > 1){ prevExpertiseSlide = (--prevExpertiseSlide);  
			if (jQuery.browser.msie) { $('#navPrevBg, #navPrev a, #navPrev').show(); $('#navPrev').stop(true, true).animate({left:'-100px'}, 400); } 
			else { $('#navPrevBg').animate({opacity:1}, 200); $('#navPrev a').show(); $('#navPrev').stop(true, true).animate({opacity:1, left:'-100px'}, 400); } }
		else { 
			if (jQuery.browser.msie) { $('#navPrevBg, #navPrev a, #navPrev').hide(); $('#navPrev').stop(true, true).animate({left:'-135px'}, 400); } 
			else { $('#navPrevBg').stop(true, true).animate({opacity:0}); $('#navPrev a').hide(); $('#navPrev').stop(true, true).animate({opacity:0, left:'-135px'}); } }
		if(slide < 4) 
			if (jQuery.browser.msie) { $('#navNextBg, #navNext a, #navNext').show(); $('#navNext').stop(true, true).animate({left:'770px'}, 400); }
			else { { $('#navNextBg').animate({opacity:1}, 200); $('#navNext a').show(); $('#navNext').stop(true, true).animate({opacity:1, left:'770px'}, 150); } }
		else { if (jQuery.browser.msie) { $('#navNextBg, #navNext a, #navNext').hide(); $('#navNext').stop(true, true).animate({left:'808px'}, 400); }
			else { $('#navNextBg').stop(true, true).animate({opacity:0}); $('#navNext a').hide(); $('#navNext').stop(true, true).animate({opacity:0, left:'808px'}); }}
		if( slide < countExpertiseSlide){nextExpertiseSlide = (++nextExpertiseSlide);}  
		$('#navPrev').unbind('click'); 
		$('#navPrev').bind('click', function(){ expertiseAnimatePrev(prevExpertiseSlide); moveBackgroundsPrev(slide); return false; });
		$('#navNext').unbind('click');
		$('#navNext').bind('click', function() {expertiseAnimateNext(nextExpertiseSlide); moveBackgroundsNext(slide); return false;});
}

// toggles the navigation in and out
function toggleNavT2(slide){
		var finalPosition;
		finalPosition = '808px';
		finalPositionRev = '808px';
		if(slide != '1'){
			if($('#expertiseNavT2Blind').css('left')!='0px'){$('#expertiseNavT2Blind').css({'left':finalPosition});}
			$('#expertiseNavT2Blind').animate({left: '0px'}, 650, 'swing');
			}
		else{
				if($('#expertiseNavT2Blind').css('left') != '808px' && $('#expertiseNavT2Blind').css('left') != '-808px'){
					$('#expertiseNavT2Blind').animate({left: finalPositionRev}, 650, 'swing');}
			}
	}

// expertise slide animation
function expertiseAnimate(slide){
		var div = '#expertiseSlide'+slide;
		var divLink = '#expertiseLink'+slide;
		toggleNavT2(slide);
		setPrevNextLinks(slide);
		$(div).queue("fx", []);
		$('#expertiseSlide'+nextExpertiseSlide).queue("fx", []);
		$('#expertiseSlide'+prevExpertiseSlide).queue("fx", []);

		// moves to individual slides by MP
		$('.expertiseLink2, #expertiseLink2').click(function() { moveToDesign();  });
		$('.expertiseLink3, #expertiseLink3').click(function() { moveToDev(); });
		$('.expertiseLink4, #expertiseLink4').click(function() { moveToCurate(); });

		// moves the backgrounds and next/prev depending on what slide is current by MP		
		if(div == '#expertiseSlide1'){
			$('.expertiseLink2, .expertiseLink3, .expertiseLink4').click(function() { moveBackgroundsNext(); }); 
			$('#navNext a').click(function() { moveToDesign(); });
		}
		else if(div == '#expertiseSlide2'){
			$('#expertiseLink3, #expertiseLink4').click(function() { moveBackgroundsNext(); });	  
			$('#navNext a').click(function() { moveToDev(); }); 
			$('#navPrev a').click(function() { moveToExpertise(); });
		}
		else if(div == '#expertiseSlide3'){
			$('#expertiseLink4').click(function() { moveBackgroundsNext() });
			$('#expertiseLink2').click(function() { moveBackgroundsPrev() });  
			$('#navNext a').click(function() { moveToCurate(); });
			$('#navPrev a').click(function() { moveToDesign(); });
		}
		else if(div == '#expertiseSlide4'){
			$('#expertiseLink2, #expertiseLink3').click(function() { moveBackgroundsPrev() }); 
			$('#navPrev a').click(function() { moveToDev(); });
		}

		// this is used to detect if an animation is currently running and prevent jumping of the page
		$('#contentExpertiseContainer').stop(false, false);
		if($('#contentExpertiseContainer').attr('style').match('height') == null){
				$('#contentExpertiseContainer').css({'height':$('#contentExpertiseContainer').innerHeight()});
			}
		else{
				$('#contentExpertiseContainer').css({'height':$('#contentExpertiseContainer').css('height')});
			}
		$('#contentExpertiseContainer').queue("fx", []);	

		// keep for loop
		jQuery.each(arrSlides, function(i) {												 
				var iGroup = ((i)+1);
				var thisSlide = '#expertiseSlide'+iGroup;
				var thisLink = '#expertiseLink'+iGroup;
				$(thisSlide).queue("fx", []);
				$(thisLink).css({'color':'', 'text-shadow':''});
			});	
		$(divLink).css({'color':'#ffffff', 'text-shadow':'1px 1px 1px #c69139'});
}

// hover for main slide navigation
$(document).ready(function() {
	var clearQueue = true;
	var gotoEnd= true;
	if (jQuery.browser.msie) { // show the hover in ie without fade
		$('div.expertiseSlideHover').hover(function() { 
		$('div.active').hide().stop(clearQueue , gotoEnd);
		$(this).children('div.active').show();
	}, function() { 
		$(this).children('div.active').hide();
	});
	$('a.arrow').hover(function() { 					
		thisHover = $(this).parent().parent().prev().children('div.active')
		$('div.active').hide().stop(clearQueue , gotoEnd);
		thisHover.show();
	}, function() { 
		thisHover.hide();
	});
	}else { // if not ie, fade the hover
		$('div.expertiseSlideHover').hover(function() { 
		$('div.active').hide().stop(clearQueue , gotoEnd);
		$(this).children('div.active').fadeIn(500);
	}, function() { 
		$(this).children('div.active').fadeOut(300);
	});
	$('a.arrow').hover(function() { 
		thisHover = $(this).parent().parent().prev().children('div.active')
		$('div.active').hide().stop(clearQueue , gotoEnd);
		thisHover.fadeIn(500);
	}, function() { 
		thisHover.fadeOut(300);
	}); }
}); 

// Initialize the page
function initExpertise(){
	arrSlides = $('.expertiseSlide');
	countExpertiseSlide = arrSlides.length;
	// set the previous & next animations
	$('#navPrev').bind('mouseover', function(){navMouseAnimate('#navPrev','-90px');});
	$('#navPrev').bind('mouseout', function(){navMouseAnimate('#navPrev','-100px');});
	$('#navNext').bind('mouseover', function(){navMouseAnimate('#navNext','760px');});
	$('#navNext').bind('mouseout', function(){navMouseAnimate('#navNext','770px');});
	
	// Show the first slide
	moveToExpertise()
	expertiseAnimate(pageLoadGroup);
}

//When DOM is ready initialize the page
$(document).ready(function(){initExpertise();});
