$(document).ready(function(){
	//###############   PRETTYPHOTO, Zoom functionality throughout content   ###############
	$("a[rel^='prettyPhoto']")
		.each(function() {
			$(this).hover(function() {$(this).children('.zoom').fadeIn(250);}, function() {$(this).children('.zoom').fadeOut(250);});
		})
		.prepend('<div class="zoom"></div>')
		.prettyPhoto({
			showTitle: false,
			counter_separator_label: " of "
		});

	//###   Get the current menu item to open appropriate accordion menus   ###
	$rootMenuItem = $("#nav_categories .current").parent();
	$rootMenu = $rootMenuItem.parent();

	//###   Set indexes for open accordion menus   ###
	rootIndex = $rootMenu.children("li").index($rootMenuItem);

	//alert($rootMenuItem+' '+$rootMenu+' '+rootIndex);
	//alert($rootMenu.hasClass('nav_categories'));

	//###   Set indexes for open accordion menus   ###
	if ($rootMenu.hasClass('nav_categories').toString() == 'true'){
		// We're at the top level
		rootIndex = $rootMenu.children("li").index($rootMenuItem);
	}else{	
		// Assume we're dealing with a sub level, so need to go up to topmost ul
		rootIndex = $rootMenu.parent().parent().children("li").index($rootMenuItem.parent().parent());
	};
	//alert(rootIndex);

	//###   Bug in IE opens first option when set to -1   ###
	if (rootIndex == -1)
		rootIndex = 100;

	//###   Root Level Accordion   ###
	$("#productmenu").accordion({
		autoHeight: false,
		collapsible: true,
		active: rootIndex,
		header: '#nav_categories > li > a',
		changestart: function(event, ui) {

			if (ui.newHeader.hasClass("ui-state-active") == false) {
				// We're top level, and have been clicked once already
				//alert('open');
				if(ui.oldHeader.next().length != 0){
					//alert('not singleton');
					// And we do have subcats (as revealed by that aforementioned 'click'), so now we can link through
					location.href = ui.oldHeader.attr("href");
					ui.accordion( "disable" )
				}else{
					//alert('singleton');
					// But with no sub cats, so reapply the correct styles, but don't link through - we're already on the correct page
					ui.oldHeader.addClass("ui-state-active");
					ui.oldHeader.removeClass("ui-state-default");
				}
			}else if (ui.newHeader.next().length == 0) {
				// We're top level, but with no sub cats
				//alert('singleton');
				if (ui.newHeader.hasClass("current") == false) {
					// And we're not the current page item, so do link through
					location.href = ui.newHeader.attr("href");
					ui.accordion( "disable" )
				}
			}

		}
	});

	$("#category-menu").change(function() {
		location.href = $(this).val();
	});

	//###   FAQ Accordion   ###
	$("#faq-accordion").accordion({
		autoHeight: false,
		collapsible: true,
		active: false
	});
});


$(function() {
    $(".anyClass").jCarouselLite({
        btnNext: ".next_btn",
        btnPrev: ".prev_btn"
    });
});


$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'random',
		animSpeed:500,
		pauseTime:10000,
		startSlide:0,
		controlNav:true,
		controlNavThumbs:false,
		captionOpacity:0.6,
		pauseOnHover:true,
		captionAnimate:true
	});
});


ddsmoothmenu.init({
	mainmenuid: "smoothmenu1", //menu DIV id
	orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
	classname: 'ddsmoothmenu', //class added to menu's outer DIV
	//customtheme: ["#1c5a80", "#18374a"],
	contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

$(function() {
	var galleries = $('.ad-gallery').adGallery({
		slideshow: {
			enable: true,
			autostart: true,
			speed: 10000
		}
	});

});
