//change className of html from .noJS to .hasJS. 
(function(el){el.className=el.className.replace("noJS", "hasJS")})(document.documentElement);
//(function(el){el.className=el.className.replace(/\bnoJS\b/, "hasJS")})(document.documentElement);

// fix background image flicker for IE 6 
try {document.execCommand("BackgroundImageCache", false, true);} catch(err) {}

// invoke the print dialog
function printPage(){
return window.print();
}


//tabbed navigation for the recipes...
var recipebrowser = {
	init:function(){
		/* use this method instead if we want to trigger the click event upon page load...*/
		this.startTabIndex=0;
		$("#recipeNav > ul.tabs a").each(function(i){
			if ($(this).hasClass("current")) recipebrowser.startTabIndex = i;
		});
		
		this.api = $("#recipeNav > ul.tabs").tabs("#recipeNav .panel",{
			effect: 'ajax', 
			api:true, 
			initialIndex:this.startTabIndex
			//initialIndex:null //Specifying null or a negative number here will not trigger the click event upon page load causing all tabs to be initially closed.
		});//.history();
	}
}
//the tabs api as defined here: flowplayer.org/tools/tabs.html
//can be called like so: recipebrowser.api.next();


///photogallery
var photogallery = {
	init:function() {
		$("a.zoom").fancybox({
			padding				:	10,
			margin				:	20,
			autoScale			:	true,
			autoDimensions		:	true,
			hideOnOverlayClick	:	true,
			hideOnContentClick	:	false,
			overlayShow			:	true,
			overlayOpacity		:	0.5,
			overlayColor		:	'#666',
			titleShow			:	true,
			titlePosition		:	'inside',	// 'outside', 'inside' or 'over'
			transitionIn		:	'fade',	// 'elastic', 'fade' or 'none'
			transitionOut		:	'fade',	// 'elastic', 'fade' or 'none'
			speedIn				:	400,
			speedOut			:	400,
			changeSpeed			:	300,
			changeFade			:	'fast',
			'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
				title = title || ""; 
				return '<span id="fancybox-imgcount">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span> ' + title;
			}
		});
	}
}

var slideshows = {
	init:function(){
		$("div.slideshow").each(function(){
			var $el=$(this); 
			var slidetabs="";
			$slides=$el.find("div.slide");
			for (var i=0; i < $slides.length; i++){
				slidetabs += '<a href="#"></a>';	
			}
			$('<div class="slidetabs">'+slidetabs+'</div>')
				.appendTo($el)
				.tabs($el.find("div.slide"), {effect:'fade',fadeOutSpeed:"slow",rotate:true})
				.slideshow({autoplay:true,autopause:true,clickable:false});
		});
	}
}



//load these on DOMready:
$(document).ready(function() {

	recipebrowser.init();
	photogallery.init();
	slideshows.init();
	
	


});


function clearCurrentLink(){
	var subnav =  document.getElementById('snOpskrifter');
    if (subnav) {
		var a = subnav.getElementsByTagName("A");
	    for(var i=0;i<a.length;i++){
	        if(a[i].href.split("#")[0] == window.location.href.split("#")[0]){
	            //removeNode(a[i]);
				a[i].className="current";
	        }
	    }
	}
}

function removeNode(n){
    if(n.hasChildNodes()){
        for(var i=0;i<n.childNodes.length;i++){
            n.parentNode.insertBefore(n.childNodes[i].cloneNode(true),n);
        }
    }
    n.parentNode.removeChild(n);
}
/*
window.onload = function() {
	clearCurrentLink();
}
*/
