// JavaScript Document

function checkliclasses(ulobj) {
	var liobj=ulobj.firstChild
	var currstat=false;
	var openclosestat=false;
	while (liobj != null) {
		if (liobj.nodeName == "LI") {
			classnames=liobj.className;
			if (classnames.indexOf("liopened")!=-1) {
				if (currstat==false) {
					classnames=classnames.replace(/liopened/,"");
					classnames=classnames.replace(/liopenedfirst/,"");
					classnames+=" liopenedfirst";
					liobj.className=classnames;
				} else {
					classnames=classnames.replace(/liopened/,"");
					classnames=classnames.replace(/liopenedfirst/,"");
					classnames+=" liopened";
					liobj.className=classnames;					
				}
			   openclosestat=true;
			   currstat=true;
			} else {
				currstat=false;
			};
		}
		liobj = liobj.nextSibling;
	};
	return openclosestat;
};


function loadartistinfo(url,obj,uid) {
	if (obj) {
		var liobj= obj.parentNode;
		var ulobj=liobj.parentNode;
		divobj=liobj.lastChild;
		obj.blur();
		
		classnames=liobj.className;
		
		if (divobj.nodeName == "DIV" && divobj.className.indexOf("artistcont")!=-1) {
			if (divobj.style.display=="none") {
				divobj.style.display="block";
				classnames=classnames.replace(/liclosed/,"liopened");
				if (classnames.indexOf("liopened")==-1) {
					classnames+=" liopened";
				};
				liobj.className=classnames;
			} else {
				divobj.style.display="none";
				classnames=classnames.replace(/liopened/,"liclosed");
				if (classnames.indexOf("liclosed")==-1) {
					classnames+=" liclosed";
				};
				liobj.className=classnames;
			};
		} else {
			var newdiv=document.createElement("DIV");
			newdiv.style.display="block";
			newdiv.className="artistcont";
			liobj.appendChild(newdiv);
			contentarr.push(new ajaxcontentloader(newdiv,url,uid));
			classnames=classnames.replace(/liclosed/,"liopened");
			if (classnames.indexOf("liopened")==-1) {
				classnames+=" liopened";
			};
			liobj.className=classnames;
		};
		openclosestat=checkliclasses(ulobj);
		if (openclosestat==true) {
			hideartistfirstimage(obj);
		} else {
			loadartistfirstimage(false,obj);
		};
	};
};

function loadartistfirstimage(url,obj) {
	
	if (obj) {
		var divlist=obj.parentNode.getElementsByTagName("DIV");
		var cdiv=null;
		for (var i=0;i<divlist.length;i++) {
			if (divlist[i].className.indexOf("firstimage")!=-1) {
					cdiv=divlist[i];
				break;
			};
		};
		var loadstat=true;
		lilist=document.getElementsByTagName("LI");
		for (i=0;i<lilist.length;i++) {
			if (lilist[i].className.indexOf("liopen")!=-1) {
					loadstat=false;
				break;
			};
		};
		if (loadstat==true) {
			if (cdiv==null && url!=false) {
				var newobj=document.createElement("div");
				newobj.className="firstimage";
				newobj.style.position="absolute";
				newobj.style.top="32px";
				newobj.style.left="465px";
				newobj.style.zIndex="10000";
				obj.parentNode.appendChild(newobj);
				var test=new ajaxcontentloader(newobj,url);
			} else {
				cdiv.style.display="block";
			};
		};
	};
	
};

function hideartistfirstimage(obj) {
	
	if (obj) {
		var divlist=obj.parentNode.getElementsByTagName("DIV");
		var cdiv=null;
		for (var i=0;i<divlist.length;i++) {
			if (divlist[i].className.indexOf("firstimage")!=-1) {
					cdiv=divlist[i];
				break;
			};
		};
		if (cdiv!=null) {
			cdiv.style.display="none";
		};
	};

};


var contentarr=new Array();

function showcontent(domelemid,url) {
  var obj=document.getElementById(domelemid);
  if (obj) {
    if (obj.hasChildNodes()) {
        alert("Already Loaded");
    } else {
        //contentarr.push(new ajaxcontentloader(obj,'http://localhost/z_entwicklungen/JS_AJAX_Contentloader/content.php'));
        contentarr.push(new ajaxcontentloader(obj,'content.php'));
    };
  };
};


