
var ie = document.all && navigator.userAgent.indexOf("Opera") == -1 ? true : false;
var safari = navigator.userAgent.indexOf("Safari") != -1 ? true : false;

function _gel(id){return document.getElementById(id);}
function _getn(n, x){return x ? x.getElementsByTagName(n) : document.getElementsByTagName(n);}
function _geta(x, n, d){return x.attributes.getNamedItem(n) ? x.attributes.getNamedItem(n).value : (d ? d : undefined);}
function _ce(a){return document.createElement(a);}
function in_array(n,h){for(var x=0;x<h.length;x++){if(h[x] == n){return true;}}return false;}
function isset(a){var b = a.split(".");for(var x=0;x<b.length;x++){var c = b[x];if(x == 0){if(typeof(self[c]) == "undefined"){return 0;}var d = self[c];}else{if(typeof(eval("d."+c)) == "undefined"){return 0;}else{var d = eval("d."+c);}}}return 1;}
function compareArrays(a,b){for(var i in a){if(b[i] == undefined){return false;}if(typeof(a[i]) == "object"){var ret = compareArrays(a[i],b[i]);if(ret === false){return false;}}else if(a[i] != b[i]){return false;}}return true;}
function addOptions(a,b){ a.length = 0; for(var c in b){ a[a.length] = new Option(b[c],c); } }
function array_keys(a){var b = [];for(var c in a){b[b.length] = c;}return b;}
function ucwords(str){return str.replace(/^(.)|\s(.)/g,function($1){return $1.toUpperCase();});}
function clone(myObj){if(typeof(myObj) != 'object'){return myObj;}var myNewObj = myObj.length == undefined ? {} : [];for(var i in myObj){myNewObj[i] = clone(myObj[i]);}return myNewObj;}
function number_format(a,b,c,d){a=Math.round(a*Math.pow(10,b))/Math.pow(10,b);e=a+'';f=e.split('.');if(!f[0]){f[0]='0';}if(!f[1]){f[1]='';}if(f[1].length<b){g=f[1];for(i=f[1].length+1;i<=b;i++){g+='0';}f[1]=g;}if(d!=''&&f[0].length>3){h=f[0];f[0]='';for(j=3;j<h.length;j+=3){i=h.slice(h.length-j,h.length-j+3);f[0]=d+i+f[0]+'';}j=h.substr(0,(h.length%3==0)?3:(h.length%3));f[0]=j+f[0];}c=(b<=0)?'':c;return f[0]+c+f[1];}
function addEvent(element, listener, handler){if(typeof(element[listener]) != 'function' ||  typeof(element[listener + '_num']) == 'undefined'){element[listener + '_num'] = 0;if(typeof(element[listener]) == 'function'){element[listener + 0] = element[listener];element[listener + '_num']++;}element[listener] = function(e){var r = true;e = (e) ? e : window.event;for(var i = 0; i < element[listener + '_num']; i++){if(element[listener + i](e) === false){ r = false;}}return r;};}for(var i = 0; i < element[listener + '_num']; i++){if(element[listener + i] == handler){return;}}element[listener + element[listener + '_num']] = handler;element[listener + '_num']++;}
function removeEvent(element, listener, handler){if(typeof(element[listener]) != 'function' || typeof(element[listener + '_num']) == 'undefined' || element[listener + '_num'] == 0){return;}var found = false;for(var i = 0; i < element[listener + '_num']; i++){if(!found){found = element[listener + i] == handler;}if(found && (i+1) < element[listener + '_num']){element[listener + i] = element[listener + (i+1)];}}if(found){element[listener + '_num']--;}}
var loadImageArr = [];function loadImage(url, func){if(loadImageArr[url]){var i = loadImageArr[url];if(func != undefined){if(i.complete){func();}else{addEvent(i, "onload", func);}}}else{var i = new Image;if(func != undefined){addEvent(i, "onload", func);}i.src = url;loadImageArr[url] = i;}return i;}
function isImageOk(img) {return !img.complete ? false : true;}
function exec(str, func, x){x = x == undefined ? 0 : x;if(x == 60){return;}var timeOut = 500;if(!isset(func)){setTimeout(function(){exec(str, func, ++x);}, timeOut);}else{if(document.all && !in_array(document.readyState, ['complete','loaded'])){addEvent(document, "onreadystatechange", str);return;}str();}}
function call(url, func){var a = document.createElement("SCRIPT");if(func != undefined){if(document.all){a.onreadystatechange = function(){if(in_array(this.readyState,['complete','loaded'])){this.onreadystatechange = null;func();}};}else{a.onload = func;}}a.isLoaded = 0;addEvent(a, "onload", function(){this.isLoaded = 1;});a.src = url;_getn("HEAD")[0].appendChild(a);return a;}
function trim(a){return a.replace(/(^[\r\n\t ]+|[\r\n\t ]+$)/g, "");}
function XHConn(){var xmlhttp;try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){try{xmlhttp = new XMLHttpRequest();}catch(e){xmlhttp = false;}}}if(!xmlhttp){return null;}this.connect = function(sURL, sMethod, sVars, fnDone){if(!xmlhttp){return false;}sMethod = sMethod.toUpperCase();try{if(sMethod == "GET"){xmlhttp.open(sMethod, sURL+"?"+sVars, true);sVars = "";}else{xmlhttp.open(sMethod, sURL, true);xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.setRequestHeader("Ajax-Request", "true");}xmlhttp.onreadystatechange = function(){if (xmlhttp.readyState == 4) {fnDone(xmlhttp);}};xmlhttp.send(sVars);}catch(z){return false;}return true;};return this;}
function print_page(id, fullURL){var i = document.createElement("IFRAME");i.width = 0; i.height = 0; i.frameBorder = 0;i.src = fullURL ? id : "print.php?id="+id;var d = document.getElementsByTagName("BODY")[0];d.appendChild(i);}

