// www.balanceofnature.com JavaScript Document

var po			= 4;
var ap 			= -1;
var bf			= -1;
var di			= 0;

// Picture array list
var PicList = new Array();
PicList[0] = DATA.SITE+"assets/graphic/cimg/bg/leaf.png";
PicList[1] = DATA.SITE+"assets/graphic/cimg/naturaltext.png";
PicList[2] = DATA.SITE+"assets/graphic/cimg/oma.png"; 
PicList[3] = DATA.SITE+"assets/graphic/cimg/menu_bar/ddloginbon.jpg"; 
PicList[4] = DATA.SITE+"assets/graphic/cimg/menu_bar/ddloginton.jpg"; 
PicList[5] = DATA.SITE+"assets/graphic/cimg/naturalbottles.png"; 
PicList[6] = DATA.SITE+"assets/graphic/p_services/tri-cal/trical.png";
PicList[7] = DATA.SITE+"assets/graphic/p_services/fiber-spice/fiber-spice.png";



$(function(){
	var PicLeaf	= new Image;
	PicLeaf.onload = function()
	{
		$('#leafs').css('background-image' ,'url('+DATA.SITE+'assets/graphic/cimg/bg/leaf.png)');
	}
	PicLeaf.src	= DATA.SITE+"assets/graphic/cimg/bg/leaf.png";
	var PicWHSP	= new Image;
	PicWHSP.onload = function()
	{
		Finish();
	}
	PicWHSP.src	= DATA.SITE+"assets/graphic/cimg/whshp.png";
	
	Preload();
	
	// Dropdown Sign In Box
	$('#signin').mouseenter(function(){
		$("#sign_ext").slideDown("slow");
	});
	$('#dropdown').mouseleave(function(){
		$("#sign_ext").stop(true, true).slideUp("slow");
	});
	
	// Button Left Right Fadein
	$('#bt_left').mouseenter(function(){
		$('#bt_left_hover').fadeIn("fast");
	});
	$('#bt_left_hover').mouseleave(function(){
		$('#bt_left_hover').fadeOut("slow");
	});
	$('#bt_left_hover, #bt_left').click(function(){
		if ((ap-1) < 0)
		{
			bf = ap;
			ap = po-1;
		}
		else
		{
			bf = ap;
			ap--;
		}
		di = 0;
		nextpic();
	});
	$('#bt_right').mouseenter(function(){
		$('#bt_right_hover').fadeIn("fast");
	});
	$('#bt_right_hover').mouseleave(function(){
		$('#bt_right_hover').fadeOut("slow");
	});
	$('#bt_right_hover, #bt_right').click(function(){
		if ((ap+1) >= po)
		{
			bf = ap;
			ap = 0;
		}
		else
		{
			bf = ap;
			ap++;
		}
		di = 1;
		nextpic();
	});
	
	// Login Fadein
	$('#bt_login_pc').mouseenter(function(){
		$('#bt_login_pc').attr('src',DATA.SITE+'assets/graphic/cimg/menu_bar/ddloginton.jpg');
	});
	$('#bt_login_pc').mouseleave(function(){
		$('#bt_login_pc').attr('src',DATA.SITE+'assets/graphic/cimg/menu_bar/ddlogintoff.jpg');
	});
	$('#bt_login_aff').mouseenter(function(){
		$('#bt_login_aff').attr('src',DATA.SITE+'assets/graphic/cimg/menu_bar/ddloginbon.jpg');
	});
	$('#bt_login_aff').mouseleave(function(){
		$('#bt_login_aff').attr('src',DATA.SITE+'assets/graphic/cimg/menu_bar/ddloginboff.jpg');
	});
	
	// Right Box Link
	$('#rightbox').click(function(){
		window.location = DATA.SITE+'testimonials/';
	});
	
	$('.bt_bar_icon').click(function(){
		bf = ap;
		ap = parseInt($(this).attr('alt'));
		if (bf < ap)
		{
			dir = 0;
		}
		else
		{
			dir = 1;
		}
		nextpic();
	});
	
	$('#pcid').blur(function(){
		if ($(this).val() == "")
		{
			$(this).val('Enter Your Promo Code');
			$(this).addClass("promo1");
		}
	});
	$('#pcid').focus(function(){
		if ($(this).val() == "Enter Your Promo Code")
		{
			$(this).val('');
			$(this).removeClass("promo1");
		}
	});
	$("a[rel^='prettyPhoto']").prettyPhoto({
			theme: 'light_rounded', /* pp_default / light_rounded / dark_rounded / light_square / dark_square / facebook */
			social_tools: false
	});
});

