// JavaScript Document

//  v. 1.2_2301
//  


$(document).ready(function(){


$animation =1; // 0 = no animation, 1 start animation 
$debug = 0;

/*  WEBFORM  TOOLS*/


//RESETTING WEBFORM STYLE

$(".qnext").addClass("qnext_disabled");
$("#edit-submit-1").addClass("send_disabled");
if ($("#edit-submitted-what-product-1").val()) $(".qnext").addClass("qnext_enable").removeClass("qnext_disabled");
if (ValidateEmail($("#edit-submitted-what-is-your-e-mail-address-1").val())) $("#edit-submit-1").removeClass("send_disabled").addClass("send_enable") ;

$(".qback").addClass("qback_enable");

$("#edit-submit-1").val("");
$("#edit-submit-1").css({"border":"0", "background-color":"transparent"});

$("#card").data("question",0);  // is the current question
//$(".qnext").addClass("qnext_enable");



$(".qnext").click(function(){
	next_step();
	//bglm(eval($(this).attr("ref")))
})

$("#node-20 #edit-submit-1").click(function(){
	if (ValidateEmail($("#edit-submitted-what-is-your-e-mail-address-1").val())) {
		$("#edit-submit-1").fadeOut(500) ;
	}
	else return false;
	
	//bglm(eval($(this).attr("ref")))
})


$(".qback").click(function(){
	$(".form-submit").hide();
	prev_step();
})

// SUBMISSION FORM DISABLED
$("form").bind("keypress", function(e) {
            if (e.keyCode == 13 || e.keyCode == 9) {
			next_step()
			return false;
	}
	
	
});


/* MENU EFFECT*/


	path = document.URL;	
	
	/* no fade 
	$("#main-menu li").hover(function(){
		if (!$(this).hasClass("menu_sel")) $(this).addClass("menu_over");
	
	}, function(){
		$(this).removeClass("menu_over");
	})	
		
	*/
	
	/* mouse over with fade */	
	
$("#main-menu li").hover(function(){
	div = $(this).find('div.menu_mouseover');
	//alert($(div).attr("class"))
	//$(div).stop().animate({"opacity": "1"}, "slow");
	$(div).fadeIn();
	},
	function() {
		$(div).fadeOut();
	//$(div).stop().animate({"opacity": "0"}, "slow");
});
		
		
	$("#main-menu li").click(function(){
		href = $(this).children().attr("href")
		window.location=href;
	})
		
	//set current page		
	i=0;
	a=0;
	
	$("ul#main-menu").children().each (function() { 
			
    		h =$(this).children().attr("href");
			if(path.indexOf(h)>-1) a= i;
			i++;
			/* create internal div for fade effect */
			div = "<div class='menu_mouseover'></div>";
			$(this).children().append(div);
    })
		
	child = "#main-menu li:eq("+a+")";		
	$(child).addClass("menu_sel");
		
/*


$("#edit-submitted-what-product").change(function(){
	base = "#webform-component-next";
	next = base + " .qnext";
	if($("#edit-submitted-what-product").val()){   
			$(next).removeClass("qnext_disabled") 	
			$(next).addClass("qnext_enable") 	
	} else {
		$(next).removeClass("qnext_enable") 	
		$(next).addClass("qnext_disabled") 
	}
	
})

*/
$(".form-text").keyup(function(){
	//e = $(this).attr("id");
	e = input_id($("#card").data("question"))	
	//alert("e: "+e+" -val: " +$(e).val())
	base = "#webform-component-next ";
	base = "";
	next = base  + ".qnext";
	if (e=="#edit-submitted-what-is-your-e-mail-address-1") {
		
		//alert("email check")
		if (ValidateEmail($("#edit-submitted-what-is-your-e-mail-address-1").val())) $("#edit-submit-1").removeClass("send_disabled").addClass("send_enable") ;
		
	}	
	else if ($(e).val()) {$(next).removeClass("qnext_disabled").addClass("qnext_enable") ;}	
	
	else $(next).addClass("qnext_disabled").removeClass("qnext_enable") 	
	
})


function next_step(){
	id = input_id($("#card").data("question"))	
	step = eval($("#card").data("question")+1);
	$(".qnext").removeClass("qnext_enable").addClass("qnext_disabled");
	//alert($(id).val() +" : "+ id )
	if ($(id).val()) bglm(step)
	new_id = input_id(eval($("#card").data("question")))	
	if ($(new_id).val()) $(".qnext").removeClass("qnext_disabled").addClass("qnext_enable");
	}

function prev_step(){
	step = Math.max(0,$("#card").data("question")-1);
	if (step ==0) $(".qback").fadeOut(); 
	 bglm(step);
	 new_id = input_id(eval($("#card").data("question")))	
	if ($(new_id).val()) $(".qnext").removeClass("qnext_disabled").addClass("qnext_enable");
}

 function ValidateEmail(email) {
        var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return expr.test(email);
};

function input_id(c)	{
	switch(c){
		case 0:
		t = "#edit-submitted-what-product-1";
		break;
		case 1:
		t = "#edit-submitted-how-many-1";
		break;
		case 2:
		t = "#edit-submitted-what-is-your-approximate-budget-1";
		break;
		case 3:
		t = "#edit-submitted-what-is-the-name-of-your-business-1";
		break;
		case 4:
		t = "#edit-submitted-what-is-your-e-mail-address-1";
		break;
	}
	
	return t;
	
}
/*  ANIMATION TOOLS */



if ($animation ==1 && $("#node-30").css("top")){ 
	$("#main").css("top", "-170px");
	$("#page_content").css("top", "-180px");
	//
	$("#card").css("z-index", 0);
	//alert($("#bar").css("top"))
	$("#bar").animate({top: "-80px",easing: 'easeInBounce'},1000, function(){
		$("#card").fadeIn(500);
		$("#bar").animate({top: "0px",easing: 'easeInBounce'},1000)
		$("#main").animate({top: "10px",easing: 'easeInBounce'},1300, function(){$("#card").css("z-index", 600)})
		$("#page_content").animate({"top":"0"})
		
		
		//$("#page_content").fadeIn(1500, function(){
		//$("#page_content").animate({"top":"0"})
		//$("#main").animate({top: "-200px",easing: 'easeInBounce'},1000, function(){
		//$("#card").animate({"height": "toggle", "opacity": "toggle"}, "slow");
		//$("#main").animate({top: "0px",easing: 'easeInBounce'},1000, function(){
			//$("#card").css("z-index", 600);
			//});
		
		//})
		
			
	
			//})
	
	});
} 

if ($animation ==0){ 
	$("#page_content").animate({"top":"0"})
	$("#bar").css({"top": "-30px"});
	$("#page_content").show()
	$("#card").show()
	
} 



if($debug == 1){
	
	$("#container").css({"border":"2px solid cyan"})
	$("#content").css({"border":"2px dotted #970f00"})
	$(".page_body").css({"border":"2px solid green"})
	$("#footer-wrap").css({"border":"2px solid yellow"})
	//alert("w: "+$("#wowslider-container1").css("width")+ " h: "+$("#wowslider-container1").css("height"))
}

$('#menuBar li').click(function()
{
  var url = $(this).find('a').attr('href');
  document.location.href = url;

});

$('#main-menu li').hover(function()
{
   
   $(this).find('.menuInfo').slideDown();
},
function()
{
  
  $(this).find('.menuInfo').slideUp();

});




	
})

