function SetCookie(name, value, expires, path, domain, secure) {
			document.cookie = name + "=" + escape (value) +
					 ((expires) ? "; expires=" + expires.toGMTString() : "") +
					 ((path) ? "; path=" + path : "") +
					 ((domain) ? "; domain=" + domain : "") +
					 ((secure) ? "; secure" : "");
	}

function getCookieVal(offset) {
		 var endstr = document.cookie.indexOf (";", offset);
		 if (endstr == -1)
				 endstr = document.cookie.length;
		 return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(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 getCookieVal (j);
		 i = document.cookie.indexOf(" ", i) + 1;
		 if (i == 0) break; 
	 }
	 return null;
}


function MainRotator(newName, newId)
{
	var name = newName;
	var id = newId;
	var objects;
	var timer=null;
	var anim=false;
	var step=0;
	var open=0;
	var pause=false;
	var direction=0;
	var prev;
	var next;
	
	function getAmount()
	{
		return objects.length+1;
	}
	this.getAmount = getAmount;
	
	function startStop(obj)
	{
		if(pause)
		{
			obj.getElementsByTagName('img').item(0).setAttribute('src', 'images/pauserotator.png');
			pause=false;
			timer = setTimeout(name+'.go(1)', 4000);
		}
		else
		{
			obj.getElementsByTagName('img').item(0).setAttribute('src', 'images/startrotator.png');
			pause=true;
			try {
				clearTimeout(timer);
			} catch(e) {}
		}
		
	}
	this.startStop = startStop;
	
	function animation()
	{
		step+=Math.abs(direction)*5;
		try {
			objects[open].style.opacity=step/100;
			objects[open].style.filter='alpha(opacity='+step+')';
			objects[prev].style.opacity=(100-step)/100;
			objects[prev].style.filter='alpha(opacity='+(100-step)+')';
		} catch (e) {}
		if(step>=100)
		{
			anim=false;
			objects[prev].style.display='none';
			objects[prev].style.position='static';
			if(next!=null) { go(next); next=null; }
			if(!pause) { timer = setTimeout(name+'.go(1)', 4000); }
		}
		else
		{
			timer = setTimeout(name+'.animation()', 30);
		}
	}
	this.animation = animation;
	
	function go(newDirection)
	{
		if(!anim)
		{
			direction = newDirection;
			clearTimeout(timer);
			anim=true;
			step=0;
			prev=open;
			open+=direction;
			if(open>=objects.length){open=0;}
			else if(open<0) { open=objects.length-1; }
			document.getElementById('banner-link'+(prev+1)).src='/layout/mainbanner2.gif';
			document.getElementById('banner-link'+(open+1)).src='/layout/mainbanner1.gif';
			objects[prev].style.position='absolute';
			objects[open].style.display='block';
			try {
				objects[prev].style.opacity=1;
				objects[prev].style.filter='alpha(opacity=100)';
				objects[open].style.opacity=0;
				objects[open].style.filter='alpha(opacity=0)';
			} catch (e) {}
			timer = setTimeout(name+'.animation()', 50);
		}
		else { next=newDirection; }
	}
	this.go = go;
	
	function openImage(nr) { go(nr-open); }
	this.openImage = openImage;
	
	function init()
	{
		objectsAll = document.getElementById(id).getElementsByTagName('div');
		objects=[];
		
		for(a=0;a<objectsAll.length;a++)
		{
			if(objectsAll[a].className=='banner') { objects[objects.length]=objectsAll[a]; }
		}
		
		if(objects.length>0)
		{
			for(a=0;a<objects.length;a++)
			{
				objects[a].style.display='none';
			}
			open=0;
			objects[0].style.display='block';
			timer = setTimeout(name+'.go(1)', 4000);
		}
	}
	this.init=init;
	
}


function Rotator(newName)
{
	var obj=[];
	var nr=0;
	var name = newName;
	var speed=0;
	var x=0;
	var animation=false;
	var prev=0;
	
	function anim()
	{
		speed-=5;
		if(speed<3) { speed=3; }
		if(x-speed<=4&&x-speed>=-4)
		{
			animation=false;
			x=0;
			obj[prev].style.display='none';
		}
		else
		{
			x=x+(direction*speed);
			setTimeout(name+'.anim()', 50);
		}
		
		obj[nr].style.left=x+'px';
	}
	this.anim=anim;
	
	function goNext()
	{
		if(!animation)
		{
			obj[nr].style.zIndex='1';
			prev=nr;
			nr++;
			if(nr>=obj.length) { nr=0; }
			x=232;
			speed=50;
			direction=-1;
			animation=true;
			obj[nr].style.zIndex='2';
			obj[nr].style.display='block';
			anim();
		}
	}
	this.goNext=goNext;
	
	function goPrev()
	{
		if(!animation)
		{
			obj[nr].style.zIndex='1';
			prev=nr;
			nr--;
			if(nr<0) { nr=obj.length-1; }
			x=-232;
			speed=50;
			direction=1;
			animation=true;
			obj[nr].style.zIndex='2';
			obj[nr].style.display='block';
			anim();
		}
	}
	this.goPrev=goPrev;
	
	function init(id)
	{
		obj=document.getElementById(id).getElementsByTagName('li');
		for(a=1;a<obj.length;a++) { obj[a].style.display='none'; }
	}
	this.init = init;
}
