//3.0

var arc_sliderObj = null;
var allArcSliders = new Array();

function arc_sliderObectj(ID, autoplay){
	this.ID = ID;
	this.drawArcScroller = drawArcScroller;
	this.updateHeight = updateHeight;
	this.obj = document.getElementById(ID);
	this.dim = getArcDimention(this.obj)
	this.viewPort = parseInt(this.dim.height)
	this.scrollHeight = this.obj.scrollHeight
	this.scrollerHeight = .99*this.viewPort;
	this.sactive = (this.viewPort < this.scrollHeight)? true:false;
	this.contentHolder = null;
	this.divLoc = null;
	
	if(this.sactive){
		this.imgPath = "/App_Themes/tourismtoronto/images/"
		this.scrollerBG = this.imgPath+"scroller-background-long.gif"
		this.scrollerTop = this.imgPath+"scroller-top.gif"
		this.nubbinBG = this.imgPath+"scroller-nubin-bottom.gif"
		this.nubbinTop = this.imgPath+"scroller-nubin-top.gif"
		this.paddingTop = 4;
		this.paddingBottom = 15;
		this.nubbinWidth = 16;
		this.paddingNubbin = 8;
		this.paddingScroller = 8;
		this.scrollerWidth = 22;
		this.squeezeContentBy = 30;
		this.content = this.obj.innerHTML;
		this.width = parseInt(this.dim.width);
		this.nubbinHeight = (this.viewPort/this.scrollHeight) * this.scrollerHeight;
		this.currentTop = null;
		if(autoplay)this.drawArcScroller();
		this.nubbin = document.getElementById('nubin'+ID);
		this.scroller = document.getElementById('scroller'+ID);
	}

	function updateHeight(){
			this.scrollHeight = this.obj.scrollHeight
			this.sactive = (this.viewPort < this.scrollHeight)? true:false;
		    if(this.sactive)this.scroller.style.display = 'block';
			else this.scroller.style.display = 'none';
			alert(this.sactive)
			this.nubbinHeight = (this.viewPort/this.scrollHeight) * this.scrollerHeight;
			this.nubbin.style.height = this.nubbinHeight+"px";
		  	//alert(this.nubbinHeight);
			//if(autoplay)this.drawArcScroller();
	}

	function drawArcScroller(){
		this.wrapper = '<div id="viewPort'+this.ID+'" style="float:left; width:'+(this.width-this.squeezeContentBy)+'px; z-index:100;  height:'+this.viewPort+'px; overflow:hidden">'+this.content+'</div>';
		this.wrapper +='<div id="scroller'+this.ID+'" align="center" style="margin-top:'+this.paddingTop+'px; float:right; background-image:url('+this.scrollerBG+'); width:'+this.scrollerWidth+'px; background-position:bottom; background-repeat:no-repeat; height:'+this.scrollerHeight+'px"><div style="position:relative; top:-'+this.paddingTop+'px"><img src="'+this.scrollerTop+'" border="0" /></div><div id="nubin'+ID+'" style="position:relative; top:-'+this.paddingTop+'px; width:'+this.nubbinWidth+'px; height:'+this.nubbinHeight+'px; background-image:url('+this.nubbinBG+'); background-position:bottom; cursor:pointer;" onmousedown="makeArcSlider(this,\''+this.ID+'\'); return false;"><div style="background-image:url('+this.nubbinTop+'); background-position:top; background-repeat:no-repeat; height:'+this.paddingNubbin+'px; cursor:pointer;"></div></div></div>'
		this.obj.innerHTML = this.wrapper;
	}	
}
	function getArcDimention(obj){
		if ( obj.currentStyle ) {
			return {height:obj.currentStyle.height,width:obj.currentStyle.width};
		} else if ( document.defaultView.getComputedStyle ){
				return {height:document.defaultView.getComputedStyle(obj,'').height,width:document.defaultView.getComputedStyle(obj,'').width};
		} else {
			return {height:obj.style.height,width:obj.style.width};
		}	
	}
	
	function makeArcSlider(obj,ID){
		document.onmousemove = mouseArcMoveNubbin;
		document.onmouseup = mouseArcUpNubbin;
	//	document.onselectstart=stopArcselect;
		arc_sliderObj = {div:obj,obj:allArcSliders[ID]};
	}
	
    function stopArcselect(){
		return false;
	}
	function mouseArcCoords(ev){
		if(ev.pageX || ev.pageY){
			return {x:ev.pageX, y:ev.pageY};
		}
		return {
			x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
			y:ev.clientY + document.body.scrollTop  - document.body.clientTop
		};
	}
	
	function mouseArcUpNubbin(ev){
		if(arc_sliderObj){
			arc_sliderObj.obj.contentHolder = null;
			arc_sliderObj.obj.currentTop = null;
			arc_sliderObj= null;
			document.onmousemove = null;
			document.onmouseup = null;
			//document.onselectstart=null;
		}
	}
	
	function findArcPosY(obj)
	{
		var curtop = 0;
		var printstring = '';
		if (obj.offsetParent){
			while (obj.offsetParent){
				printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
	
	function mouseArcMoveNubbin(ev){
		if(arc_sliderObj){
			var ev = ev || window.event;
			var mousePos = mouseArcCoords(ev);
			var obj = arc_sliderObj.obj;
			var div = arc_sliderObj.div;
			var viewPort = obj.viewPort;
			if(obj.contentHolder==null)obj.contentHolder = document.getElementById('viewPort'+obj.ID)
			if(obj.currentTop==null)obj.currentTop = parseInt(mousePos.y) - parseInt(div.style.top)
			var themover = obj.contentHolder;
			var bottomPadding = obj.paddingBottom; 
			var topPadding = obj.paddingTop;
			var scrollheight = obj.scrollerHeight;
			var p = div.offsetParent;
			
			var newloc = parseInt(mousePos.y)-obj.currentTop;
			
			if(obj.divLoc==null)obj.divLoc = findArcPosY(p);
			obj.divLoc = 0;
			if(newloc > obj.divLoc- topPadding&&newloc < (obj.divLoc+scrollheight-obj.nubbinHeight-bottomPadding)){
				div.style.top = newloc+"px";
				themover.scrollTop = (((themover.scrollHeight-viewPort)*((newloc-obj.divLoc)/(obj.divLoc+scrollheight-obj.nubbinHeight-bottomPadding)))+0);
			}else{
				if(newloc > (obj.divLoc+scrollheight-obj.nubbinHeight-bottomPadding)){
					div.style.top = (obj.divLoc+scrollheight-obj.nubbinHeight-bottomPadding)+'px';
					themover.scrollTop = themover.scrollHeight;
				}else if(newloc < obj.divLoc- topPadding){
					div.style.top = (obj.divLoc- topPadding)+'px'; 
					themover.scrollTop =0;
				}	
			}
			
		}
		return false;
		
	}
	