/*
*	GLOBAL JS CODE HERE
*/
$(function(){
		   
	/*
	*	INKOLOGY PRELOADER
	*/
	$oInkologyText = $('#topContainer .largeText,#topContainer .smallText');
	$oInkologyText.hide();
	$('<img />')
    .attr('src', '/images/inkology/inkology-main.jpg')
    .load(function(){
        $('#inkologyImage').html( $(this) );
		$oInkologyText.fadeIn();
        // Your other custom code
    });
	
	
	
	
	
	
	/*
	*	INK INNOVATION
	*/
		//Objects
		$oContainer = $('#topContainer');
		$oSlider = $('#InnovationSlider');
		$oSlides = $oSlider.find('li');
		$sSlideDistance = $oSlides.width();
		$iNumberOfSlides = $oSlides.length; // The -1 is so you dont slide of the page
		$iClicks = 1;

		//	Sets Width of The Slider Wrapper
		$oSlider.width(($iNumberOfSlides * $sSlideDistance)+100);
		
		//Arrow Slider Click
		$oContainer.find('.arrow').click(function(){
												  
			//	Direction
			$sDirection = $(this).attr("id");
			switch($sDirection){
				case "left":
					$sMovement = "+";
					$iClicks = ($iClicks>1)? $iClicks -1 : 1;
					if($iClicks == 1)$(this).hide();
					if($iClicks < $iNumberOfSlides)$oContainer.find('#right').fadeIn();
				break;
				
				default:
				case "right":
					$sMovement = "-";
					$iClicks = ($iClicks<$iNumberOfSlides)? $iClicks +1: $iNumberOfSlides;
					if($iClicks == $iNumberOfSlides)$(this).hide();
					if($iClicks > 0)$oContainer.find('#left').fadeIn();	
				break;
				
			}

			//	Move Slides
			$oSlider.animate({left: $sMovement+'='+$sSlideDistance}, 700, "easeOutExpo");
		});
		
		
		
		
		
		
		
		
		/*
        *    Meet Our Team Scroller
        */

			
			// Variables
			//Objects
		$oTeamContainer = $('#teamWrapper');
		$oTeamSlider = $('#teamMembers');
		$oTeamSlides = $oTeamSlider.find('li');
		$sTeamSlideDistance = $oTeamContainer.width(); 
		$iTeamNumberOfSlides = $oTeamSlides.length; // The -1 is so you dont slide of the page
		$iTeamClicks = 1;


		//Arrow Slider Click
		$('.meetTheTeamTopContent .bigArrow').click(function(){
												  
			//	Direction
			$sDirection = $(this).attr("id");
			
			
			switch($sDirection){
				case "left":
					$sMovement = "+";
					$iTeamClicks = ($iTeamClicks>1)? $iTeamClicks -1 : 1;
					
					if($iTeamClicks == 1)$(this).hide();
					if($iTeamClicks < $iTeamNumberOfSlides)$('.meetTheTeamTopContent #right').fadeIn();
				break;
				
				default:
				case "right":
					$sMovement = "-";
					$iTeamClicks = ($iTeamClicks<$iTeamNumberOfSlides)? $iTeamClicks +1: $iTeamNumberOfSlides;

					if($iTeamClicks == $iTeamNumberOfSlides)$(this).hide();
					if($iTeamClicks > 0)$('.meetTheTeamTopContent #left').fadeIn();	
				break;
				
			}

			//	Move Slides
			$oTeamSlider.animate({left: $sMovement+'='+$sTeamSlideDistance}, 800, "easeOutExpo");
		});




		/*
        *    Products Scroller
        */
		//	Profit Share Slider
	
		$('#bottleSlider').cycle({ 
			fx:     'scrollHorz', 
			speed:  'normal', 
			timeout: 0, 
			next:   '.productsTopContent #right', 
			prev:   '.productsTopContent #left' 
		});


		
		

			$(".productBox").colorbox({
				iframe:true,
				innerWidth: 650,
				innerHeight: 470,
				title : true,
				scrolling : false,
				onClosed:function(){ 
					
					//console.log("closed");
					//$oProducts.find("li").css("bottom","0px");
				} 
			}); 
			//	DOWN ARROW FOR HOVER
			
			$('#bottleSlider .bottle').hoverIntent(productOver,productOut);
			
			//HOver Intent in/out
			function productOver(){productBottleHover(this);}
			function productOut(){productBottleHover(this);}
			function productBottleHover($oThis){
					$($oThis).find(".glow").fadeToggle("slow", "linear");
			}
	
			
			
			/*
			*	SEARCH MENU DROPDOWN
			*/
			$oProductForm = $("#productsForm");
			$oProductButton = $("#productsContainer .toggleArea");
			
			$oProductButton.click(function(){
				$oProductForm.slideToggle(500,"easeOutExpo");		   
				$oProductButton.find(".arrow").toggleClass("up");
				
				
				$oButton = $oProductButton.find(".button");

				if($oButton.html() == "SEARCH")
				$oProductButton.find(".button").html('CLOSE');
				else
				$oProductButton.find(".button").html('SEARCH');

			});
			

	
			
			
			
			/*
			*	ASK AN INKOLOGIST QUESTION BUTTON
			*/
			$oQuestionButton = $(".qAndABlock .toggleButton");
			$oQuestionButton.click(function(){
				$(this).find(".arrow").toggleClass('up')
				$(this).parent().find(".answer").slideToggle(700);					  
			});


			
			
			/*
			*	MAP HOVER
			*/
			$('#mapWrapper .buttons a').hoverIntent(mapOver,mapOut);
			$oMapImagesWrapper = $('#mapWrapper .images');
			$oMapImages = $('#mapWrapper .images img');
			$oMapTextWrapper = $('#topContainer.contactUsTopContent #text');
			$oMapLocations = $('#topContainer.contactUsTopContent #text .location');
			
			//HOver Intent in/out
			function mapOver(){contactPage(this,true);}
			function mapOut(){contactPage(this,false);}
			
		
			function contactPage($oThis,$bHover){
					if($bHover){
					$oMapImages.fadeOut();
					$oMapLocations.fadeOut();
					$sLocation = $($oThis).attr('class');
					$oMapTextWrapper.find("."+$sLocation).fadeIn();
					$oMapImagesWrapper.find("."+$sLocation).fadeIn();
					}
			}
			
			
	
});

