$(document).ready(function(){
	
	$('.slideshow') 
	.after('<div id="slidePages">') 
	.cycle({ 
		fx:     'fade', 
		speed:  'slow', 
		timeout: 8000,
		speed:   2000,
		delay:   -2000,
		pager:  '#slidePages',
		cleartype:     true,
    	cleartypeNoBg: true
	});
	
	$(".advancedSearch ul ul:not(.last ul)").hide();
	
	$("#wrap").css("height", $(document).height());
	
	$("a#open").click(function(){
		$("div#cartPanel").slideToggle(400, 'swing');
		$(".cartTab").css("padding-top", "20px");	
	});	
	$("a#close").click(function(){
		$("div#cartPanel").slideToggle(400, 'swing');
		$(".cartTab").css("padding-top", "0px");
	});		
	$(".shopping a").click(function () {
		$(".shopping a").toggle();
	});
	
	Cufon.replace('#slidePages a');
	
	$('.advancedSearch ul ul').each(function() {
		var n = $(this).find("input:checked").length;
		if(n > 0) {
			$(this).show();
			$(this).find("input:not(:checked)").parent().hide();
		};
	});
		
	$(".advancedSearch ul li h5:not(.last h5)").click(function() {
		if($(this).parent().hasClass('active')) {
			var n = $(this).parent().find("input:checked").length;
			if(n < 1) {
				$(this).parent().find("ul").slideUp();
			} else {
				$(this).parent().find("input:not(:checked)").parent().slideUp();
			};
			$(".advancedSearch ul li").removeClass("active");
			return false;
		};
		
		$('.advancedSearch ul ul:not(.last ul)').each(function(index) {
			var n = $(this).find("input:checked").length;
			if(n < 1) {
				$(this).slideUp();
			} else {
				$(this).find("input:not(:checked)").parent().slideUp();
			};
		});
		
		$(".advancedSearch ul li").removeClass("active");
		$(this).parent().addClass("active");
		var activeTab = $(this).parent().find("ul")
		$(activeTab).slideDown();
		$(this).parent().find("input:not(:checked)").parent().slideDown();
		return false;
	});
	
	$('ul#nav ul.dropdown').each(function() {
		$(this).css({ visibility: "hidden", display: "block" });
		var width = 12;
		$(this).children("ul li").each(function() {
			width += $(this).width();
		});
		$(this).css({ visibility: "", display: "none" });
		$(this).css('width', width);
	});
	
	/*
	$('ul#nav ul.dropdown li ul').each(function() {
		$(this).css("height", $(this).parent().parent().height());
	});
	*/
	$('ul#nav ul.dropdown').each(function() {
		var ul_height=$(this).height();
		$(this).find('li ul').css("height", ul_height);	
	});
	
	$('ul#nav ul.dropdown li:first-child').css("border-left", "none");
	$('ul#nav ul.dropdown li:last-child').css("border-right", "none");
	
	
	
	function myStartFunction() { $("select.selectbox").selectbox(); }
	
	$("#loginMenu a.fbox").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding':0,
		'onComplete': myStartFunction
	});
	
	$("#footer a.fbox").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding':0,
		'onComplete': myStartFunction
	});
	

	
});
