
/* ------------------------------------------------------------------------------------------------ */
/* All intellectual property rights relating to this code are owned by EURO RSCG DSW Partners, LLC. */
/* ------------------------------------------------------------------------------------------------ */

// FYI: This code is prototype only (e.g. Does not have DSW Q&A Stamp of Approval) and has not passed a formal I-Lab.
//      Thus, all cross-platform issues may not have been addressed.
// 	Anyone using this code must ensure it passes DSW's Q&A process before delivery.
//
// IMPORTANT: Please remove all comments, except the "property rights" comment, from this code before delivery ( js comments should be internal use only )
//
// If you have any questions about this code Contact: Jared Newbold (e.g. don't change or delete something if you don't know what it does)


var ns = (document.layers) ? 1 : 0; /* Netscape 4.0 + */
var ie = (document.all) ? 1 : 0; /* IE 4.0 + */

// Equalizing Variables
var hidden = (ie)? 'hidden':'hide';
var visible = (ie)? 'visible':'show';

var currentScroll = ''; /* contains name of current scroll object. (The one being scrolled) */

var scrollTimer = setTimeout('null',100);
function checkScroll() { /* This function determines if scrollbar is need and turns in on/off */
	var b = this.bottom;
	this.findBottom();
	if (this.bottom!=b) {
		this.scrollBar.style.visibility= ((this.bottom==0)? hidden:visible);
		if (this.bottom==0) this.contents.style.top=0;
		if (parseInt(this.contents.style.top)<this.bottom) this.contents.style.top=this.bottom;
		this.syncScroll(); }
	clearTimeout(scrollTimer); scrollTimer = setTimeout(this.name+'.checkScroll()',1000); }

function findBottom(){ /* calculates bottom of scroll contents */
	if (ie) this.bottom = (this.height-this.tb-this.bb)-this.contents.scrollHeight
	if (ns) this.bottom = (this.height-this.tb-this.bb)-this.contents.document.height;
	if (this.bottom>0) this.bottom = 0; }

//******* Scrolling Functions ********//

var inSlide = 0; var inScroll=0; var offset = 0;

/* these functions scroll contents using the up/down scroll arrows */
function scrollUp() { if (!this.ready) return; currentScroll=this; this.findBottom(); inScroll=1; document.onmouseup=scrollStop; scrollIt(this.speed); }
function scrollDn() { if (!this.ready) return; currentScroll=this; this.findBottom(); inScroll=1; document.onmouseup=scrollStop; scrollIt(-this.speed); }
function scrollIt(s) { if (!inScroll) return; var c = currentScroll;
		var y = parseInt(c.contents.style.top)+s;
		if (y>0) y=0; if (y<c.bottom) y=c.bottom;
		c.contents.style.top= y; c.syncScroll();
		setTimeout('scrollIt('+s+')',20); }

function scrollIt2(s) { if (!inScroll) return;
		var y = parseInt(this.contents.style.top)+s;
		if (y>0) y=0; if (y<this.bottom) y=this.bottom;
		this.contents.style.top= y; this.syncScroll();
		setTimeout(this.name+'.scrollIt('+s+')',20); }

 function slideStart(e) {  /* starts the dragging of the scroll island */
	var c = currentScroll = this.box; if (!c.ready) return;
	c.findBottom();
	if (ns) { offset = e.pageY-(c.slider.pageY-c.scrollBar.pageY); }
	if (ie) { offset = event.clientY + document.body.scrollTop - this.style.pixelTop; }
	inSlide = 1;
	document.onmousemove = slideUpdate;
	document.onmouseup = scrollStop;
	}

function scrollStop() { inSlide = 0; inScroll=0; document.onmousemove=null; document.onmouseup=null; }

/* onmousemove function, moves the scroll island and syncs contents*/
function slideUpdate(e) { if (!inSlide) return false; var y = 0; var c = currentScroll;
	if (ns) { y = e.pageY - offset; }
	if (ie) { y = event.clientY + document.body.scrollTop - offset;}
	if (y<c.sb.uh) y=c.sb.uh; if (y>(c.height-c.sb.dh-c.sb.ih)) { y= c.height-c.sb.dh-c.sb.ih; }
	c.slider.style.top = y; c.syncText(); return false;  }

/* syncs contents based on position of scroll island */
function syncText() { if ((this.height-this.sb.uh-this.sb.dh-this.sb.ih)<=0) return;
	this.contents.style.top= Math.round(this.bottom*((parseInt(this.slider.style.top)-this.sb.uh)/(this.height-this.sb.uh-this.sb.dh-this.sb.ih))); }

/* syncs scroll island based on position of contents */
function syncScroll() { if (this.bottom==0) return;
	this.slider.style.top= Math.round((this.height-this.sb.uh-this.sb.dh-this.sb.ih)*((parseInt(this.contents.style.top))/this.bottom))+this.sb.uh; }

//******* End Scrolling Functions ********//

