// Made by geeeet@ghtml.com
// Keep these two lines and you're free to use this code

// Known bugs :
// If ie4.5 mac, please press apple-t to remove sidebar, otherwise everything is pushed 20px to the right...

// Corrected bugs :
// 25.01.2001 - When the height of the span "content" was less than the height of the span "contentClip" a javascript error occured, function changed : move()
// 21.02.2001 - Scrolling text wasn't selectable in ie, function changed : move()
// 05.03.2001 - Ie x and y coordinates was wrong when page was scrolled, function changed : getMouse()

// 19.04.2001 - Finally able to remove browser-scrollbar if content is longer than the browser is high:
// Just put this in the style-tag right before the end head-tag:
// body {margin-left:0; margin-right:0; margin-top:0; margin-bottom:0; width:100%;height:100%;overflow:hidden}

// Touch me here :-)
var upH = 18; // Height of up-arrow
var upW = 12; // Width of up-arrow
var downH = 18; // Height of down-arrow
var downW = 12; // Width of down-arrow
var dragH = 26; // Height of scrollbar
var dragW = 17; // Width of scrollbar
var scrollH = 500; // Height of scrollbar
var speed = 50;

var slideDur = 200;
var destination = 0;
var steps = 245;
var curIndex = 0;
var curPadding = 15; //default padding, it will be changed when page fired
var halfstateHeight = 115; //default halfstateHeight
var currImageHeight = 230; // default ImageHeight, it will be changed when page fired
var initBlurObjName = ''
var maxContentT = 0;
var lastRound = true;
// And now... go to the bottom of the page...

// Browser detection
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;

var mouseY; // Mouse Y position onclick
var mouseX; // Mouse X position onclick

var clickUp = false; // If click on up-arrow
var clickDown = false; // If click on down-arrow
var clickDrag = false; // If click on scrollbar
var clickAbove = false; // If click above scrollbar
var clickBelow = false; // If click below scrollbar

//var timer = setTimeout("",500); // Repeat variable
var timer = 0;
var upL; // Up-arrow X
var upT; // Up-arrow Y
var downL; // Down-arrow X
var downT; // Down-arrow Y
var dragL; // Scrollbar X
var dragT; // Scrollbar Y
var rulerL; // Ruler X
var rulerT; // Ruler Y
var contentT; // Content layer Y;
var contentH; // Content height
var contentClipH; // Content clip height
var scrollLength; // Number of pixels scrollbar should move
var startY; // Keeps track of offset between mouse and span

// Mousedown
function down(e){

	if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
	
	getMouse(e);
	startY = (mouseY - dragT);
	
	// If click on up-arrow
	if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
		clickUp = true;
		return scrollUp();
	}	
	// Else if click on down-arrow
	else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
		clickDown = true;
		return scrollDown();
	}
	// Else if click on scrollbar
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
		clickDrag = true;
		return false;
	}
	else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
		// If click above drag
		
		if(mouseY < dragT){
			clickAbove = true;
			clickUp = true;
			return scrollUp();
		}
		// Else click below drag
		else{
		
			clickBelow = true;
			clickDown = true;
			return scrollDown();
		}
	}
	// If no scrolling is to take place
	else{
	
		return true;
	}
}

// Drag function
function move(e){
	if(clickDrag && contentH > contentClipH){
		getMouse(e);
		dragT = (mouseY - startY);
		
		if(dragT < (rulerT))
			dragT = rulerT;		
		if(dragT > (rulerT + scrollH - dragH))
			dragT = (rulerT + scrollH - dragH);
		
		contentT = ((dragT - rulerT)*(1/scrollLength));
		contentT = eval('-' + contentT);

		moveTo();
		
		// So ie-pc doesn't select gifs
		if(ie4)
			return false;
	}
}

function up(){
	clearTimeout(timer);
	// Resetting variables
	clickUp = false;
	clickDown = false;
	clickDrag = false;
	clickAbove = false;
	clickBelow = false;
	return true;
}

// Reads content layer top
function getT(){
	if(ie4)
		contentT = document.all.RightNavInner.style.pixelTop;
	else if(nn4)
		contentT = document.RightNavOuter.document.RightNavInner.top;
	else if(dom)
		contentT = parseInt(document.getElementById("RightNavInner").style.top);
}

// Reads mouse X and Y coordinates
function getMouse(e){
	if(ie4){
		mouseY = event.clientY + document.body.scrollTop;
		mouseX = event.clientX + document.body.scrollLeft;
	}
	else if(nn4 || dom){
		mouseY = e.pageY;
		mouseX = e.pageX;
	
	}
}

