/*
 *	jQuery Crossfade plugin for background images v0.9
 *	Frederik Raabye [http://www.rostrapr.com]
 *  Depends on jQuery.timers by Blair Mitchelmore
 */
jQuery.fn.crossfade = function (imageLocation, images, speed, delay) {
	
	for(var i = 0; i<images.length; i++) { // Make browser preload images
  		jQuery("<img />").attr("src", imageLocation + images[i]);
	}
	
	
	return this.each(function () { 

		var item = jQuery(this);
		
		item.everyTime(delay, function() {
			
			var original_image = this.style.backgroundImage;
			var new_image = "url(" + imageLocation + images[Math.floor(Math.random()*images.length)] + ")";	
			
			while (new_image == original_image) {
				var new_image = "url(" + imageLocation + images[Math.floor(Math.random()*images.length)] + ")";					
			}
			
			item.animate({opacity: 0}, speed/2, function() {
				jQuery(item).css("background-image", new_image);
				//jQuery(item).css("background-image", "url(" + imageLocation + image +")");
			})
			.animate({opacity: 1}, speed/2, function() {});

	
      	});	
	}); 
      
};

jQuery(document).ready(function() {
	
	var imageLocation = 'http://solmedomtanke.dk/wp-content/themes/dsf/images/front/';
	
	if (jQuery('body#home #content-main').height) {
		var images = 		['Forside01.jpg','Forside02.jpg','Forside03.jpg','Forside04.jpg','Forside05.jpg','Forside06.jpg','Forside07.jpg','Forside08.jpg','Forside09.jpg','Forside10.jpg','Forside11.jpg'];
		jQuery('body#home #content-main').crossfade(imageLocation, images, 2000, 5000)	
	}
	

	
	if (jQuery("#subpage-container").height) {
		var containerHeight = jQuery("#subpage-container").height();
		var menuHeight = containerHeight-156-jQuery("#subpage-container ul").height();
		jQuery("#secondary-navigation").css({height: containerHeight});
	}
	
	jQuery('#quicklink-contact').after('<li id="quicklink-print"><a href="#print">Udskriv</a></li>');
	jQuery('#quicklink-print a').click(function() {
		window.print();
		return false;
	});
	
				
});