// JavaScript Document

/**********************************************************************************   
PageSlideFade 
*   Copyright (C) 2001 <a href="/dhtmlcentral/michael_van_ouwerkerk.asp">Michael van Ouwerkerk</a>
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by <a href="/dhtmlcentral/michael_van_ouwerkerk.asp">Michael van Ouwerkerk</a> 
*********************************************************************************/

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
        this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
        this.ie8=(this.ver.indexOf("MSIE 8")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6||this.ie7||this.ie8
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new lib_bwcheck()

/*** variables to configure... ***/

var numScrollPages = 2;        //Set the number of pages (layers) here. Add and remove the pages in the body too. The first layer is called dynPage0, the second is dynPage1, and so on.
var transitionOut = 0;         //The 'out' effect... 0= no effect, 1= fade
var transitionIn = 0;          //The 'in' effect... 0= no effect, 1= fade, 2= slide
var slideAcceleration = 0.9;   //If you use the slide animation, set this somewhere between 0 and 1.
var transitionOnload = 0;      //Use the 'in' transition when the page first loads? If you want the transition fx only when the links are clicked, you can set it to 0.
var scrollTimeoutDur = 20;
var scrollGran = "px";
var scrollLineHeight = 15;
var activePageIdx = 0;

var mouseOffset = null;

window.last_scroll_pos = new Array(numScrollPages);

// NOTE: if you change the position of divScroller1 from absolute to relative, you can put the scroller in a table.
// HOWEVER it will no longer work in netscape 4. If you wish to support netscape 4, you have to use absolute positioning.

// Please note that there are no effects available in ns4 and ie4, or exlorers on the Mac!

/*** There should be no need to change anything beyond this. ***/ 

// A unit of measure that will be added when setting the position of a layer.
var px = bw.ns4||window.opera?"":"px";

if(document.layers){ //NS4 resize fix...
	scrX= innerWidth; scrY= innerHeight;
	onresize= function(){if(scrX!= innerWidth || scrY!= innerHeight){history.go(0)} }
}

//object constructor...
function scrollerobj(obj,nest){
	nest = (!nest)?"":'document.'+nest+'.'
	this.elm = bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):document.getElementById(obj)
	this.css = bw.ns4?this.elm:this.elm.style
	this.doc = bw.ns4?this.elm.document:document
	this.obj = obj+'scrollerobj'; eval(this.obj+'=this')
	this.x = (bw.ns4||bw.opera5)?this.css.left:this.elm.offsetLeft
	/*this.y = (bw.ns4||bw.opera5||bw.ie7||bw.ie8)?this.css.top:this.elm.offsetTop*/
	this.y = (bw.ns4||bw.opera5)?this.css.top:this.elm.offsetTop
	this.w = (bw.ie4||bw.ie5||bw.ie6||bw.ns6||bw.ie7||bw.ie8)?this.elm.offsetWidth:bw.ns4?this.elm.clip.width:bw.opera5?this.css.pixelWidth:0
	this.h = (bw.ie4||bw.ie5||bw.ie6||bw.ns6||bw.ie7||bw.ie8)?this.elm.offsetHeight:bw.ns4?this.elm.clip.height:bw.opera5?this.css.pixelHeight:0
}

//object methods...
scrollerobj.prototype.moveTo = function(x,y){
	if(x!=null){this.x=x; this.css.left=x+px}
	if(y!=null){this.y=y;this.css.top=y+px}
	if(y!=null&&activePageIdx==0){navigator.last_cur_sub_y=y}
	
	
}
scrollerobj.prototype.moveBy = function(x,y){this.moveTo(this.x+x,this.y+y)}
scrollerobj.prototype.hideIt = function(){this.css.visibility='hidden'}
scrollerobj.prototype.showIt = function(){this.css.visibility='visible'}
scrollerobj.prototype.update = function(obj,nest){
	nest = (!nest)?"":'document.'+nest+'.'
	this.elm = bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):document.getElementById(obj)
	this.css = bw.ns4?this.elm:this.elm.style
	this.doc = bw.ns4?this.elm.document:document
	this.obj = obj+'scrollerobj'; eval(this.obj+'=this')
	this.x = (bw.ns4||bw.opera5)?this.css.left:this.elm.offsetLeft
	this.y = (bw.ns4||bw.opera5)?this.css.top:this.elm.offsetTop
	/*this.y = (bw.ns4||bw.opera5)?this.css.top:this.elm.offsetTop*/
	this.w = (bw.ie4||bw.ie5||bw.ie6||bw.ns6||bw.ie7||bw.ie8)?this.elm.offsetWidth:bw.ns4?this.elm.clip.width:bw.opera5?this.css.pixelWidth:0
	this.h = (bw.ie4||bw.ie5||bw.ie6||bw.ns6||bw.ie7||bw.ie8)?this.elm.offsetHeight:bw.ns4?this.elm.clip.height:bw.opera5?this.css.pixelHeight:0
}

