$(function(){
	// Initialisierung Bildergalerie und Video in Overlay
	if ( $("ul.bilder").length > 0 ) {
		// Bildergalerie
		$("ul.bilder li a").fancybox({
			'overlayColor': '#000',
			'overlayOpacity': 0.77
		});
		
		// Flowplayer wird im Overlay geladen
		$("ul.video li a[rel]").overlay({
			top: '30%',
			mask: {
				color: '#000',
				loadSpeed: 100,
				opacity: 0.77
			},
			onLoad: function(content) {
				this.getOverlay().find("a.player").flowplayer(0).load();
			},
			onClose: function(content) {
				$f().unload();
			}
		});
		$("a.player").flowplayer("../../media/include/flowplayer-3.2.5.swf");
	}
	
	// Initialisierung automatischer Bildwechsel
	if ( $("ul.bilderstapel").length > 0 ) {
		setInterval( "daumenKino()", 3000 );
	}
	
	// Initialisierung Scrolling
	$("#scrollable").scrollable({
		speed : 400,
		items : '.produktbilder',
		
		// Nachdem gescrollt wurde
		onSeek : function () {
			$('.next').removeClass('initial');
		}
	});
	
});


// Automatischer Bildwechsel
function daumenKino() {
	var $alt = $('ul.bilderstapel li.obersteebene');
	
	if($alt.next().length) {
		var $neu = $alt.next();
	}
	else {
		var $neu = $('ul.bilderstapel li.erstesbild');
	}
	
	$alt.addClass('mittlereebene');
	$alt.removeClass('obersteebene');
	$neu.css({opacity: 0.0});
	$neu.addClass('obersteebene');
	
	$neu.animate({opacity: 1.0}, 1500, function() {
		$alt.removeClass('mittlereebene');
	});
}


// Anzeige von Flash Dateien
function ReWriteFlashExtended (id, url, width, height, version) {
	version = (version=='')?4:version;
	var flash = "";
	if (document.getElementById) {	
		if (document.getElementById(id)) {	
			flash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + version + ',0,2,0" width=' + width + ' height=' + height + '">';
			flash += '<param name="wmode" value="transparent">';
			flash += '<param name="movie" value=' + url + '>';
			flash += '<embed src="' + url + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>';
			flash += '</object>';
			document.getElementById(id).innerHTML = flash;
		}
	}
}
