$(document).ready(function(){
	$(".SP_module").each(function(){
		var $info, 
			$image, 
			$fadeLayer;
		
		
		function mOver() {
			if (jQuery.browser.msie) {
				$image.stop().animate({
					'opacity': 0.15
				}, 150, function() {
					// Animation complete.
					$fadeLayer.css({'z-index':'1000'});
				});
				$fadeLayer.css({'z-index':'1000'});
				$fadeLayer.stop().animate({
					'margin': 0 // trick IE to wait as delay() didn't work alright
				}, 50, function() {
					// Animation complete.
					$(this).animate({
						'opacity': 0
					}, 150, function() {
						// Animation complete.
						$(this).css({'z-index':'-1000'}); // put fadeLayer behind the link and make the link clickable
					});
				});
			} // end explorer workaround
			else {
				$image.clearQueue();
				$image.stop().animate({
					'opacity': 0.15
				}, 300, function() {
				});
				$info.clearQueue();
				$info.stop().delay(150).animate({
					'opacity': 1
				}, 250, function() {
					//Animation complete.
				});
			}
		}
		
		function mOut() {
			if (jQuery.browser.msie) {
				$fadeLayer.css({'z-index': '2000'});
				$fadeLayer.stop().animate({
					'opacity': 1
				}, 350, function() {
					// Animation complete.
				});
			}
			else {
				$info.clearQueue();
				$info.stop().animate({
					'opacity': 0
				}, 300, function() {
					// Animation complete.
				});
				$image.clearQueue();
				$image.stop().delay(150).animate({
					'opacity': 1
				}, 350, function() {
					// Animation complete.
				});
			}
		}
		
		if(!$(this).is('.SP_logo, .SP_news, .SP_mega')) {
			if($(this).find('.SP_video').length) {
				$image = $(this).find('div.SP_video');
			}			
			else {
				$image = $(this).find('div.SP_image');
			}
			$info = $(this).find('div.SP_info');
			/*
				workaround for IE, as it cannot handle text-transitions with clearType
				create a fading layer on top of the module
			*/
			if (jQuery.browser.msie) {
				if($(this).find('.SP_video').length) {
					$fadeLayer = $image.clone().appendTo(this).css({ 'position': 'absolute', 'top': 0, 'left': 0, 'z-index': 2000, 'background': '#fff' });
					$fadeLayer.removeClass('SP_video').addClass('fadeLayer');
					$info.css({ 'visibility': 'visible' });
				}
				else {
					$fadeLayer = $image.clone().appendTo(this).css({ 'position': 'absolute', 'top': 0, 'left': 0, 'z-index': 2000 });
					$fadeLayer.removeClass('SP_image').addClass('fadeLayer');
					$info.css({ 'visibility': 'visible' });
				}
			}
			$(this).hover(mOver,mOut);
		}
	});
	
	/* add scaling background to all browsers not supporting background-size (CSS3) */
	/*
	if('MozBackgroundSize' in document.body.style == false && 'WebkitBackgroundSize' in document.body.style == false && 'BackgroundSize' in document.body.style == false) {
		//$('body').prepend('<div id="bg"><img style="display: block;" src="/BackgroundImage.axd"></div>');
	}
	*/
});