function addCSS(a,b){var c = a.className.split(/ +/g);for(var x=0;x<c.length;x++){var d = c[x];if(d == b){return;}}a.className = c.join(" ")+" "+b;}
function removeCSS(a,b){var c = a.className.split(/ +/g);var e = [];for(var x=0;x<c.length;x++){var d = c[x];if(d != b){e[e.length] = d;}}a.className = e.join(" ");}
function addStyle(a,b){var c = a.className.split(" ");for(var x=0;x<c.length;x++){if(c[x] == b){return;}}c[c.length] = b;a.className = c.join(" ");}
function removeStyle(a,b){var c = a.className.split(" ");var d = [];for(var x=0;x<c.length;x++){if(c[x] != b){d[d.length] = c[x];}}a.className = d.join(" ");}

// Cookies
var exp = new Date(); var expDays = 365 * 2;exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function SetCookie (name, value) {  var argv = SetCookie.arguments;  var argc = SetCookie.arguments.length;  var expires = (argc > 2) ? argv[2] : null;  var path = (argc > 3) ? argv[3] : null;  var domain = (argc > 4) ? argv[4] : null;  var secure = (argc > 5) ? argv[5] : false;  document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) +  ((domain == null) ? "" : ("; domain=" + domain)) +    ((secure == true) ? "; secure" : "");}
function getCookieVal(offset){var endstr = document.cookie.indexOf (";", offset);if (endstr == -1){endstr = document.cookie.length;}return unescape(document.cookie.substring(offset, endstr));}
function GetCookie (name) {  var arg = name + "=";  var alen = arg.length;  var clen = document.cookie.length;  var i = 0;  while (i < clen) {    var j = i + alen;    if (document.cookie.substring(i, j) == arg){return getCookieVal (j);}i = document.cookie.indexOf(" ", i) + 1;if (i == 0){ break;}}  return null;}

var Debugger = {arr: [],dbg : "",debugElement: function(a, noMultiDim){switch(typeof(a)){case 'object':for(var b in a){this.dbg += (!noMultiDim ? "<ul>" : "<br>")+b+": "+(!noMultiDim ? "" : a[b]);if(!noMultiDim){this.debugElement(a[b]);}}break;case 'function': break;default: this.dbg += a;}this.dbg += "</ul>";},debug: function(a, noMultiDim, appender){noMultiDim = noMultiDim == undefined ? 0 : noMultiDim;appender = appender == undefined ? 0 : appender;if(appender){this.arr[this.arr.length] = a;a = this.arr;}this.dbg = "Debug:";this.debugElement(a, noMultiDim);if(!_gel("debug")){var d = document.createElement("DIV");d.id = "debug";document.getElementsByTagName("BODY")[0].appendChild(d);}_gel("debug").innerHTML = this.dbg;}}