// Moves the layer
function moveTo(){
	if(ie4){
		document.all.RightNavInner.style.top = contentT;
		//document.all.ruler.style.top = dragT;
		//document.all.drag.style.top = dragT;
	}
	else if(nn4){
		document.RightNavOuter.document.RightNavInner.top = contentT;
		//document.ruler.top = dragT;
		//document.drag.top = dragT;
	}
	else if(dom){
		document.getElementById("RightNavInner").style.top = contentT + "px";
		//document.getElementById("drag").style.top = dragT + "px";
		//document.getElementById("ruler").style.top = dragT + "px";
	}
}

function calculatePadding()
{
    curPadding = ((scrollH - (halfstateHeight * 2)) - currImageHeight) / 2;
    document.writeln("<style> .ImageGalleryObject{padding-bottom: " + curPadding + "px}</style>");  
}
var index=1;
// Scrolls up
function scrollUp(){
	getT();
	
//	if(clickAbove){
//		if(dragT <= (mouseY-(dragH/2)))
//			return up();
//	}
//	
	if(clickUp)
	{	
	    if( currSteps < steps){
		    if(contentT < 0){		
			    //dragT = dragT - (speed*scrollLength);
    			
			    //if(dragT < (rulerT))
				 //   dragT = rulerT;    			  
				
			    currSteps += speed;
			    
			    if(currSteps >= steps) 
			   	{
			   	    contentT = contentT + (steps - (currSteps - speed));			   	    
			   	}
			   	else
			   	    contentT = contentT + speed;
			     //if(contentT > maxContentT)
			        //contentT = maxContentT-1;
			    if(contentT > 0)
				    contentT = 0;
    			
			    moveTo();
			    timer = setTimeout("scrollUp()",1);
			    
		    }
		}
		else
		{
		    timer = 0;//reset timer
		    adjustShadow();
		}
	}
	return false;
}

// Scrolls down
function scrollDown(){
	getT();
	
//	if(clickBelow){
//		if(dragT >= (mouseY-(dragH/2)))
//			return up();
//	}

	if(clickDown)
	{	    
	    if( currSteps < steps)
	    {
		    if(contentT - curPadding > -(contentH - contentClipH)){			
			    //dragT = dragT + (speed*scrollLength);
			    //if(dragT > (rulerT + scrollH - dragH))
				 //   dragT = (rulerT + scrollH - dragH);					    
				
			    currSteps += speed;
			   	if(currSteps >= steps) 
			   	{
			   	    contentT = contentT - (steps - (currSteps - speed));			   	    
			   	}
			   	else
			   	    contentT = contentT - speed;
			    //if(contentT < maxContentT)
			      //  contentT = maxContentT + 1;	 
			       
			    if(contentT < -(contentH - contentClipH))
				    contentT = -(contentH - contentClipH);
    			
    			
			    moveTo();    			
			    timer = setTimeout("scrollDown()",1);
			    
		    }
		}
		else
		{
		    timer = 0;
		    adjustShadow();
		}
	}
	return false;
}

function callScroll(direction)
{	
	if(timer > 0)
	{	    
	    return false;
	}
	if(direction == "up")
	{	    
	    currSteps = 0;	
		destination = dragT - steps;		
		steps = curPadding + currImageHeight;		
		clickUp=true;
		lastRound = false;
		scrollUp()	
			
	}
	else
	{	   
	    currSteps = 0;	    
		destination = dragT + steps;
		clickDown=true;
		lastRound = false;		
		steps = curPadding + currImageHeight;
		scrollDown();			
	}
}

function adjustShadow()
{
    if(contentT >= 0)   
    {         
        if(ie4)
            document.all.dvImageTopBlur.style.visibility = 'hidden'//hide top shadow
        else
            document.getElementById('dvImageTopBlur').style.visibility = 'hidden'//hide top shadow
    }
    else   
    {    
        if(ie4)
            document.all.dvImageTopBlur.style.visibility = 'visible'//hide top shadow       
        else
            document.getElementById('dvImageTopBlur').style.visibility = 'visible'//show top shadow
    }
    if(contentT - curPadding <= -(contentH - contentClipH))
    {
        if(ie4)
            document.all.dvImageBottomBlur.style.visibility = 'hidden'//hide top shadow        
        else
            document.getElementById('dvImageBottomBlur').style.visibility = 'hidden'//get rid of bottom shadow
    }
    else 
    {
        if(ie4)
            document.all.dvImageBottomBlur.style.visibility = 'visible'//hide top shadow        
        else
            document.getElementById('dvImageBottomBlur').style.visibility = 'visible'//show bottom shadow
    }
}

