//Constants per formar noms identificatius (unics)
var ScrollCount=0;
var n = (document.layers) ? 1:0;      
var agent=navigator.userAgent.toLowerCase();
var ns6=(agent.indexOf("gecko")>-1 || window.sidebar)? 1:0;//estils();

//Objecte Scroll

//Constructor
//Parametres:
//		Variable de tipus Layer
//		Variable int desplaçament

function SlowScroll(div,despl,top,bottom,left,right,du,dd)
{
//Atributs
 this.name		= 'Scroll'+(ScrollCount++);
 this.actiu		= true;
 this.div		= div;
 this.xInici	= parseInt(div.left);
 this.yInici	= parseInt(div.top);
 this.xPos		= parseInt(div.left);
 this.yPos		= parseInt(div.top);
 this.offSet	= despl;
 this.salt		= 150;
 this.yTop		= top;
 this.yBottom	= bottom;
 this.xLeft		= left;
 this.xRight	= right;	
 this.obj	 	= 'var'+this.name;	//Jo mateix
 eval(this.obj+"=this")
 
 this.dup		= du;
 this.ddown		= dd;
 
//Metodes
 this.StartUp	 = fStartUp;
 this.StartDown	 = fStartDown;
 this.SaltUp	 = fSaltUp;
 this.SaltDown	 = fSaltDown;
 this.StartLeft  = fStartLeft;
 this.StartRight = fStartRight;
 this.Stop	 	 = fStop;
 this.PosInici	 = fPosInici;
 this.PosXY		 = fPosXY;	//parametres: int left, int top
 
 this.StartUpClip	 = fStartUpClip;
 this.StartDownClip  = fStartDownClip;
 this.SlideVClip 	 = fSlideVClip;
 this.StartLeftClip	 = fStartLeftClip;
 this.StartRightClip = fStartRightClip;
 this.SlideHClip 	 = fSlideHClip;
 this.PosIniciClip   = fPosIniciClip;
 
 this.SlideV = fSlideV;
 this.SlideH = fSlideH;
}

//Metodes
function fPosInici()
{
 this.div.top  = this.yInici;
 this.div.left = this.xInici; 
 this.xPos	   = this.xInici;
 this.yPos	   = this.yInici;
 this.actiu	   = true;
}

function fPosXY(left,top)
{
 this.xPos	   = left;
 this.yPos	   = top;
 this.div.left = this.xPos;
 this.div.top  = this.yPos;
}

function fStop()
{
 this.actiu = false;
}

function fStartUp()
{
 this.actiu = true;
 this.offSet = Math.abs(this.offSet);
 this.SlideV();
}

function fStartDown()
{
 this.actiu = true;
 this.offSet = (Math.abs(this.offSet))*(-1);
 this.SlideV();
}

function fSaltUp()
{
 this.PosXY(this.xPos,this.yPos+this.salt)
}

function fSaltDown()
{
 this.PosXY(this.xPos,this.yPos-this.salt)
}

function fStartLeft()
{
 this.actiu = true;
 this.offSet = Math.abs(this.offSet);
 this.SlideH();
}

function fStartRight()
{
 this.actiu = true;
 this.offSet = (Math.abs(this.offSet))*(-1);
 this.SlideH();
}

function fSlideV()
{
 if (this.actiu==true)
 {
	if (((this.yPos + this.offSet) < this.yTop) && ((this.yPos + this.offSet) > this.yBottom)){
		this.yPos += this.offSet;
		this.div.top = this.yPos;
		setTimeout(this.obj+'.SlideV()',1);
	}
	else{
		if ((this.yPos + this.offSet) < this.yTop){
		
			showDiv(this.ddown);
		}
		else{
			showDiv(this.dup);
		}
	}	
 }
}

function fSlideH()
{
 if (this.actiu==true)
 {
	this.xPos += this.offSet;
	this.div.left = this.xPos;
	setTimeout(this.obj+'.SlideH()',1);
 }
}


//Particulars d'aquesta pagina
function fPosIniciClip()
{
 this.div.top  = this.yInici;
 this.div.left = this.xInici; 
 this.xPos	   = this.xInici;
 this.yPos	   = this.yInici;
 this.actiu	   = true;
 //clipTo(this.div,0,365,40,0);
}

function fStartUpClip()
{
 this.actiu = true;
 this.offSet = Math.abs(this.offSet);
 showDiv(this.ddown);
 this.SlideVClip();
}

