//////////////////////////////////////////////////////////
// Browser Check
//////////////////////////////////////////////////////////
function checkBrowser()
{		
		this.ver=navigator.appVersion; 
		this.agent=navigator.userAgent 
		this.dom=document.getElementById?1:0 
		this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
		this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0; 
		this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom)?1:0; 
		this.ie4=(document.all && !this.dom)?1:0; 
		this.ie=this.ie4||this.ie5||this.ie6 || this.ie7 
		this.mac=this.agent.indexOf("Mac")>-1 
		this.opera5=this.agent.indexOf("Opera 5")>-1 
		this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
		this.ns7=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
		this.ns4=(document.layers && !this.dom)?1:0; 
		this.ipn=this.agent.indexOf('iPhone') >-1;
		this.ipd=this.agent.indexOf('iPod') >-1;
		this.bw=(this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom) 
		return this 
}


//////////////////////////////////////////////////////////
//define Globals, vars, objects ...
//////////////////////////////////////////////////////////
bw=new checkBrowser()
var speed = 3;
var loop, timer, loaded;
var px = bw.ns4||window.opera?"":"px";
var SwaySlideRight = 0;
var SwaySlideLeft = 0;
var SwayScrollUp = 0;
var SwayScrollDown = 0;

function makeObj(obj,nest)
{
    nest=(!nest) ? '':'document.'+nest+'.'
       
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
    
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight;
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight;
	this.scrollWidth=bw.ns4?this.css.document.width:this.el.offsetWidth;
    this.clipWidth=bw.ns4?this.css.clip.width:this.el.offsetWidth;
   	
    this.up=goUp;
    this.down=goDown;
    this.left=goLeft;
    this.right=goRight;
    this.moveIt=moveIt;
    this.scrollTo=scrollTo;
	this.fscrTo=fscrTo;
    this.slideTo=slideTo;
    this.centerIt=centerIt; 
    this.show=show;
    this.scroll=scroll;
    this.slide=slide;
	this.slideStep=slideStep;
    this.x; 
    this.y;
	this.width;
	this.height;
	this.obj = obj + "Object";

    eval(this.obj + "=this");
    return this;
}

//////////////////////////////////////////////////////////
//General moves, center the layer
//////////////////////////////////////////////////////////
function moveIt(x,y)
{
        this.x = x
        this.y = y
        this.css.left = this.x + "px"
        this.css.top = this.y + "px"
        
}

function centerIt(lt,tp)
{	
	var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	
	
	this.css.left=(myWidth-lt)/2 + "px";
	this.css.top=(myHeight-tp)/2 + "px";
}

//////////////////////////////////////////////////////////
// Vertical scroll
//////////////////////////////////////////////////////////
function goDown(move,clpd,to)
{
        par = (to) ? to : (-this.scrollHeight+clpd);
        
        if(this.y>par)
        {
                if(this.y<=(par+50))move=2;
                this.moveIt(0,this.y-move)
                        if(loop) SwayScrollDown = setTimeout(this.obj+".down("+move+","+clpd+","+to+")",speed)
        }
}

function goUp(move,to)
{

        
        par=(!to)?0:to;
        if(this.y<par)
        {
                if(this.y>=(par-50))move=-2;
                this.moveIt(0,this.y-move)

                if(loop) SwayScrollUp = setTimeout(this.obj+".up("+move+","+to+")",speed)
        }
}


function scroll(speed,clp)
{
        if(loaded)
        {
                loop=true;
                if(speed>0) this.down(speed,clp)
                else this.up(speed)
        }
}

function scrollTo(final_position)
{
	speed=20;
	loop=true;
 	clp=400;
 	
 	((this.y-final_position)<=0)? move=-30:move=30;

	if(loop&&(move<0)) 
	{
			SwayScrollUp = setTimeout(this.obj+".up("+move+","+final_position+")",speed)
	}
	else if(loop&&(move>0))
	{
			SwayScrollDown = setTimeout(this.obj+".down("+move+","+clp+","+final_position+")",speed)
	}
}
function fscrTo(final_position)
{
	speed=20;
	loop=true;
 	clp=400;
 	
 	((this.y-final_position)<=0)? move=-240:move=240;

	if(loop&&(move<0)) 
	{
			SwayScrollUp = setTimeout(this.obj+".up("+move+","+final_position+")",speed)
	}
	else if(loop&&(move>0))
	{
			SwayScrollDown = setTimeout(this.obj+".down("+move+","+clp+","+final_position+")",speed)
	}
}

