/*
 * this file ist to controll the video player on tunnel.de
 * 07.02.2008 by dennis-boldt.de
 */

	// some variables to save
	var currentPosition;
	var lastSecond = false;
	var bannerStartet = false;
	var index = 0;

	// Offset to store the position
	var offset = 0;

	// 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];
		}
	};

	// send a command to the player
	function sendEvent(typ,prm) { 
		thisMovie("mpl").sendEvent(typ,prm); 
	};

	// Load the spezific video in the player
	function loadVideo(id){
		// store the y-position
		offset = window.pageYOffset;

		try
		{
			// Show the "jump back" button
			if (document.getElementById('back').style.display == "none"){
				document.getElementById('back').style.display = "";
			}

			// scroll to the top
			window.scrollTo(0,275);
		}
		catch(err)
		{
		//Handle errors here
		}


		// stop th player
		sendEvent('stop');

		// load the file in the player
		thisMovie("mpl").loadFile({file:'http://www.tunnel.de/media/video/flv/' + id + '.flv'}); 
		
		// count the click
		countClick(id);
	};

	// count the clicks on the video with ajax
	function countClick(id)
	{
		var http;
		if (window.XMLHttpRequest) {
			http = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}

		if (http != null) {
			http.open("GET", "inc/php/cnt.php?id=" + id, true);
			http.onreadystatechange = function() {};
			http.send(null);
		}
	};

	function goBack(){
		window.scrollTo(0,offset);
	};
