var MWJ_slider_controls = 0;

function getRefToDivNest( divID, oDoc ) {
	//get a reference to the slider control, even through nested layers
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; } else {
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) {
				y = getRefToDivNest(divID,oDoc.layers[x].document); }
			return y; } }
	if( document.getElementById ) { return document.getElementById(divID); }
	if( document.all ) { return document.all[divID]; }
	return document[divID];
}

function sliderMousePos(e) {
	//get the position of the mouse
	if( !e ) { e = window.event; } if( !e || ( typeof( e.pageX ) != 'number' && typeof( e.clientX ) != 'number' ) ) { return [0,0]; }
	if( typeof( e.pageX ) == 'number' ) { var xcoord = e.pageX; var ycoord = e.pageY; } else {
		var xcoord = e.clientX; var ycoord = e.clientY;
		if( !( ( window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) || ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 ) || window.navigator.vendor == 'KDE' ) ) {
			if( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) ) {
				xcoord += document.documentElement.scrollLeft; ycoord += document.documentElement.scrollTop;
			} else if( document.body && ( document.body.scrollTop || document.body.scrollLeft ) ) {
				xcoord += document.body.scrollLeft; ycoord += document.body.scrollTop; } } }
	return [xcoord,ycoord];
}

function slideIsDown(e) {
	if( document.onmousemove == slideIsMove ) { return false; } //protect against multi-button click
	//make note of starting positions and detect mouse movements
	window.msStartCoord = sliderMousePos(e); window.lyStartCoord = this.style?[parseInt(this.style.left),parseInt(this.style.top)]:[parseInt(this.left),parseInt(this.top)];
	if( document.captureEvents && Event.MOUSEMOVE ) { document.captureEvents(Event.MOUSEMOVE); document.captureEvents(Event.MOUSEUP); }
	window.storeMOUSEMOVE = document.onmousemove; window.storeMOUSEUP = document.onmouseup; window.storeLayer = this;
	document.onmousemove = slideIsMove; document.onmouseup = slideIsMove; return false;
}

function slideIsMove(e) {
	//move the slider to its newest position
	var msMvCo = sliderMousePos(e); if( !e ) { e = window.event ? window.event : ( new Object() ); }
	var theLayer = window.storeLayer.style ? window.storeLayer.style : window.storeLayer; var oPix = document.childNodes ? 'px' : 0;
	if( window.storeLayer.hor ) {
		var theNewPos = window.lyStartCoord[0] + ( msMvCo[0] - window.msStartCoord[0] );
		if( theNewPos < -8 ) { theNewPos = -8; } if( theNewPos > window.storeLayer.maxLength - 9) { theNewPos = window.storeLayer.maxLength - 7; }
		theLayer.left = theNewPos + oPix;
		document.getElementById('Dark_Skala').style.width = theNewPos + 8 + oPix;
	}
	//run the user's functions and reset the mouse monitoring as before
	if( e.type && e.type.toLowerCase() == 'mousemove' ) {
		if( window.storeLayer.moveFunc ) window.storeLayer.moveFunc(theNewPos/window.storeLayer.maxLength);
	} else {
		document.onmousemove = storeMOUSEMOVE; document.onmouseup = window.storeMOUSEUP;
		if( window.storeLayer.stopFunc ) window.storeLayer.stopFunc(theNewPos/window.storeLayer.maxLength);
	}
}

function setSliderPosition(oPortion) {
	//set the slider's position
	if( isNaN( oPortion ) || oPortion < 0 ) { oPortion = 0; } if( oPortion > 1 ) { oPortion = 1; }
	var theDiv = getRefToDivNest(this.id); if( theDiv.style ) { theDiv = theDiv.style; }
	oPortion = Math.round( oPortion * this.maxLength ); var oPix = document.childNodes ? 'px' : 0;
	if( this.align ) { theDiv.left = oPortion - 8 + oPix; } else { theDiv.top = oPortion + oPix; }
}