function bglm(c){
	p = "/sites/all/themes/liquidmerc/";
	//$(".qnext").fadeOut("slow")
	$("#card").data("question",c);  // update the current question

	
	/*$(".form-item").animate({"top":"-100px"},2500, function(){
		$(".webform-component").css({"top":"100px"})
	});*/
								
			switch(c){

					case 0:
 						//$("body").css("background-image","url("+p+"images/skyline.jpg)");
						//$("#slogan_card").css("background-image","url("+p+"images/slogan_01.png)");
						//$("#card").css("background-image","url("+p+"images/card_black.png)");
		
						show_me("#webform-component-what-product","#webform-component-next")
						$("#card_nav").children().fadeOut(2000);
						$("#icon_step").animate({'left':'170px'},2000);
						
  					break;

					case 1:
					
 						//$("body").css("background-image","url("+p+"images/skyline_purple.jpg)");
						//$("#card").css("background-image","url("+p+"images/card_purple.png)");
						//$("#slogan_card").css("background-image","url("+p+"images/slogan_02.png)");
						//$("#card_cache").css("background-image","url("+p+"images/card_gold.png)");
						
						show_me("#webform-component-how-many","#webform-component-next2")

						$("#card_nav_2").fadeIn(1);
						$("#icon_step").animate({'left':'238px'},2000);
					break;
					
					case 2:
 						//$("body").css("background-image","url("+p+"images/skyline_yellow.jpg)");
						//$("#card").css("background-image","url("+p+"images/card_gold.png)");
						//$("#slogan_card").css("background-image","url("+p+"images/slogan_03.png)");	
						//$("#card_cache").css("background-image","url("+p+"images/card_blue.png)");
						
						show_me("#webform-component-what-is-your-approximate-budget","#webform-component-next3")

						
						$("#card_nav_3").fadeIn(1);
						$("#icon_step").animate({'left':'300px'},2000);

					// alert(c)
					  break;
					
					 case 3:
 						//$("body").css("background-image","url("+p+"images/skyline_cyan.jpg)"); //alert(p+"images/skyline_cyan.jpg");
						//$("#card").css("background-image","url("+p+"images/card_blue.png)");
						//$("#slogan_card").css("background-image","url("+p+"images/slogan_04.png)");	
						//$("#card_cache").css("background-image","url("+p+"images/card_white.png)");
						
						show_me("#webform-component-what-is-the-name-of-your-business","#webform-component-next4")

						
						$("#card_nav_4").fadeIn(2000);
						$("#icon_step").animate({'left':'350px'},2000);

	
					// alert(c)
 					break;
 					case 4:
 						//$("body").css("background-image","url("+p+"images/skyline_gray.jpg)"); 
						//$("#slogan_card").css("background-image","url("+p+"images/slogan_05.png)");	
						//$("#card").css("background-image","url("+p+"images/card_white.png)");
						
					show_me("#webform-component-what-is-your-e-mail-address",".form-actions")

						$("#card_nav_5").fadeIn(2000);
						$("#icon_step").animate({'left':'410px'},2000);


				// alert(c)
  				break;
  
   				case 5:
				
 					//$("body").css("background-image","url("+p+"images/skyline_gray.jpg)"); 
					$("#slogan_card").css("background-image","url("+p+"images/slogan_05.png)");	
					//$("#card").css("background-image","url("+p+"images/card_white.png)");
					$("#card_nav_6").fadeIn(2000);
					$("#icon_step").animate({'left':'468px'},2000);
				// alert(c)
				break;
  
				default:
			 	//$("body").css("background-image","url("+p+"images/skyline.jpg)");
				$("#slogan_card").css("background-image","url("+p+"images/slogan_06.png)");
				//$("#card").css("background-image","url("+p+"images/card_black.png)");
				$("#icon_step").animate({'left':'500px;'},2000);
				$("#card_nav").children().fadeOut(2000);
			}
				
				
				
				
			
		
		
	
	/*  
	
		this function (bglm(e))
	
	*/	
	
	
	
	//alert(location.href);
	
		
	}

function hide_all(){
			$(".webform-component").hide()
}

function show_me(divo, button){
			hide_all();
			$(divo).fadeIn("slow")
			$(button).fadeIn("slow")
			if (button==".form-actions") $("#webform-component-next5").fadeIn("slow");
			if (button==".form-actions") $("#edit-submit-1").fadeIn("slow")

}



