var idCounter = 0;
function openDiv(data,type,filetype) //data ist in den meisten faellen ein pfad
{
	
	//if (filetype)
	//{
	//	filetype = filetype.replace(' ','');
	//}
	if (filetype)
	{
		filetype = filetype.trim();
	}
	
	var openShowDivArr = getElementsByClass('showDiv');
	if (openShowDivArr.length > 0)
	{
		var openShowDiv = openShowDivArr[0];
		openShowDiv.parentNode.removeChild(openShowDiv);
	}
	
	//vertikale scrollpos herausfinden
	// ff/moz/netscape...
	if(window.pageYOffset != 0)
		var scrollY = window.pageYOffset;
	else
		var scrollY = 1;
	//ie..
	if(document.documentElement.scrollTop != 0)
		var scrollY = document.documentElement.scrollTop;
	else
		var scrollY = 1;
	
	var blackDiv = document.createElement('div');
	blackDiv.id = "blackDiv" + idCounter;
	blackDiv.style.position = "absolute";
	blackDiv.style.left = 0;
	blackDiv.style.top = 0;
	blackDiv.style.width = '99.5%';
	blackDiv.style.height = '300%';
	blackDiv.style.zIndex = 0;
	blackDiv.style.Opacity = 0.6;
	blackDiv.style.MozOpacity = 0.6;
	blackDiv.style.KhtmlOpacity = 0.6;
	blackDiv.style.filter = "alpha(opacity=" + 60 + ")";
	blackDiv.style.backgroundColor = "#000";
	blackDiv.style.backgroundRepeat = "no-repeat";
	blackDiv.style.border ="solid 1px black";
	blackDiv.className = "blackDiv";
	
	//erstellen des divs; killt sich selber wenn man
	//drauf klickt
	var rootDiv = document.createElement('div');
	rootDiv.id = "showDiv" + idCounter;
	rootDiv.style.position = "absolute";
	rootDiv.style.left = 38 + "px";
	rootDiv.style.top = scrollY + 83 + "px";
	rootDiv.style.zIndex = 9 + idCounter;
	rootDiv.style.backgroundColor = "#fff";
	rootDiv.style.backgroundRepeat = "no-repeat";
	rootDiv.style.cursor = "pointer";
	rootDiv.style.border ="solid 1px black";
	rootDiv.className = "showDiv";
	//rootDiv.innerHTML = "loading...";
	rootDiv.onclick = function ()
	{
		
		var obj = this.firstChild;
		if (obj.tagName != 'IMG')
			obj.innerHTML = "ruelps";
		
		this.parentNode.removeChild(this);
		blackDiv.parentNode.removeChild(blackDiv);
	};
	
	// p mit 'click to close'
	var closetext = document.createElement('p');
	closetext.id = closeid = "txt" + idCounter;
	closetext.className = "close";
	closetext.style.zIndex = 6 + idCounter;
	closetext.style.display = "none";
	closetext.style.backgroundColor = "#55BF00";
	closetext.style.color = "#fff";
	closetext.innerHTML = "[x]";
	//closetext.onclick = function ()
	//{
	//	var obj = rootDiv.firstChild;
	//	obj.innerHTML = "ruelps";
	//	rootDiv.parentNode.removeChild(rootDiv);
	//	blackDiv.parentNode.removeChild(blackDiv);
	//};
	
	//wenn ein bild angezeigt werden soll
	if (type == 'b')
	{
		var image = document.createElement('img');
		image.id = "img" + idCounter;
		image.className = "showimg";
		image.alt = data;
		image.src = data;
		image.style.zIndex = 6 + idCounter;
		image.onmouseover = function()
		{
			this.nextSibling.style.display = "block";
		}
		//image.onmouseout = function()
		//{
		//	this.nextSibling.style.display = "none";
		//}
	
		rootDiv.appendChild(image);
	}
	
	if (type == 't')
	{
		var text = document.createElement('p');
		text.id = "txtentry" + idCounter;
		text.className = "txt";
		text.style.zIndex = 6 + idCounter;
		text.style.width = '400px';
		text.style.padding = '20px';
		text.innerHTML = data;
		text.onmouseover = function()
		{
			this.nextSibling.style.display = "block";
		}
		//text.onmouseout = function()
		//{
		//	this.nextSibling.style.display = "none";
		//}
	
		rootDiv.appendChild(text);
	}
	
	if (type == 'a')
	{
		
		closetext.style.display = "block";
		var anim = document.createElement('p');
		anim.id = "animentry" + idCounter;
		anim.className = "anim";
		anim.style.zIndex = 6 + idCounter;
		//anim.style.width = '400px';
		anim.style.padding = '20px';
		anim.innerHTML = videoPlayer(data, filetype);
		//anim.onmouseover = function()
		//{
		//	this.nextSibling.style.display = "block";
		//}
		//anim.onmouseout = function()
		//{
		//	this.nextSibling.style.display = "none";
		//}
	
		rootDiv.appendChild(anim);
	}
	
	if (type == 's')
	{
		closetext.style.display = "block";
		
		var sound = document.createElement('p');
		sound.id = "soundentry" + idCounter;
		sound.style.zIndex = 6 + idCounter;
		sound.style.width = '300px';
		sound.style.padding = '10px';
		sound.style.backgroundColor = '#ccc';
		sound.innerHTML = soundPlayer(data);
		//sound.onmouseover = function()
		//{
		//	this.nextSibling.style.display = "block";
		//}
		//sound.onmouseout = function()
		//{
		//	this.nextSibling.style.display = "none";
		//}
	
		rootDiv.appendChild(sound);
	}
	
	if (type == 'i')
	{
		closetext.style.display = "block";
		
		var interaktiv = document.createElement('p');
		interaktiv.id = "interaktiventry" + idCounter;
		interaktiv.className = "interaktiv";
		interaktiv.style.zIndex = 6 + idCounter;
		interaktiv.style.width = '400px';
		interaktiv.style.padding = '20px';
		interaktiv.innerHTML = videoPlayer(data, filetype);
		//interaktiv.onmouseover = function()
		//{
		//	this.nextSibling.style.display = "block";
		//}
		//interaktiv.onmouseout = function()
		//{
		//	this.nextSibling.style.display = "none";
		//}
	
		rootDiv.appendChild(interaktiv);
	}
	
	
	rootDiv.appendChild(closetext);
	//$('contentdiv').appendChild(rootDiv);
	$('gallery').appendChild(rootDiv);
	$('gallery').appendChild(blackDiv);
	
	
}

