// JavaScript Document

var slideshowarray = [];
var aktuellesslide = 0;
var fullmediaAktuell = "blabla";

var bildx;
var bildy;
//var bildx = 8 + xKorrektur;
//var bildy = 225 + yKorrektur;
var bildbreite = 765;
var bildhoehe = 310;

function adclick_refresh(){
		//alert(spon_vdz_src);
		frames['spon_vdz'].location.href = spon_vdz_src;
	}

function aslshow(aslurl){
	var tbl = document.getElementById('fullmedia');
	
	var myfullMediaName = "asl"; 
	if(fullmediaAktuell != myfullMediaName){
		del_fullmedia();
	}
	
	if(!tbl.rows.length){ // Tabelle ist nicht offen
		fullmediaAktuell = myfullMediaName;
		//window.location.href = "#navAnker";
	
		tbl.style.marginTop = "4px";
		tbl.style.width = "500px";
		tbl.style.height = "353px";
		tbl.style.background = "#F2F2F2";
		tbl.style.border = "solid black 1px";
		
		// if there's no header row in the table, then iteration = lastRow + 1
		var lastRow = tbl.rows.length;
		var iteration = lastRow +1;
		var row = tbl.insertRow(lastRow);
		// right cell
		var cell_1 = row.insertCell(0);
		//cell_1.style.width = "448px";
		
	}
	
	var flashhtml = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"500\" height=\"353\" id=\"audioSlideShow\" align=\"middle\">\n";
	flashhtml += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />\n";
	flashhtml += "<param name=\"movie\" value=\"/bilder/home/audioSlideShow.swf"+aslurl+"\" />\n";
	flashhtml += "<param name=\"salign\" value=\"lt\" />";
	flashhtml += "<param name=\"quality\" value=\"high\" />\n";
	flashhtml += "<param name=\"scale\" value=\"noscale\" />";
	flashhtml += "<param name=\"wmode\" value=\"transparent\">";
	flashhtml += "<embed src=\"/bilder/home/audioSlideShow.swf"+aslurl+"\" quality=\"high\" bgcolor=\"#ffffff\" width=\"500\" height=\"353\" name=\"audioSlideShow\" align=\"middle\" allowScriptAccess=\"sameDomain\" wmode=\"transparent\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
	flashhtml += "</object>\n";
	
	tbl.rows[0].cells[0].innerHTML = flashhtml;
}


function beitraglinksbauen(id,tbl){
	
	var rand = Math.random();
	//var requesturl = "linkdump_1.php?id="+id+"&r=" + rand;
	var requesturl = "linkdump_2.php?id="+id+"&linktbl="+tbl+"&r=" + rand;
	var linkhtml = "";
	//debug(requesturl);
	var linkrequest = GXmlHttp.create();
	linkrequest.open("GET", requesturl, true);
	linkrequest.onreadystatechange = function() {
		if (linkrequest.readyState == 4) {
			var linkxmlDoc = linkrequest.responseXML;
			var linkxmlnodes = linkxmlDoc.documentElement.getElementsByTagName("link");
			
			for (var i = 0; i < linkxmlnodes.length; i++) {
				
				var linkurl = linkxmlnodes[i].getAttribute("linkurl");
				var linkname = linkxmlnodes[i].getAttribute("linkname");
				linkhtml += "<a href=\"http://"+linkurl+"\" target=\"_blank\">"+linkname+"</a><br>";
			}
			
			var tbl = document.getElementById('links');
			
			if(!tbl.rows.length){
				tbl.style.marginTop = "10px";
				
				var lastRow = tbl.rows.length;
				var iteration = lastRow +1;
				var row_0 = tbl.insertRow(lastRow);
				var cell_00 = row_0.insertCell(0);
				cell_00.cssClass = "font_toolbarheader";
				//cell_1.style.width = "448px";
				var header = "<table width=\"100%\" height=\"20\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"margin-bottom:2px;\"><tr bgcolor=\"#DFDFDF\"><td bgcolor=\"#DFDFDF\" class=\"font_toolbarheader\" style=\"padding-left:10px;\">";
				header += "BEITRAG LINKS";
				header += "</td></tr></table>";
				cell_00.innerHTML = header;
				
				var lastRow = tbl.rows.length;
				var iteration = lastRow +1;
				var row_1 = tbl.insertRow(lastRow);
				var cell_10 = row_1.insertCell(0);
			}
			
			var tablebodyhtml = "<table width=\"100%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" bgcolor=\"#F0F0F0\" ><tr><td align=\"left\" class=\"home_fliesstext\">";
			tablebodyhtml += linkhtml;
			tablebodyhtml += "</td></tr></table>";
			tbl.rows[1].cells[0].innerHTML = tablebodyhtml;
			
		}	
	}
	linkrequest.send(null);

}

