/* 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';
	    }
    }
}



var newsScroller={
    init:function(){	        
	    newsScroller.docH = gI("news_content").offsetHeight;
	    newsScroller.contH = gI("news_container").offsetHeight;
	    newsScroller.scrollAreaH = gI("news_scrollArea").offsetHeight;
	    newsScroller.scrollH = (newsScroller.contH * newsScroller.scrollAreaH) / newsScroller.docH;
	    newsScroller.scrollDist = Math.round(newsScroller.scrollAreaH-parseInt(gI("news_scroller").offsetHeight));
	    Drag.init(gI("news_scroller"),null,0,0,-1,newsScroller.scrollDist);
	    gI("news_scroller").onDrag=function(x,y){
		    var scrollY=parseInt(gI("news_scroller").style.top);
		    var docY=0-(scrollY*(newsScroller.docH-newsScroller.contH)/newsScroller.scrollDist);
		    gI('news_content').style.top = docY+'px';
	    }
    }
}




var eventsScroller={
    init:function(){        
	    eventsScroller.docH = gI("events_content").offsetHeight;
	    eventsScroller.contH = gI("events_container").offsetHeight;
	    eventsScroller.scrollAreaH = gI("events_scrollArea").offsetHeight;
	    eventsScroller.scrollH = (eventsScroller.contH * eventsScroller.scrollAreaH) / eventsScroller.docH;
	    eventsScroller.scrollDist = Math.round(eventsScroller.scrollAreaH-parseInt(gI("events_scroller").offsetHeight));
	    Drag.init(gI("events_scroller"),null,0,0,-1,eventsScroller.scrollDist);
	    gI("events_scroller").onDrag=function(x,y){
		    var scrollY=parseInt(gI("events_scroller").style.top);
		    var docY=0-(scrollY*(eventsScroller.docH-eventsScroller.contH)/eventsScroller.scrollDist);
		    gI('events_content').style.top = docY+'px';
	    }
    }
}

function scrollWheel(divPrefix){window.event.returnValue=false;beginScroll(event.wheelDelta, divPrefix)}

function scrollClick(dir,e, divPrefix){
	if(navigator.platform.indexOf('Mac')!=-1&&navigator.userAgent.indexOf('MSIE')!=-1){
		scrollDir = dir;
		beginScroll(divPrefix);
	}else{
		scrollDir = dir;
		iTimerID = window.setInterval('beginScroll('+ dir +', "' + divPrefix + '")',100);
	}
}
function stopScroll(){window.clearInterval(iTimerID);}
function beginScroll(dir, divPrefix){
    if(!divPrefix || divPrefix == 'undefined') divPrefix = ""; 
    
	if(dir!=null) scrollDir = dir;
	var px=0;var top=parseInt(gI(divPrefix + "scroller").style.top);var bottom=gI(divPrefix + "scrollArea").offsetHeight-gI(divPrefix + "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(divPrefix + "scroller").style.top=px+'px';docH=gI(divPrefix + "content").offsetHeight;contH=gI(divPrefix + "container").offsetHeight;scrollAreaH=gI(divPrefix + "scrollArea").offsetHeight;
	scrollH=(contH*scrollAreaH)/docH;scrollDist=Math.round(scrollAreaH-parseInt(gI(divPrefix + "scroller").offsetHeight));var scrollY=parseInt(gI(divPrefix + "scroller").style.top);
	var docY=0-(scrollY*(docH-contH)/scrollDist);
	gI(divPrefix + "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');	
	
	if(document.getElementById("events_content")){
	    eventsScroller.init();
	}
	
	if(document.getElementById("news_content")){
	    newsScroller.init();
	}
	
	if(document.getElementById("content")){
	    scroller.init();
	}
	
	if(window.addEventListener) {
		
		if(document.getElementById("events_content")){
		    gI('events_content').addEventListener("DOMMouseScroll", MOZScrollWheelEvents, false);
		    gI('events_content').addEventListener("select", MOZDrag, false);
		}
		
		if(document.getElementById("news_content")){
		    gI('news_content').addEventListener("DOMMouseScroll", MOZScrollWheelNews, false);
		    gI('news_content').addEventListener("select", MOZDrag, false);
		}
		
		if(document.getElementById("content")){
		    gI('content').addEventListener("DOMMouseScroll", MOZScrollWheel, false);
		    gI('content').addEventListener("select", MOZDrag, false);
		}
		
		
	}
}
//Get the content to scroll in Mozilla
function MOZScrollWheelEvents(e){
    var strPrefix = "events_";
    MOZScrollWheel(e, strPrefix);
}

function MOZScrollWheelNews(e){
   var strPrefix = "news_";
   MOZScrollWheel(e, strPrefix);
}

function MOZScrollWheel(e, strPrefix){  
    if(!strPrefix) strPrefix = ""; 
    e.preventDefault();
    var top=parseInt(gI(strPrefix + "scroller").style.top);
    var bottom=gI(strPrefix + "scrollArea").offsetHeight-gI(strPrefix + "scroller").offsetHeight;
    beginScroll(e.detail*-1, strPrefix);
}

function MOZDrag(e){
	e.preventDefault();	
}