function ajaxcontentloader(domelem,url,uid) {

  var domelem=domelem;
  var xmlurl=url;
  var self = this;
  var auid=uid;
  
  this.cookiePath = "";
  this.cookieDomain = "";
  this.savestatus = true;
  
  var xmlHTTPReq = new xmlHttpRequestObj('POST',url,true,'',self,'loadcomplete','')
  
	this.loadcomplete = function(XML) {
		//self.setloadbar(false);
		//this.XML=XML.responseXML;
		this.XML=XML.responseText;
		//alert(this.XML);
		//this.loadstat=true;
		//this.setupChildes();
		//alert(this.XML);
		//alert(domelem);
		//var dummy = this.XML.getElementsByTagName("div");
		//alert(dummy[0].nodeName);
		//domelem.appendChild(dummy[0]);
		if (!document.layers) {
			domelem.innerHTML = this.XML;
		} else {
      		domelem.document.open();
      		domelem.document.write(this.XML);
      		domelem.document.close();
    	};
		setdivheighttoimg(auid);
    	//alert(this.savestatus);
	};

	function xmlHttpRequestObj(method,url,async,para,robj,rfunction,rpara) {
		var xmlHttp;
		var rfunction = rfunction;
		var rpara = rpara;
		var robj= robj;
		
		try {
			xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
		}
		catch (e) { // Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				};
			};
		};
		
		this.oreadystatechange = function() {
			switch (xmlHttp.readyState) {
				case 0:
				//alert("0");
				break;
				case 1:
				//alert("1");
				break;
				case 2:
				break;
				case 3:
				break;
        case 4:
					// Ready
					robj[rfunction](xmlHttp,rpara);			
				break;
			};
		};
		
		xmlHttp.onreadystatechange = this.oreadystatechange;
		xmlHttp.open(method,url,async);
		xmlHttp.send(null);
	};
  function Cookie() {
      this.get = function(name) {
          var cookies = document.cookie.split(";");
          for (var i = 0; i < cookies.length; ++i) {
              var a = cookies[i].split("=");
              if (a.length == 2) {
                  a[0] = a[0].trim();
                  a[1] = a[1].trim();
                  if (a[0] == name) {
                      return unescape(a[1]);
                  };
              };
          };
          return "";
      };
      this.set = function(name, value, seconds, path, domain, secure) {
          var cookie = (name + "=" + escape(value));
          if (seconds) {
              var date = new Date(new Date().getTime()+seconds*1000);
              cookie += ("; expires="+date.toGMTString());
          }
          cookie += (path    ? "; path="+path : "");
          cookie += (domain  ? "; domain="+domain : "");
          cookie += (secure  ? "; secure" : "");
          document.cookie = cookie;
      };
      this.del = function(name) {
          document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
      };
  };	
};

function MyCookie() {
    this.get = function(name) {
        var cookies = document.cookie.split(";");
        for (var i = 0; i < cookies.length; ++i) {
            var a = cookies[i].split("=");
            if (a.length == 2) {
                a[0] = a[0].trim();
                a[1] = a[1].trim();
                if (a[0] == name) {
                    return unescape(a[1]);
                };
            };
        };
        return "";
    };
    this.set = function(name, value, seconds, path, domain, secure) {
        var cookie = (name + "=" + escape(value));
        if (seconds) {
            var date = new Date(new Date().getTime()+seconds*1000);
            cookie += ("; expires="+date.toGMTString());
        }
        cookie += (path    ? "; path="+path : "");
        cookie += (domain  ? "; domain="+domain : "");
        cookie += (secure  ? "; secure" : "");
        document.cookie = cookie;
        //alert(cookie);
    };
    this.del = function(name) {
        document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
    };
};

/* Strip whitespace from the beginning and end of a string */
if (!String.prototype.trim) {
    String.prototype.trim = function() {
        return this.replace(/^\s*|\s*$/g, "");
    };
};

function rewritelinks() {
	var listarray=document.getElementsByTagName("ul");
	for (var i=0;i<listarray.length;i++) {
		if (listarray[i].className == "gt_dynamiclist") {
			var linode = listarray[i].firstChild;
			while (linode != null) {
				if (linode.nodeName == "LI") {
					var alink=linode.getElementsByTagName("A");
					if (alink.length>0) {
						var linkurl = alink[0].getAttribute("href",0);
						alink[0].setAttribute("href","javascript:void(0);",0);
					}
				}
				linode=linode.nextSibling;
			}
		}
	}
}

function setlage() {
	
}


