$(function() {

	$("#latestNews div.nyhed:nth-child(even)").addClass("even");
	$(document).find("*:not(td)").pngFix();
	
	$('ul#uddLinks li a').hover(
		function(){
			$(this).stop().animate({paddingLeft: '5px'}, 200);
		}, function(){
			$(this).stop().animate({paddingLeft: '0px'}, 200);
		}			
	);
	
	// SHUFFLE LUFFLE FLUFFLE FLUFFER
	(function($){
  		$.fn.shuffle = function() {
    		return this.each(function(){
      			var items = $(this).children();
      			return (items.length)
        		? $(this).html($.shuffle(items)) : this;
    		});
  		}
 
  		$.shuffle = function(arr) {
    		for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
    		return arr;
  		}
	})(jQuery);
	
	// Shuffle 3 items, hide the rest
	var maxItems = 2;
	var newList = $.shuffle($('#annoncer .abox'));
	
	$('#annoncer').html('');
	for(var i=0; i<maxItems; i++) $('#annoncer').append(newList[i]);
	
	$('.abox').css("display", "inline"); //prevent showing all six before load
	
	
	
	// Gør cases til store links
	$('div.abox').css("cursor", "pointer");
	$('div.abox').click(function(){
		window.location = $('.abox .link a').attr("href");
	});
	
	
	function onBefore() { 
		$('#pager span').html("Loading..."); 
	} 
	function onAfter() { 
		$('#pager span').empty().append('<strong>' + this.alt + '</strong>'); 
	}

	if( $('table:first').is('table#p3786') ) {
		$('#topSlider').cycle({ 
			fx:     	'scrollLeft', 
			timeout:	 9000, 
			next:   	'#pager #next',
			prev:		'#pager #prev',
			speed:		1000,
			speedIn: 	1000, 
			speedOut: 	1000, 
			easing:		'easeOutBounce',
			pause: 		1,
			slideExpr: 	'span img',
			before:		onBefore,
			after:		onAfter
		});
	}

	$('a#tip').fancybox({
		'overlayShow'			: true,
		'overOpacity'			: 0.1,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack',
		'zoomOpacity'			: true
	});

});