/* ############################################################################################ */
/* Master Objekt */
/* ############################################################################################ */

var coo= {};

/* ############################################################################################ */
/* Variablen Initialisieren */
/* ############################################################################################ */

coo.expdays=365;
coo.bildnr=0;

/* ############################################################################################ */
/* Cookie setzten */
/* ############################################################################################ */

coo.setCookie = function (name, value, expires, path, domain, secure){
	if (!expires){expires = new Date();}
	document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
};

/* ############################################################################################ */
/* Cookie finden */
/* ############################################################################################ */

coo.getCookie = function (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg){
			return coo.getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
};

/* ******************************************************************************** */

coo.getCookieVal = function (offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1){
	endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
};

/* ############################################################################################ */
/* Cookie löschen */
/* ############################################################################################ */

coo.deleteCookie = function (name,path,domain){
	document.cookie = name + "=" +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	"; expires=Thu, 01-Jan-00 00:00:01 GMT";
};

/* ############################################################################################ */
/* Scrollposition setzten */
/* ############################################################################################ */

coo.saveScroll = function (site, uprojekt, position){ // added function
	var expdate = new Date ();
	expdate.setTime (expdate.getTime() + (coo.expdays*24*60*60*1000)); // expiry date
	if(typeof(position)=="string"){/* von Slideshow und Scroll to Bild -> String, sonst undefined */
		if(position == "scrollto"){ 
			/* von Slideshow kommend */
			var x = (slide.getBildname(slide.getCurrentbild()));
		} else {
			/* Scroll to Bild */
			var x = (position);
		}
	} else {
		/* bei back oder refresh */
		var x = (band.getPosition());
	}
	if(uprojekt == "fromStart"){
		/* von Slideshow kommend */
		var y = (slide.getBildprojekt(slide.getCurrentbild()));
	} else {
		/* bei back oder refresh */
		var y = (uprojekt);
	}
	Data=x + "_" + y; /* x = Position / y = UProjekt */
	coo.setCookie(site,Data,expdate,'/'); /* Path = / wegen mod-rewrite */
};

/* ############################################################################################ */
/* Scrollposition laden */
/* ############################################################################################ */

coo.loadScroll = function (site, uprojekt) {
	band.onReady(); /* Init bevor Scrollposition gesetzt wird */
	inf=coo.getCookie(site);
	if(!inf){return;} /* Cookie noch nicht vorhanden, dann return */
	var ar = inf.split("_");
	if(ar.length == 2){
		/* Stimmt Uprojekt ? */
		if(ar[1] == uprojekt){
			/* Scrollposition oder Bildname ? */
			if(isNaN(ar[0])){
				/* von Slideshow kommend */
				/*Klammern ersetzen, da bei abspeichern gewndelt uwrden */

				ar[0]=ar[0].replace("%28","(");
				ar[0]=ar[0].replace("%29",")");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");
				ar[0]=ar[0].replace("--","_");

				band.setPosition(band.scrolltobild(ar[0]));
			} else {
				/* bei back oder refresh */

				band.setPosition(ar[0]);
			}
		}
	}
};

/* ******************************************************************************** */

// add onload="loadScroll()" onunload="saveScroll()" to the opening BODY tag