// JavaScript Document


$(document).ready(function() {
						   
//cart function: set bill to same as ship to based on checkbox

$("input[name=billSame]").click(function() { //show email composition DIV when clicked
	//$("#composeEmail").show("slow");
	
	if ($('input[name=billSame]').is(':checked'))
	{
		$("#billNameFirst").val($("#shipNameFirst").val());
		$("#billNameLast").val($("#shipNameLast").val());
		$("#billCompany").val($("#shipCompany").val());
		$("#billAdd1").val($("#shipAdd1").val());
		$("#billAdd2").val($("#shipAdd2").val());
		$("#billCity").val($("#shipCity").val());
		$("#billState").val($("#shipState").val());
		//var shipState = $("#shipState").val();
		//$("#billState option[value=" + shipState + "]").attr("selected",true);
		//console.log($("#shipState").val());
		//console.log($("#billState").val());
		//console.log(shipState);
		$("#billZip").val($("#shipZip").val());
		$("#billCountry").val($("#shipCountry").val());
		$("#billPhone").val($("#shipPhone").val());
		$("#billEmail").val($("#shipEmail").val());
		$("#billFax").val($("#shipFax").val());
	}
	else {
		$("#billNameFirst").val('');
		$("#billNameLast").val('');
		$("#billCompany").val('');
		$("#billAdd1").val('');
		$("#billAdd2").val('');
		$("#billCity").val('');
		$("#billState").val('');
		$("#billZip").val('');
		$("#billCountry").val('');
		$("#billPhone").val('');
		$("#billEmail").val('');
		$("#billFax").val('');
	}
	
});
						   
						   
						   
						   
						   
						   
//fancybox 
/* This is basic - uses default settings */ 
$("a#single_image").fancybox(); 
/* Using custom settings */ 
$("a#inline").fancybox({ 'hideOnContentClick': true }); 
$("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false }); 

$("a.zoom").fancybox();

$("a.zoom1").fancybox({
	'overlayOpacity'	:	0.7,
	'overlayColor'		:	'#FFF'
});

$("a.zoom2").fancybox({
	'zoomSpeedIn'		:	500,
	'zoomSpeedOut'		:	500
});

$("a.zoom3").fancybox({
				'width'				: 750,
				'height'			: 500,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',	 
				'overlayOpacity'		: 0.4,
				'overlayColor'			: '#FFF',
				'hideOnContentClick'	: false
});
						   
//search fields clear on click. Nice bit of UX.
$("#searchTextBox").click(function(){
var varSelection = String($(this).val());
if(varSelection==" PRODUCT SEARCH"){$(this).val('');}
return false;			
}); //close $("#searchTextBox").click	

$("#searchButton").click(function(){
$varSearch = "search.php?searchTextBox=" + $("#searchTextBox").val() + "&btnG=Search";
if($("#searchTextBox").val()!=''){
self.location=($varSearch);
}
//alert($varSearch);
return false;			
}); //close $("#searchButton").click
		
//mailingListTextBox clear on click.
$("#mailingListTextBox, #mailingListTextBoxFooter").click(function(){
var varSelection = String($(this).val());
if(varSelection==" EMAIL ADDRESS"){$(this).val('');}
return false;			
}); //close $("#mailingListTextBox").click	

//mailingListButton posts loginForm via ajax
$("#mailingListButton").click(function(){ 							
//send data 
$.post("_inc/ajaxEmailSubscription.php",   { email: $("#mailingListTextBox").val() },
  function(data){
	//successful email subscription:
if (data.email!="") 
		{
			//console.log(data.email);
			$("#mailingList").html('<span style="color: yellow; font-size:12px;">Thank You!</span><br /> We\'ve added you to our mailing list. Stay tuned for more info!');
		}
  }, "json");
return false;			
}); 

//mailingListButton posts loginForm via ajax
$("#mailingListButtonFooter").click(function(){ 							
//send data 
$.post("_inc/ajaxEmailSubscription.php",   { email: $("#mailingListTextBoxFooter").val() },
  function(data){
	//successful email subscription:
if (data.email!="") 
		{
			//console.log(data.email);
			$("#emailFooterDiv").html('<span style="font-family:Verdana, Geneva, sans-serif; color:#FFF;">Thank You!</span><br /> We\'ve added you to our mailing list. Stay tuned for more info!');
		}
  }, "json");
return false;			
}); 


						   
//toggle loginWrapper on loginLink click, loginCancel hides it						   
$("#loginLink, #loginCancel").click(function(){ 
	$("#loginWrapper").toggle("slow");
	$("#loginSubmit").fadeIn('fast');
	$("#loginLoader").fadeOut('fast');
return false;			
}); 

//loginSubmit posts loginForm via ajax
$("#loginSubmit").click(function(){ 
	$("#loginSubmit").fadeOut('fast');
	$("#loginLoader").fadeIn('fast');								 
//send data 								 
$.post("_inc/ajaxLogin.php",   { loginEmail: $("#loginEmail").val(), loginPassword: $("#loginPassword").val() },
  function(data){
	//successful login:
	if (data.login=="TRUE") 
		{
			$("#profileLink").html(data.user);
			$("#loginWrapper").toggle("slow");
		}
		else
		{
			$("#loginSubmit").fadeIn('fast');
			$("#loginLoader").fadeOut('fast');
			alert("Sorry, no matching username. Please try again!");
		}
  }, "json");
return false;			
}); 
						   
//alert $e
var errorMsg = $("#e").val();
if (errorMsg != "" && errorMsg != "0")
{
//alert (errorMsg);
$("#errorMsg").slideDown("slow");
}
						   
//LOADING POPUP
	//Click the button event!
	$("a.cs").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		return false;	
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});						   
						   
//fade initial homeMainImage in
$("#homeImageMain1").fadeIn("slow");

//image thumb swap on details.php
$(".thumb").click(function(){
		//alert('thumb');
		var largePath = $(this).attr("src");
		var oldPath = $("#largeImg").attr("src");
		//alert(largePath);
		$("#largeImg").attr({ src: largePath});
		 $(this).attr({ src: oldPath});
		return false;	
	});
						   

$(function() {
    setInterval( "dogSwitch()", 6000 ); //6000
});	

////cart
//$("#shipState").change(function() {
//alert( $(this).val());
//});

  
}); //jQuery END



