// JavaScript Document


var videoheight=540;
var elmheight=300;

var activeplayer=null;


$(document).ready(function()
{
	
		
	
	$(".studielm .bildlink").click(function(e){
		e.preventDefault();
		var studielm=$(this).parents(".studielm");
		var container=studielm.children(".container");
		closeAllElements();
		showVideo(studielm);
	});
		
	
	$(".studielm .textlink").click(function(e){
		var studielm=$(this).parents(".studielm");
		var container=studielm.children(".container");
		closeAllElements();
		showZusatzAjax(studielm);	
	});
	
	
	$(".studielm .videolink").click(function(e){
		var studielm=$(this).parents(".studielm");
		var container=studielm.children(".container");
		closeAllElements();
	});
	
	$(".studielm .zusatzlink").click(function(e){
		var studielm=$(this).parents(".studielm");
		var container=studielm.children(".container");
		$("#mainwrapper").scrollTo({top:studielm.attr("number")*elmheight},300);
		closeAllElements();
	});
	
	
	$(".left, .right, .bottom .minititle, .top .minititle").mouseover(function(e){
		$(this).find(".normal").hide();
		$(this).find(".over").show();
		
	});
	$(".left, .right, .bottom .minititle, .top .minititle").mouseout(function(e){
		$(this).find(".normal").show();
		$(this).find(".over").hide();
	});
	
	
	
	function closeAllElements(){
		
		
		
		if(activeplayer!=null){
			activeplayer.hide();
			activeplayer.stop();
		}
		
		$(".zusatz").html("");
		
		$(".studielm").attr('isopen',0);
		$(".studielm .container").animate({
		 	left:"0px",
			top:"0px",
		 },300);
		 $(".studielm").animate({
			height:"300px",
		},300, function(){
			if(activeplayer!=null){
				activeplayer.unload();
				
		
		}
		});
		
		
	}
	
	
	function showVideo(studielm){
		
		
	
		var container=studielm.find(".container");
		studielm.stop();
		container.stop();
		
		
	
		
		studielm.animate({
			height:videoheight,
		},300);
		container.animate({
			top:videoheight+"px",
		},300, function() {	
			activeplayer=$f(parseInt(studielm.attr("number")));
			activeplayer.play();

		});
		
		$("#mainwrapper").scrollTo({top:studielm.attr("number")*elmheight},300);
	
	}
	
	function showZusatz(studielm){
		var container=studielm.find(".container");
		var bottom=container.find(".bottom");
		
		studielm.stop();
		container.stop();
		
		studielm.animate({
			height:(bottom.height()+20)+"px",
		},300);
		container.animate({
			top:"-300px",
		},300);
		
		$("#mainwrapper").scrollTo({top:studielm.attr("number")*elmheight},300);
		
		
		
		//$("#mainwrapper").scrollTo(studielm,300);
	}

	
	
	function showZusatzAjax(studielm){
		var container=studielm.find(".container");
		var bottom=container.find(".bottom");
		var zusatz=container.find(".zusatz");
		var id=studielm.attr("id");
		
		studielm.stop();
		container.stop();	
		
		$("#mainwrapper").scrollTo({top:studielm.attr("number")*elmheight},300);
		container.animate({
				top:"-300px",
		},300);
		
		zusatz.html("am laden...");

		
		$.post("ajaxview", { viewfile: "contentmodule/studiajax", contentid:id  },
  		 function(data) {
     		zusatz.html(data);
			zusatz.find('img').batchImageLoad({
				loadingCompleteCallback: function(){
				
				studielm.animate({
				height:(bottom.height()+20)+"px",
				},300);
				},
				
			
			});
			
							
			
			
			
			
			
			
			
			
			
			
			flowplayer("div.smallPlayer", "vendor/flowplayer/flowplayer-3.2.7.swf", {
			// this is the player configuration. You'll learn on upcoming demos.
			
			clip: {
				
				// these two configuration variables does the trick
				autoPlay: false, 
				autoBuffering: true, // <- do not place a comma here  
				scaling: "fit"
			},	
			});
	
			
			
		});	
	}	
	
	// a- tags with class "myPlayer" are transformed into video players
	flowplayer("a.studiPlayer", "vendor/flowplayer/flowplayer-3.2.7.swf", {
	// this is the player configuration. You'll learn on upcoming demos.
	
	clip: {
		
		// these two configuration variables does the trick
		autoPlay: false, 
		autoBuffering: false, // <- do not place a comma here  
		scaling: "fit"
		
	},
	
	
	plugins:  {	
		
		controls:  {
			volume: false,	
			backgroundGradient: 'none',
			backgroundColor: 'transparent',
			all:false,
			fullscreen:true,
			
			
		}
		
		
	}
	
	});
	
	
	flowplayer("div.smallPlayer", "vendor/flowplayer/flowplayer-3.2.7.swf", {
	// this is the player configuration. You'll learn on upcoming demos.
	
	clip: {
		
		// these two configuration variables does the trick
		autoPlay: false, 
		autoBuffering: true, // <- do not place a comma here  
		scaling: "fit"
	},	
	});
	
	
	

	Cufon.replace('h1', {
		fontFamily: 'Graphik Medium' ,
		
	});

	Cufon.replace('h2', {
		fontFamily: 'Graphik Regular' ,
		
	});
	
	
	Cufon.replace('.graphikreg', {
		fontFamily: 'Graphik Regular',
	});
	
	Cufon.replace('.graphikmed', {
		fontFamily: 'Graphik Medium',
	});
	
	Cufon.replace('.indented_menu', {
		fontFamily: 'Graphik Regular',
		hover:true,
	});
	Cufon.replace('.indented_menu .selected', {
		fontFamily: 'Graphik Medium',
		hover:true,
	});
	
	
	Cufon.replace('#navi .supertitle', {
		fontFamily: 'Graphik Medium',
		hover:true,

	});
	
	
	
	
	
	
});