/****************************************************************
scroll functions...
****************************************************************/
var scrollTimer = null;

function scroll(step){
	
	clearTimeout(scrollTimer);
	var scrollStep;
	var scrollDur;
	
	/*for (var i=0; i<numScrollPages; i++){
		pages[i].update('dynPage'+i, 'divScroller'+i);
		update_thumb(i);	
	}*/
	
	
	activePage.update('dynPage'+ activePageIdx, 'divScroller'+ activePageIdx);
	update_thumb(activePageIdx);

	if (scrollGran=="line"){
		scrollStep = step*2;
		scrollDur = 200;
	}
	else
	{
		scrollStep = step;
		scrollDur = scrollTimeoutDur;
	}
	
	if ( !busy && (scrollStep<0&&activePage.y+activePage.h> activePage.elm.parentNode.clientHeight || scrollStep>0&&activePage.y<0) ){
		activePage.moveBy(0,scrollStep);
		update_thumb(activePageIdx);
		scrollTimer = setTimeout('scroll('+scrollStep+')',scrollDur);
		}
	
}

function update_thumb(num){
	var dyna_pos = pages[num].y/(pages[num].h-pages[num].elm.parentNode.clientHeight);
	var slider_ind_range = document.getElementById('slider'+num).clientHeight-document.getElementById('slider_up_'+num).clientHeight-document.getElementById('slider_thumb_'+num).clientHeight-document.getElementById('slider_down_'+num).clientHeight;
	var thumb_pos = (-1)*slider_ind_range*dyna_pos;
	document.getElementById('slider_thumb_'+num).style.top=thumb_pos+px;
}


function scroll_0(step){
	activePage = pages[0];
	activePageIdx = 0;
	scroll(step);
}

function scroll_1(step){
	activePage = pages[1];
	activePageIdx = 1;
	scroll(step);
}

function stopScroll(){
	clearTimeout(scrollTimer);
}


	
/****************************************************************
activating the correct layers...
****************************************************************/
var activePage = null;
var busy = 0;
function activate(num){
	if (activePage!=pages[num] && !busy){
		busy = 1;
		if (transitionOut==0 || !bw.opacity){ activePage.hideIt(); activateContinue(num); }
		else if (transitionOut==1) activePage.blend('hidden', 'activateContinue('+num+')');
	}
}
function activateContinue(num){
	busy = 1;
	activePage = pages[num];
	/*activePage.moveTo(0,0);*/
	if (transitionIn==0 || !bw.opacity){ activePage.showIt(); busy=0; }
	else if (transitionIn==1) activePage.blend('visible', 'busy=0');
	else if (transitionIn==2) activePage.slide(0, slideAcceleration, 80, 'busy=0');
}


/****************************************************************
Slide methods...
****************************************************************/
scrollerobj.prototype.slide = function(target, acceleration, time, fn){
	this.slideFn= fn?fn:null;
	this.moveTo(0,scroller1.h);
	if (bw.ie4&&!bw.mac||bw.ie7||bw.ie8) this.css.filter = 'alpha(opacity=100)';
	if (bw.ns6) this.css.MozOpacity = 1;
	this.showIt();
	this.doSlide(target, acceleration, time);
}
scrollerobj.prototype.doSlide = function(target, acceleration, time){
	this.step = Math.round(this.y*acceleration);
	if (this.step<1) this.step = 1;
	if (this.step>this.y) this.step = this.y;
	this.moveBy(0, -this.step);
	if (this.y>0) this.slideTim = setTimeout(this.obj+'.doSlide('+target+','+acceleration+','+time+')', time);
	else {	
		eval(this.slideFn);
		this.slideFn = null;
	}
}


