window.onload = function () {
	if (self.init) init();
}

var scrollers = new Array();
var scrollParams = new Array();

if(document.getElementById("recently_scroll")) scrollers.push('recently_scroll');
if(document.getElementById("hor_scroll")) scrollers.push('hor_scroll');
if(document.getElementById("hotitems_scroll")) scrollers.push('hotitems_scroll');
if(document.getElementById("brands_scroll")) scrollers.push('brands_scroll');
if(document.getElementById("related_scroll")) scrollers.push('related_scroll');
	
for(i=0;i<scrollers.length;i++){
	scrollParams[i] = new Array('clipTop', 'clipWidth', 'clipBottom', 'topper', 'lyrheight');
	if(scrollers[i] == 'recently_scroll'){
		scrollParams[i]['clipTop'] = 0; scrollParams[i]['clipWidth'] = 167; scrollParams[i]['clipBottom'] = 420; scrollParams[i]['topper'] = 0; scrollParams[i]['lyrheight'] = 0;
		document.getElementById("recently_scroll").style.visibility = 'visible';
	}else if(scrollers[i] == 'hotitems_scroll'){
		scrollParams[i]['clipTop'] = 0; scrollParams[i]['clipWidth'] = 167; scrollParams[i]['clipBottom'] = 320; scrollParams[i]['topper'] = 0; scrollParams[i]['lyrheight'] = 0;
		document.getElementById("hotitems_scroll").style.visibility = 'visible';
	}else if(scrollers[i] == 'hor_scroll'){
		scrollParams[i]['clipTop'] = 0; scrollParams[i]['clipWidth'] = 112; scrollParams[i]['clipBottom'] = 365; scrollParams[i]['topper'] = 0; scrollParams[i]['lyrheight'] = 0;
		var horUl = document.getElementById("hor_ul");
		var ulQty = (horUl.getElementsByTagName('LI').length * 73);
		document.getElementById("hor_scroll").style.width = ulQty+'px';
		document.getElementById("hor_scroll").style.visibility = 'visible';
	}else if(scrollers[i] == 'related_scroll'){
		scrollParams[i]['clipTop'] = 0; scrollParams[i]['clipWidth'] = 151; scrollParams[i]['clipBottom'] = 530; scrollParams[i]['topper'] = 0; scrollParams[i]['lyrheight'] = 0;
		var horUl = document.getElementById("related_scroll_ul");
		var ulQty = (horUl.getElementsByTagName('A').length * 173);
		document.getElementById("related_scroll").style.width = ulQty+'px';
		document.getElementById("related_scroll").style.visibility = 'visible';
	}else if(scrollers[i] == 'brands_scroll'){
		scrollParams[i]['clipTop'] = 0; scrollParams[i]['clipWidth'] = 167; scrollParams[i]['clipBottom'] = 428; scrollParams[i]['topper'] = 0; scrollParams[i]['lyrheight'] = 0;
		document.getElementById("brands_scroll").style.visibility = 'visible';
	}
}

var time,amount,theTime,theHeight,DHTML;

function init()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	for(i=0;i<scrollers.length;i++){
		var x = new getObj(scrollers[i]);
		if (document.layers)
		{
			if(scrollers[i] == 'hor_scroll' || scrollers[i] == 'related_scroll'){
				scrollParams[i]['lyrheight'] = x.style.clip.right;
				x.style.clip.left = scrollParams[i]['clipTop'];
				x.style.clip.top = 0;
				x.style.clip.bottom = scrollParams[i]['clipWidth'];
				x.style.clip.right = scrollParams[i]['clipBottom'];
			}else{
				scrollParams[i]['lyrheight'] = x.style.clip.bottom;
				x.style.clip.top = scrollParams[i]['clipTop'];
				x.style.clip.left = 0;
				x.style.clip.right = scrollParams[i]['clipWidth'];
				x.style.clip.bottom = scrollParams[i]['clipBottom'];
			}
			scrollParams[i]['lyrheight'] += 20;
		}
		else if (document.getElementById || document.all)
		{
			if(scrollers[i] == 'hor_scroll' || scrollers[i] == 'related_scroll'){
				scrollParams[i]['lyrheight'] = x.obj.offsetWidth;
				var clipstring = 'rect('+scrollParams[i]['clipTop']+'px,'+scrollParams[i]['clipBottom']+'px,'+scrollParams[i]['clipWidth']+'px,0)';
			}else{
				scrollParams[i]['lyrheight'] = x.obj.offsetHeight;
				var clipstring = 'rect('+scrollParams[i]['clipTop']+'px,'+scrollParams[i]['clipWidth']+'px,'+scrollParams[i]['clipBottom']+'px,0)';
			}
			x.style.clip = clipstring;
		}
	}
	
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	if (document.all) { theTime = tim*10; } // adjusting speed for IEs
	for(i=0;i<scrollers.length;i++){
		if(layername == scrollers[i]){
			var arr_index = i;
		}
	}
	realscroll(arr_index);
}

function stopScroll()
{
	if (time) clearTimeout(time);
}

function realscroll(ind)
{
	if (!DHTML) return;
	scrollParams[ind]['clipTop'] += amount;
	scrollParams[ind]['clipBottom'] += amount;
	scrollParams[ind]['topper'] -= amount;
	if (scrollParams[ind]['clipTop'] < 0 || scrollParams[ind]['clipBottom'] > scrollParams[ind]['lyrheight'])
	{
		scrollParams[ind]['clipTop'] -= amount;
		scrollParams[ind]['clipBottom'] -= amount;
		scrollParams[ind]['topper'] += amount;
		return;
	}
	if (document.getElementById || document.all)
	{
		if(scrollers[ind] == 'hor_scroll' || scrollers[ind] == 'related_scroll'){ clipstring = 'rect(0,'+scrollParams[ind]['clipBottom']+'px,'+scrollParams[ind]['clipWidth']+'px,'+scrollParams[ind]['clipTop']+'px)';
		}else{ clipstring = 'rect('+scrollParams[ind]['clipTop']+'px,'+scrollParams[ind]['clipWidth']+'px,'+scrollParams[ind]['clipBottom']+'px,0)' }
		thelayer.style.clip = clipstring;
		if(scrollers[ind] == 'hor_scroll' || scrollers[ind] == 'related_scroll'){ thelayer.style.marginLeft = scrollParams[ind]['topper'] + 'px';
		}else{ thelayer.style.marginTop = scrollParams[ind]['topper'] + 'px'; }
	}
	else if (document.layers)
	{
		if(scrollers[ind] == 'hor_scroll' || scrollers[ind] == 'related_scroll'){
			thelayer.style.clip.left = scrollParams[ind]['clipTop'];
			thelayer.style.clip.right = scrollParams[ind]['clipBottom'];
			thelayer.style.left = scrollParams[ind]['topper'];
		}else{
			thelayer.style.clip.top = scrollParams[ind]['clipTop'];
			thelayer.style.clip.bottom = scrollParams[ind]['clipBottom'];
			thelayer.style.top = scrollParams[ind]['topper'];
		}
	}
	time = setTimeout('realscroll('+ind+')',theTime);
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}
