//	JavaScript Document

/*	Validator 
http://docs.jquery.com/Plugins/Validation

-------------------*/
$(document).ready(function(){
   $("#subscribe-form, #contact-us-form, #register_form, #proceed-coupon-form").validate({
		errorPlacement: function(error, element) {  
                $(element).attr({"label": error.append()});
            },
            highlight: function(element){
                //$(element).css({"border": "2px solid #CC0000"});
                $(element).removeClass("textinput");
                $(element).addClass("error");
            },
            unhighlight: function(element){
                //$(element).css({"border": "2px solid #CC0000"});
                $(element).removeClass("error");
                $(element).addClass("textinput");
            }
						 
	});
});

/* Show / Hide controls

-------------------*/

/* CREDIT CART DETAILS */

 $(document).ready(function() {
							
		// Shows CC-Details DIV on load
		$('#cc-details-wrap').show();
		 
		$("#payment_type_credit").click(function(){
		
		// If Credit Card is checked
        if ($("#payment_type_credit").is(":checked"))
        {
            //show the hidden div
			$('#cc-details-wrap').show();
			//Hide Paypal div
			$("#paypal").hide();
        }
        else
        {     
            //otherwise, hide it
            $("#cc-details").hide("fast");
        }
		});
			
});

$(document).ready(function() {
		
		// hides Paypal Details DIV on load
		$('#paypal').hide();		   

		$("#payment_type_paypal").click(function(){
		
		// If Paypal is checked
        if ($("#payment_type_paypal").is(":checked"))
        {
            //show the hidden div
			$("#paypal").show();
			//Hide CC details div
			$("#cc-details-wrap").hide();
        }
        else
        {     
            //otherwise, hide it
            $("#paypal").hide();
        }
		
        });	
});

/* BILLING ADDRESS */

$(document).ready(function() {
		
		// hides billing form on load
		$('#billing-form').hide();		   

		$(".billing-address-input").click(function(){
		
		// If billing address checkbox is checked
        if ($(".billing-address-input").is(":checked"))
        {
            //show the hidden div
			$("#billing-form").show();
        }
        else
        {     
            //otherwise, hide it
            $("#billing-form").hide();
        }
		
        });	
});

/* Search Results Sidebar */

$(document).ready(function() {
		
  $('a.collapse-category').click(function() {
	 $('#browse-category').toggle(400);
	 return false;
  });
  
  $('a.collapse-brand').click(function() {
	 $('#browse-brand').toggle(400);
	 return false;
  });
  
  $('a.collapse-colour').click(function() {
	 $('#browse-colour').toggle(400);
	 return false;
  });
  
  
});


// Fires the Product Detail Carousel

$(document).ready(function() {

  var carouselNumItems = Math.min(9, $(".carousel li").length); // Hardi jCarousel bug workaround 29 Jun 2011

  $(".carousel").jCarouselLite({
    btnNext: ".next",
    btnPrev: ".prev",
    mouseWheel: true,
    visible: carouselNumItems
  });
});


/*	ClearField 

http://labs.thesedays.com/projects/jquery/clearfield/
-------------------*/
$(document).ready(function() {
	$('.clearField').clearField();
});


/*	Footer Menu fixed to bottom
-------------------*/

/*	Calculate Window Height */

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


/*	Relative-positioned Footer */

function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.top = '0px';
			}
		}
	}
}
window.onload = function() {
	setFooter();
}
window.onresize = function() {
	setFooter();
}

$(function() {
              $('#nav-site > li').mouseover(function() {
                     $(this).addClass('hover');
                     $('.sub-nav', this).show(); 
              }).mouseout(function() {
                     $(this).removeClass('hover');
                     $('.sub-nav', this).hide(); 
              });
});

