
// <![CDATA[
	var videoEndTxt;
	var contactOpen = false;
	
	var ticker_count;
	var ticker_interval;
	var old_ticker = 0;
	var current_ticker = 0;
	
	
	var promo_count;
	var promo_interval;
	var old_promo = 0;
	var current_promo = 0;
	
	var horzHeroScroll_bool = true;
	
	
	function heroPromotion_rotate() {
		
		//console.log(promo_count-1);
		
		if(current_promo == (promo_count - 1)){
			current_promo = 0;
		}else{
			current_promo = current_promo + 1;	
		}
		
		//console.log(current_promo + " = promo");
		//console.log(old_promo + " = old promo");
	
	   $("div#heroPromo a:eq(" + old_promo + ")").fadeOut("normal", function(){
	   		$("div#heroPromo a:eq(" + current_promo + ")").fadeIn("normal");
			old_promo = current_promo;
	  	});
	 }
	
	
	 function ticker_rotate() {
		
		if(current_ticker == (ticker_count - 1)){
			current_ticker = 0;
		}else{
			current_ticker = current_ticker + 1;	
		}
	//	console.log(current_ticker + " = ticker" );
	   $("div#ticker a:eq(" + old_ticker + ")").fadeOut("normal", function() {
		 	$("div#ticker a:eq(" + current_ticker + ")").fadeIn("normal");
			old_ticker = current_ticker;
	   });
	  
	 }

	var contactMoveDown = function(){
		
		$("input.textField").focus(function(){
			
			if(!contactOpen){
				$("#contactArrowDown").click();
			}
			
		});
		
		$("#contactArrowDown").click(function() {
			$("#contactArrowDown").toggle();
			$("#contactBlock").toggleClass("contactHomeSM").toggleClass("contactHomeBG");
			$("#contactBlock").animate({ "height": "461px"}, 500, function(){
				$("#contactArrowUp").toggle();	
				contactOpen = true;				
			});
			$("div#contactFormBottom").css({"display": "block"});
			$("div#contactFormBottom").css({"opacity": "1"});
			
			
			
		});
	}

	var contactMoveUp = function(){
		$("#contactArrowUp").click(function(){
			
			
			
			$("#contactBlock").animate({ "height": "211px" }, 500, function(){
				$("#contactBlock").toggleClass("contactHomeSM").toggleClass("contactHomeBG");
				$("div#contactFormBottom").css({"display": "none"});	
				$("div#contactFormBottom").css({"opacity": "0"});
				$("#contactArrowDown").toggle();
				$("#contactArrowUp").toggle();
				contactOpen = false;	
			});
		});	
	}
	var transitionHeroSectionToHorz = function(toFadeIn){
		$("#heroToggleFlash").hide();
		$("#heroToggle").hide();
		var heroH = $("#heroSpacer").height();
		// console.log(heroH);
		$(".fadeableHero:visible").fadeOut(function(){
			
			//check to see if should animate
			 if(heroH > 250){
				//change background to fit new area
				
				$("#heroSpacer").animate({
					height : "215px"
				}, 1000, function(){
					
					//when complete fadeIn
					$(toFadeIn).fadeIn(1000);

				});
				$("#contactBlock").animate({
					top : "330px"
				}, 1000);
			 }else{
				$(toFadeIn).fadeIn(1000);
			 }
		});
		
	}
	var transitionHeroSectionToVert = function(toFadeIn){
		//fade out
		$("#heroToggleFlash").hide();
		$(".fadeableHero:visible").fadeOut(function(){
			var heroH = $("#heroSpacer").height();
			//check to see if should animate
			if(heroH < 250){
				//change background to fit new area
				$("#heroSpacer").css("background", "url(common/images/heroVideo_BG_big2.jpg) 0 19px no-repeat");
				$("#heroSpacer").animate({
					height : "415px"
				}, 1000, function(){
					
					//when complete fadeIn
					$(toFadeIn).fadeIn(function(){
						$("#heroSpacer").css("background", "none");
						$("#heroToggle").show();
					});

				});
				$("#contactBlock").animate({
					top : "530px"
				}, 1000);
			}else{
				//else fade in
				$("#heroSpacer").css("background", "url(common/images/heroVideo_BG_big2.jpg) 0 19px no-repeat");
				$(toFadeIn).fadeIn(function(){
					$("#heroSpacer").css("background", "none");
					$("#heroToggle").show();
				});
			}
		});
		
	
	}
	
	var transitionHeroSectionToVideo = function(toFadeIn){
		$("#heroToggle").hide();
			
		$(".fadeableHero:visible").fadeOut(function(){
			var heroH = $("#heroSpacer").height();
			// console.log(heroH);
			//check to see if should animate
			if(heroH < 250){
				//change background to fit new area
				$("#heroSpacer").css("background", "url(common/images/heroVideo_BG_big2.jpg) 0 19px no-repeat");
				$("#heroSpacer").animate({
					height : "415px"
				}, 1000, function(){
					
					//when complete fadeIn
					$(toFadeIn).fadeIn(function(){
						$("#heroSpacer").css("background", "none");
						$("#heroToggleFlash").show();
					});

				});
				
				$("#contactBlock").animate({
					top : "530px"
				}, 1000);
			}else{
				//else fade in
				
				$(toFadeIn).fadeIn(function(){
					$("#heroSpacer").css("background", "none");
					$("#heroToggleFlash").show();
				});
			}
		});
		
	}
	var transitionHeroSectionToVideo2 = function(toFadeIn){
					$(toFadeIn).fadeIn(100, function(){
						$("#heroSpacer").css("background", "none");
						$("#heroToggleFlash").show();
					});
	}
    var playHeroVideo = function(url, bool){
	
	  if($("div#heroContainer").length > 0){
		   $("div#heroContainer").remove();
	   };
		$.get(url, function(response){
			$(response).appendTo($("#heroAJAX"));
		});
	
	};
	
	var playHeroVideo2 = function(url){
	
	  if($("div#heroContainer").length > 0){
		   $("div#heroContainer").remove();
	   };
		$.get(url, function(response){
			$(response).appendTo($("#heroAJAX"));
		});
	
	};
	
	var sendToJavaScriptVideoComplete = function(){
		//switch background image -- or switch for image
		$("img#replayVideo").toggle();
		$("a#contactUsToday").toggle();
		$("h2#afterFlashTxt").toggle();
	 	$("#swfobject_target").toggle();	
	}
	
	var loadVideoOnClick = function(){
		
		$(".heroScrollItem a").mouseover(function(){
		//	console.log("Over Video");
		});
		
		
		$(".heroScrollItem a").click(function(){
			//console.log("Click Video");
			loadFromSmallScroll = false;
			var url = $(this).attr("href");
			playHeroVideo(url, true);
			return false;
		});
		
		$(".heroV_ScrollItem a").click(function(){
			loadFromSmallScroll = false;
			var url = $(this).attr("href");
			playHeroVideo(url, true);
			return false;
		});	
	};
	
	
	var heroToggleOnClick = function(){
		
		$("#heroToggle").mouseover(function(){
			$(this).css("cursor", "pointer");
			$(this).attr("src", "common/images/videoToggleBTN_hover.jpg");
		});
		$("#heroToggle").mouseout(function(){
			$(this).css("cursor", "auto");
			$(this).attr("src", "common/images/videoToggleBTN.jpg");	
		});
		
		
		$("#heroToggle").click(function () {
			
		transitionHeroSectionToHorz($("#heroSM"));	
						// 
						// $(this).toggle();	
						// 		  	$("div.hero").toggle();
						// horzHeroScroll_bool = true;
		});
	};
	
	
	var viewAllOnClick = function(){
		
		$("#viewAllVideosLink").mouseover(function(){

			$(this).css("cursor", "pointer");

		});

		$("#viewAllVideosLink").mouseout(function(){
			$(this).css("cursor", "auto");		
		});
		
		
		
		$("#viewAllVideosLink").click(function () {
			
			transitionHeroSectionToVert($("div#heroBG"));
			// $("#heroToggle").toggle();
			// 		$("div.hero").toggle();
			// 		horzHeroScroll_bool = false;
		});
	};
	
	var leftArrowOnClick = function(){
		
		$("img#arrowRight").mouseout(function() { 
			$(this).css("cursor", "auto");
			$(this).attr("src", "common/images/heroArrow_right.jpg");
		});
		$("img#arrowRight").mouseover(function() { 
			$(this).css("cursor", "pointer");
			$(this).attr("src", "common/images/heroArrow_right_hover.jpg");
		});
		
		 $("img#arrowRight").click(function() {
		// 			var getLeftPos =$("div#heroScroll").position();
		// 			var leftPos = getLeftPos.left + 224;
		// 			if(leftPos < 1){	
		// 				$("div#heroScroll").animate({
		// 					"left" : (leftPos + "px")
		// 					}, 500 );
		// 				};
		// 	
		//console.log("left click");
		loadVideoOnClick();
			// if(!movingLG){
			// 				var getLeftPos1 =$("div#heroScroll1").position();
			// 				var leftPos1 = getLeftPos1.left + 224;
			// 				if(leftPos1 < 1){	
			// 					movingLG = true;
			// 					$("div#heroScroll1").animate({
			// 						"left" : (leftPos1 + "px")
			// 						}, 500, function(){
			// 							movingLG = false;
			// 						} );
			// 					};
			// 				var getLeftPos2 =$("div#heroScroll2").position();
			// 				var leftPos2 = getLeftPos2.left + 224;
			// 				if(leftPos2 < -447){	
			// 					$("div#heroScroll2").animate({
			// 						"left" : (leftPos2 + "px")
			// 						}, 500 );
			// 					};
			// 			}
		});
		
	};
	
	var rightArrowOnClick = function(){
		
		$("img#arrowLeft").mouseout(function() { 
			$(this).css("cursor", "auto");
			$(this).attr("src", "common/images/heroArrow_left.jpg");
		});
		$("img#arrowLeft").mouseover(function() {
			$(this).css("cursor", "pointer"); 
			$(this).attr("src", "common/images/heroArrow_left_hover.jpg");
		});
		
		
		$("img#arrowLeft").click(function() { 
				//if($("div#heroScroll").width() > 672){
				// var maxLeft = (-1 * ($("div#heroScroll").width() - 672) - 1) + 224;
				// 				var getLeftPos = $("div#heroScroll").position();
				// 				var leftPos = getLeftPos.left - 224;
				// 				if(maxLeft < leftPos){
				// 					$("div#heroScroll").animate({
				// 						"left" : (leftPos + "px")
				// 						}, 500 );
				// 				};
				//}
				
				//hero1
				//console.log("right click");
				loadVideoOnClick();
				// if(!movingLG){
				// 					if($("div#heroScroll1").width() > 672){
				// 						var maxLeft1 = (-1 * ($("div#heroScroll1").width() - 672) - 1);
				// 						var getLeftPos1 = $("div#heroScroll1").position();
				// 						var leftPos1 = getLeftPos1.left - 224;
				// 						if(maxLeft1 < leftPos1){
				// 							movingLG = true;
				// 							$("div#heroScroll1").animate({
				// 								"left" : (leftPos1 + "px")
				// 								}, 500, function(){
				// 									movingLG = false;
				// 								});
				// 						};
				// 					}
				// 					//hero2
				// 					if($("div#heroScroll2").width() > 672){
				// 						//maxLeft also goes to -448 as zero
				// 					
				// 						var maxLeft2 = (-1 * ($("div#heroScroll2").width() - 672) - 1) - 448;
				// 						var getLeftPos2 = $("div#heroScroll2").position();
				// 						var leftPos2 = getLeftPos2.left - 224;
				// 						if(maxLeft2 < leftPos2){
				// 							$("div#heroScroll2").animate({
				// 								"left" : (leftPos2 + "px")
				// 								}, 500 );
				// 						};
				// 					}
				// 				}
		});
	};
	
	
	var arrowDownMouseOver = function(){
	$("#contactArrowDown").mouseover(function(){
			$(this).css("cursor", "pointer");
			$(this).attr("src", "common/images/contactArrow_hover.jpg");
		});
	};

	var arrowDownMouseOut = function (){
		$("#contactArrowDown").mouseout(function (){
			$(this).css("cursor", "auto");
			$(this).attr("src", "common/images/contactArrow.jpg");
		});
	};

	var arrowUpMouseOver = function(){
		$("#contactArrowUp").mouseover(function(){
			$(this).css("cursor", "pointer");
			$(this).attr("src", "common/images/contactArrow_up_hover.jpg");
		});
	};

	var arrowUpMouseOut = function (){
		$("#contactArrowUp").mouseout(function (){
			$(this).css("cursor", "auto");
			$(this).attr("src", "common/images/contactArrow_up.jpg");
		});
	};
	
	var loadFromSmallScroll = false;
	var movingLG = false;
	
      $(document).ready(function(){
		$("div#contactFormBottom").css({"opacity": "0"});
		$("div#contactFormBottom").css({"display": "none"});
		
		var scrollItemCount  = $("div#heroScroll1 div.heroScrollItem").size();
		
		// $("div#heroScroll").css({"width" : (scrollItemCount*224) + "px"});
		$("div#heroScroll1").css({"width" : (scrollItemCount*224) + "px"});
		$("div#heroScroll2").css({"width" : (scrollItemCount*224) + "px"});	
		
		//console.log($("div#heroScroll1").width());
		
		$("div#heroScroll2").css("left", "-448px");
		
		
		ticker_count = $("div#ticker").children().length;
		//console.log(ticker_count);
		if(ticker_count > 1){
		   $("div#ticker a:eq("+current_ticker+")").fadeIn("normal");
		   ticker_interval = setInterval(ticker_rotate,5000); //time in milliseconds
		   $("div#ticker a").mouseover(function() {
		     clearInterval(ticker_interval);
		   }, function() {
		     ticker_interval = setInterval(ticker_rotate,5000); //time in milliseconds
		   });
		}
		promo_count = $("div#heroPromo").children().length;
		//console.log(promo_count);
		$("div#heroPromo a:eq("+current_promo+")").fadeIn("normal");
		if(promo_count > 1){
		promo_interval = setInterval(heroPromotion_rotate,7000); //time in milliseconds
		$("div#heroPromo a").mouseover(function() {
					clearInterval(promo_interval);
					}, function(){
					promo_interval = setInterval(heroPromotion_rotate,7000); //time in milliseconds	
					});
		}
		
		
		
		loadVideoOnClick();
		heroToggleOnClick();
		viewAllOnClick();
		contactMoveDown();
		contactMoveUp();
		leftArrowOnClick();
		rightArrowOnClick();
		
		arrowUpMouseOver();
		arrowUpMouseOut();

		arrowDownMouseOver();
		arrowDownMouseOut();
		
		
		
		$("div#heroSM").fadeIn(1000);
	
		
      });
// ]]>
