﻿$(function(){
	$('#product-tabs').tabs();	
	$('.search').toggleVal();
	$(".search-results-product-options div:even").addClass("alt");
	$(".search-results-product-options div:odd").addClass("odd");
	$(".reccommended-heading").click(function(){$(".reccomended-listings").slideToggle();});
	$(".reccommended-heading").toggle(function(event){
			event.preventDefault();
			$(this).css({'background-image': 'url(images/addtocart.gif)'});
		},function(event) { // same here
			event.preventDefault();
			$(this).css({'background-image': 'url(images/close.gif)'});
	});

	$(".main-heading").one("click",showMenu);
	$(".main-heading-arrow").one("click",showMenu);
  
	if ($.cookie('submit-member-form') == '1'){$('#members-only-form').hide();$(".success").show().html("<strong>Thank you for joining.</strong>");}else{showForm();}
	
	var options = { 
		success: function(){
			$('#members-only-form').fadeOut("fast",function(){$(".success").fadeIn("slow").html("<strong>Thank you for submitting...</strong>");});
			$.cookie('submit-member-form', '1'); // set cookie
		}
	}; 
    $('#members-only-form').submit(function(){$(this).ajaxSubmit(options);return false;});
});
function showForm(){
	$("#showForm").html("<form action='test.php' id='members-only-form'><p><input type='text' value='Enter Email Address' name='members-email' id='members-email' class='members-email' /><br /><input type='submit' value='' alt='Submit' class='members-submit'/></p></form>");
	$('#members-email').toggleVal();
	
}
function showMenu(){
	$(".openMenu").each(HideMenu);//Hide any open menus
	$(this).parent().addClass("openMenu");
        if (this.id=="flea-tick-nav"){//If it is out problem one
           h = "260px";//Or what ever the hight needs to be for that tab
        }
        else {
	   var h = 0;//Master height for multi div
	   //All these figures are guestimates, you might have to fiddle them a bit
	   var liH = 17;//Height of li
	   var h5H = 25;//Height of h5 item
	   var margH = 35;//Combined height of margins on items, used to get exact right height
	   $(".sub-drop div",this.parentNode).each(function(){//cycle through each div
	       var innerH = 0;//Height of this div
	       innerH+=$("li",this).length*liH;
	       innerH+=$("h3",this).length*h5H;
	       innerH+=margH;
	       if(innerH>h){
	         h = innerH;
	       }		
	   })
	   h = h+"px";
       } 
	$(".sub-drop",this.parentNode).show().animate({
		height:h
	},500,"linear",function(){
		$(this).parent(".main-menu").one("mouseleave",HideMenu);
	});
}

 
function HideMenu(){
	$(".sub-drop:visible",this).stop().animate({height:"0px"},500,"linear",function(){
		$(this).hide().parent(".main-menu").removeClass("openMenu");
        $(".main-heading",this.parentNode).one("click", showMenu);
	});
}