function setShadow(objName,showShadow)
{
    var obj;
    if(ie4)
        obj = eval("document.all." + objName);    
    else
        obj = document.getElementById(objName);
        
    if(!showShadow)
        obj.style.visibility = 'hidden'
    else
        obj.style.visibility = 'visible'
}

function setInitBlur()
{
    if(initBlurObjName != '')
        setShadow(initBlurObjName,true);
}
function alterLogoImage(logoName,imageID)
{
    if(ie4) 
        eval("document.all." + logoName + ".src = '" + LogoArr[imageID] + "'")  
    else if(nn4)
        eval("document." + logoName + ".src = '" + LogoArr[imageID] + "'")  
    else
        document.getElementById(logoName).src = LogoArr[imageID];            
}

// reloads page to position the layers again
function reloadPage(){
	location.reload();
}

// Preload
function eventLoader(){
	if(ie4){
		// Up-arrow X and Y variables
		//upL = document.all.up.style.pixelLeft;
		//upT = document.all.up.style.pixelTop;		
		// Down-arrow X and Y variables
		//downL = document.all.down.style.pixelLeft;
		//downT = document.all.down.style.pixelTop;
		// Scrollbar X and Y variables
		dragL = 14//document.all.drag.style.pixelLeft;
		dragT = 221//document.all.drag.style.pixelTop;	
		
		currSteps = 0;	
		curIndex = 0;
		// Ruler Y variable
		//rulerT = document.all.ruler.style.pixelTop;		
		// Height of content layer and clip layer
		contentH = parseInt(document.all.RightNavInner.scrollHeight);
		contentClipH = parseInt(document.all.RightNavOuter.style.height);
		
	}
	else if(nn4){
		// Up-arrow X and Y variables
		//upL = document.up.left;
		//upT = document.up.top;		
		// Down-arrow X and Y variables
		//downL = document.down.left;
		//downT = document.down.top;		
		// Scrollbar X and Y variables
		dragL = document.drag.left;
		dragT = document.drag.top;		
		// Ruler Y variable
		//rulerT = document.ruler.top;
		// Height of content layer and clip layer
		contentH = document.RightNavOuter.document.RightNavInner.clip.bottom;
		contentClipH = document.RightNavOuter.clip.bottom;
	}
	else if(dom){
		// Up-arrow X and Y variables
		//upL = parseInt(document.getElementById("up").style.left);
		//upT = parseInt(document.getElementById("up").style.top);
		// Down-arrow X and Y variables
		//downL = parseInt(document.getElementById("down").style.left);
		//downT = parseInt(document.getElementById("down").style.top);
		// Scrollbar X and Y variables
		//dragL = parseInt(document.getElementById("drag").style.left);
		//dragT = parseInt(document.getElementById("drag").style.top);
		// Ruler Y variable
		//rulerT = parseInt(document.getElementById("ruler").style.top);
		// Height of content layer and clip layer
		contentH = parseInt(document.getElementById("RightNavInner").offsetHeight);
		contentClipH = parseInt(document.getElementById("RightNavOuter").offsetHeight);
		document.getElementById("RightNavInner").style.top = 0 + "px";
		
		dragL = 14//document.all.drag.style.pixelLeft;
		dragT = 221//document.all.drag.style.pixelTop;	
		currSteps = 0;	
		curIndex = 1;
		
		
	}
	// Number of pixels scrollbar should move
	scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
	// Initializes event capturing
	if(nn4){
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
		window.onresize = reloadPage;
	}
	//document.onmousedown = down;
	//document.onmousemove = move;
	//document.onmouseup = up;
	
}


var ie=document.all;
var nn6=document.getElementById&&!document.all;

var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    //dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    var oldTop = parseInt(dobj.style.top + 0);
    var newTop = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    var minTop = 30;
    var maxTop = 530;
    if(newTop >= 42 && newTop <= maxTop)
    {    
//        if(oldTop < newTop)
//            dragDown(newTop-oldTop);
//        else
//            dragUp(oldTop-newTop);
        dobj.style.top = newTop;
    }
    else if (newTop > maxTop)
        dobj.style.top = maxTop;
    else
        dobj.style.top = minTop;
    return false;
  }
}
function moveImage(e)
{
    var oldTop = parseInt(dobj.style.top + 0);
    var newTop = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    
}
function autoAdjust(e)
{
    isdrag = false;
}
function selectmouse(e) 
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";

  while (fobj.tagName != topelement && fobj.className != "dragMe")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }

  if (fobj.className=="dragMe")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;

    
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup= autoAdjust//new Function("isdrag=false");




