$(document).ready(function() {
	
	// PNG fix
	// Include 'jquery.pngFix.pack.js' if needed
	//$(document).pngFix();
	
	// Photo archive - Adjust height to category nav
	if( $("#categorynav").length > 0 ) {
		var maxValue = 0;
		$("#categorynav ul").each(function() {
			if( $(this).height() > maxValue ) {
				maxValue = $(this).height()
			}
		})
		$("#categorynav ul").each(function() {
			$(this).height(maxValue);
			$("#categorynav").height(maxValue+20);
		})
	}
	
	// Add hover/href to entire product spot
	$("div.thumb").each(function() {
		$(this).mouseover(function() { $(this).addClass('hover'); })
		.mouseout(function() { $(this).removeClass('hover') })
		.click(function() {
			var href = $(this).find('a:first').attr('href');
			window.location = href;
		});
	})
	
	if (typeof(CufonReplace) == "function")
	{
		CufonReplace();
	}
	
	// Font replace (Cufon)
	//Cufon.replace('h1, #feature h3, #gallery h3, #checkout div.related h3, #country-select h3, #mainnav ul li a, #subnav ul li a', { hover: true, fontFamily: 'Georg Jensen' });
	
	// Sticky Tag/Navigation
	if( $.cookie('tag') == 'on' ) {
		if( $.cookie('tagpos') == 'on' ) {
			$('#tag').css({'position' : 'fixed'});
		} else {
			var tagTop = $("#tag").offset().top;
			var tagWidth = $("#tag").width();
			$(window).scroll( function() {
			    if (tagTop - $(window).scrollTop() <= 0) {
			    	$('#tag').css({'position' : 'fixed', 'top' : '0', 'width' : tagWidth });
				}
				else if (tagTop - $(window).scrollTop() > 0) {
					$('#tag').css({'position' : 'static'});
				}
			});
		}
	}
	
	// Superfish Dropdown Navigation
	if( $("ul.sf-menu").length > 0 ) {
		$("ul.sf-menu").superfish({ 
			hoverClass:    'sfHover',          // the class applied to hovered list items 
			pathClass:     'overideThisToUse', // the class you have applied to list items that lead to the current page 
			pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
			delay:         500,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
			animation:     {height:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
			speed:         1,           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
			autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
			dropShadows:   false,               // completely disable drop shadows by setting this to false 
			disableHI:     true,              // set to true to disable hoverIntent detection 
			onInit:        function(){},       // callback function fires once Superfish is initialised – 'this' is the containing ul 
			onBeforeShow:  function(){},       // callback function fires just before reveal animation begins – 'this' is the ul about to open 
			onShow:        function(){},       // callback function fires once reveal animation completed – 'this' is the opened ul 
			onHide:        function(){}        // callback function fires after a sub-menu has closed – 'this' is the ul that just closed		
		});
	}
	
	if( $("#gallery-slider").length > 0 ) {
		$("#gallery-slider").easySlider({
			nextId: 'nextBtn',
			prevId: 'prevBtn',
			prevText: 'Previous',
			nextText: 'Next',
			autogeneratePagination: true,
			orientation: '',
			speed: 400,
			autoplayDuration: 5000,
			restartDuration: 0,
			loop: true,
			hoverPause: 0,
			hover: false,
			easing: 'swing'
		});
	}
	
	// Fancybox (Lightbox content)
	if( $("a.lightbox").length > 0 ) {
		$("a.lightbox").fancybox({
			'zoomSpeedIn':	0, 
			'zoomSpeedOut':	0,
			'overlayShow':	true,
			'overlayOpacity': .3,
			'frameWidth':	730,
			'frameHeight':	480,
			'hideOnContentClick': false
		});
	}
	
	if( $("#country-select").length > 0 ) {
		$("#country-select").jFlow({
			slides: "#region-wrap",
			controller: ".toggle-region",
			slideWrapper : "#jFlowSlide",
			selectedWrapper: "jFlowSelected",
			width: "540px",
			height: "484px",
			duration: 200
		});
	}
	
	// FAQ
	if( $(".faq").length > 0 ) {
		$('.faq dd').hide();
		//$('.faq dd:first').show();
		//$('.faq dt:first').addClass('active');
		$('.faq dt a').click(
		function() {
			var checkElement = $(this).parent().next();
			if((checkElement.is('dd')) && (checkElement.is(':visible'))) {
				return false;
			}
			if((checkElement.is('dd')) && (!checkElement.is(':visible'))) {
				// Hide desc and remove class
				$('.faq dd:visible').slideUp(200);
				$('.faq dd:visible').prev().removeClass('active');
				// Show desc and add class
				checkElement.slideDown(400);
				$(this).parent().addClass('active');
				return false;
			}
		});
	}
})

// Plugin's
$.fn.delay = function(time, callback) {
    jQuery.fx.step.delay = function(){};
    return this.animate({delay:1}, time, callback);
}

function getCookie(key)
{
	if (document.cookie.length>0)
	{
		start = document.cookie.indexOf(key + "=");
		if (start!=- 1)
		{ 
			start = start + key.length + 1; 
			end = document.cookie.indexOf(";", start);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(start, end));
		} 
	}
	return "";
}
	
function setCookie(key, value, expiryDays, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
		if the expiryDays variable is set, make the correct
		expiryDays time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expiryDays )
	{
		expiryDays = expiryDays * 1000 * 60 * 60 * 24;
	}
	var expiryDate = new Date( today.getTime() + (expiryDays) );

	document.cookie = key + "=" + escape( value ) +
	( ( expiryDays ) ? ";expires=" + expiryDate.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function feedbackCloud(iux, type, message)
{
	$("div.feedback").animate( { opacity: 1, top: "-130px" }, 300 )
	.animate( { top: "-130px" }, 4000 )
	.animate( { opacity: 0, top: "-140px" }, 300 )
	.delay(0, function() { $(this).remove();  } );
	//.animate( { top: "-120px" }, 0 )
}

function feedbackCloudNewsletter(result)
{
	$("div.feedback.newsletter").addClass(result);

	$("div.feedback.newsletter").animate( { opacity: 0.9, top: "23px" }, 300 )
	.animate( { top: "23px" }, 4000 )
	.animate( { opacity: 0, top: "15px" }, 300 )
	
	setTimeout(function() {$("div.feedback.newsletter").remove()}, 5000);
}

function clickButtonOnEnter(e, buttonid) {
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);
    if (bt) {
        if (evt.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