//////////////////////////////////////////////////////////
// Horizontal slide
//////////////////////////////////////////////////////////
function goRight(move,clpd,to)
{
        par=(!to)?(-this.scrollWidth+clpd):to;
        if (this.x>par)
        {
                if((this.x-par)<=50)move=2;
                this.moveIt(this.x-move,0)
                        if (loop) SwaySlideRight = setTimeout(this.obj+".right("+move+","+clpd+","+to+")",speed)
        }
}

function goLeft(move, to)
{
        par=(!to)?0:to;
        
        if (this.x<par)
        {
                if((this.x-par)>=-50)move=-2;
                this.moveIt(this.x-move,0)
                if (loop) SwaySlideLeft = setTimeout(this.obj+".left("+move+","+to+")",speed)
        }
}

function slide(speed,clp)
{
        if(loaded)
        {
        	loop=true;
            if(speed>0) this.right(speed,clp)
            else this.left(speed)
        }
}

function slideTo(final_position)
{
	speed=20;
	loop=true;
 	clp=400;
		
 	//((this.x-final_position)=0)? return;
	
 	((this.x-final_position)<=0)? move=-30:move=30;

	if(loop&&(move<0)) 
	{
			SwaySlideLeft =  setTimeout(this.obj+".left("+move+","+final_position+")",speed)
	}
	else if(loop&&(move>0))
	{
			SwaySlideRight = setTimeout(this.obj+".right("+move+","+clp+","+final_position+")",speed)
	}
}

//////////////////////////////////////////////////////////
// Event handling ::: STOP
//////////////////////////////////////////////////////////
function stop()
{
        loop=false;
        if(timer) clearTimeout(timer);
	if(SwaySlideRight) clearTimeout(SwaySlideRight);
	if(SwaySlideLeft) clearTimeout(SwaySlideLeft);
	if(SwayScrollDown) clearTimeout(SwayScrollDown);
	if(SwayScrollUp) clearTimeout(SwayScrollUp);
}

//////////////////////////////////////////////////////////
// Event handling ::: SHOW LAYER
//////////////////////////////////////////////////////////
function show(sh)
{
(sh)?this.css.visibility='visible':this.css.visibility='hidden';
}

function hm()
{
oTopR1.show(0);oTopR2.show(0);oTopR3.show(0);oTopR4.show(0);

}

//////////////////////////////////////////////////////////
// positioning ::: preserve CURRENT POSITION
//////////////////////////////////////////////////////////
function cPos(what, bx, ly, ry)
{
stop()
loop = true;
	if(what == 0)
	{
		oBigCnt.moveIt(0,0);
		oLeftCnt.moveIt(0,-400);
		oRightCnt.moveIt(0,-1600);
		
		/*oBigCnt.moveIt(-800,0);
		oLeftCnt.moveIt(0,0);
		oRightCnt.moveIt(0,-1600);*/
		
		
	}
	else
	{		
		oBigCnt.slideTo(bx);
		oLeftCnt.scrollTo(ly);
		oRightCnt.scrollTo(ry);
	}
}

function i(step)
{
	where = -19*step;
	oTopLC.moveIt(0,where);
	
}

//////////////////////////////////////////////////////////
// positioning ::: preserve CURRENT POSITION
//////////////////////////////////////////////////////////
function slideStep(side,step)
{
	var finx;
	(side==-1)? finx=parseInt(this.x-step):finx=parseInt(this.x+step);
	((finx > 0)||(finx < -1600))?this.slideTo(0):this.slideTo(finx);
	
}
//////////////////////////////////////////////////////////
// open ::: OPEN LYRICS AT PRECISE POSITION
//////////////////////////////////////////////////////////
function lOpen(d,p)
{
	//d is document, p is position within the document
	var urb = 'SWAY_LYRICS_C'+d+'.html#s'+p;
	window.open (urb, 'SWAY Lyrics', config='height=600, width=800, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no')	
}

