/**
 * Mediaplayer
 */

function Mediaplayer(swfplayerUrl, width, height, localizedTagsTitle, mediapath, screencolor, baseUrl) {
	this.swfplayerUrl = swfplayerUrl;
	this.height = height;
	this.localizedTagsTitle = localizedTagsTitle;
	this.mediapath = mediapath;
	this.baseUrl = baseUrl;	
	
	this.swf = new SWFObject(swfplayerUrl,'mediaplayer', width, height, '8');
	this.swf.addParam('allowfullscreen','false');
	this.swf.addVariable('screencolor', screencolor);
	this.swf.addVariable('width', width);
	this.swf.addVariable('height', height);
	
}

/**
 * Medien-Object wechseln
 */
Mediaplayer.prototype.changeMedia = function (titel, subtitel, desc, path, typ, autostart, updateUsage) {
	if (updateUsage) {
		this.updateCounter(path);
	}

	document.getElementById('title').innerHTML = titel;
	document.getElementById('sub_title').innerHTML = subtitel;
	document.getElementById('description').innerHTML = desc;

	this.swf.addVariable('autostart', autostart);
	this.swf.addVariable('file', this.mediapath+path);
	
	if (typ == "video") {
		this.swf.addVariable('shownavigation','true');
		this.swf.addVariable('showicons','true');
		this.swf.addVariable('linkfromdisplay', 'false'); 
		this.swf.addVariable('image','');
	} else if (typ == "photo"){
		//chemicals-html escapen		
		if (titel){
			titel = titel.replace(/</g,'&lt;');
			titel = titel.replace(/>/g,'&gt;');
			titel = titel.replace(/"/g,'&quot;');
		}
		
		var imageLink = 'javascript:'
			+'var imageLink = document.createElement(\'a\');'
			+'imageLink.setAttribute(\'href\', \''+this.mediapath+path+'\');'
			+'imageLink.setAttribute(\'title\', \''+titel+'\');'
			+'imageLink.setAttribute(\'rel\',\'lytebox\');'
			+'myLytebox.start(imageLink, false, false);';
		this.swf.addVariable('link', imageLink);
		this.swf.addVariable('linktarget', '_self'); 
		this.swf.addVariable('linkfromdisplay', 'true'); 
		this.swf.addVariable('shownavigation','false');
		this.swf.addVariable('showicons','false');
		this.swf.addVariable('image','');
	} else {
		this.swf.addVariable('shownavigation','true');
		this.swf.addVariable('showicons','true');
		this.swf.addVariable('image', this.baseUrl + '/images/icon_mp3_big.gif');
		this.swf.addVariable('linkfromdisplay', 'false'); 
	}

	this.swf.write('container');
	
};

Mediaplayer.prototype.updateCounter = function(path){
	if (path != '') {
		var xmlHttp = false;
		
			// Mozilla, Opera, Safari sowie Internet Explorer 7
		if (typeof(XMLHttpRequest) != 'undefined') {
		   	xmlHttp = new XMLHttpRequest();
		}
		
		if (!xmlHttp) {
		   // Internet Explorer 6 und älter
		    try {
		        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch(e) {
		        try {
		            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
		        } catch(e) {
		            xmlHttp  = false;
		        }
		    }
		}
		
		if (xmlHttp) {
		    xmlHttp.open('GET', this.baseUrl + '/incl/mediathek/mediaobjectcounter.php?path=' + path, true);
		    xmlHttp.onreadystatechange = function () {
		        if (xmlHttp.readyState == 4) {
		            xmlHttp.responseText;
		        }
		   	};
		   	xmlHttp.send(null);
		}
	}
};