  
/**
 * globaler jQuery-Initblock
 * @project ESMT
 * @sincs jQuery 1.3.x
 * @internal
 *		- CrossSlide (0.3.7) mit piMicroPimp
 *		- UIAccordion (1.7.2)
 *		- piStagesSwitch (0.1.2) 
 *		- piFounderSwitch (0.1.2) 
 * @ToDo
 * - alles in ein Object packen?
 * - Mehrsprachigkeit?
 */

//CMS sollte diesesen Teil befüllen
var aBilder = ['pictures/stage_students.jpg', 'pictures/stage_library.jpg', 'pictures/stage_stairs.jpg','pictures/100_3940.jpg','pictures/100_3940.jpg'];


var iStageID	= 1;			//aktueller Stage
var bStageRun	= false;		//stages laufen
var iTimer		= 0;			//timerhandle
var tPlaytime	= 8000; 		//anzeigedauer je Spot
var iStageMax	= 0;			//Anzahl der Stages

var iFounderID		= 1;		//aktueller Founder
var bFounderRun	= false;	//stages laufen
var iFounderTimer = 0;		//timerhandle
var tFounderTime	= 5000; 	//anzeigedauer je Founder
var iFounderMax	= 0;		//Anzahl der Founder
var FounderPLAY	= "-0px -162px";  //vs. const sch... IEs
var FounderPAUSE	= "-16px -162px"; //vs. const sch... IEs

/* ~~~~~~~~~~~~ Stages ~~~~~~~~~~~ */

/**
 * piStagesSwitch: schaltet die Stages der Reihe nach durch 
 * @see tPlaytime, iStageID, bStageRun, iTimer
 * @calling itself 4 ever ;)
 */
var stSwitch = function() {

	if (bStageRun)
	{
		//0 means per automatic
		setStage(0);
		iTimer = window.setTimeout("stSwitch()", tPlaytime);
	}

}
/* piStagesSwitch: Start/Stop */
var stRun = function() {

	bStageRun = !bStageRun;

	if (bStageRun)
	{
		$(".buttonPlay").css({backgroundPosition: "0px -20px" });
		iTimer = window.setTimeout("stSwitch()", tPlaytime);
	}
	else
	{
		$(".buttonPlay").css({backgroundPosition: "0px 0px" });
		window.clearTimeout(iTimer);
	}
}
/**
 * piStagesSwitch: Stage aktieren: alle a-inactiv + this-a-activ, infolayer aus + datenlayer an;  bookmarkicon
 * @param i Integer Nummer des Datenblocks; 0=automaisch interner call
 */
var setStage = function (i) {

	if (i==0)
		iStageID = (iStageID<iStageMax ? iStageID+1 : 1);
	else
		iStageID = i;

	window.status = "setStage Parm: "+i+" macht "+iStageID;

	//A) wenn Handauslösung: stop den Timer 1st
	if (i && bStageRun) stRun();

	//B) die 4 Button: activ-Status wechseln
	$(".sta").children().removeClass("active");
	// - sich selber aktivieren
	$("ul.buttons > li.sta:eq("+(iStageID-1)+")").children().addClass("active");

	//C) die 4 Inhalsblöcke: alle layer verstecken
	//$("div.infolayer").slideUp("fast");
	$("div.infolayer").fadeOut(1500);	
	// - aktuellen layer zeigen
	//$("div.stage > div.infolayer:eq("+(iStageID-1)+")").slideToggle("fast");
	$("div.stage > div.infolayer:eq("+(iStageID-1)+")").fadeIn(1500);

	//D) die 4 passenden bookmarkicons:
	//- das Icon oben soll sich auch noch ändern
	// Änderungen afi, die bookmarkicons müssen auch versteckt und dann angezeigt werden
	//$(".bookmarkicon").css({backgroundPosition: "-"+((iStageID-1)*24)+"px 0px" });
	$(".bookmarkicon").fadeOut(0);
	$(".bookmarkicon:eq("+(iStageID-1)+")").fadeIn(0);

	//E) die 4 Slider je Thema: alle verstecken
	//$(".allSlides").slideUp("fast");
	$(".allSlides").fadeOut(1500);
	// - aktuellen zeigen
	//	$("div.stage > div.allSlides:eq("+(iStageID-1)+")").show("slow");
	$("div.stage > div.allSlides:eq("+(iStageID-1)+")").fadeIn(1500);	

	//debug
	window.status = "S: "+iStageID+" P: "+ $(".bookmarkicon").css("background-position");
	

}

/* ~~~~~~~~~~~~ Founder ~~~~~~~~~~~ */

var foSwitch = function() {

	iFounderID = (iFounderID<iFounderMax ? iFounderID+1 : 1);

	if (bFounderRun)
	{
		$("#founderCounter").html(iFounderID+' / '+iFounderMax);
		
		if (iFounderID)
		{
			$(".conFon").hide();
			$("div.boxFounders > div.conFon:eq("+(iFounderID-1)+")").show();
			//$("#conFon"+iFounderID).show();
		}
		else
			$("#conFon1").show(); 

		iFounderTimer = window.setTimeout("foSwitch()", tFounderTime);
	}
}

var foRun = function() {

			bFounderRun = !bFounderRun;

			if (bFounderRun)
			{
				 $("#founderStopPlay").css({ backgroundPosition: FounderPAUSE });
				 $("#founderVor").hide();
				 $("#founderWeiter").hide();
				 iFounderTimer = window.setTimeout("foSwitch()", 2000);
			}
			else
			{
				window.clearTimeout(iFounderTimer);
				$("#founderVor").show();
				$("#founderWeiter").show();
				$("#founderStopPlay").css({ backgroundPosition: FounderPLAY });
			}

}