/****************************************************************
Opacity methods...
****************************************************************/
scrollerobj.prototype.blend= function(vis, fn){
	if (bw.ie5||bw.ie6||bw.ie7||bw.ie8 && !bw.mac) {
		/*if (vis=='visible') this.css.filter= 'blendTrans(duration=0.9)';
		else this.css.filter= 'blendTrans(duration=0.6)';*/
		this.elm.onfilterchange = function(){ eval(fn); };
		/*this.elm.filters.blendTrans.apply();*/
		this.css.visibility= vis;
		/*this.elm.filters.blendTrans.play();*/
	}
	else if (bw.ns6 || bw.ie&&!bw.mac){
		this.css.visibility= 'visible';
		vis=='visible' ? this.fadeTo(100, 7, 40, fn) : this.fadeTo(0, 9, 40, fn);
	}
	else {
		this.css.visibility= vis;
		eval(fn);
	}
};

scrollerobj.prototype.op= 100;
scrollerobj.prototype.opacityTim= null;
scrollerobj.prototype.setOpacity= function(num){
	this.css.filter= 'alpha(opacity='+num+')';
	this.css.MozOpacity= num/100;
	this.op= num;
}
scrollerobj.prototype.fadeTo= function(target, step, time, fn){
	clearTimeout(this.opacityTim);
	this.opacityFn= fn?fn:null;
	this.op = target==100 ? 0 : 100;
	this.fade(target, step, time);
}
scrollerobj.prototype.fade= function(target, step, time){
	if (Math.abs(target-this.op)>step){
		target>this.op? this.setOpacity(this.op+step):this.setOpacity(this.op-step);
		this.opacityTim= setTimeout(this.obj+'.fade('+target+','+step+','+time+')', time);
	}
	else {
		this.setOpacity(target);
		eval(this.opacityFn);
		this.opacityFn= null;
	}
}


/**************************************************************
Init function...
**************************************************************/
var pageslidefadeLoaded = 0;
function initPageSlideFade(){
	
	/*scroller0 = new scrollerobj('divScroller0');
	scroller1 = new scrollerobj('divScroller1');*/
	
	pages = new Array();
	for (var i=0; i<numScrollPages; i++){
		pages[i] = new scrollerobj('dynPage'+i, 'divScroller'+i);
		pages[i].dragging = 0;
	}
	
/*	for (var i=0; i<numScrollPages; i++){
		if(document.getElementById("dynPage"+i).clientHeight > document.getElementById("slider"+i).clientHeight)
			{
			document.getElementById("slider"+i).style.display="block";
			}
			else
			{
			document.getElementById("slider"+i).style.display="none";
			}
			
	}*/
	
	for (var i=0; i<numScrollPages; i++){
		document.getElementById("slider"+i).style.display="none";
	}
			
	
								  
	bw.opacity = ( bw.ie && !bw.ie4 && navigator.userAgent.indexOf('Windows')>-1 ) || bw.ns6
	/*if (bw.ie5||bw.ie6||bw.ie7||bw.ie8 && !bw.mac) pages[0].css.filter= 'blendTrans(duration=0.6)';*/ // Preloads the windows filters.
	
	if (transitionOnload) activateContinue(0);
	else{
		activePage = pages[0];
		activePage.showIt();
		activePage = pages[1];
		activePage.showIt();
		activePage = pages[0];
		activePageIdx = 0;
	}

	if (bw.ie) for(var i=0;i<document.links.length;i++) document.links[i].onfocus=document.links[i].blur;
	pageslidefadeLoaded = 1;
}

function hideSlider(num){
	document.getElementById("slider"+num).style.display="none";
}

