/**
	Author: mizi
	Version: v 1.0
	Description: Hängt einen window.onload Event in die schon bestehende Kette um keine window.onload Events von außen zu überschrieben.
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function writeFlashPlayerStat(userID, time, movieID, sessionID){
	/*
	document.getElementById("time").innerHTML = userID+" "+time+" "+movieID+" "+sessionID;
	var url = 'userID='+userID+'&time='+time+'&movieID='+movieID+'&sessionID='+sessionID;
	var myAjax = new Ajax.Request("php/saveStatistik.php", { method: 'post', parameters: url, onComplete: confimStat});
	*/
}

function confimStat(){
}

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); };
function removeItem(idx) { thisMovie("mpl").removeItem(idx); };
function getLength() { return thisMovie("mpl").getLength(); };
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,swf) {
	document.getElementById("playerUpdate").innerHTML = typ+" "+pr1+" "+pr2+" "+swf;
	
	//Do special operations at certain events
	operations(typ,pr1,pr2,swf);
};

function operations(typ,pr1,pr2,swf){
	//Wenn das zutrift, dann ist die Playlist fertig gespielt
	if(typ == "item" && pr1 == 0 && typeof pr2 == "undefined" && play == true){
		removeAdVideo();
	}
}

function init_flash(path,hoch,breit){
	var s2 = new SWFObject(path + "flvplayer/flvplayer.swf","mpl",hoch,breit,"7");
	
	s2.addParam("allowfullscreen","true");
	for(var i = 0; i < vars.length; i++ ){
		var help = vars[i];
		var help_array = help.split("|");
		var variable = help_array[0];
		var value = help_array[1];
		eval(s2.addVariable(variable,value));
	}
	
	s2.addParam("wmode", "transparent");
	s2.write("flashPlayer");
	
	window.setTimeout("includeAdVideo()", 1000);
}

/*** AdTags Functions ***/
function includeAdVideo(){
	try {
		//First Video
		if( typeof PreAdURL != "undefined" && PreAdURL != "" && typeof PreAdLINK != "undefined" && PreAdLINK != "") {
			addItem({file:PreAdURL, title:'Intro', link:PreAdLINK},0);
		}
		//Second Video
		if( typeof PostAdURL != "undefined" && PostAdURL != "" && typeof PostAdLINK != "undefined" && PostAdLINK != "" ) {
			addItem({file:PostAdURL, title:'Intro', link:PostAdLINK},2);
		}
		sendEvent('playpause');
		play = true;
	} catch(e) {
		window.setTimeout("includeAdVideo()", 1000);
	}
}

function removeAdVideo(){
	window.setTimeout("removeAdVideoPre()", 0);
	window.setTimeout("removeAdVideoPost()", 1000);
}

function removeAdVideoPre(){
	if( typeof PreAdURL != "undefined" && PreAdURL != "" && typeof PreAdLINK != "undefined" && PreAdLINK != ""){
		removeItem(0);
		PreAdURL = "";
		PreAdLINK = "";
	}
}

function removeAdVideoPost(){
	if( typeof PostAdURL != "undefined" && PostAdURL != "" && typeof PostAdLINK != "undefined" && PostAdLINK != "" ){
		removeItem(1);
		PostAdURL = "";
		PostAdLINK = "";
	}
}
/*** AdTags Functions END ***/

/**
	Author: mizi
	Version: v 1.0
	Description: Adds the init_flash() function to the window.open queue
*/
//addLoadEvent ( function(){
jQuery(function() {
	if( typeof VideoWIDTH == "undefined" || VideoWIDTH == "") {
		VideoWIDTH = 462;
	}
	if( typeof VideoHEIGHT == "undefined" || VideoHEIGHT == "") {
		VideoHEIGHT = 370;
	}
	if( typeof VideoPATH == "undefined" || VideoPATH == "") {
		VideoPATH = 'http://www.kleinezeitung.at/mmt/';
	}
	init_flash(VideoPATH,VideoWIDTH,VideoHEIGHT);
});