function fStartDownClip()
{
 this.actiu = true;
 this.offSet = (Math.abs(this.offSet))*(-1);
 showDiv(this.dup);
 this.SlideVClip();
}

function fSlideVClip()
{
 if (this.actiu==true)
 {//alert('yPos: '+this.yPos+' yTop: '+this.yTop+' yBottom: '+this.yBottom);
	if (((this.yPos + this.offSet) < this.yTop) && ((this.yPos + this.offSet) > this.yBottom)){
		this.yPos += this.offSet;
		this.div.top = this.yPos;
		scroll_clip(this.div,this.offSet);
		setTimeout(this.obj+'.SlideVClip()',1);
		
	}
	else{
		if (clipValues(this.div,'t')==4) scroll_clip(this.div,this.offSet);
		
		if ((this.yPos + this.offSet) < this.yTop){
			showDiv(this.dup);
			hideDiv(this.ddown);
		}
		else{
			hideDiv(this.dup);
			showDiv(this.ddown);
		}
	}	
 }
}

function fStartLeftClip()
{
 this.actiu = true;
 this.offSet = Math.abs(this.offSet);
 showDiv(this.ddown);
 this.SlideHClip();
}

function fStartRightClip()
{
 this.actiu = true;
 this.offSet = (Math.abs(this.offSet))*(-1);
 showDiv(this.dup);
 this.SlideHClip();
}



function fSlideHClip()
{
 if (this.actiu==true)
 {//alert('xPos: '+this.xPos+' xLeft: '+this.xLeft+' xRight: '+this.xRight);
	if (((this.xPos + this.offSet) < this.xLeft) && ((this.xPos + this.offSet) > this.xRight)){
		this.xPos += this.offSet;
		this.div.left = this.xPos;
		scroll_clip2(this.div,this.offSet);
		setTimeout(this.obj+'.SlideHClip()',1);

	}
	else{
		if (clipValues(this.div,'l')==4) scroll_clip2(this.div,this.offSet);
			//alert(this.xPos);		alert(this.xLeft);	
		if ((this.xPos + this.offSet) < this.xLeft){
			showDiv(this.dup);
			hideDiv(this.ddown);
		}
		else{	
			hideDiv(this.dup);
			showDiv(this.ddown);
		}
	}	
 }
}


function clipValues(obj,which)
{
	if (n)
	{
    	if (which=="t") return obj.clip.top
        if (which=="r") return obj.clip.right
        if (which=="b") return obj.clip.bottom
        if (which=="l") return obj.clip.left
    }
	else if (ns6)
	{	    	
		//alert('valors');	
        var clipv = obj.clip.replace("pt","px").replace("pt","px").split("rect(")[1].split(")")[0].split("px")
        if (which=="t") return Number(clipv[0])
        if (which=="r") return Number(clipv[1])
        if (which=="b") return Number(clipv[2])
        if (which=="l") return Number(clipv[3])
    }
    else
    {
        var clipv = obj.clip.split("rect(")[1].split(")")[0].split("px")
        if (which=="t") return Number(clipv[0])
        if (which=="r") return Number(clipv[1])
        if (which=="b") return Number(clipv[2])
        if (which=="l") return Number(clipv[3])
		
    }
}
  
  
        
function clipTo(obj,t,r,b,l)
{

	
	
	if (n)
	{
    	obj.clip.top = t
        obj.clip.right = r
        obj.clip.bottom = b
        obj.clip.left = l
    }   
	else if (ns6)
	{	
    	obj.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
    }    
    else  obj.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
}
  
  
        
function scroll_clip (div,pPixels)
{
 /*	div		:	objecte DIV
	pPixels :	desplaçament per click
 */
	
	var	t	 = clipValues(div,'t');
	var	r	 = clipValues(div,'r');
	var	b	 = clipValues(div,'b');
	var	l	 = clipValues(div,'l');
	
   clipTo(div, (t - pPixels) , (r), (b - pPixels), (l));
}

function scroll_clip2 (div,pPixels)
{
 /*	div		:	objecte DIV
	pPixels :	desplaçament per click
 */
	
	var	t	 = clipValues(div,'t');
	var	r	 = clipValues(div,'r');
	var	b	 = clipValues(div,'b');
	var	l	 = clipValues(div,'l');
	
   clipTo(div, (t) , (r - pPixels), (b), (l - pPixels));
}