function displaySlider(num){
		
		if(document.getElementById("dynPage"+num).clientHeight > document.getElementById("divScroller"+num).clientHeight)
			{
			document.getElementById("slider"+num).style.display="block";
			document.getElementById("divScroller"+num).style.overflow="hidden";
			document.getElementById("slider_thumb_"+num).onmousedown = start_drag;
			update_thumb(num);
			}
			else
			{
			document.getElementById("slider"+num).style.display="none";
			document.getElementById("divScroller"+num).style.overflow="visible";
			}
			
}

function sub_menu_jump(){
window.sub_menu_jump = true;
}

function resetScrolledPage(num){
	
	var activePageIdx_last = activePageIdx;
	activePageIdx=num;
	pages[num].moveTo(0,0);
	pages[num].dragging = 0;
	activePageIdx = activePageIdx_last;
	
}

function updateScrolledPage(num){
	pages[num].update('dynPage'+num, 'divScroller'+num);
}


function moveToScrolledPageLine(page,num){
	var virtual_height = document.getElementById("dynPage"+page).clientHeight;
	var linepos=15*(num+1)+5;
	var scroller_height=document.getElementById("slider"+page).clientHeight;
	var diff = scroller_height/2 - linepos;
	if (diff>0) diff =0;
	pages[page].moveTo(0,diff);
	navigator.last_page0_pos=diff;
}
	
//if the browser is ok, the script is started onload..
//if(bw.bw && !pageslidefadeLoaded) onload = initPageSlideFade;##


function start_drag(ev){
	/*activePageIdx = 0;
	activePage = pages[activePageIdx];*/
	activePage.dragging = 1;
	document.onmouseup = stop_drag;
	mouseOffset = getMouseOffset(this, ev);
}

function stop_drag(ev){
/*	activePageIdx = 0;
	activePage = pages[activePageIdx];
*/	activePage.dragging = 0;
	document.onmouseup = null;
}

function select_drag(num){
	activePageIdx = num;
	activePage = pages[activePageIdx];
}
	
document.onmousemove = mousemove;
	
function mousemove(ev){ 

	    ev  = ev || window.event; 
	    var mousePos = mouseCoords(ev); 
	 
	 	if (activePage!=null){
			if(activePage.dragging==1){ 
				
				var thumb = document.getElementById("slider_thumb_"+activePageIdx);
				var offset = getMouseOffset(thumb,ev);
				var diff = thumb.offsetTop + offset.y;
				
				var slider_ind_range = document.getElementById('slider'+activePageIdx).clientHeight-document.getElementById('slider_up_'+activePageIdx).clientHeight-document.getElementById('slider_thumb_'+activePageIdx).clientHeight-document.getElementById('slider_down_'+activePageIdx).clientHeight;
				
				if (diff < 0) diff = 0;
				if (diff > slider_ind_range) diff = slider_ind_range;
				
				thumb.style.top = diff+px;
				
				var dyna_upper = (-1)*diff/slider_ind_range*(pages[activePageIdx].h-pages[activePageIdx].elm.parentNode.clientHeight);
				activePage.moveTo(0,dyna_upper);
				
				
				return false; 
			}
		}
	} 
	 
function mouseCoords(ev){ 
    if(ev.pageX || ev.pageY){ 
        return {x:ev.pageX, y:ev.pageY}; 
    } 
 	/*var relX = ev.clientX + document.body.scrollLeft - document.body.clientLeft;
	var relY = ev.clientY + document.body.scrollTop  - document.body.clientTop;*/
	return{x:ev.clientX,y:ev.clientY};
    
} 

function getMouseOffset(target, ev){ 
	    ev = ev || window.event; 
	 
	    var docPos    = getPosition(target); 
	    var mousePos  = mouseCoords(ev); 
	    return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y}; 
} 
	 
	
function getPosition(e){ 
	    var left = 0; 
	    var top  = 0; 
	 
	    while (e.offsetParent){ 
	        left += e.offsetLeft; 
	        top  += e.offsetTop; 
	        e     = e.offsetParent; 
	    } 
	 
	    left += e.offsetLeft; 
	    top  += e.offsetTop; 
	 
	    return {x:left, y:top}; 
	} 
