$(document).ready(function(){

	//Adding classes for Background of the month/week
	Date.prototype.getWeek = function() {
    	var determinedate = new Date();
    	determinedate.setFullYear(this.getFullYear(), this.getMonth(), this.getDate());
   		var D = determinedate.getDay();
    	if(D == 0) D = 7;
    	determinedate.setDate(determinedate.getDate() + (4 - D));
    	var YN = determinedate.getFullYear();
    	var ZBDoCY = Math.floor((determinedate.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
    	var WN = 1 + Math.floor(ZBDoCY / 7);
    	return WN;
	};
	
	var d = new Date();
	var curr_month = d.getMonth();
	var curr_week = d.getWeek();
	
    $('body').addClass('mth' +(curr_month+1));
    $('body').addClass('wk' +(curr_week));


	//Timezone correction for facebook-rss
		
		//adds leading zero to single-digits. turns 1:00 into 01:00.
		var makeDual = function(value) {
			var dual;
			if(value.toString().length < 2) {dual = '0'+value;}
			else {dual = value;}
			
			return dual;
		}

		$('.fb-rss .published-date').text(function() {
		var estTime = new Date($(this).attr('title') + '-05:00');
		var utcTime = new Date(estTime.toUTCString());
		
		return utcTime.getFullYear() + '-' + makeDual(utcTime.getMonth()+1) + '-' + makeDual(utcTime.getDate()) + ' ' + makeDual(utcTime.getHours()) + ':' + makeDual(utcTime.getMinutes());
		});

	// Initialize shadow box
	var options = {
		handleLgImages:     'resize',
		handleUnsupported:  'remove',
		keysClose:          ['s'], // c or esc
		keysPrev: ['t',37],
		keysNext: ['n',39],
		autoplayMovies:     false,
		overlayOpacity: .78,
		continuous: true,
		counterType: 'skip',
		animSequence: 'sync',
		displayNav: true
	};
	Shadowbox.init(options);

	// 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
	});
	
	// Slideshow
	/*
	$('.slideshow').cycle({
		timeout:  3000, 
		speed:  1500
	});
	*/
	
	// Homepage logo animation
	/*
	if ($('.temp #product-in-focus').length > 0) {
		$('<div id="big-logo"></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
	/*
	if($('body').hasClass('products')) { // if page is in the products folder
	$('#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();
	*/
	/*
	function facebookLike(code, el, pos) {
		var fb_like_btn = code;
		if( pos === "first" ) {
			fb_like_btn.prependTo(el);
		} else if (pos === "last") {
			fb_like_btn.appendTo(el);
		}
	}
	var global_fb_like = $('<fb:like href="http://www.facebook.com/pages/Abecita/177105385667258" layout="button_count" show_faces="false"></fb:like>');
	var home_fb_fanbox = $('<fb:like-box href="http://www.facebook.com/pages/Abecita/177105385667258" width="292" show_faces="true" stream="false" header="true"></fb:like-box>');
	var product_fb_like = $('<fb:like show_faces="false"></fb:like>');
	facebookLike(global_fb_like, $('#nav'), "first");
	facebookLike(home_fb_fanbox, $('#category-blurbs + .col'), "last");
	facebookLike(product_fb_like, $('.article:not(#articles-in-series .article)'), "first");
	*/



	
	
});