function divInhalt(inhalt, divname) {
	if (document.all) // Internet Explorer ab 4
    	document.all(divname).innerHTML = inhalt;
		//document.all("vorschlagFeld").innerHTML = "<h1>"+inhalt+"</h1>";
  	else if (document.getElementById) // Netscape 6, Opera
    	document.getElementById(divname).innerHTML = inhalt;
  	else if (document.layers) // Netscape 4
   		with (document.layers[divname].document) {
      		open();
      		write("geladen");
      		close();
    }
	<!-- alert(testvar); -->
}

function del_fullmedia(){
	var tbl = document.getElementById('fullmedia');
	var lastRow = tbl.rows.length;
	if (lastRow > 0) tbl.deleteRow(lastRow - 1); // alte Anzeige loeschen
	tbl.style.marginTop = "0px";
	tbl.style.height = "0px";
	tbl.style.border = "none black 0px";
	del_linktable();
	
	if (window.slidemarker_remove != null){
		slidemarker_remove();
	}
}

function del_linktable(){
	var tbl = document.getElementById('links');
	var lastRow = tbl.rows.length;
	if (lastRow > 0){ // wenn wirklich offen
		tbl.deleteRow(1);
		tbl.deleteRow(0);
		tbl.style.marginTop = "0px";
		tbl.style.height = "0px";
	}
}

function fullmedia(bild){
	
	adclick_refresh();
		
	var tbl = document.getElementById('fullmedia');
	
	var myfullMediaName = "vollbild"; 
	if(fullmediaAktuell != myfullMediaName){
		del_fullmedia();
	}
	
	if(!tbl.rows.length){ // Tabelle ist nicht offen
		fullmediaAktuell = myfullMediaName;
		//fullmediatable_build(tbl,336);
		tbl.style.marginTop = "4px";
		tbl.style.width = "500px";
		tbl.style.height = "336px";
		tbl.style.background = "#F2F2F2";
		tbl.style.border = "solid black 1px";
		
		// if there's no header row in the table, then iteration = lastRow + 1
		var lastRow = tbl.rows.length;
		//var iteration = lastRow +1;
		var row = tbl.insertRow(0);
		var cell_1 = row.insertCell(0);
		cell_1.style.width = "448px";
		
		var cell_2 = row.insertCell(1);
		cell_2.style.textAlign = "right";
		cell_2.style.verticalAlign = "top";
		cell_2.innerHTML = "<span class=\"home_fliesstext\"><a href=\'javascript:del_fullmedia();\'>[x]</a></span>";
	}
	tbl.rows[0].cells[0].innerHTML = bild;
	
} 

function fullvideo(pfad){
	//window.location.href = "#navAnker";
	adclick_refresh();
	
	var tbl = document.getElementById('fullmedia');
	
	var myfullMediaName = "vollvideo"; 
	if(fullmediaAktuell != myfullMediaName){
		del_fullmedia();
	}
	
	if(!tbl.rows.length){ // Tabelle ist nicht offen
		fullmediaAktuell = myfullMediaName;
		
		// ab hier ehemalige fullmediatable_build func, safari bug patch
	
		tbl.style.marginTop = "4px";
		tbl.style.width = "500px";
		tbl.style.height = "240px";
		tbl.style.background = "#F2F2F2";
		tbl.style.border = "solid black 1px";
		
		// if there's no header row in the table, then iteration = lastRow + 1
		var lastRow = tbl.rows.length;
		//var iteration = lastRow +1;
		var row = tbl.insertRow(0);
		var cell_1 = row.insertCell(0);
		cell_1.style.width = "448px";
		
		var cell_2 = row.insertCell(1);
		cell_2.style.textAlign = "right";
		cell_2.style.verticalAlign = "top";
		cell_2.innerHTML = "<span class=\"home_fliesstext\"><a href=\'javascript:del_fullmedia();\'>[x]</a></span>";
	
	}
	
	var html = videoplayer(pfad);
	tbl.rows[0].cells[0].innerHTML = html;
	//tbl.rows[0].cells[0].innerHTML = "bla";
	
} 
	
function gm_showreport(lat,lng,bildordner,bild,mimety,zoomstufe){
	
	imagedirectzoom(lat,lng,bildordner,bild,mimety,zoomstufe);

}
function videoplayer(pfad){
	var html = 	"<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=\"320\" height=\"240\" id=\"FLVPlayer\">";
	html += "<param name=\"movie\" value=\"FLVPlayer_Progressive.swf\" />";
	html += "<param name=\"salign\" value=\"lt\" />";
	html += "<param name=\"quality\" value=\"high\" />";
	html += "<param name=\"scale\" value=\"noscale\" />";
	html += "<param name=\"wmode\" value=\"transparent\">";
	html += "<param name=\"FlashVars\" value=\"&skinName=clearSkin_3&streamName="+pfad+"&autoPlay=true&autoRewind=false\" />";
	html += "<embed src=\"FLVPlayer_Progressive.swf\" flashvars=\"&skinName=clearSkin_3&streamName="+pfad+"&autoPlay=true&autoRewind=false\" quality=\"high\" scale=\"noscale\" width=\"320\" height=\"240\" name=\"FLVPlayer\" salign=\"LT\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
	html += "</object>";
	
	return html
}

