$(function() {
	var prevVal;									
	
	$('input,textarea').click(function(){
		if($(this).attr('type')!=('radio')&&$(this).attr('type')!=('checkbox')){
			if(!$(this).hasClass('altered')){
				prevVal = $(this).val();
				$(this).data('value',prevVal);
				$(this).val('');
				$(this).addClass('altered');
			}
		}
	}).blur(function(){
		if($(this).attr('type')!=('radio')&&$(this).attr('type')!=('checkbox')){
			if($(this).val()==''){
					$(this).removeClass('altered');
					$(this).val($(this).data('value'));
				}
			}
	});
	
	$('#submitOrder').click(function(){
		var elem;
		var num;
		var pid;
		var products = "";
		$('input.field').each(function(){
			num = $(this).val();
			pid = $(this).attr('id');
			if(num>0)
				products = products + pid.substring(3)+"¤"+num+"#";
		});
		if(products.length==0){
			$('#shop').prepend('<b class="formError">Handlekurven er tom</b>');
			return false;
		}
		else{
			elem = '<input type="hidden" value="'+products+'" name="orderedProducts" />';
			$('#shop').append(elem);
		}
	});
	$('#slideshow').cycle({
		fx: 'fade',
		delay: 3000,
		speed:1000,
		fit:1,
		before: onBefore,
		after: onAfter
	});
	
	function onBefore(){
		$('.imageDesc').html('');
	}
	function onAfter(){
		$('.imageDesc').html('<i>'+this.alt+'</i>');
	}
	

	
	
	
	$('#datepicker').datepicker({
							dateFormat: 'yy-mm-dd',
							changeMonth : true,
							showOtherMonths : true,
							dayNamesMin: ['s', 'm', 't', 'o', 't', 'f', 'l'],
							monthNames: ['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'],
							monthNamesShort: ['Jan','Feb','Mar','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Des'],
							firstDay: 1
					});
	
		/*$('div[id^=toggle]').each(function(){
			$(this).css('display','none');
		});
		$('img[id^=toggle]').each(function(){
			$(this).css('display','block');
		});*/
	 // toggles the slickbox on clicking the noted link
	  $('div[id^=toggleBtn]').click(function() {
	  	
	  	$(this).toggleClass("active");
	  	if(	$(this).hasClass("active"))
	  		$(this).children('img').attr("src","/gfx/blog_right_arrow.png")
	  	else
	  		$(this).children('img').attr("src","/gfx/blog_down_arrow.png")
	    $('div#toggle').slideToggle(500);
	    return false;
	  });

});