///

$(function(){

	///

	var cache = [];

	$.preload = function() {

		var args_len = arguments.length;
		
		for (var i = args_len; i--;) {
		
			var cacheImage = document.createElement('img');
			
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		
		}

	}

	///

	$("#navigation ul li.panel00").hoverIntent({

		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		interval: 0, // number = milliseconds for onMouseOver polling interval    
		over: navigation.show, // function = onMouseOver callback (REQUIRED)    
		timeout: 500, // number = milliseconds delay before onMouseOut    
		out: navigation.hide // function = onMouseOut callback (REQUIRED) 

	});

	$("#navigation a, #panel01 a").click(function(){

		if ($(this).attr("rel") == "") {

			var href = $(this).attr("href");
	
			if (href == "#") return false;
	
			track(href);
	
			var x = -$(href).position().left;
			var y = $(href).position().top;

			//alert(x + " : " + y);

			$("#canvas").animate({
	
				scrollTop: y
	
			},"slow");
	
			$("#panels").animate({
	
				left: x
	
			}, "slow");
	
			return false;

		} else {

			var href = $(this).attr("rel");
			
			if (href == 'facebook') {
				if (confirm(EXIT_MSG)) {
					track(href);
					return true;				
				}
				return false;				
				
			} else {
				track(href);
			}

		}

	});

	///

	$("#panel04 form map area").hover(function(){

		var month = $(this).attr("href").replace("#month-", "");

		$(".wheel img").attr("src", "images/flavorscope-wheel-" + month + "-hover.jpg");

	},function(){

		if ($(".wheel img").hasClass("selected")) {

			var selected = $("#panel04 form select[name=month]").val();

			$(".wheel img").attr("src", "images/flavorscope-wheel-" + selected + "-selected.jpg");

		} else {

			$(".wheel img").attr("src", "images/flavorscope-wheel.png");

		}

	});

	$("#panel04 form map area").click(function(){

		var month = $(this).attr("href").replace("#month-", "");

		$(".wheel img").attr("src", "images/flavorscope-wheel-" + month + "-selected.jpg").addClass("selected");

		$("#panel04 form select[name=month]").val(month);

		return false;

	});

	$("#panel04 form button").click(function(){

		var month = parseInt($("#panel04 form select[name=month]").val());
		var day = parseInt($("#panel04 form select[name=day]").val());

		$.getJSON("flavorscope/horoscope.php?month=" + month, function(data) {

			if (data) {

				$("#panel04 div.data").fadeOut('fast', function(){	
					$(this).css("background-image", "url(images/flavorscope-" + data.flavor + ".jpg)");
					$(this).find("p.horoscope").text(data.horoscope);
					$(this).find("p.facebook a").attr("href", data.share_url).attr("target", "_blank").show();
					$(this).fadeIn('fast');
				});

				track("flavorscope-button");

			}

		});

		return false;

	});

	$("#panel04 div.controls ul li a").hover(function(){

		var flavor = $(this).parent().attr("class");		

		$(this).parent().parent().css("background-image", "url(images/flavorscope-icons-" + flavor + "-hover.jpg)");

	},function(){

		var target = $(this).parent().parent();

		if (target.hasClass("selected")) {

			var selected = target.attr("class").replace("selected ", "");

			target.css("background-image", "url(images/flavorscope-icons-" + selected + "-selected.jpg)");

		} else {

			target.css("background-image", "url(images/flavorscope-icons.png)");

		}

	});

	$("#panel04 div.controls ul li a").click(function(){

		var flavor = $(this).parent().attr("class");

		$(this).parent().parent().removeClass().addClass("selected " + flavor).css("background-image", "url(images/flavorscope-icons-" + flavor + "-selected.jpg)");

		$.getJSON("flavorscope/horoscope.php?flavor=" + flavor, function(data) {

			if (data) {

				$("#panel04 div.data").fadeOut('fast', function(){	
					$(this).css("background-image", "url(images/flavorscope-" + data.flavor + ".jpg)");
					$(this).find("p.horoscope").text(data.horoscope);
					$(this).find("p.facebook a").attr("href", data.share_url).attr("target", "_blank").show();
					$(this).fadeIn('fast');
				});

				track("flavorscope-icon");

			}

		});

		return false;

	});

	$("#panel04 div.data p.facebook a").click(function(){

		track("flavorscope-facebook");

	});

	///

	$("#popups").bgiframe();

	$("#popups .popup .background").append("<div class='image'></div>");
	$("#popups .popup .background").append("<div class='close'><a href='#close'>Close</a></div>");

	$("#popups .popup .close a").click(function(){

		popups.hide();
		
		return false;

	});

	$("#footer p a").click(function(){

		if ($(this).attr("rel") == "") {

			var href = $(this).attr("href").replace("#", "");

			track(href);
				
			popups.show( href );

			return false;

		} else {

			var href = $(this).attr("rel");

		}

	});

	///

	$.preload(

		"images/navigation.png",
		"images/navigation-hover.png",

		"images/flavorscope-wheel-01-hover.jpg",
		"images/flavorscope-wheel-02-hover.jpg",
		"images/flavorscope-wheel-03-hover.jpg",
		"images/flavorscope-wheel-04-hover.jpg",
		"images/flavorscope-wheel-05-hover.jpg",
		"images/flavorscope-wheel-06-hover.jpg",
		"images/flavorscope-wheel-07-hover.jpg",
		"images/flavorscope-wheel-08-hover.jpg",
		"images/flavorscope-wheel-09-hover.jpg",
		"images/flavorscope-wheel-10-hover.jpg",
		"images/flavorscope-wheel-11-hover.jpg",
		"images/flavorscope-wheel-12-hover.jpg",

		"images/flavorscope-wheel-01-selected.jpg",
		"images/flavorscope-wheel-02-selected.jpg",
		"images/flavorscope-wheel-03-selected.jpg",
		"images/flavorscope-wheel-04-selected.jpg",
		"images/flavorscope-wheel-05-selected.jpg",
		"images/flavorscope-wheel-06-selected.jpg",
		"images/flavorscope-wheel-07-selected.jpg",
		"images/flavorscope-wheel-08-selected.jpg",
		"images/flavorscope-wheel-09-selected.jpg",
		"images/flavorscope-wheel-10-selected.jpg",
		"images/flavorscope-wheel-11-selected.jpg",
		"images/flavorscope-wheel-12-selected.jpg",

		"images/flavorscope-icons-cherry-hover.jpg",
		"images/flavorscope-icons-grape-hover.jpg",
		"images/flavorscope-icons-orange-hover.jpg",
		"images/flavorscope-icons-peach-hover.jpg",
		"images/flavorscope-icons-pineapple-hover.jpg",
		"images/flavorscope-icons-strawberry-hover.jpg",

		"images/flavorscope-icons-cherry-selected.jpg",
		"images/flavorscope-icons-grape-selected.jpg",
		"images/flavorscope-icons-orange-selected.jpg",
		"images/flavorscope-icons-peach-selected.jpg",
		"images/flavorscope-icons-pineapple-selected.jpg",
		"images/flavorscope-icons-strawberry-selected.jpg"

	);

	///	

});

