$=function(idd)
{
 try{return document.getElementById(idd);}
 catch(e){return;}
}
function captureSelectionEvents()
{
	document.body.onselectstart = function(){return false};
	document.body.onselect = function(){return false};
	document.body.ondblclick = function(){return false};
	document.body.onmousedown = function(){return false};
}
function releaseSelectionEvents()
{
	document.body.onselectstart = function(){};
	document.body.onselect = function(){};
	document.body.ondblclick = function(){};
	document.body.onmousedown = function(){};
}
//<scrollbar_related_functions>
var theId=null;
toScrollId=null;
procScrlBar=null;
procToScrl=null;
r=null;
function pick(idd, idd1, evt)
{
 if($(idd1).scrollHeight>$(idd1).offsetHeight)
 {
  evt = (evt) ? evt : ((window.event) ? event : null);
  theId = idd;
  toScrollId = idd1;

	procScrlBar = $(theId).parentNode.offsetHeight-$(theId).offsetHeight;
	procToScrl = Math.abs(($(toScrollId).scrollHeight - $(toScrollId).offsetHeight));
	r=procToScrl/procScrlBar;

	dify = evt.clientY - parseInt(document.getElementById(theId).offsetTop);
	captureSelectionEvents();
  document.onmousemove = moveY;
 }
}

function moveY(evt)
{
 evt=(evt)?evt:((window.event)?event:null);
 if(theId!=null)
  {
    if(parseInt(evt.clientY-dify) >= 0 && parseInt(evt.clientY-dify) <= ($(theId).parentNode.offsetHeight-$(theId).offsetHeight))
    {
			$(theId).style.top = parseInt(evt.clientY) - dify + "px";
			$(toScrollId).scrollTop = parseInt($(theId).offsetTop * r);
		}
		else
		{
			if(parseInt(evt.clientY-dify) < 0) 
			{ 
				$(theId).style.top = '0px';
				$(toScrollId).scrollTop = 0;
			}
			 else
			{
				$(theId).style.top = parseInt($(theId).parentNode.offsetHeight-$(theId).offsetHeight) + 'px';		
				$(toScrollId).scrollTop = parseInt($(toScrollId).scrollHeight + $(toScrollId).offsetHeight);
			}
    }
  }
}

function leave()
{
 theId = null;
 toScrollId = null;
 releaseSelectionEvents();
 window.clearInterval(scrlArrItv);
 document.onmousemove = function(){};
}

document.onmouseup = leave;

scrlArrItv=null;
function scrlDown(scrlCont, scrlIdd, amt)
{
	if(amt==0){amt=$(scrlCont).offsetHeight/50}
	else {amt=$(scrlCont).offsetHeight/Math.abs(amt);};

	scrlDownStep(scrlCont, scrlIdd, amt);
	scrlArrItv=window.setInterval("scrlDownStep('"+scrlCont+"', '"+scrlIdd+"', "+amt+")", parseInt(1000/50));
}
function scrlDownStep(scrlCont, scrlIdd, amt)
{
	procScrlBar = ($(scrlIdd).parentNode.offsetHeight - $(scrlIdd).offsetHeight) / 100;
	procToScrl = ($(scrlCont).scrollHeight - $(scrlCont).offsetHeight) / 100;
	
	$(scrlCont).scrollTop += amt;
	$(scrlIdd).style.top = parseInt(($(scrlCont).scrollTop/procToScrl) * procScrlBar)+"px";
}

function scrlUp(scrlCont, scrlIdd, amt)
{
	if(amt==0){amt=$(scrlCont).offsetHeight/50}
	else {amt=$(scrlCont).offsetHeight/Math.abs(amt);};

	scrlUpStep(scrlCont, scrlIdd, amt);
	scrlArrItv=window.setInterval("scrlUpStep('"+scrlCont+"', '"+scrlIdd+"', "+amt+")", parseInt(1000/50));
}
function scrlUpStep(scrlCont, scrlIdd, amt)
{
	procScrlBar = ($(scrlIdd).parentNode.offsetHeight - $(scrlIdd).offsetHeight) / 100;
	procToScrl = ($(scrlCont).scrollHeight - $(scrlCont).offsetHeight) / 100;
	
	$(scrlCont).scrollTop -= amt;
	$(scrlIdd).style.top = parseInt(($(scrlCont).scrollTop/procToScrl) * procScrlBar) + "px";
}
//</scrollbar_related_functions>
//<animation_related_functions>
function animTop(idd, fps, time, lim, onfinish)
{
	if(!onfinish)onfinish=function(){};
	var o=idd;
	if(!o.JSAnimTop)o.JSAnimTop=new Object();
	o.JSAnimTop.stpNo=(time/1000)*fps;

	o.JSAnimTop.stp=(lim-parseFloat(o.offsetTop))/o.JSAnimTop.stpNo;
	
	if(o.JSAnimTop.itv){window.clearInterval(o.JSAnimTop.itv);};
	var h=parseFloat(o.offsetTop);
	var hh=h-1;
	o.JSAnimTop.itv=window.setInterval(function(){if((Math.abs(lim-h)<=Math.abs(o.JSAnimTop.stp)) || (hh==h)){o.style.top=parseInt(lim)+"px";onfinish();window.clearInterval(o.JSAnimTop.itv);}else{hh=h;h=parseFloat(o.offsetTop)+parseFloat(o.JSAnimTop.stp);o.style.top=parseInt(h)+"px";};}, 1000/fps);
}

//</animation_related_functions>
var opentab=null;
function openOfferTab(tabO)
{
	if(opentab!=null && opentab!=tabO)closeOfferTab(opentab);
	opentab=tabO;
	tabO.style.zIndex="10";
	animTop(tabO, 70, 200, 0, function(){});
}

function closeOfferTab(tabO)
{
	tabO.style.zIndex="11";
	animTop(tabO, 70, 200, -433, function(){});
}


function logIt(txt)
{
	document.getElementById("logit").innerHTML=txt;
}

scrollmethistime=null;
function detectWheel(ev)
{
	var rolls=0;
	if(ev.detail)
	{
		rolls=-ev.detail/3;
	}
	else if(ev.wheelDelta)
	{
		rolls=ev.wheelDelta/120;
	}
	window.defaultStatus=rolls;
	//if(window.opera)rolls=rolls/2.33;
	if(scrollmethistime!=null)
	{
		if(rolls<0)
		{
			//alert('no shit. it works!');
			scrlDownStep('pageResponse', 'dragmetoscroll', Math.abs(rolls)*40);//
		}
		if(rolls>0)
		{
			scrlUpStep('pageResponse', 'dragmetoscroll', Math.abs(rolls)*40);//
		}

		if (ev.preventDefault)ev.preventDefault();
		ev.returnValue = false;
	}

}

if (window.addEventListener)
        window.addEventListener('DOMMouseScroll', detectWheel, false);
window.onmousewheel = document.onmousewheel = function(){detectWheel(event);};

function initTextScrollBar()
{
	var scrollBar = $('scrollBar');
	var textBlock = $('pageResponse');
	if(textBlock == null) return;
	else {
		if(textBlock.scrollHeight <= textBlock.offsetHeight) 
		{ scrollBar.style.display = "none"; } 
		else if(textBlock.scrollHeight > textBlock.offsetHeight) 
		{ scrollBar.style.display = "block"; }
	}
}