//functions:


 var dogCounter = 0;
 function dogSwitch() {
    dogCounter += 1;
	//alert(kidSection);
	
			if(dogCounter==17){dogCounter=1;}
			//alert(dogCounter);
			switch(dogCounter)
			{
			case 1:
			$("#homeImageMain2").fadeIn(10000, function() {$("#homeImageMain1").fadeOut(5000);});
			break;
			case 3:
			$("#homeImageMain3").fadeIn(10000, function() {$("#homeImageMain2").fadeOut(5000);});
			break;
			case 5:
			$("#homeImageMain4").fadeIn(10000, function() {$("#homeImageMain3").fadeOut(5000);});
			break;
			case 7:
			$("#homeImageMain5").fadeIn(10000, function() {$("#homeImageMain4").fadeOut(5000);});
			break;
			case 9:
			$("#homeImageMain6").fadeIn(10000, function() {$("#homeImageMain5").fadeOut(5000);});
			break;
			case 11:
			$("#homeImageMain7").fadeIn(10000, function() {$("#homeImageMain6").fadeOut(5000);});
			break;
			case 13:
			$("#homeImageMain8").fadeIn(10000, function() {$("#homeImageMain7").fadeOut(5000);});
			break;
			case 15:
			$("#homeImageMain1").fadeIn(10000, function() {$("#homeImageMain7").fadeOut(5000); $("#homeImageMain8").fadeOut(5000); });
			break;
			
			}
	
	
}

/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}








 