///

navigation = {}

navigation.hide = function() {

	$("#navigation .background").removeClass("hover");

	$("#navigation ul li.panel00 ul").hide();

}

navigation.show = function() {

	$("#navigation .background").addClass("hover");

	$("#navigation ul li.panel00 ul").show();

}

///

popups = {}

popups.hide = function() {

	$("#popups .popup:visible").fadeOut("normal", function(){

		$("#popups").hide();

	});

}

popups.show = function(href) {

	$("#popups .popup").hide();

	$("#popups").hide();

	$("#popups").css({

		"height": $(window).height(),
		"width": $(window).width()

	});
	
	if (href == 'register') {
		$("#popups ." + href).find('iframe').attr('src', 'user/register.php');
	} else if (href == 'signin') {
		$("#popups ." + href).find('iframe').attr('src', 'user/login.php');
	}

	$("#popups").show();

	$("#popups ." + href).show();

}

///

function track(href) {
	
	/*
	console.log(href);
	return;
	*/
	
	var oThis = null;
	
	switch (href) {

		/// homepage

		case "facebook" :
			s=s_gi(s_account);
			linkName="CrushSoda - Join the Facebook Fan Page";
			s.tl(this,"o",linkName);
			break;

		/// products

		case "#panel02" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Cherry"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Cherry";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel03" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Diet Orange"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Diet Orange";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel05" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Orange"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Orange";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel06" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Strawberry"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Strawberry";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel07" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Grape"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Grape";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel09" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Pineapple"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Pineapple";
			s.events="event12,prodView";
			void(s.t());
			break;

		case "#panel11" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="products";
			s.prop28=s.prop7=s.eVar7="Peach"; 
			s.pageName=s.eVar12= s.channel + ":" + s.prop28 + ": - Crush Soda";
			s.products = ";Peach";
			s.events="event12,prodView";
			void(s.t());
			break;

		/// home

		case "#panel01" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="home";
			s.prop28=s.prop7=s.eVar7=""; 
			s.pageName=s.eVar12= s.channel + ": - Crush Soda";
			s.products="";
			s.events="event12";
			void(s.t());
			break;

		/// flavorscope

		case "#panel04" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="new at crush";
			s.prop28=s.prop7=s.eVar7="";
			s.pageName=s.eVar12= s.channel + ": - Crush Soda";
			s.products=";";
			s.events="event12";
			void(s.t());
			break;

		case "flavorscope-button" :
			s=s_gi(s_account);
			linkName="CrushSoda - Flavorscope - Go Button";
			s.tl(this,"o",linkName);
			break;

		case "flavorscope-icon" :
			s=s_gi(s_account);
			linkName="CrushSoda - Flavorscope - Fruit Button";
			s.tl(this,"o",linkName);
			break;

		case "flavorscope-facebook" :
			s=s_gi(s_account);
			linkName="CrushSoda - Flavorscope - Facebook Link";
			s.tl(this,"o",linkName);
			break;

		/// about

		case "#panel08" :
			s.prop5=s.prop9=s.eVar9="Crush Soda";
			s.prop8=s.eVar8="South West";
			s.prop10=s.eVar10="CSDs";
			s.prop11=s.eVar14="NonFlash";
			s.channel=s.eVar13="all about crush";
			s.prop28=s.prop7=s.eVar7=""; 
			s.pageName=s.eVar12= s.channel + ": - Crush Soda";
			s.products="";
			s.events="event12";
			void(s.t());
			break;

		/// footer

		case "register" :
			/*
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Join";
			s.tl(this,"o",linkName);		
			*/
			break;

		case "company" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Company Info";
			s.tl(this,"o",linkName);		
			break;

		case "faqs" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - FAQ";
			s.tl(this,"o",linkName);		
			break;
			
		case "privacy" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Privacy Policy";
			s.tl(this,"o",linkName);	
			break;

		case "terms" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Terms of Use";
			s.tl(this,"o",linkName);
			break;

		case "accessibility" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Accessibility Statement";
			s.tl(this,"o",linkName);	
			break;

		case "contact" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Contact Us";
			s.tl(this,"o",linkName);
			break;

		case "canada" :
			s=s_gi(s_account);
			linkName="CrushSoda Footer - Canadian Website";
			s.tl(this,"o",linkName);
			break;

		/// default

		default :
			s=s_gi(s_account);
			s=s_gi(s_account);
			s.tl(oThis,'o',href);
			break;

		///

	}

}

var	EXIT_MSG 	= " You are now leaving CrushSoda.com for a website operated \n by a third party. We do not control, recommend or endorse and \n are not responsible for these sites or their content, products, \n services or privacy policies. Downloading material from certain \n sites may risk infringing intellectual property rights or \n introducing viruses into your system. We recommend that you read \n the privacy policies and terms of these other sites. The \n requested website will open in a new browser window. \n\n Would you like to continue? \n ";