//******* Scroll Object Functions ********//


 /* holds object specs and defines object functions | (object name, left, top, width, height,z-index) */

 function scrollBarObject(color,w,uh,dn,ih) {this.color=color; this.w=w;   this.uh=uh;  this.dh = dn;  this.ih = ih;}

 function scrollObject(theName,x,y,w,h,z) {

	this.name = theName;
	this.left = x; 
	this.top = y; 
	this.width = w; this.height = h;
	this.lb = 0;   this.tb = 0;  this.rb = 0;    this.bb = 0;
	this.bottom = 0; this.z = z;
	this.speed = 8;
	this.sb = new scrollBarObject('gray',16,16,16,41);
	this.checkScroll = checkScroll;
	this.syncText = syncText;
	this.syncScroll = syncScroll;
	this.swapTo = swapTo;
	this.up = scrollUp;
	this.dn = scrollDn;
	this.scrollIt = scrollIt;
	this.findBottom = findBottom;
	this.setPadding = setPadding;
	this.beginMain = beginMain;
	this.initMain = initMain;
	this.createScrollBar = createScrollBar;
	this.initScrollBar = initScrollBar;
	this.equalize = scrollEqualize;
	this.init = initScroll;
	this.ready = false;
}

 /* sets content area padding | (left,top,right,bottom) */
function setPadding(l,t,r,b) { this.lb=l; this.tb=t; this.rb=r; this.bb=b; }

/* create a clipped layer which houses the content layers to be scrolled */   /* FYI: Need To change values here to match your scrollbar graphics*/
function beginMain() { var l,t,w,h; l= this.left+this.lb; t= this.top+this.tb; w = this.width-this.lb-this.rb-this.sb.w; h = this.height-this.tb-this.bb; this.contentWidth = w;
	if (ie) var stuff = '<DIV ID="'+ this.name +'Main" STYLE="position:absolute; overflow:hidden; clip:rect(0,'+w+','+h+',0); left:'+ l +'px; top:'+ t +'px; width:'+ w +'px; height:'+ h +'px; visibility:visible; z-index:'+this.z+'">';
	if (ns) var stuff = '<LAYER name="'+ this.name +'Main" left='+ l +' top='+ t +' width='+ w +' height='+ h +' clip="'+ w +','+ h +'" visibility=visible z-index='+this.z+'>';
	return(stuff); }
function initMain() { this.main = getLayer(this.name+'Main'); }


/* create a scrollbar layer */  /* FYI: Need To change values here to match your scrollbar graphics*/
function createScrollBar() {
	var stuff= layerTag(this.name +'Scroll',this.z,hidden,(this.left+this.width-this.sb.w),this.top,this.sb.w,this.height);
	stuff += '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="'+this.sb.w+'" BACKGROUND="images/scroll_bar.gif">';
	stuff += '<TR><TD HEIGHT="'+this.sb.uh+'"><A '; if (ns) {stuff += 'HREF="javascript://" ';} else {stuff += 'STYLE="cursor:hand" ';} stuff += 'ONMOUSEDOWN="'+ this.name +'.up(); return(false);" ONMOUSEUP="scrollStop();" ONMOUSEOUT="scrollStop();"><IMG SRC="images/scroll_up.gif" WIDTH="'+this.sb.w+'" HEIGHT="'+this.sb.uh+'" BORDER="0"></A></TD></TR>';
	stuff += '<TR><TD HEIGHT="'+(this.height-this.sb.uh-this.sb.dh)+'"><IMG SRC="../../images/spacer.gif" WIDTH="'+this.sb.w+'" HEIGHT="'+(this.height-this.sb.uh-this.sb.dh)+'"></TD></TR>';
	stuff += '<TR><TD HEIGHT="'+this.sb.dh+'"><A '; if (ns) {stuff += 'HREF="javascript://" ';} else {stuff += 'STYLE="cursor:hand" ';} stuff += 'ONMOUSEDOWN="'+ this.name +'.dn(); return(false);" ONMOUSEUP="scrollStop();" ONMOUSEOUT="scrollStop();"><IMG SRC="images/scroll_down.gif" WIDTH="'+this.sb.w+'" HEIGHT="'+this.sb.dh+'" BORDER="0"></A></TD></TR></TABLE>';
	stuff += newLayer(this.name +'Slider','<IMG SRC="images/scroll.gif" WIDTH="'+this.sb.w+'" HEIGHT="'+this.sb.ih+'">',1,'inherit',0,this.sb.uh,this.sb.w,this.sb.ih);
	stuff += endTag; return(stuff); }

function initScrollBar() {

	this.scrollBar = getLayer(this.name+'Scroll');
	this.slider = getLayer(this.name+'Slider'); this.slider.box=this;

	if (ns) this.slider.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);

	this.slider.onmousedown = slideStart;
	this.slider.onmouseup = scrollStop;
}


function initScroll(who) { this.equalize(); this.ready=true; this.swapTo(who); }



function scrollEqualize() { if (!ns) return; /* for netscape sets a .style for layers (simplifies cross-browser layer manipulation) */
	for (j=0; j<this.main.document.layers.length; j++) { this.main.document.layers[j].style = this.main.document.layers[j]; }
	this.scrollBar.style = this.scrollBar;
	this.slider.style = this.slider; }

//******* End Scroll Object Functions ********//


//******* Layer Functions ********//

/* returns a layer object | spec = name of layer to retrieve */
function getLayer(spec,base) { if (ie) return document.all[spec]; var q=0; var temp=null;
	if (base==null) base=document; if (base.layers[spec]!=null) return base.layers[spec];
	for (q=0; q<base.layers.length; q++) { if(base.layers[q].document.layers.length>0) { temp = getLayer(spec,base.layers[q].document); if (temp != null) return temp; } }
	return null; }

//******* End Layer Functions ********//

