$(document).ready(function() {
	// Focus form fields
	$('.focus').focus();
	
	// Preload hover images
	$(".hover img").each(function() {
		// Set the original src
		hoversrc = $(this).attr("src");
		hoverActive = hoversrc.replace(/.png$/ig,"-hover.png");
		$("<img>").attr("src", hoverActive);
	});
		
	// Hover effect
	$(".hover").mouseover(function(){
		imgsrc = $(this).children("img").attr("src");
		matches = imgsrc.match(/-hover/);
		// don't do the hover if state is already ACTIVE
		if (!matches) {
		imgsrcActive = imgsrc.replace(/.png$/ig,"-hover.png"); // strip off extension
		$(this).children("img").attr("src", imgsrcActive);
	}
	});
	$(".hover").mouseout(function(){
		$(this).children("img").attr("src", imgsrc);
	});
	// SJEKK: http://www.shopdev.co.uk/blog/jquery-rollovers-using-this/

	// Equal height function
	function equalHeight(group) {
		var tallest = 0;
		group.each(function() {
			var thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
		});
		group.height(tallest);
	}

	// Set equal heights
	//$('body.Presse .equalOne').removeClass('equalOne'); //debug-test
	equalHeight($(".equalOne"));

	// fade producscroller arrows
	$("#productscroller_arrows img").fadeTo("fast", 0.0);
	$("#productscroller_container").hover(function(){
		$("#productscroller_arrows img").fadeTo("normal", 0.6); // This sets the opacity to 100% on hover
	},function(){
   		$("#productscroller_arrows img").fadeTo("normal", 0.0); // This sets the opacity back to 60% on mouseout
	});
	
	// Add classes to Nav ul/li
	$("#nav li a.depth0").each(function() {
		 $(this).parent().addClass('depth0');
	});
	$("#nav li a.depth1").each(function() {
		 $(this).parent().addClass('depth1');
	});
	
	// Cufon font replacment
	Cufon.replace('h1, h2, h3, h4, .cufon', { fontFamily: 'fmLight' });				  
//	Cufon.replace('#nav a', { hover: true });

	// productlisting classes
	$("#productlist.summarylist .item:odd").addClass("odd");

	// forhandlerliste classes
	$("#forhandlerliste .forhandler:odd").addClass("odd");
	
	// Clickable (big targets)
	$(".clickable").fitted();

	// Fancybox
	$(".productdrawing a.fancy").fancybox({
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	500, 
		'speedOut'			:	400, 
		'changeSpeed'		:	200,
		'overlayShow'		:	true,
		'overlayColor'		:	'#000',
		'overlayOpacity'	:	0.5,
		'overlayShow'		:	false,
		'hideOnContentClick' :	true,
		'titlePosition'		: 'outside'
	});
	$("a.produktfakta_popup").fancybox({
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'speedIn'			:	600, 
		'speedOut'			:	600, 
		'padding'			:	0,
		'margin'			:	30,
		'height'			: 	710,
		'width'				:	990,
		'scrolling'			:	'yes',
		'autoScale'			: 	false,
		'centerOnScroll'	:	false,
		'type'				:	'iframe',
		'centerOnScroll'	:	true,
		'overlayColor'		:	'#000',	
		'overlayOpacity'	: 	0
	});
	/* Apply fancybox to multiple items */
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	500, 
		'speedOut'		:	400, 
		'overlayShow'	:	true,
		'overlayColor'	:	'#000',
		'overlayOpacity' :	0.5,
		'changeSpeed'	:	200,
		'titlePosition'	: 'outside'
	});


});

