/**
 *  Crossfader based upon a script from http://www.brandspankingnew.net
 *  MP3 based upon a script from http://www.gemeindebund.at
 *  info based upon a script from http://www.gemeindebund.at
 */

var useKNETns;

if (useKNETns)
{
	if (typeof(KNET) == "undefined")
		KNET = {}
	var _KNET = KNET;
}
else
{
	var _KNET = this;
}

_KNET.Crossfader = function (divs, fadetime, delay )
{	
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var i=0;i<divs.length;i++)
	{
		document.getElementById(divs[i]).style.opacity = 0;
		document.getElementById(divs[i]).style.position = "absolute";
		document.getElementById(divs[i]).style.filter = "alpha(opacity=0)";
		document.getElementById(divs[i]).style.visibility = "hidden";
	}
	
	this.nDur = fadetime;
	this.nDelay = delay;
		
	this._newfade();
}

_KNET.Crossfader.prototype._newfade = function()
{
	if (this.nID1)
		clearInterval(this.nID1);
	
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct])	this.nAct = 0;
	
	if (this.nAct == this.nOldAct)
		return false;
	
	document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}

_KNET.Crossfader.prototype._fade = function()
{
	this.nTime += this.nInt;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	document.getElementById( this.aDivs[this.nAct] ).style.opacity = op;
	document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.nOldAct > -1)
	{
		document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	if (this.nTime == this.nDur)
	{
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1)
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";	
		
		var p=this;
		this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	}
}

_KNET.Crossfader.prototype._easeInOut = function(t,b,c,d)
{
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}

_KNET.createCookie = function (name, value, days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime() + (days*24*60*60*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

_KNET.readCookie = function (name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

_KNET.eraseCookie = function (name)
{
	createCookie(name, "", -1);
}

_KNET.mp3 = function (dummy1, dummy2, file, windowtitle, dummy3)
{	
	var poshorizontal=screen.width-360;
	var posvertikal=screen.height-160;
	var eigenschaften="width=350,height=80,left="+poshorizontal+",top="+posvertikal+"menubar=no,resizable=yes,locationbar=no,statusbar=no,scrollbars=no";
	var newwindow=window.open("http://www.gemeindebund.at/"+file, windowtitle, eigenschaften);
}

_KNET.info = function (width, height, file, windowtitle, scrollbars)
{
	var poshorizontal=(screen.width-width)/2;
	var posvertikal=(screen.height-height)/2;
	var eigenschaften="width="+width+",height="+height+",left="+poshorizontal+",top="+posvertikal+",menubar=no,resizable=yes,locationbar=no,statusbar=no,scrollbars="+scrollbars;
	var newwindow=window.open("http://www.gemeindebund.at/"+file, windowtitle, eigenschaften);
}

_KNET.popup = function (width, height, file, windowtitle, scrollbars)
{
	var poshorizontal=(screen.width-width)/2;
	var posvertikal=(screen.height-height)/2;
	var eigenschaften="width="+width+",height="+height+",left="+poshorizontal+",top="+posvertikal+",menubar=no,resizable=yes,locationbar=no,statusbar=no,scrollbars="+scrollbars;
	window.open(file, windowtitle, eigenschaften);
}

_KNET.changeParent = function (url)
{
    opener.document.location = url;
    opener.document.reload;
}

_KNET.popupogm = function (width, height, windowtitle)
{
	var poshorizontal=(screen.width-width)/2;
	var posvertikal=(screen.height-height)/2;
	var eigenschaften="width="+width+",height="+height+",left="+poshorizontal+",top="+posvertikal+",menubar=no,resizable=yes,locationbar=no,statusbar=no,scrollbars=yes";
	if (readCookie('OGM'))
	{
		return null;
	}
	var newwindow=window.open('', windowtitle, eigenschaften);
	newwindow.document.writeln('<html><head><title>' + windowtitle + '</title>');
	newwindow.document.writeln('<link media=screen type=text/css href=\"/css/1_default.css\" rel=stylesheet></link>');
	newwindow.document.writeln('<script src=\"/upload/1/common.js\" type=\"text/javascript\" language=\"javascript\"></script>');	
	newwindow.document.writeln('</head><body style=\"margin:0px;\">');
	newwindow.document.writeln('<div class=main><div class=content style=\"padding:10px 0px 0px 10px;\"><p><h3><img src=\"/upload/1/kn_ausruf.jpg\" align=middle> Machen Sie mit!</h3></p>');
	newwindow.document.writeln('<p>Nur noch <b>bis 15. Juli</b> l&auml;uft die gro&szlig;e e-Government Erhebung des Bundeskanzleramts.</p>');	
	newwindow.document.writeln('<p>Machen Sie mit, und helfen Sie, das e-Government-Angebot &Ouml;sterreichs zu verbessern!</p>');	
	newwindow.document.writeln('<p><form><input type=\"submit\" value=\"Umfrage starten\" onclick=\"changeParent(\'https://www.kommunalnet.at/default.aspx?detailonr=33887\');self.close();\"/></form></p>');
	newwindow.document.writeln('<p style=\"font-size:81%;\"><a href=\"javascript:self.close();\">Fenster schliessen</a></p>');	
	newwindow.document.writeln('</div></div></body></html>');
	newwindow.document.close();
	createCookie('OGM', 'done', 1);
}
