$(document).ready(function(){
	
	/* Tooltips for feaured items
	-------------------------------------------------------------------------------------------------- */
	/*
	$(".featured-product-image").mouseenter(function(){
		var imgPos = $(this).offset();
		var tipX = imgPos.left + $(this).width()/2 - $(this).next(".tooltip").width()/2 - 15;
		var tipY = imgPos.top - $(this).next(".tooltip").height() - 30;
		$(this).next(".tooltip").css({
			"left":tipX+"px",
			"top":tipY+"px"
		});
		$(this).next(".tooltip").fadeIn();
	});
	$(".featured-product-image").mouseleave(function(){
		$(this).next(".tooltip").fadeOut();
	});
	*/
	
	/* Tabs for product details
	-------------------------------------------------------------------------------------------------- */
	$(".tab-details .panes div").hide();
	$(".tab-details .panes div:first").show();
	$(".tab-details .tabs li a:first").addClass('current');
	
	$(".tab-details .tabs li a").click(function(){
		var currentTab = $(this).attr('name');
		$(".tab-details .tabs li a").removeClass('current');
		$(this).addClass('current');
		$(".tab-details .panes div").hide();
		$(currentTab).show();
		return false;
	});
	
	/* Additional styling for sidebar navigation
	-------------------------------------------------------------------------------------------------- */
	$("#sidebar ul#menu-list-products li.level-1:gt(0)").css({"margin-top":"3px"});
	$("#sidebar ul#menu-list-products li.level-3:last").css({"margin-bottom":"5px"});
	
	/* Sets the active navigation item
	-------------------------------------------------------------------------------------------------- */
	var link = $.cookie("active");
	link = unescape(link);
	link = link.replace("%2F", "/");
	
	$("#sidebar a[href='"+link+"']").addClass("selected");
	
	$("#mainnav a").click(function(){
		$.cookie("active", $(this).attr('href'), {path:"/"});
	});
	
	$("#sidebar a").click(function(){
		$.cookie("active", $(this).attr('href'), {path:"/"});
	});
	
	$("#location a").click(function(){
		$.cookie("active", $(this).attr('href'), {path:"/"});
	});
	
	$("#footer a").click(function(){
		$.cookie("active", $(this).attr('href'), {path:"/"});
	});
	
	/* nyroModal Settings
	-------------------------------------------------------------------------------------------------- */
	$(function() {
		$.nyroModalSettings({
			processHandler: function(settings) {
				var from = settings.from;
				if (from && from.href && from.href.indexOf('http://www.youtube.com/watch?v=') == 0) {
					$.nyroModalSettings({
						type: 'swf',
						height: 344,
						width: 425,
						url: from.href.replace(new RegExp("watch\\?v=", "i"), 'v/')
					});
				}
			}
		});
	});
	
});