function setdivheighttoimg(uid) {
	if (uid) {
		imgobj=document.getElementById("exhimg_"+uid);
		txtobj=document.getElementById("txtinfo_"+uid);
		if (imgobj && txtobj) {
			var currheight=imgobj.getAttribute("height");
			var txtheight=txtobj.offsetHeight;
			if (currheight && txtheight) {
				if (currheight<txtheight) {
					var newheight=Math.round(currheight/16)*16;
					txtobj.style.height=newheight+"px";
					txtobj.style.overflow = "hidden";
					txtobj.style.marginBottom="10px";
					txtobj.style.position="relative";
					var morelink=document.createElement("A");
					morelink.id="linkdiv_"+uid;
					morelink.setAttribute("href","javascript:setdivheightfull("+uid+");");
					/*morelink.style.position="absolute";
					morelink.style.display="block";
					morelink.style.zIndex="auto";
					morelink.style.right="0px";
					morelink.style.bottom="0px";
					morelink.style.backgroundColor="#FFFFFF";
					morelink.style.paddingLeft="10px";
					morelink.style.paddingTop="10px";*/
					var moretext=document.createTextNode("mehr ...");
					morelink.appendChild(moretext);
					txtobj.parentNode.appendChild(morelink);
				};
			};
		};
	};
};
function setdivheightfull(uid) {
	if (uid) {
		imgobj=document.getElementById("exhimg_"+uid);
		txtobj=document.getElementById("txtinfo_"+uid);
		linkobj=document.getElementById("linkdiv_"+uid);
		if (imgobj && txtobj && linkobj) {
			txtobj.style.height="auto";
			//txtobj.style.width="auto";
			txtobj.style.overflow="visible";
			txtobj.style.marginBottom="0px";
			txtobj.style.position="static";	
			linkobj.style.display="none";
			//linkobj.parentNode.removeChild(linkobj);
		}
	}
}

// GLOBALES KLAPPMENU F�R INHALTE

function checkopencontendivs() {
	var currstat=false;
	var divlist=document.getElementsByTagName("DIV");
	for (var i=0;i<divlist.length;i++) {
		classnames=divlist[i].className;
		if (classnames.indexOf("dyncontent")!=-1) {
			if (classnames.indexOf("dyncontentopen")!=-1) {
				if (currstat==false) {
					classnames=classnames.replace(/dyncontentopen/,"");
					classnames=classnames.replace(/dyncontentopenfirst/,"");
					classnames+=" dyncontentopenfirst";
					divlist[i].className=classnames;
				} else {
					classnames=classnames.replace(/dyncontentopen/,"");
					classnames=classnames.replace(/dyncontentopenfirst/,"");
					classnames+=" dyncontentopen";
					divlist[i].className=classnames;					
				}
			   currstat=true;
			} else {
				currstat=false;
			};							   
		};
	};
};

function closealldivsexeptfirst() {
	var divlist=document.getElementsByTagName("DIV");
	var mdivstat=false;
	var sdivstat=false;
	var classnames;
	for (var i=0;i<divlist.length;i++) {
		classnames=divlist[i].className;
		if (classnames.indexOf("dyncontent")!=-1) {
			classnames=classnames.replace(/dyncontentopen/,"");
			classnames=classnames.replace(/dyncontentopenfirst/,"");			
			classnames=classnames.replace(/dyncontentclose/,"");
			if (mdivstat==false) {
				classnames+=" dyncontentopenfirst";
				mdivstat=true;
			} else {
				classnames+=" dyncontentclose";
			};
			divlist[i].className=classnames;
		};
		if (classnames.indexOf("sdyncont")!=-1) {
			if (sdivstat==false) {
				divlist[i].style.display="block";
				sdivstat=true;
			} else {
				divlist[i].style.display="none";
			};
		};
	};
};

function switchdivvisibilty(domid) {
	var divobj=document.getElementById('cont_'+domid);
	var mobj=document.getElementById('mcont_'+domid);
	classnames=mobj.className;
	if (divobj) {
		if (divobj.style.display=="none") {
			divobj.style.display="block";
			classnames=classnames.replace(/dyncontentclose/,"dyncontentopen");
			if (classnames.indexOf("dyncontentopen")==-1) {
				classnames+=" dyncontentopen";
			};
			mobj.className=classnames;
		} else {
			divobj.style.display="none";
			classnames=classnames.replace(/dyncontentopen/,"dyncontentclose");
			if (classnames.indexOf("dyncontentclose")==-1) {
				classnames+=" dyncontentclose";
			};
			mobj.className=classnames;
		};
	};
	checkopencontendivs();
};

function initdivvisibility() {
	closealldivsexeptfirst();
	checkopencontendivs();
};