function slider(oThght,oTwdth,oTRcol,oBhght,oBwdth,oBcol,oBthk,oBtxt,oAlgn,oMf,oSf,oCrs,position) {
	//draw the slider using huge amounts of nested layers (makes the borders look normal in as many browsers as possible)
	this.maxLength = (oAlgn?oTwdth:oThght)-((oAlgn?oBwdth:oBhght)+(2*oBthk));
	if( document.layers ) {
		/*document.write(
			'<ilayer left="'+oTBthk+'" top="'+oTBthk+'" height="'+oThght+'" width="'+oTwdth+'">'+
			'<layer left="'+(oAlgn?0:Math.floor((oTwdth)/2))+'" top="'+(oAlgn?Math.floor((oThght)/2):0)+'" height="'+(oAlgn?:oThght)+'" width="'+(oAlgn?oTwdth)+'" bgcolor="'+oTRcol+'"><\/layer>'+
			'<layer left="'+(oAlgn?0:Math.floor((oTwdth-(oBwdth+(2*oBthk)))/2))+'" top="'+(oAlgn?Math.floor((oThght-(oBhght+(2*oBthk)))/2):0)+'" height="'+(oBhght+(2*oBthk))+'" width="'+(oBwdth+(2*oBthk))+'" bgcolor="#000000" onmouseover="this.captureEvents(Event.MOUSEDOWN);this.hor='+oAlgn+';this.maxLength='+((oAlgn?oTwdth:oThght)-((oAlgn?oBwdth:oBhght)+(2*oBthk)))+';this.moveFunc='+oMf+';this.stopFunc='+oSf+';this.onmousedown=slideIsDown;" name="MWJ_slider_controls'+MWJ_slider_controls+'">'+
			'<layer left="0" top="0" height="'+(oBhght+oBthk)+'" width="'+(oBwdth+oBthk)+'" bgcolor="#ffffff"><\/layer>'+
			'<layer left="'+oBthk+'" top="'+oBthk+'" height="'+oBhght+'" bgcolor="#00ffff" width="'+oBwdth+'">'+oBtxt+'<\/layer><\/layer><\/ilayer>'
		);*/
	} else {
        document.write(
			'<div style="position:relative;left:0px;top:0px;height:'+oThght+'px;width:'+oTwdth+'px;font-size:0px;">'+
			'<div style="position:absolute;left:0px;top:0px;height:'+oThght+'px;background-image:url(\'../img/bg_skala.gif\');" ><img src="../img/blank.gif" width="'+ position * this.maxLength +'" height="1" id="Dark_Skala"/></div>'+
			'<div style="position:absolute;left:'+(oAlgn?0:Math.floor((oTwdth-(oBwdth+(2*oBthk)))/2))+'px;top:'+(oAlgn?Math.floor((oThght-(oBhght+(2*oBthk)))):0)+'px;height:'+(oBhght+(2*oBthk))+'px;width:'+(oBwdth+(2*oBthk))+'px;font-size:0px;" ondragstart="return false;" onselectstart="return false;" onmouseover="this.hor='+oAlgn+';this.maxLength='+((oAlgn?oTwdth:oThght)-((oAlgn?oBwdth:oBhght)+(2*oBthk)))+';this.moveFunc='+oMf+';this.stopFunc='+oSf+';this.onmousedown=slideIsDown;" id="MWJ_slider_controls'+MWJ_slider_controls+'">'+oBtxt+'<\/div><\/div>'
		);
	}
	this.id = 'MWJ_slider_controls'+MWJ_slider_controls; 
	this.align = oAlgn; this.setPosition = setSliderPosition; MWJ_slider_controls++;

    this.setPosition(position);
}

function moveFunction(sliderPosition) {
	//do something with the position of the slider
    sliderPosition = Math.round( 100 * sliderPosition );
    sliderPosition += 5;
    if ( sliderPosition < 0 ) sliderPosition = 0;
    if ( sliderPosition > 100 ) sliderPosition = 100;

    window.status = 'The position of the slider is ' + sliderPosition + '%';
}

function stopFunction(sliderPosition) {
	//do something with the position of the slider
	lastKnownPosition = sliderPosition;
}

function win_go(w, h, href, win_name, close, scrol_on, toolbar_on, resizable) {
    l = (!screen)? '' : 'left='+(screen.width - w)/2+',top='+(screen.height - h)/2
    if (close)
        window.close()
    win = window.open(href, win_name,
        'directories=yes,status=yes,menubar=yes,'+
        'resizable=' + (resizable? 'yes': 'no') + ',' +
        'toolbar=' + (toolbar_on? 'yes': 'no') + ',' +
        'scrollbars=' + (scrol_on? 'yes' : 'no') + ',' +
        'location=yes,' +
        'width=' + w + ',height=' + h + ',' + l
    );
    if (win)
        win.focus();
    return win;
}