// JavaScript Document
$(document).ready(function(){

//WHAT ORGINAL


//ROLL OVER MAILTO
$("a[href^=mailto]").hover(function(){ $(this).fadeTo('fast', 0.5)}, function(){ $(this).fadeTo('fast', 1)});



//LISTING PAGE
	/*BIG LInk*/
	 var target ='.biglink';
	 var hoverClass = 'hoverBigLink';
	 $(target).each(function(){
		
		$(this).hover(
			function(){
				$(this).addClass(hoverClass);
			},
			
			function(){
				$(this).removeClass(hoverClass);
				
			});
			
			$(this).click(function(){
				var whattodo = $(this).find('a').attr('target');
				if(whattodo=="_blank"){
					window.open($(this).find('a').attr('href'));
				}else{
					location = $(this).find('a').attr('href');
				}
			});
			
			$(this).css('cursor','pointer');
			
	 });

//CONTACT US FORM
$("#formcontainer input").focus(function(){
		$(this).val("");
});//ON Foucs

$("#formcontainer textarea").focus(function(){
		$(this).val("");
});//ON Foucs

$("#fullname").blur(function(){
		if($(this).val()==""){
			 $(this).val("Full Name");
		 }
	});//blur
	

$("#email").blur(function(){
		if($(this).val()==""){
			 $(this).val("Email");
		 }
});//blur

$("#company").blur(function(){
		if($(this).val()==""){
			 $(this).val("Company ");
		 }
});//blur

$("#address1").blur(function(){
		if($(this).val()==""){
			 $(this).val("Address 1");
		 }
});//blur


$("#address2").blur(function(){
		if($(this).val()==""){
			 $(this).val("Address 2");
		 }
});//blur


$("#comments").blur(function(){
		if($(this).val()==""){
			 $(this).val("Question / Comment");
		 }
});//blur


//SENDING EMAIl 
	$("#sendmailbtn").click(function(){
		var relvalue = $(this).attr("rel");
		
		var fullname = $("#fullname").val();
		var email = $("#email").val();
		var company = $("#company").val();
		var address1 = $("#address1").val();
		var address2 = $("#address2").val();
		var comments = $("#comments").val();
		
		var emailok = validate(email);	
		
			if((emailok==true) && (email != "")){
				
			var data = {email:email, fullname:fullname , email:email , company:company, address1:address1, address2:address2, comments:comments  };
			
			//XML HERE
			$.ajax({
					type: "POST",
					url: "ajax/mail.php",
					data: data,
					dataType: "json",
					success: function(data){
					  	if(data["error_msg"] =="0"){
							$("#requestaqutoecol p").html("<strong>Your request has been sent. </strong> One of our representative will contact you as soon as possible. Thank you!");
							$("#fullname").val("Full Name");
							$("#email").val("Email");
							$("#company").val("Company ");
							$("#address1").val("Address 1");
							$("#address2").val("Address 2");
							$("#comments").val("Question / Comment");							
						}else{
						$("#requestaqutoecol p").html("<strong class='error'>Please provide a valid email</strong>");
						}
					}//SUCCESS ENDS
			});//END OF AJAX CALL
		}else{
			$("#requestaqutoecol p").html("<strong class='error'>Please provide a valid email</strong>");
		}
		//SEE IF THERE IS A VALUE SEND 
			
		
	 	
		return false;
	});




//FOR SLIDE SHOWS
$("#slideshowContainer a").click(function(){
			
			  var mainimagename = $(this).attr("rel");
			
			  var img = new Image();
			  img.src =  "gallery/"+ mainimagename;
			  var newsrc = img.src;
			
			$("#slideshowmainimage").fadeOut('slow', function(){ 
				$(this).attr("src", newsrc).fadeIn('slow');
			});
			
			//$("#prodimage").attr("src", newsrc);
			return false;
})

$("#iconlist li:nth-child(5n)").addClass("nomargin");

// FAQ PAGE

$("#accordiancontinaer h4.menu_head").click(function()
{
	if($(this).hasClass("avtivefaq")){
		$(this).removeClass("avtivefaq");
	}
	else{
		$(this).addClass("avtivefaq");	
	}
    $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
    $(this).siblings().removeClass("avtivefaq");
});


////////OVERLAY
	$("#signuppopup").overlay({
			mask: {
					// you might also consider a "transparent" color for the mask
					color: '#000',
			
					// load mask a little faster
					loadSpeed: 200,
			
					// very transparent
					opacity: 0.4,
					
					onBeforeLoad: function() {
						$("#msg").hide();
						$("#emailofperson").val("Your Email");
						$("#nameofperson").val("Your Name");
						$(".dropdownsignup dt a span").html("Your Province");
						$(".signup_overlay .error").hide(); 
						$("#signupintro").show();
					}
				}				
	});
	
	//THE FORM
	$("#sendtocake").click(function(){
		
		$(".signup_overlay .error").hide(); 
		
		var email = $("#emailofperson").val(); 
		var emailok = validate(email);							 
		
		var  nameofperspon = $("#nameofperson").val();
		var countryofperson = $("#countryofperson").text();

		
		if((emailok==true) && (email != "")){
				
				var data = {email:email, nameofperspon:nameofperspon , country:countryofperson };
				
				$.ajax({
						type: 'POST',
						url: "ajax/to-cake-mail.php",
						data: data,
						success: function(response) { 
						},
						error: function(xhr, type, exception) { /*alert("Error: " + type);*/ }
					})
				
											$("#emailofperson").val("Your Email");
							$("#nameofperson").val("Your Name");
							$("#contryofperson").val("Your Country");
							
							//SHOW THANK YOU MESSAGE
							$(".signup_overlay .error").hide(); 
							$("#signupintro").hide();
							$("#msg").show();
				
				return false;
		
		}else{
		   
		   	$(".signup_overlay .error").show(); 
			return false;
		
		}	
	})//SUMBIT 
	
	$(".signup_overlay input").focus(function(){
		$(this).val("");
	});//ON Foucs
	
	$("#emailofperson").blur(function(){
		if($(this).val()==""){
			 $(this).val("Your Email");
		 }
	});//blur
	
	$("#nameofperson").blur(function(){
		if($(this).val()==""){
			 $(this).val("Your Name");
		 }
	});//blur
	
	
	
	 
	 //CUSTOM DROP DOWN FEILD AND AJAX RESPONSE
    $(".dropdownsignup dt a").click(function() {
             $(".dropdownsignup dd ul").slideToggle("slow");
               return false;
        });
                        
           
    $(".dropdownsignup dd ul li a").click(function() {
       		var text = $(this).html();
            $(".dropdownsignup dt a span").html(text);
            $(".dropdownsignup  dd ul").slideToggle("fast");
			
            return false;
     }); // end of drop down

	

////** HOVER MENU **/

	var megaConfig = {
     interval: 100,
     sensitivity: 4,
	  over: addMega,
	 timeout: 200,
     out: removeMega
    };

$("li.mega").hoverIntent(megaConfig);



	$("#mailinglist .button").click(function(){ 
		 		
				$("#mailinglist .error").hide();
				
		 		var email =  $("#mailinglist input").val();
		 
		 		var emailok = validate(email);		
				
				var data = {email:email};
				
				
				if(emailok){
				
					$.ajax({
							type: 'POST',
							url: "ajax/to-cake-mail.php",
							data: data,
							success: function(response) { 
								$("#mailinglist input").val(" ");
								$("#mailinglist .msg p").empty().text("You are now signed up to are email list");
							},
							error: function(xhr, type, exception) { /*alert("Error: " + type);*/ }
						})
				} else{
					$("#mailinglist .error").show();	
				}
	});



	$("#disclaimerlink").click(function(){
			openlink();						
			return false;
	});


   //ON HOVER FILES MAP
	$("#leftsidemenu li a").hover(
	  function () {
			var thisnumber = $(this).attr("rel");
			$(thisnumber).fadeIn("fast");
	  },
	  function () {
			var thisnumber = $(this).attr("rel");
			$(thisnumber).fadeOut("fast");
	  }
	);
	


}); // end of ready() function

/************FUNCTONS NEEDED*****************/

//FOR HOVER
function addMega(){
 	/*$(this).addClass("hovering");*/
 	$(this).find(".submenu").slideDown("fast");
}
function removeMega(){
	$(this).find(".submenu").slideUp("fast");
  	/*$(this).removeClass("hovering");*/  
}

/*******************FOR EMAIL */
/////FUNCTION FOR EMAIL CHECK
function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = email;
   if(reg.test(address) == false) {
      return false;
   }else{
	  return true;
	}
}

/***********FUNCTION ***/
function openlink(){
	
	myRef = window.open('disclaimer.html','mywin',
'left=20,top=20,width=500,height=400,toolbar=0,resizable=0');


}