function vorschlaganzeigen(name) {
	if (document.all) // Internet Explorer ab 4
    	document.all("vorschlagFeld").innerHTML = name;
		//document.all("vorschlagFeld").innerHTML = "<h1>"+name+"</h1>";
  	else if (document.getElementById) // Netscape 6, Opera
    	document.getElementById("vorschlagFeld").innerHTML = name;
  	else if (document.layers) // Netscape 4
   		with (document.layers["vorschlagFeld"].document) {
      		open();
      		write("geladen");
      		close();
    }
	<!-- alert(testvar); -->
}

function slideanzeigen(aktuellsSlide){
	
	adclick_refresh();
	
	var tbl = document.getElementById('fullmedia');
	var myfullMediaName = "slideshow"; 
	if(fullmediaAktuell != myfullMediaName){
		del_fullmedia();
	}
	
	if(!tbl.rows.length){ // Tabelle ist nicht offen
		fullmediaAktuell = myfullMediaName;
		//fullmediatable_build(tbl,336);
		tbl.style.marginTop = "4px";
		tbl.style.width = "500px";
		tbl.style.height = "336px";
		tbl.style.background = "#F2F2F2";
		tbl.style.border = "solid black 1px";
		
		// if there's no header row in the table, then iteration = lastRow + 1
		var lastRow = tbl.rows.length;
		//var iteration = lastRow +1;
		var row = tbl.insertRow(0);
		var cell_1 = row.insertCell(0);
		cell_1.style.width = "448px";
		
		var cell_2 = row.insertCell(1);
		cell_2.style.textAlign = "right";
		cell_2.style.verticalAlign = "top";
		cell_2.innerHTML = "<span class=\"home_fliesstext\"><a href=\'javascript:del_fullmedia();\'>[x]</a></span>";
	}
	//tbl.rows[0].cells[1].innerHTML = "hallo";
	
	var slidenav = "<span class=\"home_fliesstext\"><a href=\'javascript:del_fullmedia();\'>[x]</a></span>";
	slidenav += "<br><table width=50 border=0 class=\"home_fliesstext\"><tr><td align=center>BILD</td></tr><tr><td align=center>"+(aktuellesslide+1)+"/"+slideshowarray.length+"</td></tr>";
	slidenav += "<tr><td align=center><a href=\'javascript:slideback()\'>&lt;</a> | <a href=\'javascript:slideff()\'>&gt;</a></td></tr></table>";
	tbl.rows[0].cells[1].innerHTML = slidenav;
		
	
	var slidepfad = slideshowarray[aktuellsSlide][0];
	var slidedatei = slideshowarray[aktuellsSlide][1];
	var mimety = slideshowarray[aktuellsSlide][2];
	
	if(mimety == "JPG"){
		tbl.rows[0].cells[0].innerHTML = "<img src=\'"+slidepfad+slidedatei+"\' border=0>";
	}
	if(mimety == "AVI"){
		var videopfad = slidepfad+"videos/";
		var videoname = videoname_patch(slidedatei);
		var html = videoplayer(videopfad+videoname);
		tbl.rows[0].cells[0].innerHTML = html;
	}
			
}

function slideback(){
	if(aktuellesslide > 0){
		aktuellesslide--;
	}else{
		aktuellesslide = slideshowarray.length -1;
	}
	slideanzeigen(aktuellesslide);
}

function slideff(){
	if(aktuellesslide < slideshowarray.length -1){
		aktuellesslide++;
	}else{
		aktuellesslide = 0;
	}
	slideanzeigen(aktuellesslide);
}

function slideshow(xmlName){
	aktuellesslide = 0;
	slideshowarray = [];
	GDownloadUrl(seitenrootUrl+"/clusterfiles/media_"+projektid+"/"+xmlName+"_medienstrecke.xml", function(data, responseCode) {
		var xml = GXml.parse(data);
		var slideliste = xml.documentElement.getElementsByTagName("slide");
		for (var i = 0; i < slideliste.length; i++) {
			var einzelslidearray = [slideliste[i].getAttribute("pfad"),slideliste[i].getAttribute("datei"),slideliste[i].getAttribute("mimety")];
			slideshowarray.push(einzelslidearray);
			
		}
		slideanzeigen(aktuellesslide);
	});
	
	
}

function videoname_patch(bildname){
	var bildnamearry = bildname.split(".");
	var videoname = bildnamearry[0]+"_wtrip001.flv";
	return videoname;
}
