/* You may find some of this code bunched up and lacking line breaks.  This is intentional to save bandwidth. A few bytes here
and there really add up.*/
var oTimerID = 0; //Show preview timer
var iTimerID = 0; //scroller timer
var uTimerID = 0; //Mask/unmask timer
var ftElm;
var scrollDir = 0;
/*function mask(e){
	if(uTimerID!=0)window.clearTimeout(uTimerID);
	if(ftElm!=null&&ftElm!=e){
		dounmask();//reset the previous box that was masked
	}
	e.style.filter='Alpha(opacity=80)';e.style.MozOpacity=0.8;
	ftElm = e;
}*/
function mask(i){
	if(uTimerID!=0)window.clearTimeout(uTimerID);
	if(ftElm!=null&&ftElm!=i){
		dounmask();//reset the previous box that was masked
	}
	gI('feattop'+i).style.filter='Alpha(opacity=80)';gI('feattop'+i).style.MozOpacity=0.8;
	gI('featmid'+i).style.filter='Alpha(opacity=80)';gI('featmid'+i).style.MozOpacity=0.8;
	gI('featbottom'+i).style.filter='Alpha(opacity=80)';gI('featbottom'+i).style.MozOpacity=0.8;

	ftElm = i;
}
function unmask(i){
	uTimerID=window.setTimeout(dounmask,500);
}
function dounmask(){
	gI('feattop'+ftElm).style.filter='Alpha(opacity=100)';gI('feattop'+ftElm).style.MozOpacity=1.0;
	gI('featmid'+ftElm).style.filter='Alpha(opacity=100)';gI('featmid'+ftElm).style.MozOpacity=1.0;
	gI('featbottom'+ftElm).style.filter='Alpha(opacity=100)';gI('featbottom'+ftElm).style.MozOpacity=1.0;
}

var scroller={
	init:function(){
		scroller.docH = gI("content").offsetHeight;
		scroller.contH = gI("container").offsetHeight;
		scroller.scrollAreaH = gI("scrollArea").offsetHeight;
		scroller.scrollH = (scroller.contH * scroller.scrollAreaH) / scroller.docH;
		scroller.scrollDist = Math.round(scroller.scrollAreaH-parseInt(gI("scroller").offsetHeight));
		Drag.init(gI("scroller"),null,0,0,-1,scroller.scrollDist);
		gI("scroller").onDrag=function(x,y){
			var scrollY=parseInt(gI("scroller").style.top);
			var docY=0-(scrollY*(scroller.docH-scroller.contH)/scroller.scrollDist);
			gI('content').style.top = docY+'px';
		}
	}
}
function scrollWheel(){window.event.returnValue=false;beginScroll(event.wheelDelta)}
function scrollClick(dir,e){
	if(navigator.platform.indexOf('Mac')!=-1&&navigator.userAgent.indexOf('MSIE')!=-1){
		scrollDir = dir;
		beginScroll();
	}else{
		scrollDir = dir;
		iTimerID = window.setInterval(beginScroll,100,dir);
	}
}
function stopScroll(){window.clearInterval(iTimerID);}
function beginScroll(dir){
	if(dir!=null) scrollDir = dir;
	var px=0;var top=parseInt(gI("scroller").style.top);var bottom=gI("scrollArea").offsetHeight-gI("scroller").offsetHeight;
	if(scrollDir>0){
		if(top>0)px=top-5;
		else return false
	}
	else{
		if(top<bottom)px=top+5;
		else return false
	}
	gI("scroller").style.top=px+'px';docH=gI("content").offsetHeight;contH=gI("container").offsetHeight;scrollAreaH=gI("scrollArea").offsetHeight;
	scrollH=(contH*scrollAreaH)/docH;scrollDist=Math.round(scrollAreaH-parseInt(gI("scroller").offsetHeight));var scrollY=parseInt(gI("scroller").style.top);
	var docY=0-(scrollY*(docH-contH)/scrollDist);
	gI("content").style.top=docY+"px"
}
function showPreview(e,txt) {
    window.clearTimeout(oTimerID);
    var offsetX=0;var offsetY=0;var parent;

    for(parent=e; parent; parent=parent.offsetParent) {
		if(parent.offsetLeft)offsetX+=parent.offsetLeft;
		if(parent.offsetTop)offsetY+=parent.offsetTop;
	}
	var Bub=document.getElementById('bubbleContainer');
	gI('bubble').innerHTML=txt;
	Bub.style.top=offsetY+'px';
	//Bub.style.left=getElementsByTagName('body')[0].offsetWidth - offsetX;
	Bub.style.left = e.offsetLeft+350+'px';
	Bub.style.visibility='visible';
}
function hidePreview(){oTimerID=window.setTimeout(doHidePreview,1000);}
function doHidePreview(){gI('bubbleContainer').style.visibility='hidden';}


/********************* onLoad ***************/
window.onload = function() {
	MM_preloadImages('/img/search_btn_ro.gif','/img/cart_icon_ro.gif');	
	scroller.init();
	if(window.addEventListener) {
		gI('content').addEventListener("DOMMouseScroll", MOZScrollWheel, false);
		gI('content').addEventListener("select", MOZDrag, false);
	}
}
//Get the content to scroll in Mozilla
function MOZScrollWheel(e){e.preventDefault();var top=parseInt(gI("scroller").style.top);var bottom=gI("scrollArea").offsetHeight-gI("scroller").offsetHeight;beginScroll(e.detail*-1);}
function MOZDrag(e){
	e.preventDefault();	
}