function soundPlayer(data)
{
	return '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" align="middle" height="15" width="300">' +
	'<param name="allowScriptAccess" value="sameDomain">' +
	'<param name="movie" value="player/xspf_player_slim.swf?song_url=' + data + '&amp;song_title=' + basename(data) + '&amp;autoplay=true">' +
	'<param name="quality" value="high">' +
	'<param name="bgcolor" value="#cccccc">' +
	'<embed src="player/xspf_player_slim.swf?song_url=' + data + '&amp;song_title=' + basename(data) + '&amp;autoplay=true" quality="high" bgcolor="#e6e6e6" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" align="middle" height="15" width="300">' +	
	'</object>';
}

function videoPlayer(data, filetype)
{
	if (filetype == 'mov' || filetype == 'avi' || filetype == 'mpg')
	{
		var retValue = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="auto" height="auto" codebase="http://www.apple.com/qtactivex/qtplugin.cab">' +
		'<param name="src" value="' + data + '">' +
		'<param name="autoplay" value="true">' +
		'<param name="controller" value="true">' +
		'<param name="loop" value="false">' +
		'<embed src="' + data + '" width="400" height="300" autoplay="true" controller="true" loop="false" pluginspage="http://www.apple.com/quicktime/download/">' +
		'</embed>' +
		'</object>';
	}
	
	if (filetype == 'wmv')
	{
		var retValue = '<object id="mediaPlayer" width="400" height="300" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"' + 
		'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"' +
		'standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject">' +
		'<param name="fileName" value="' + data + '">' +
		'<param name="animationatStart" value="true">' +
      		'<param name="transparentatStart" value="true">' +
      		'<param name="autoStart" value="true">' +
      		'<param name="showControls" value="true">' +
      		'<param name="loop" value="false">' +
      		'<embed type="application/x-mplayer2" width="400" height="300"' +
       		'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/"' +
       		'id="mediaPlayer" name="mediaPlayer" displaysize="4" autosize="-1"' + 
       		'bgcolor="darkblue" showcontrols="true" showtracker="-1"' +
       		'showdisplay="0" showstatusbar="-1" videoborder3d="-1" ' +
       		'src="' + data + '" autostart="true" designtimesp="5311" loop="false">' +
		'</embed>' +
		'</object>';
	}
	
	if (filetype == 'swf' || filetype == 'dcr')
	{
		var retValue = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
        	'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="400" height="300"'  +
        	'>' +
        	'<param name="movie" value="' + data + '">' +
        	'<param name="quality" value="high">' +
        	'<param name="bgcolor" value="#FFFFFF">' +
        	'<param name="loop" value="false">' +
        	'<embed src="' + data + '" quality="high" bgcolor="#FFFFFF" width="400" height="300"' +
        	'loop="false" type="application/x-shockwave-flash"' +
        	'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">' +
        	'</embed>' +
        	'</object>';
	}
	
	if (filetype == 'gif')
	{
		var retValue = '<img src="' + data + '" alt="' + basename(data) + '" />';
	}
	
	if (filetype == 'flv')
	{
		var retValue = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="400" height="300" id="FLVPlayer">' +
		'<param name="movie" value="FLVPlayer_Progressive.swf" />' +
		'<param name="salign" value="lt" />' +
		'<param name="quality" value="high" />' +
		'<param name="scale" value="noscale" />' +
		'<param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName=' + cutExt(data) + '&autoPlay=true&autoRewind=false" />' +
		'<embed src="FLVPlayer_Progressive.swf" flashvars="&MM_ComponentVersion=1&skinName=Clear_Skin_3&streamName=' + cutExt(data) + '&autoPlay=true&autoRewind=false" quality="high" scale="noscale"' +
		'width="400" height="300" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
		'</object>';
	}
	
	if (retValue)
		return retValue;
	else
		return "die datei " + basename(data) + " kann leider nicht direkt angezeigt werden. verwende stattdessen den <a href='" + data + "'>downloadlink</a>";
}
function basename(path)
{
	var filename = path.split('/');
	if (filename.length == 1) {
	    var filename = path.split("\\");    
	}
	filename = filename[filename.length-1];
	return filename;
}

function cutExt(path)
{
	var size = path.length - 4;
	noExt = path.substring(0,size);
	return noExt;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

