(function($) {
	
	$(document).ready(function() {

        $('.clickGetALink').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		
		$('.searchBox input.search').bind('keyup', function(e) {
			var key = e.keyCode || e.which;
			
			if (key === 13)
				location.href = '/sok/' + $(this).attr('value');
		});
		$('.searchBox input.magnifyer').bind('click', function(e) {
			location.href = '/sok/' + $(this).parent().find('input.search').attr('value');
		});
		
		var divHeight = 0;
		$('.stdPadding.startBottomBoxes > div').each(function(){
			if($(this).height() > divHeight)
				divHeight = $(this).height();
		});
		
		$('.stdPadding.startBottomBoxes > div').each(function(){
			if(!$(this).hasClass('clearDiv'))
				$(this).height(divHeight);
		});
		
		$('#top').find('li').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		$('#top li').hover(function(){
			$(this).css('background-color', '#BE2D59');
		}, function(){
			if(!$(this).hasClass('active'))
				$(this).css('background-color', 'transparent');
		});
		$('.prevElementHeight').css('min-height', function(){
			return $(this).prev().outerHeight();
		});
		
		$('.productsContainer').find('li').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		
		$('.leftPageMenu ul > li').bind('click', function() {
			location.href = $(this).find('a').attr('href');
			return false;
		});
		
		$('.medierumPost').find('.commentIcon').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		
		$('.widget').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		
		$('.flavours li').bind('click', function() {
			location.href = $(this).find('a').attr('href');
		});
		
		$('.click-for-big-image').fancybox();

		$('.newsletterLink a').fancybox({
			width: 480,
			height: 490
		});
		
		$('.verticalCentered .centerThis').css("padding-top", function() {
			return ($('.verticalCentered').height() - $(this).height()) / 2;
		});
		
		$('.worldicecream-template .recipeDiv .right').css("margin-top", function() {
			return (70 - $(this).height()) / 2;
		});
		
		var orgHeight = $('.worldicecream-template .recipeHolder').height();
		if($('.recipeHolder .recipeDiv').length > 3)
			$('.worldicecream-template .recipeHolder').css('height', '220px');
		
		$('.worldicecream-template #seeMoreRecipes').click(function(){
			$('.worldicecream-template .recipeHolder').animate({'height': orgHeight});
			$(this).hide('slow');
		});
			
		
		var i = 0;
		var counter = 0;
		var parentwidth = 18;
		$('.flavSpinner .item').each(function(){
			if(counter % 4 == 0)
			{
				var div = $('<div/>');
				i == 0 ? $(div).addClass('button active') : $(div).addClass('button');
				$(div).attr('id', i);
				$('.spinnerController').append($(div));
				parentwidth += 18;
				i++;
			}
			counter++;
		});
		$('.spinnerController').css('width', parentwidth);
		
		$('.spinnerController .button').click(function(){
			$('.spinnerController .button.active').removeClass('active');
			var nr = $(this).attr('id');
			var leftValue = nr * -920;
			$('.flavSpinner .itemHolder').animate({'left': leftValue});
			$(this).addClass('active');
		});
		
		$('.breadCrumb .fill').css("width", function() {
			var width = 0;
			
			$('.breadCrumb').find('li').each(function(index, element) {
				width += $(element).width();
			});
			return $('.breadCrumb').width() - width;
		});
		
		while(true)
		{
			if ($('.breadCrumb').length == 0)
				break;
		
			if($('.breadCrumb').height() > 20)
			{
				$('.breadCrumb .fill').css("width", $('.breadCrumb .fill').width() - 1);
				break;
			}
			else
			{
				$('.breadCrumb .fill').css("width", $('.breadCrumb .fill').width() + 1);
			}
		}
		
		$('.leftPageMenu > ul > li:last, .allRecipe > ul > li:last, .otherBooks > li:last').addClass("last");
	    
    /* START RECEPISCRIPT */
		
		var allRecipeListHeight = $('.allRecipe').height();
		$('.allRecipe').css('height', '19px');
		$('.allRecipe').hover(
		function(){
			$('.allRecipe').addClass('out');
			$('.bookMenu .allRecipe table').css('display', 'block');
		},
		function(){
			$('.allRecipe').removeClass('out');
			$('.bookMenu .allRecipe table').css('display', 'none');
		});
		
		$('.allRecipe li').click(function(){
			$('.recipes li').css('display', 'none');
			$('.recipes > .' + $(this).attr('class')).css('display', 'block');
		});	
			
		var otherBooksListHeight = $('.otherBooks').height();
		$('.otherBooks').css('height', '19px');
		$('.otherBooks').hover(
		function(){
			$('.otherBooks').css('height', otherBooksListHeight);
			$('.otherBooks').addClass('out');
		},
		function(){
			$('.otherBooks').css('height', '19px');
			$('.otherBooks').removeClass('out');
		});
		
    	$('.printLink').click(function(){
      		window.open($(this).attr('href'),"Print recipe", "width=450, height=600");
      		return false;
    	});
		
		var emailRecipeHeight = $('.emailRecipeHeight').height();
		$('.emailRecipe').toggle(0);
		$('.emailLink').click(function(){
			$('.emailRecipe').toggle('fast');
			return false;
		});
		
		$('.turnPage').hover(
		function(){
			$(this).addClass('active');
		},
		function(){
			$(this).removeClass('active');
		});
		
		$('.turnPage').click(function(){
			location.href = $(this).find('a').attr('href');
		});
		
		$('.moreRecipes').find('li').each(function(){
			$(this).css('opacity', '0.65');
		});
		
		
		$('.moreRecipes li').hover(
		function(){
	    	$(this).find('.name').css('visibility', 'visible');
	    	$(this).find('.name').css('opacity', '1');
			$(this).css('opacity', '1');
		},
		function(){
			$(this).find('.name').css('visibility', 'hidden');
			$(this).find('.name').css('opacity', '0');
			$(this).css('opacity', '0.65');
		});
	    
	    $('.moreRecipes li').mousemove(function(e){
	    	$(this).find('.name').css('left', e.pageX + 13);
	    	$(this).find('.name').css('top', e.pageY - 4);
	    });
	    		
	    $('.moreRecipes .bookVersion li').mousemove(function(e){
	    	$(this).find('.name').css('left', e.pageX - (($(window).width() - 1000) / 2));
	    	$(this).find('.name').css('top', e.pageY - 184);
	    });

		
	   /* END RECIPESCRIPT */
	   
	   /* START RETROSCRIPT */
	   var mapCounter=[];
	   $('.leftArrow').css('display', 'none');
	   $('.arrow').css('opacity' , '0.6');
	   
	   $('.arrow').hover(function(){$(this).css('opacity', '1');}, function(){$(this).css('opacity', '0.6');});
	   
	   $('.retroMapContainer').each(function(indx){
	   	   
	   	   mapCounter.push(0);
	   	   $(this).find('.arrow').attr('rel', indx)
		   $(this).find('a').each(function(index){
		   	if(index > 1)
		   		$(this).parent().css('display', 'none');
		   });
	   });
	   
	   $('.arrow').css('top', function(){
	       return ($(this).parent().height() - 30) / 2;
	   });
	   
	   $('.rightArrow').click(function(){
	   	var me = $(this).attr('rel');
	   	var i = 0;
	   	mapCounter[me]++;
	   	   $(this).parent().find('a').parent().each(function(index){
	   	   	   switch(mapCounter[me])
	   	   	   {
	   	   	   	case index : $(this).css('display', 'block'); break;
	   	   	   	case (index - 1) : $(this).css('display', ''); break;
	   	   	   	default : $(this).css('display', 'none');	
	   	   	   }
	   	   	   i++;
	   	   });
	   	   if(mapCounter[me] >= (i - 2))
	   	   	$(this).css('display', 'none');
	   	   if(mapCounter[me] >= 1)
	   	    $(this).parent().find('.leftArrow').css('display', 'block');
	   });
	   
	   $('.leftArrow').click(function(){
	   	var me = $(this).attr('rel');
	   	var i = 0;
	   	mapCounter[me]--;
	   	   $(this).parent().find('a').parent().each(function(index){
	   	   	   switch(mapCounter[me])
	   	   	   {
	   	   	   	case index : $(this).css('display', 'block'); break;
	   	   	   	case (index - 1) : $(this).css('display', ''); break;
	   	   	   	default : $(this).css('display', 'none');
	   	   	   }
	   	   	   i++;
	   	   });
	   	   if(mapCounter[me] <= 0)
	   	   	$(this).css('display', 'none');
	   	   if(mapCounter[me] < i)
	   	    $(this).parent().find('.rightArrow').css('display', 'block');
	   });
	   /* END RETROSCRIPT */
	   
	   
	   /* 
	    if(($('#page').height() - $(window).scrollTop() - ($(window).height())) < 554)
	    {
	    	$(document.body).css({'background-position': 'center -700px', 'background-attachment': 'scroll'});
	    }
	    else{
	    	$(document.body).css({'background-position': 'center -300px', 'background-attachment': 'fixed'});
	    }
	    
	    
	    var backgroundImageHeight = 1907;
	    var backgroundContentAwareHeight = 354;
	    
	    var bottomBackground = ($('#page').height() - backgroundImageHeight);

	    var stdBackgroundVerticalPadding = backgroundImageHeight - ($(window).height()+backgroundContentAwareHeight);
	    //alert(stdBackgroundVerticalPadding);
	   */
	   /* $(window).scroll(function () {
	    	if(($('#page').height() - $(window).scrollTop() - ($(window).height())) < backgroundContentAwareHeight)
	    	{
	    		$(document.body).css({'background-position': 'left bottom' , 'background-attachment': 'scroll'});
	    		//alert(($('#page').height() - $(window).scrollTop()));
	    	}
	    	else
	    	{
	    		//alert('fdsaf');
	    		$(document.body).css({'background-position': '0px -'+stdBackgroundVerticalPadding+'px' , 'background-attachment': 'fixed'});
	    	}
      		//alert(($('#page').height() - $(window).scrollTop()));
      		//$("span").css("display", "inline").fadeOut("slow"); 
		});

		*/
		
	});
			
})(jQuery);


