/* VIDEOPLAYER */

// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;
	var currentState = 0;
	var timeRemaining = -1;
	var videoPlayClicked = false;
	var sendVideoPlayClickedEvent = true;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };

	function getUpdate(typ,pr1,pr2,pid) {	
      
		if(typ == "time") { 
			currentPosition = pr1; 
			timeRemaining = pr2;	
			// added event to reset the videplayClick variable in event, when playing only one title, or something
			if (timeRemaining == 0 && videoItemFinishedEvent) {
				videoItemFinishedEvent(currentItem);
			}	
		}
		if(typ == "state") {					
			if (pr1 == 2 && !videoPlayClicked) {				
				// added event to receive on each page as "callback"
				if(videoPlayClickedEvent && sendVideoPlayClickedEvent) {
					videoPlayClickedEvent();
				}
				else if(sendVideoPlayClickedEvent){
					alert("Es konnte die Callbackmethode 'videoPlayClickedEvent' nicht gefunden werden. Diese muss implentiert werden, oder die Variable sendVideoPlayClickedEvent gesetzt werden.");
				}
				videoPlayClicked = true;
			}
			currentState = pr1; 			
		}
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") { 
			currentItem = pr1; 			
         currentPlayedVideoIndex = currentItem;
			//setTimeout("getItemData(currentItem)",100);
		}
		return;
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
		pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
		if(pid != "null") {
			document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
		}
	};

	// These functions are caught by the feeder object of the player.
	function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
	function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
	function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
	function getItemData(idx) {
		var obj = thisMovie("mpl").itemData(idx);
		/*
		var nodes = "";		
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}*/
		//document.getElementById("data").innerHTML = nodes;
	};

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

/* VIDEOPLAYER END */


/* RESIZE OF MAINDIV */
var layoutTimeout = null;
function doMainContainerResize() {
	if (!layoutTimeout) {
		layoutTimeout = window.setTimeout(function() {
			layoutTimeout = null;
			var currentHeight = $('body').height();			
			$('.mainScrollDiv').height(currentHeight - 97);
		}, 300);
	}	
}
$(document).ready(function(){	
	$(window).bind("resize", doMainContainerResize);
	doMainContainerResize();	// first resize on load
});
/* RESIZE OF MAINDIV END */

/* LIGHTBOX */
$(document).ready(function(){	
	$('a[@rel*=lightbox]').lightBox({
		imageBtnPrev : "js/jquery_lightbox/images/de/lightbox-btn-prev.gif",
		imageBtnNext : "js/jquery_lightbox/images/de/lightbox-btn-next.gif",
		imageBtnClose : "js/jquery_lightbox/images/de/lightbox-btn-close.gif",
		imageLoading : "js/jquery_lightbox/images/lightbox-ico-loading.gif"
	});
	$('a[@rel*=lightbox] > img').each(function() {
		var title = $(this).attr("title");
		var lastSl = title.lastIndexOf("/");
		if (title && lastSl > -1) {
			title = title.substring(0,lastSl);
		}
		else {
			title = "";
		}
		title += "Zum Vergrößern klicken"
		$(this).attr("title",title);
	});
});
/* LIGHTBOX END */

/* TABLES */

var currentPlayedVideoIndex = 0;

$(document).ready(function(){	
	$('#playWholeWeek').bind("click", function() {	
		videoPlayClicked = false;
		currentPlayedVideoIndex = 0;	
		sendEvent('playitem', 0);
	});	
	
	$('.tableVideoFavouriteRow').bind("click", function() {
		//var index = $(".tableVideoFavouriteRow").index(this);
		//alert("show detail of video number: " + index);
		var id = $(this).attr('id').split('_')[1];
		window.location = 'videodetail.php?id='+id;
	});
	
	
	// play item in playlist when clicking on xxx item
	$('.tableVideoRow').bind("click", function() {
		var index = $(".tableVideoRow").index(this);
		currentPlayedVideoIndex = index;
		var id = $(this).attr("id").split("_")[1];
		//alert("increment medium: " + id);
		$.post("incrementmovie.php?id="+id, function(data) { 
			// ignore callback
		});
		// reset global variable
		videoPlayClicked = true;
		sendEvent('playitem', index);
	});
	
	$('.tableVideoRow, .tableVideoFavouriteRow').hover(
		function() {
			$(this).css('background', '#F8DECF');	
		},
		function() {
			$(this).css('background', '#FFFFFF');
		}
	);
	
	
	/* ARTICLE */
	$('.tableArticleRow').bind("click", function() {		
		var id = $(this).attr('id').split('_')[1];
		window.location = 'detail.php?artnr='+id;
	});
	$('.tableArticleRow').hover(
		function() {
			$(this).css('background', '#F8DECF');	
		},
		function() {
			$(this).css('background', '#FFFFFF');
		}
	);		
	/* ARTICLE END */
   
   /* Markt*/
	$('.tableMarktRow').bind("click", function() {		
		var id = $(this).attr('id').split('_')[1];
		window.location = 'markt.php?ukatnr='+id;
	});
	$('.tableMarktRowAktWerbung').bind("click", function() {		
		window.location = 'archiv.php?searchWord=werbung&searchAction=1';
	});
	$('.tableMarktRow, .tableMarktRowAktWerbung').hover(
		function() {
			$(this).css('background', '#F8DECF');	
		},
		function() {
			$(this).css('background', '#FFFFFF');
		}
	);		
   
   $('.marketing').bind("click", function() {		
		var id = $(this).attr('id').split('_')[1];
		window.location = 'markt.php?artnr='+id;
	});
   $('.marketing').hover(
		function() {
			$(this).css('background', '#F8DECF');	
		},
		function() {
			$(this).css('background', '#FFFFFF');
		}
	);	
	/* Markt END */
	
});  

/* TABLES END */