function nextpic()
{
	if (bf != ap)
	{
		var time = 1100;
		// getting rid of old pic
		switch (bf)
		{
			case 0:
				if (di == 0) 
				{
					$("#p1").animate({
						"margin-left" : "-=1200px"
					}, 1300)
				}
				else
				{
					$("#p1").animate({
						"margin-left" : "+=1200px"
					}, 1300);
				}
				setTimeout("$(\"#p1\").remove();", 1300);
				break;
			
			case 1:
				$('#p2').animate({
					"margin-top" : "-=412px"
				}, 900);
				$("#p4").animate({
					"margin-top" : "+=288px"
				}, 900);
				$("#p3").fadeOut(600);
				setTimeout("$(\"#p4, #p2, #p3\").remove();", 900);
				time = 900;
				break;
				
			case 2:
				if (di == 0) 
				{
					$("#p5").animate({
						"margin-left" : "-=1200px"
					}, 1300)
				}
				else
				{
					$("#p5").animate({
						"margin-left" : "+=1200px"
					}, 1300);
				}
				setTimeout("$(\"#p5\").remove();", 1300);
				break;
				
			case 3:
				if (di == 0) 
				{
					$("#p6").animate({
						"margin-left" : "-=1200px"
					}, 1300)
				}
				else
				{
					$("#p6").animate({
						"margin-left" : "+=1200px"
					}, 1300);
				}
				setTimeout("$(\"#p6\").remove();", 1300);
				break;
		}
		setTimeout("picin()",time);
		
	}
}

function picin()
{
	// getting the new one
	switch (ap)
	{
		case 0:
			$('#product').html("<img id=\"p1\" class=\"prod\" style=\"margin-top: -629px\" src=\""+DATA.SITE+"assets/graphic/cimg/whshp.png\" alt=\"Whole Health System\" />");
			$("#p1").animate({
				"margin-top" : "+=669px"
			}, 900);
			break;
			
		case 1:
			$('#product').html("<img id=\"p2\" style=\"margin-left: 160px; margin-top: -412px; position: absolute;\" src=\""+DATA.SITE+"assets/graphic/cimg/naturalbottles.png\" alt=\"Natural Bottles\" /><img id=\"p3\" style=\"margin-left: 540px; margin-top: 95px; display: none; position: absolute;\" src=\""+DATA.SITE+"assets/graphic/cimg/naturaltext.png\" alt=\"Naturalish\" /><img id=\"p4\" style=\"left: 50%; margin-left: 50px; margin-top: 498px; position: absolute;\" src=\""+DATA.SITE+"assets/graphic/cimg/oma.png\" alt=\"Grandma\" />");
			$("#p2").animate({
				"margin-top" : "+=412px"
			}, 900);
			$("#p4").delay(700).animate({
				"margin-top" : "-=288px"
			}, 900);
			$("#p3").delay(1000).fadeIn("slow");
			break;
			
		case 2:
			$('#product').html("<img id=\"p5\" class=\"prod\" style=\"margin-top: -629px\" src=\""+DATA.SITE+"assets/graphic/p_services/tri-cal/trical.png\" alt=\"Trical\" />");
			$("#p5").animate({
				"margin-top" : "+=720px"
			}, 900);
			break;
			
		case 3:
			$('#product').html("<img id=\"p6\" class=\"prod\" style=\"margin-top: -629px\" src=\""+DATA.SITE+"assets/graphic/p_services/fiber-spice/fiber-spice.png\" alt=\"Fiber & Spice\" />");
			$("#p6").animate({
				"margin-top" : "+=720px"
			}, 900);
			break;
	}
	$('.bt_bar_icon').each(function(index) {
		$(this).attr('src', DATA.SITE+'assets/graphic/cimg/switch2.png');
	});
	$('#bt_bar_'+ap).attr('src', DATA.SITE+'assets/graphic/cimg/switch1.png');
}

function Preload() 
{
	for (i = 0; i < PicList.length; i++)
	{
		var Pic = new Image();
		Pic.src = PicList[i];
	}
}

function Finish()
{
	bf	= -1;
	ap	= 0;
	$('#loader').fadeOut(300);
	nextpic();
}

setTimeout("asseenontv()",7000);
function asseenontv() {
	if($('#tvlink').is(':visible')) {
		$('#tvlink').fadeOut();
		$('#ontv').attr('src', DATA.SITE+'/assets/graphic/home/promoanimation1.gif');
	} else {
		$('#tvlink').fadeIn();
		$('#ontv').attr('src', DATA.SITE+'/assets/graphic/home/promoanimation2.gif');
	}
	setTimeout("asseenontv()",7000);
}
