$(document).ready(function(){

	// Initialize Nivo slider	
	var total = $('.slider img').length;
	var rand = Math.floor(Math.random()*total);
	$('.slider').nivoSlider({
		effect:'random', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:rand, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavHide:true,
		controlNavThumbs:true, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '-thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
	
	// Homepage logo animation
	if ($('.temp #product-in-focus').length > 0) {
		$('<div id="big-logo"></div>').hide().prependTo('#wrapper').fadeIn(3000).delay(3000).fadeOut(3000);
		//$('<div id="big-logo"><img src="/CommonResources/Files/www.abecita.se/img/layout/abecita-big-logo.png" /></div>').hide().prependTo('#wrapper').fadeIn(3000).delay(3000).fadeOut(3000);
	}
	
	//zebra striped tables
	$("table tr:nth-child(2n)").addClass("even");

	//hide and show product tip
	$("#available-products .form").addClass("off-screen");
	$(".tip a").click(function(){
		$(this).parent().parent().next().removeClass("off-screen").addClass("on-screen");
		return false;
	});	

	/* Highlight anchors */
	/*
	var hash = document.location.hash;
	if (hash) {
		$(hash).find("h2").addClass("highlight");
	}
	$("a").click(function(){
		 $(this.hash).addClass("highlight");
	});
	*/
	
	//Apply hover effect on clickable list items
	$(".clickable-items li").hover(function() {
		$(this).addClass("hover"); //over
	}, function() {
		$(this).removeClass("hover"); //out			
	});
	
	//Make list items clickable, with parent containing class .clickable-items
	$(".clickable-items li").click(function() {
		var the_url = $(this).find("a:first").attr("href");
		if (the_url != null){
			location.href = the_url;
		}
	});
	
	//Product menu fix
	$('#sub-nav > ul > li:not(:first-child) > a').each(function() { // replace the link in every other Top level category element
		var the_text = $(this).text();
		$(this).replaceWith('<h3>' + the_text + '</h3>');
	});
	$('#sub-nav > ul > li:first-child > a, #sub-nav > ul > li:first-child > ul > li:not(:first-child)').hide();
	
	//Used for help texts in input fields
	/*
	var fakePlaceholder = function(){
		var config = {
			placeholderText : 'Ex. artikelnr.',
			input : '.product-search',
			cssClass : 'placeholder'
		};
		function setPlaceholderText(){
			$(config.input).val(config.placeholderText);
		};
		function resetPlaceholderText(){
			$(config.input).val('');
		}
		function addPlaceholderClass(){
			$(config.input).addClass(config.cssClass);
		};
		function removePlaceholderClass(){
			$(config.input).removeClass(config.cssClass);
		}
		function init(){
			addPlaceholderClass();
			setPlaceholderText();
		};
		$(config.input)
		.focus(function(){
			if($(config.input).val() == config.placeholderText){
				removePlaceholderClass();
				resetPlaceholderText();
			};
		})
		.blur(function(){
			if($(config.input).val() == ''){
				addPlaceholderClass();
				setPlaceholderText();
			};
		});
		return {
			init:init
		};
	}();
	fakePlaceholder.init();
	*/
});