var foForward = function() {

	iFounderID = (iFounderID>1	?	iFounderID-1	:	iFounderMax);
	$("#founderCounter").html(iFounderID+' / '+iFounderMax);

	window.status = " sind in Stage: " + iFounderID;
	$("div.boxFounders > div.conFon").hide();
	$("div.boxFounders > div.conFon:eq("+(iFounderID-1)+")").show();
}
var foNext = function() {

	iFounderID = (iFounderID<iFounderMax	?	iFounderID+1	:	1);
	$("#founderCounter").html(iFounderID+' / '+iFounderMax);

	window.status = " sind in Stage: " + iFounderID;
	$("div.boxFounders > div.conFon").hide();
	$("div.boxFounders > div.conFon:eq("+(iFounderID-1)+")").show();
}

    /* Bildunterschriften in der CenterBox auf Bildbreite anpassen und umbrechen */
    $(window).load(function() {
        $(".contentBoxMov").each(function(){
          var bildbreite = $(".contentBoxMov").children("img").width();
          var bildhoehe = $(".contentBoxMov").children("img").height();
          if(bildbreite<5){
            bildbreite = $(".contentBoxMov").children("a").children("img").width();
            bildhoehe = $(".contentBoxMov").children("a").children("img").height();
          }
          $(".contentBoxMov").children("a").css("width",bildbreite);
          $(".contentBoxMov").children("a").css("height",bildhoehe);
          var bildbreite = bildbreite + 6;
          var bildhoehe = bildhoehe + 15;
          $(this).css("width",bildbreite);
          $(this).parent().css("min-height",bildhoehe);
        });    
      }); 

/* Bildunterschriften im Video auf Bildbreite anpassen und umbrechen */
$(window).load(function() {
    $(".contentVideo").each(function(){
      var bildbreite = $(this).children("a").children("img").attr("width");
      var bildbreite = bildbreite + 6;
      $(this).parent("div").css("width",bildbreite);
    });    
  });


/* jINTI starts here */
$(document).ready(function(){

			// rss Button Hover Funktion
			$(".rssfeed").hover(
			  function () {
        			$(this).children('span').css('background-image','url(/fm/244/icon_rss_a.gif)');
			  }, 
			  function () {
				$(this).children('span').css('background-image','url(/fm/244/icon_rss_na.png)');
			  }
			);
			
			// delete "Search" from Searchfield
			jQuery("#Search").click( function (){
			  if(jQuery("#Search").attr("value") == "Search") 
			   jQuery("#Search").attr("value","");
			});
		// Accordion
			$("#accordion").accordion({ header: "h2", autoHeight: false, animated: false  });
            $("#accordionContent").accordion({ header: "h2", collapsible: true, active: false, autoHeight: false, animated: false }); 
            $(".additionlaccordion").accordion({ header: "h2", autoHeight: false, animated: false  }); 
			//Maximum setzen
			iStageMax	 =  $('.stage > .infolayer').size();
			//init: den ersten gleich anzeigen
		   $("#cslide1").show();
			//piStagesSwitch: per Hand
			$("#st1").click(function(){
				  setStage(1);
			});
			$("#st2").click(function(){
 				   setStage(2);
			});
			$("#st3").click(function(){
				   setStage(3);
			});
			$("#st4").click(function(){
				   setStage(4);
			});
			$("#stStartStop").click(function(){
				stRun();
			});
			//init: Stage-1 aktivieren...
			$("#st1").click();
			//... und Start des Zaubers (Timer)
			stRun();

		
		//customSelect
		$("#quickSearch select").custSelectBox({alldisabled: false, hoverstyle:	"hover"});

		//customSelect: piAddons - jump & colorized
		$("ul.selectboxoptions_radio > li").click(function(){
				//alert('Beep');
				var to = $("span.elmValue",this).html();
				if (to != "#")
					window.location.href = to;
		});
		$("span.elmValue:contains('#')").parent().css({fontWeight: "bold"});
		
		
		
		
			//Foundersbox:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			iFounderMax =  $('.boxFounders > .conFon').size();
			$("#founderStopPlay").click(function(){
					foRun();
			});

			$("#founderVor").click(function(){
					foForward();
			});
			$("#founderWeiter").click(function(){
					foNext();
			});
			//init
			$("#founderCounter").html('1 / '+iFounderMax);
			$("div.boxFounders > div.conFon:eq(0)").show();
			//hier: den Timer starten
			foRun();

			//Flowplayer			
			// $f("a.player", "https://static.esmt.org/player/flowplayer/flowplayer.commercial-3.1.0.swf",  { 
			//$f("a.player", "/en/flowplayer-3.1.0.swf",  { 
			$f("a.player", "https://static.esmt.org/player/flowplayer/flowplayer.commercial-3.1.0.swf",  { 
					plugins:  { controls:  { backgroundColor: '#333333',  backgroundGradient: 'low', all: false,  play: true, time: true, scrubber:true,  mute:true, fullscreen: true,  height:25,  progressColor: '#999999', bufferColor: '#333333', opacity: 0.5, autoHide: 'always' }},
					clip: {  
                                          scaling: 'fit',
					  onFinish: function() {  
						this.getScreen().fadeOut(3000); 
					  } 
					},
					key: '#@e42bd5f2444e209cf25'
    	   });
jQuery('#moreEventsB').toggle(function() { 
    jQuery('#moreEvents').show(); 
    }, function() { 
      jQuery('#moreEvents').hide(); 
    }); 

	$(".pubsearch .results ul").each(function(){
		if($(this).text().trim() == ""){
			$(this).hide();
			$(this).prev().hide();
		}
	})

});