//////////////////////////////////////////////////////////
// buzzOf ::: REDIRECT FOR THE MOBILE DEVICES
//////////////////////////////////////////////////////////
function buzzOf()
{
	if ((this.ipn) || (this.ipd)) 
	{ document.location = "http://www.sway.at/iphone/";} 
}


//////////////////////////////////////////////////////////
// Initialization onLoad
//////////////////////////////////////////////////////////
function initAll()
{
		
		buzzOf();
		
		//BORDER
		oBigBrd = 	new makeObj('bigBrd');
		oBigBrd.centerIt(900,650);
		
		//OUTTER CONTAINER
        oBigOut	=	new makeObj('bigOut');
		oBigCnt	=	new makeObj('bigCnt','bigOut');
		oBigOut.centerIt(800,550);
		
		oTopL	=	new makeObj('mTopL');
		oTopLC	=	new makeObj('mTopLCnt','mTopL');
		oTopL.centerIt(800,590);
		
       
	   		//Les SWAYS:::content nested in the Big Out Container
			oLeftOut	=	new makeObj('leftOut');
			oLeftCnt	=	new makeObj('leftCnt','leftOut');

				oMhrOut	=	new makeObj('mhrOut');
				oMhrCnt	=	new makeObj('mhrCnt','mhrOut');
				oMhrCnt.moveIt(-400,0);
				
			
				bYviOut	=	new makeObj('yviOut');
				bYviCnt	=	new makeObj('yviCnt','yviOut');
				bYviCnt.moveIt(0,0);
				
				/*lGigOut	=	new makeObj('gigOut');
				lGigCnt	=	new makeObj('gigCnt','gigOut');
				lGigCnt.moveIt(0,0);*/
	
			oRightOut	=	new makeObj('rightOut');
			oRightCnt	=	new makeObj('rightCnt','rightOut');
				//scrollTo ne radi na ovome ....?
				bIvnOut	=	new makeObj('ivnOut');
				bIvnCnt	=	new makeObj('ivnCnt','ivnOut');
				bIvnCnt.moveIt(0,0);
				
				oMhlOut	=	new makeObj('mhlOut');
				oMhlCnt	=	new makeObj('mhlCnt','mhlOut');
				oMhlCnt.moveIt(0,0);
					
					ol1	=	new makeObj('l1');
					ol1Cnt	=	new makeObj('l1Cnt','l1');
					ol1Cnt.moveIt(0,0);
					ol2	=	new makeObj('l2');
					ol2Cnt	=	new makeObj('l2Cnt','l2');
					ol2Cnt.moveIt(0,0);
					ol3	=	new makeObj('l3');
					ol3Cnt	=	new makeObj('l3Cnt','l3');
					ol3Cnt.moveIt(0,0);
					ol4	=	new makeObj('l4');
					ol4Cnt	=	new makeObj('l4Cnt','l4');
					ol4Cnt.moveIt(0,0);
			
			cPos(0);
			//cPos(1,-800,0,-1600);
		
		//MENUS
		
		
		oMenBot	=	new makeObj('mBot');
		oMenBot.centerIt(800,-250);
		
		oMenNet	=	new makeObj('mTopNet');
		oMenNet.centerIt(-325,650);
		
		oTopR1	=	new makeObj('mTopR1');
		oTopR1.centerIt(-800,550);
		oTopR2	=	new makeObj('mTopR2');
		oTopR2.centerIt(-800,550);
		oTopR3	=	new makeObj('mTopR3');
		oTopR3.centerIt(-800,550);
		oTopR4	=	new makeObj('mTopR4');
		oTopR4.centerIt(-800,550);
		
		
	
	var rand = Math.round(Math.random()*7+1);
	document.getElementById('first').style.background="url('pic/front"+[rand]+".jpg')";

	
	//Cover for preloading		
	    oCover	=	new makeObj('cover');
		oCover.centerIt(900,650);
		var t1 = setTimeout("oCover.css.visibility='hidden'",1000);
		
		//Finalize
		loaded	=	true;        
}

//Initialize all
onload=initAll;
