/*-------------------------------------------------
  Document Ready
-------------------------------------------------*/
$(document).ready(function(){

	/*var nav = $("#global-nav");
	
	//add indicators and hovers to submenu parents
	nav.find("li").each(function() 
	{
		if ($(this).find("ul").length > 0) 
		{  
            //show subnav on hover  
            $(this).mouseenter(function() {  
                $(this).find("ul").stop(true, true).slideDown();  
            });  
  
            //hide submenus on exit  
            $(this).mouseleave(function() {  
                $(this).find("ul").stop(true, true).slideUp();  
            });  
         }
     });
     */  

	//Global navigation
	$("nav li").mouseenter(function(){ $(this).children("ul").css("display","block");});
	$("nav li").mouseleave(function(){ $(this).children("ul").css("display","none");});
	
	//Video Gallery
	$(".scrollable").scrollable({ vertical: true, mousewheel: true }).navigator();
	
	//Product Photo Gallery
	$(".thumb_nav").scrollable();
	
	// Tabs
	$("ul.css-tabs").tabs("div.css-panes > div");
	$("#vtabs").tabs("#vtab-content section");
	
	initSpecsAccordion();
	
	//HOMEPAGE
	//JCarouselLite Activation
	$("#mainSlider").jCarouselLite({
		btnNext: "#sliderBtnNext",
		btnPrev: "#sliderBtnPrev",
		visible: 1,
		auto: 10000,
    	speed: 200
		});
	
	//Product Gallery
	$(".thumbs img").click(function(e) {
		e.preventDefault(); /* prevents default behavior */
		if ($(this).hasClass("active")) { return; }
		
		var url = $(this).attr("src").replace("sm.jpg", "med.jpg");
		var zurl = url.replace("med.jpg", "lg.jpg");
		var wrap = $("#image_wrap").fadeTo("fast", 1);
		var zoom = $(this).attr
		var img = new Image();
		
		img.onload = function() {
			wrap.fadeTo("fast", 1);
			wrap.find("img").attr("src", url);
			wrap.find("a").attr("href", zurl);
		};
		
		img.src = url;
		$(".thumbs img").removeClass("active");
		$(this).addClass("active");

	}).filter(":first").click();
	
	

	//FORMS
	/*	
	//RMA Progression Forms
	$("#rma_form").formToWizard({ submitButton: 'SaveAccount' })
	*/
	
	
	//Hide State/Zip for internationals
	$("#country").change(function () {
          var value = $(this).val();
          if(value == "US" || value == "CA") {
          	$("li.eval").show();
          } else {
          	$("li.eval").hide();
          }   
     });
     
     $("#autofill").change(function() {
     	if( $("#autofill").is(':checked')) {
     		$.getJSON('/rma/autofill', function(data){
     			$('#first_name').val(data.first_name); 
            	$('#last_name').val(data.last_name);
            	$('#company').val(data.company);
            	$('#email').val(data.email);
            	$('#phone').val(data.phone);
            	$('#address_1').val(data.address_1);
            	$('#address_2').val(data.address_2);
            	$('#address_3').val(data.address_3);
            	$('#city').val(data.city);
            	$('#postcode').val(data.postcode);
            	$('#state').val(data.state);
            	$('#country').val(data.country);
            	$.uniform.update("#state");
            	$.uniform.update("#country");
            });
     	} else {
     		$('#first_name').val(""), 
            $('#last_name').val(""),
            $('#company').val(""),
            $('#email').val(""),
            $('#phone').val(""),
            $('#address_1').val(""),
            $('#address_2').val(""),
            $('#address_3').val(""),
            $('#city').val(""),
            $('#postcode').val("");
            $('#state').val('AL');
            $('#country').val('US');
     	}
     });
});

/*-------------------------------------------------
  Specifications Accordian
-------------------------------------------------*/
function initSpecsAccordion(){
  $('.specs h3 a').click(function(){
    if ($(this).hasClass('open')) {
      $(this).removeClass('open').parent('h3').siblings('div').slideUp();
    } else {
      $(this).addClass('open').parent('h3').siblings('div').slideDown();
      $(this).parents('li')
      .siblings().find('a.open')
      .removeClass('open')
      .parent('h3').siblings('div').delay(400).slideUp();
    return false;
    }
  }); 
} 
   