var callOnceArr = [];
function callOnce(url, func){
	waitForLoad(function(){
		url = url.substring(0,4) != "http" ? "http://static.superstart.se/"+url.replace(/^\//,"") : url;
		if(callOnceArr[url] == undefined){
			callOnceArr[url] = call(url, func);
		}else{
			if(func != undefined){
				if(document.all && !in_array(callOnceArr[url].readyState,['complete','loaded'])){
					addEvent(callOnceArr[url], "onreadystatechange", function(){
						if(in_array(this.readyState,['complete','loaded'])){
							func();
						}
					});
				}else if(!document.all && !callOnceArr[url].isLoaded){
					addEvent(callOnceArr[url], "onload", func);
				}else{
					func();
				}
			}
		}
	});
}

function call2(url, id, ret, xmRet, forcePost){
	var myConn = new XHConn();
	if(id){var ret = function (g) {if(_gel(id)){_gel(id).innerHTML = g.responseText;}};
	}else if(!ret){
		var ret = function (oXML) {eval(oXML.responseText);};
		// var ret = function (g) {try{eval(g.responseText);}catch(e){var lurl = "js.error.log.php?url="+escape(url);for(var ek in e){lurl += "&"+ek+"="+escape(e[ek]);}lurl += "&data="+escape(g.responseText);call2(lurl, false, function(){});}};
	}
	if(xmRet){
		var r = ret;
		var ret = function (g) {r(g.responseXML != null ? g.responseXML : g.responseText);};
		if(typeof(xmRet) == "object"){
			forcePost = 1;
			url = "/api.special.php?url="+escape(url)+
				"&header="+(xmRet.headers != undefined ? escape(xmRet.headers) : "")+
				"&post="+(xmRet.post_data != undefined ? escape(xmRet.post_data) : "");
		}
	}
	var c = "";
	if(/^http/i.test(url)){
		c += "PROXY_URL="+encodeURIComponent(url);
		var a =[];
		a[0] = !xmRet ? "/proxy.js.php" : "/proxy.xml.js.php";
	}else{
		var a = url.split("?"); 
		if(a[1]){
			var b = a[1].split("&");
			for(var x=0;x<b.length;x++){
				var d = b[x].split("=");
				c += (c != "" ? "&" : "")+d[0]+(d[1] ? "="+escape(d[1]) : "");
			}
		}else{
			var c = "";
		}
	}
	var cc = forcePost != undefined ? 1 : 0;
	myConn.connect(a[0], cc ? "POST" : "GET", c, ret);
}

function formSubmit(frm) {
	var qs = '';
	for(var x=0;x<frm.elements.length;x++) {
		var g = frm.elements[x];
		if(g.name != ''){
			if(g.type.toUpperCase() == "CHECKBOX"){
				if(!g.checked){continue;}
			}else if(g.type.toUpperCase() == "RADIO"){
				if(!g.checked){continue;}
			}
			qs += qs == '' ? '' : '&' ;
			qs += g.name+'='+escape(g.value); // encodeURIComponent - fuckar up charset
		}
	}
	var m = !frm.method ? "GET" : frm.method;
	for(var x=0;x<frm.attributes.length;x++){
		var g = frm.attributes[x];
		if(g.name.toUpperCase() == "ACTION"){
			var a = g.value;
			break;
		}
	}
	var myConn = new XHConn();
	var ret = function (oXML){eval(oXML.responseText);};
	myConn.connect(a, m, qs, ret);
	return false;
}


Date.prototype.getWeek = function(dowOffset){
	dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 1; // 1 = monday, 0 = sunday
	var newYear = new Date(this.getFullYear(),0,1);
	var day = newYear.getDay() - dowOffset;
	day = (day >= 0 ? day : day + 7);
	var daynum = Math.floor((this.getTime() - newYear.getTime() -
	(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
	var weeknum;
	if(day < 4) {
		weeknum = Math.floor((daynum+day-1)/7) + 1;
		if(weeknum > 52) {
			nYear = new Date(this.getFullYear() + 1,0,1);
			nday = nYear.getDay() - dowOffset;
			nday = nday >= 0 ? nday : nday + 7;
			weeknum = nday < 4 ? 1 : 53;
		}
	}else{
		weeknum = Math.floor((daynum+day-1)/7);
	}
	return weeknum;
};

// Superstart custom
var keyNum = 0;
function getKey(keyStroke) {isNetscape=(window.sidebar);eventChooser = (isNetscape) ? keyStroke.keyCode : event.keyCode;keyNum = eventChooser;if(keyNum == 27 && typeof(top.App) != "undefined" && top.App.bigDiv){top.App.closeBig();}keyString = String.fromCharCode(eventChooser).toLowerCase();}
function waitForLoad(a){if(typeof(App) == "undefined" || App.loaded){a();}else{App.loads.push(a);}}
// analytics tracking of usage: var t = x;while(t){if(t && t.className && t.className.match(/blk_content/)){var t = t.className.split(" ");if(t.length > 1 && t[1] != ""){if(pageTracker != undefined){pageTracker._trackEvent('block','click', t[1]);}}break;}t = t.parentNode;}
addEvent(window,"onload", function(){window.loaded = true;});
addEvent(document,"onkeydown",getKey);
// dont work good with addEvent
document.onclick = function(e){var x = ie ? event.srcElement : e.target;if(typeof(App) == "undefined" || App.target != "_blank"){}else{while(1){if(x.tagName == undefined){ return true;}if(x.tagName.toUpperCase() != "A"){if(x.parentNode){ x = x.parentNode;}else{break;}}else{break;}}if(x.href && x.href.substring(0,10).toLowerCase() == "javascript"){eval(decodeURIComponent(x.href.substring(11)));return false;}}}




var Drag = {
obj : null,
init : function(o, oRoot, minX, maxX, minY, maxY){
	o.onmousedown	= Drag.start;
	o.root = oRoot && oRoot != null ? oRoot : o ;
	if (isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
	if (isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
	o.minX	= typeof minX != 'undefined' ? minX : null;
	o.minY	= typeof minY != 'undefined' ? minY : null;
	o.maxX	= typeof maxX != 'undefined' ? maxX : null;
	o.maxY	= typeof maxY != 'undefined' ? maxY : null;
	o.root.onDragStart	= new Function();
	o.root.onDragEnd	= new Function();
	o.root.onDrag		= new Function();
},
start : function(e){
	if(App.titleEdit){return;}
	var o = Drag.obj = this;
	e = Drag.fixE(e);
	var y = parseInt(o.root.style.top);
	var x = parseInt(o.root.style.left);
	o.root.onDragStart(x, y);
	o.lastMouseX	= e.clientX;
	o.lastMouseY	= e.clientY;
	if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
	if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
	if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
	if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
	addEvent(document, "onmousemove", Drag.drag);
	addEvent(document, "onmouseup", Drag.end);
	return false;
},
drag : function(e){
	get_mouse(e);
	e = Drag.fixE(e);
	var o = Drag.obj;
	var ey	= e.clientY;
	var ex	= e.clientX;
	var y = parseInt(o.root.style.top);
	var x = parseInt(o.root.style.left);
	var nx, ny;
	if (o.minX != null) ex = Math.max(ex, o.minMouseX);
	if (o.maxX != null) ex = Math.min(ex, o.maxMouseX);
	if (o.minY != null) ey = Math.max(ey, o.minMouseY);
	if (o.maxY != null) ey = Math.min(ey, o.maxMouseY);
	nx = x + ((ex - o.lastMouseX) * 1);
	ny = y + ((ey - o.lastMouseY) * 1);
	Drag.obj.root.style["left"] = nx + "px";
	Drag.obj.root.style["top"] = ny + "px";
	Drag.obj.lastMouseX	= ex;
	Drag.obj.lastMouseY	= ey;
	Drag.obj.root.onDrag(nx, ny);
	return false;
},
end : function(){
	removeEvent(document, "onmousemove", Drag.drag);
	removeEvent(document, "onmouseup", Drag.end);
	Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style["left"]), parseInt(Drag.obj.root.style["top"]));
	Drag.obj = null;
},
fixE : function(e){
	if (typeof e == 'undefined') e = window.event;
	if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
	if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
	return e;
}
};

var dragSort = {
force: false,
getMargin: function(elem) {
	var elmHeight, elmMargin;
	if(document.all){
		var t,r,b,l;
		t = elem.currentStyle.marginTop.replace(/\D+/g,"");
		r = elem.currentStyle.marginRight.replace(/\D+/g,"");
		b = elem.currentStyle.marginBottom.replace(/\D+/g,"");
		l = elem.currentStyle.marginLeft.replace(/\D+/g,"");
		elmMargin = (t ? parseInt(t) : 0)+(b ? parseInt(b) : 0);
		elmMargin2 = (l ? parseInt(l) : 0)+(r ? parseInt(r) : 0);
	} else {
		elmMargin = parseInt(document.defaultView.getComputedStyle(elem, '').getPropertyValue('margin-top'))+parseInt(document.defaultView.getComputedStyle(elem, '').getPropertyValue('margin-bottom'));
		elmMargin2 = parseInt(document.defaultView.getComputedStyle(elem, '').getPropertyValue('margin-left'))+parseInt(document.defaultView.getComputedStyle(elem, '').getPropertyValue('margin-right'));
	}
	return [
		/^\d+$/.test(elmMargin) ? elmMargin : 0,
		/^\d+$/.test(elmMargin2) ? elmMargin2 : 0
	];
},

// c: y || x&y
// d: func if moved
// e: extra find function
// f: extra init func
// g: extra end func
// h: hide/show embeds
init: function(a,b,c,d,e,f,g,hider){
	b = b ? b : a;
	Drag.init(a,b,c ? null : 0, c ? null : 0);
	var div = false;
	var move = 0;
	var diff = [];
	var size = false;
	var yBuff = 0;
	var dragDelay = 0;
	var hasDragged = 0;
	b.onDragStart = function(){
		size = FindXYWH(this);
		var scrollY = parseInt(document.body.scrollTop);
		yBuff = scrollY;
		this.style.left = (size.x + (document.all ? 0 : 0))+"px";
		this.style.top = (size.y+scrollY)+"px";
		this.style.width = (size.w + (document.all ? 0 : 0))+"px";
		dragSort.force = false;
		dragDelay = 0;
		hasDragged = 0;
	}

	b.onDrag = function(x,y){
		
		if(dragDelay < 1){
			dragDelay++;
			return;
		}else if(!hasDragged){
			if(hider){showSel(0);}
			hasDragged = 1;
		}
		
		var scrollY = parseInt(document.body.scrollTop);
		if(yBuff != scrollY){
			this.style.top = (parseInt(this.style.top) - (yBuff - scrollY))+"px";
			y -= (yBuff - scrollY);
			yBuff = scrollY;
		}
		y -= scrollY;
		if(!div){
			if(f){f(this);}
			div = _ce("DIV");
			div.style.height = size.h+"px";
			div.style.width = "100%";
			
			this.style.position = "absolute";
			this.style.zIndex = 1000;
			this.parentNode.insertBefore(div,this);
			
			var s2 = FindXYWH(this);
			diff = {
				x: size.x - s2.x,
				y: size.y - s2.y,
				w: size.w - s2.w,
				h: size.h - s2.h
			};
			move = 0;
			var b = _getn("BODY")[0].appendChild(this);
		}
		
		var w = div.offsetWidth;
		var h = div.offsetHeight;

		if(c){
			var col = div.parentNode;
			var xc = x + w/2;
			var pc = col.previousSibling;
			if(pc){
				var s = FindXYWH(pc);
				if(xc < s.x + s.w){
					var z = dragSort.beforeInCol(pc, y + h/2);
					if(z){
						pc.insertBefore(div,z);
					}else{
						pc.appendChild(div);
					}
					var wd = pc.offsetWidth - col.offsetWidth;
					this.style.width = (this.offsetWidth + diff.w + wd)+"px";
					this.style.left = (x-wd/2)+"px";
					div.style.height = this.offsetHeight+"px";
					col = pc;
					w = div.offsetWidth;
					h = div.offsetHeight;
					move = 1;
				}
			}
			var nc = col.nextSibling;
			if(nc){
				var s = FindXYWH(nc);
				if(xc > s.x){
					var z = dragSort.beforeInCol(nc, y + h/2);
					if(z){
						nc.insertBefore(div,z);
					}else{
						nc.appendChild(div);
					}
					var wd = nc.offsetWidth - col.offsetWidth;
					this.style.width = (this.offsetWidth + diff.w + wd)+"px";
					this.style.left = (x-wd/2)+"px";
					div.style.height = this.offsetHeight+"px";
					col = nc;
					w = div.offsetWidth;
					h = div.offsetHeight;
					move = 1;
				}
			}
		}

		var ps = div.previousSibling;
		if(ps){
			var s = FindXYWH(ps);
			if(y < s.y){
				div.parentNode.insertBefore(div, ps);
				move = 1;
			}
		}
		var ns = div.nextSibling;
		if(ns){
			var s = FindXYWH(ns);
			if(y + h/2 > s.y ){ //
				ns.parentNode.insertBefore(ns,div);
				move = 1;
			}
		}
		if(e){e(this,x,y);}
	}

	b.onDragEnd = function(){

		this.style.left = "auto";
		this.style.top = "auto";
		this.style.width = "100%";

		if(!hasDragged){return;}
		if(hider){showSel(1);}
		if(div){
			div.parentNode.insertBefore(this,div);
			div.parentNode.removeChild(div);
			div = false;
		}
		this.style.position = "static";
		// this.style.height = "auto";

		if(dragSort.force){
			dragSort.force(this);
		}else if(move){
			if(d){d();}
		}
		move = 0;
		dragSort.force = false;
		if(g){g(this);}
	}
},

beforeInCol: function(col, y){
	var a = col.childNodes;
	for(var x=0;x<a.length;x++){
		var b = a[x];
		var c = FindXYWH(b);
		if(c.y + c.h/2 > y){
			return b;
		}
	}
	return false;
}
};


// pop
document.write("<div id='pup'>.</div>");

var ie = document.all && navigator.userAgent.indexOf("Opera") == -1 ? true : false;
var safari = navigator.userAgent.indexOf("Safari") != -1 ? true : false;
var pup = _gel("pup");
var pupActive = false;
var mouseX = 0;
var mouseY = 0;
var dragScrollTimer = null;
var pupDelay = null;
var pupBuff = ["",""];
var popMaxImg = [500,400];
var popMaxImgW = popMaxImg[0];
var popMaxImgH = popMaxImg[1];
var popTimer = null;

function get_mouse(e){
	mouseX = ie ? event.clientX : (e ? e["clientX"] : mouseX);
	mouseY = ie ? event.clientY : (e ? e["clientY"] : mouseY);
	renderPopup();
	if(App.dragging){
		if(dragScrollTimer){
			clearTimeout(dragScrollTimer);
			dragScrollTimer = null;
		}
		dragScroll(e);
	}
}

function dragScroll(e){
	var ch = !safari ? document.body.clientHeight : window.innerHeight;
	var cw = !safari ? document.body.clientWidth : window.innerWidth;
	var scrollOffset = 20;
	var scrollY = document.body.scrollTop;
	var s = mouseY < scrollOffset && scrollY > 0 ? -1 : (mouseY >  ch - scrollOffset ? 1 : 0);
	if(s != 0){
		window.scrollTo(0, scrollY + s * 2);
		dragScrollTimer = setTimeout(function(){if(!ie){document.onmousemove(e);}else{dragScroll();}}, 4);
	}
}

function renderPopup(){
	if(!pupActive){return;}
	var scrollY = document.body.scrollTop;
	var x = mouseX;
	var y = mouseY + scrollY;
	var w = pup.firstChild.offsetWidth;
	var h = pup.offsetHeight;
	var ch = !safari ? document.body.clientHeight : window.innerHeight;
	var cw = !safari ? document.body.clientWidth : window.innerWidth;
	var heightExtreem = ch + scrollY - h;
	var widthExtreem = cw - w;
	var l = x + 40;
	var t = y + 20;
	t = t < heightExtreem ? t : heightExtreem;
	l = l < widthExtreem ? l : widthExtreem;
	if(t < y && t+h > y && l < x && l+w > x){
		t = y - h - 10;
		if(t < scrollY){
			l = x - w - 10;
		}
	}
	if(t < scrollY){t = scrollY;}
	if(t == scrollY && h > ch){
		var tw = parseInt(pup.firstChild.width);
		if(tw < cw / 2){
			tw = tw + 100 < cw / 2 ? tw + 100 : Math.ceil(cw / 2);
			pup.firstChild.width = tw;
			pup.style.width = tw+"px";
			renderPopup();
			return;
		}
	}
	pup.style.top = t+"px";
	pup.style.left = l+"px";
	if(pupActive){
		var arr = ie ? ["SELECT", "IFRAME", "EMBED"] : ["EMBED", "IFRAME"];
		for(var j=0;j<arr.length;j++){
			var objs = _getn(arr[j]);
			for(var i=0;i<objs.length;i++){
				var obj = objs[i];
				var o = FindXYWH(obj);
				obj.style.visibility = (o.x > (l + w) || (o.x + o.w) < l) || (o.y > (t + h) || (o.y + o.h) < t) ? "visible" : "hidden";
			}
		}
	}
}

function popup(str, rubrik, w, maxImg){
	if(maxImg == undefined){
		popMaxImgW = popMaxImg[0];
		popMaxImgH = popMaxImg[1];
	}else{
		if(typeof(maxImg) == "object" && maxImg.length == 2){
			popMaxImgW = maxImg[0];
			popMaxImgH = maxImg[1];
		}else{
			popMaxImgW = parseInt(maxImg);
			popMaxImgH = parseInt(maxImg);
		}
	}
	
	if(killTimer){
		clearTimeout(killTimer);
		killTimer = null;
	}
	if(str == pupBuff[0] && rubrik == pupBuff[1]){
		return;
	}
	pupBuff = [str,rubrik];
	str = str.replace(/(<img[^>]+)/ig, "$1 class=img_temp");
	pup.style.zIndex = "100000000";
	if(App.dragging){return;}
	pupActive = true;
	pup.style.visibility = "hidden";
	pup.style.display = "block";
	if(rubrik == undefined){rubrik = "Information";}
 	rubrik += "<img src=images/s.gif height=16 width=1>";
	pup.innerHTML = "<table cellspacing=0 cellpadding=0 width="+(w ? w : 320)+" class='pop_table'><tr><td><div class='expblock'><div class='round_b"+(App.blockColor ? " "+App.blockColor : "")+"' id='popTheme'><div class='rbtop'><div><div><span class='topic'>"+rubrik+"</span></div></div></div><div class='rbcontent'><div class='rbright'><div id='pop_content' class='pop_content'>"+str+"<div style='clear:both'></div><img src='images/s.gif'></div></div></div><div class='rbbot'><div><div></div></div></div></div></div></td></tr></table>";
 	pup.style.width = pup.offsetWidth;
	pupDelay = setTimeout("pup.style.visibility = 'visible';",50);
	popCheckSize();
}

function popCheckSize(){
	var is = _gel("pop_content") ? _gel("pop_content").getElementsByTagName("IMG") : [];
	if(is.length){
		for(var x=0;x<is.length;x++){
			if(!isImageOk(is[x])){
				if(is[x].src.indexOf("/s.gif") != -1){continue;}
				if(_gel("pop_content").style.backgroundImage.indexOf("indicator") == -1){
					_gel("pop_content").style.background = "url(\"images/indicator.gif\") no-repeat top right";
					if(parseInt(_gel("pop_content").offsetHeight) < 20){
						_gel("pop_content").style.height = "20px";
					}
				}
				if(popTimer){
					clearTimeout(popTimer);
					popTimer = null;
				}
				popTimer = setTimeout(popCheckSize, 300);
				renderPopup();
				return false;
			}
		}
		_gel("pop_content").style.height = "auto";
		// all images ok, check width and resize if neccessary
		for(var x=0;x<is.length;x++){
			if(parseInt(is[x].offsetWidth) > popMaxImgW){
				is[x].style.width = popMaxImgW+"px";
				is[x].style.height = "auto";
			}
			if(parseInt(is[x].offsetHeight) > popMaxImgH){
				is[x].style.height = popMaxImgH+"px";
				is[x].style.width = "auto";
			}
			is[x].className = "";
		}
		_gel("pop_content").style.background = "";
		renderPopup();
	}else{
		renderPopup();
	}
}

var killTimer = null;
function kill(){
	if(killTimer){
		clearTimeout(killTimer);
		killTimer = null;
	}
	killTimer = setTimeout(dokill, 10);
}

function dokill(){
	if(popTimer){
		clearTimeout(popTimer);
		popTimer = null;
	}	
	pupBuff = ["",""];
	if(pupDelay != undefined && pupDelay){clearTimeout(pupDelay);}
	pupDelay = null;
	pupActive = false;
	pup.style.display = "none";
	pup.style.width = "auto";
	pup.innerHTML = "";
	showSel();
}

function showSel(a){var arr = ie ? ["SELECT", "IFRAME", "EMBED"] : ["EMBED", "IFRAME"];a = a == undefined ? 1 : a;for(var x=0;x<arr.length;x++){var b = _getn(arr[x]);for(var y=0;y<b.length;y++){b[y].style.visibility = a ? "visible" : "hidden";}}}
function FindXY(obj){var x=0;var y=0;while(obj!=null){x+=obj.offsetLeft-obj.scrollLeft;y+=obj.offsetTop-obj.scrollTop;obj=obj.offsetParent;}return {x:x,y:y};}
function FindXYWH(obj){var objXY = FindXY(obj);return objXY?{ x:objXY.x, y:objXY.y, w:obj.offsetWidth, h:obj.offsetHeight }:{ x:0, y:0, w:0, h:0 };}

document.onmousemove=get_mouse;



// format: New array(extension, decimals, decimalSplit, thousandSplit[,hours[,prefix]]) // hours:["", 2, ":", "",1],96
function addSlider(container, bi, values, val, func, format, hops, overrideMinText, overrideMaxText, noSideText){
	var min = values[0];
	var max = values[1];
	values = values[2] || false;
	
	var percentPos = [];
	format = format == undefined ? ["",0,".",""] : format;
	hops = hops == undefined ? false : hops;
	var arrowImg = "/images/slider_ctrl.png"; // "images/arrow_down.gif";
	var arrowH = 16; // 9
	var arrowW = 7; // 9
	
	var arrMargin = Math.round(arrowW/2);
	var mainW = container.offsetWidth;
	var bg = document.createElement("DIV");

	bg.className = "slider_meter";
	bg.style.marginTop = (arrowW + 2)+"px";
	container.appendChild(bg);

	var levelsFunc = function(){
		if(values){
			var cn = container.childNodes;
			for(var x=0;x<cn.length;x++){
				if(cn[x].className == "slider_levels"){
					container.removeChild(cn[x]);
					break;
				}
			}
			var levels = document.createElement("DIV");
			levels.className = "slider_levels";
			levels.style.width = mainW+"px";
			container.appendChild(levels);
			var range = max - min;
			var ranges = Math.floor(mainW / 5);
			var rangeArr = [];
			for(var x=0;x<ranges;x++){ rangeArr[x] = 0; }
			for(var x=0;x<values.length;x++){
				var v = values[x];
				v = (v - min) / range;
				v = v * 100;
				v = Math.floor(v / (100 / ranges));
				v = v == ranges ? (v - 1) : v;
				rangeArr[v]++;
			}

			var levelMax = 0;
			for(var x=0;x<ranges;x++){
				if(rangeArr[x] > levelMax){
					levelMax = rangeArr[x];
				}
			}
			var maxH = levels.offsetHeight;
			var levelW = Math.floor(mainW / ranges);

			var ww = 0;
			for(var x=0;x<ranges;x++){ 
				ww += levelW;
				//alert(ww+" "+(ww + levelW));
				var g = rangeArr[x];
				var d = document.createElement("DIV");
				d.style.width = levelW+"px";
				var h = !levelMax ? 0 : Math.floor(maxH * (g / levelMax));
				d.style.height = h+"px";
				d.style.marginTop = (maxH - h)+"px";
				// d.onmouseover = function(){Debugger.debug([this.offsetHeight, this.style.height,this.style.marginTop]);};
				if(!h){
					d.style.backgroundColor = "transparent";
					d.style.background = "transparent";
				}
				levels.appendChild(d);
			}
		}
	}
	levelsFunc();
	
	var arr1 = document.createElement("IMG");
	arr1.src = arrowImg;
	arr1.style.position = "absolute";
	arr1.style.left = -arrMargin+"px";
	arr1.style.cursor = "e-resize";
	arr1.style.marginTop = "2px";
	arr1.style.zIndex = 100;
	if(bi){
		var arr2 = document.createElement("IMG");
		arr2.src = arrowImg;
		arr2.style.position = "absolute";
		arr2.style.left = mainW-arrMargin+"px";
		arr2.style.cursor = "e-resize";
		arr2.style.marginTop = "2px";
		arr2.style.zIndex = 100;

		Drag.init(arr2, arr2, null,null,0,0);
		arr2.onDrag = function(x,y){
			App.dragging = true;
			var pn = this.parentNode;
			if(x < -arrMargin){
				this.style.left = -arrMargin+"px";
			}else if(x > pn.offsetWidth - arrMargin){
				this.style.left = (pn.offsetWidth - arrMargin)+"px";
			}else if(x < arr1.offsetLeft){
				arr1.style.left = this.style.left;
				// this.style.left = arr1.offsetLeft+"px";
			}
			meter();
		}
		arr2.onDragEnd = function(x,y){
			App.dragging = false;
			if(hops){setHops();}
			meter();
		}
		container.appendChild(arr2);
	}	
	Drag.init(arr1, arr1, null,null,0,0);
	arr1.onDrag = function(x,y){
		App.dragging = true;
		var pn = this.parentNode;
		if(x < -arrMargin){
			this.style.left = -arrMargin+"px";
		}else if(x > pn.offsetWidth - arrMargin){
			this.style.left = (pn.offsetWidth - arrMargin)+"px";
		}else if(bi && x > arr2.offsetLeft){
			arr2.style.left = this.style.left;
			// this.style.left = arr2.offsetLeft+"px";
		}
		meter();
	}
	var setHops = function(){
		var x = parseInt(arr1.style.left);
		var jump = mainW / hops;
		arr1.style.left = ( (Math.round((x+arrMargin) / jump) * jump)-arrMargin)+"px";
		if(bi){
			x = parseInt(arr2.style.left);
			arr2.style.left = ( (Math.round((x+arrMargin) / jump) * jump)-arrMargin)+"px";
		}
	}
	
	arr1.onDragEnd = function(x,y){
		App.dragging = false;
		if(hops){setHops();}
		meter();
	}
	container.appendChild(arr1);
	
	// set initial value and positions
	if(bi){
		var ll = (((val[0]-min) / (max - min)) * mainW - arrMargin);
		ll = isNaN(ll) ? -arrMargin : ll;
		arr1.style.left = ll+"px";
		var ll = (((val[1]-min) / (max - min)) * mainW - arrMargin);
		ll = isNaN(ll) ? mainW - arrMargin : ll;
		arr2.style.left = ll+"px";
	}else{
		var ll = (((val[0]-min) / (max - min)) * mainW - arrMargin);
		ll = isNaN(ll) ? mainW - arrMargin : ll;
		arr1.style.left = ll+"px";
	}
	
	if(typeof(format) == "function"){
		var formater = format;
	}else{
		var formater = function(num){
			if(num == min && overrideMinText){return overrideMinText;}
			if(num == max && overrideMaxText){return overrideMaxText;}
			var num = number_format(num,format[1],format[2],format[3]);
			if(format[4]){
				num = num.split(":");
				num[0] = num[0] < 10 ? "0"+num[0] : num[0];
				num[1] = number_format(num[1] * .6 / 100,2,".","");
				num[1] = num[1].split(".")[1];
				num = num[0]+":"+num[1];
			}
			return (format[5] ? format[5] : "")+num+format[0];
		}
	}
	
	var meterDiv = document.createElement("DIV");
	var meterL = document.createElement("DIV");
	var meterC = document.createElement("DIV");
	var meterR = document.createElement("DIV");

	meterDiv.className = "meter";
	
	meterL.innerHTML = noSideText ? "" : (!overrideMinText ? formater(min) : overrideMinText);
	meterC.innerHTML = bi ? formater(min)+" - "+formater(max) : formater(min);
	meterR.innerHTML = noSideText ? "" : (!overrideMaxText ? formater(max) : overrideMaxText);

	meterC.style.textAlign = "center";
	meterR.style.textAlign = "right";
	
	meterDiv.appendChild(meterL);
	meterDiv.appendChild(meterC);
	meterDiv.appendChild(meterR);
	
	container.appendChild(meterDiv);
	
	var sliderSizer = function(){
		meterC.style.width = mainW+"px";
		meterR.style.width = mainW+"px";
		
		if(hops){
			var jump = mainW / hops;
			if(bi){
				var l = ( (Math.round((parseInt(arr1.style.left)+arrMargin) / jump) * jump));
				var r = ( (Math.round((parseInt(arr2.style.left)+arrMargin) / jump) * jump));
			}else{
				var l = 0;
				var r = ( (Math.round((parseInt(arr1.style.left)+arrMargin) / jump) * jump));
			}
			if(!isNaN(l)){
				bg.style.marginLeft = l+"px";
			}
			if(!isNaN(r)){
				bg.style.width = (r-l)+"px";
			}
		}else{
			if(bi){
				var l = parseInt(arr1.style.left)+arrMargin;
				var r = parseInt(arr2.style.left)+arrMargin;
				bg.style.marginLeft = l+"px";
				bg.style.width = (r-l)+"px";
			}else{
				bg.style.width = parseInt(arr1.style.left)+arrMargin+"px";
			}
		}
	}

	var meter = function(x){
		mainW = container.offsetWidth;
		percentPos[0] = (parseInt(arr1.style.left)+arrMargin) / mainW;
		var v1 = (parseInt(arr1.style.left)+arrMargin) / mainW;
		if(hops){
			var jump = mainW / hops;
			v1 = parseInt(arr1.style.left)+arrMargin;
			v1 = min + (Math.round(v1 / jump)) * ((max-min)/hops);
		}else{
			v1 = (v1 * (max-min)) + min;
		}
		if(x){v1 = val[0];}
		if(bi){
			percentPos[1] = (parseInt(arr2.style.left)+arrMargin) / mainW;
			var v2 = (parseInt(arr2.style.left)+arrMargin) / mainW;
			if(hops){
				var jump = mainW / hops;
				v2 = parseInt(arr2.style.left)+arrMargin;
				v2 = min + (Math.round(v2 / jump)) * ((max-min)/hops);
			}else{
				v2 = (v2 * (max-min)) + min;
			}
			if(x){v2 = val[1];}
			meterC.innerHTML = formater(v1)+" - "+formater(v2);
		}else{
			meterC.innerHTML = formater(v1);
		}
		sliderSizer();
		if(!App.dragging && !x){
			func(v1,v2,formater(v1),formater(v2));
		}
	}

	container.onmouseup = function(){
		if(!App.dragging){
			var x = mouseX - FindXY(this).x;
			var x2 = x / mainW;
			if(x2 > .98){
				x = mainW;
			}else if(x2 < .02){
				x = 0;
			}
			if(bi){
				// Find closest
				var a1 = Math.abs(parseInt(arr1.style.left) - x);
				var a2 = Math.abs(parseInt(arr2.style.left) - x);
				var a = a1 < a2 ? arr1 : arr2;
			}else{
				var a = arr1;
			}
			a.style.left = (x - arrMargin)+"px";
			if(hops){setHops();}
			meter();
		}
	}
	
	var sliderResize = function(){
		if(!container){return;}
		var mainW = container.offsetWidth;
		if(!mainW){return;}
		arr1.style.left = (percentPos[0] * mainW) - arrMargin;
		if(bi){
			arr2.style.left = (percentPos[1] * mainW) - arrMargin;
		}
		sliderSizer();
		levelsFunc();
		meter(1);
	}
	
	App.addResizeEvent(sliderResize);
	
	meter(1);
};
