/*	

**************************************	
*    (c) 2006-2010 Oliver Zeidler    *
*    http://intergraphica.de         *
*                                    *
**************************************

*/



// AJAX FUNCTIONS


// EMPTY AJAX CACHE --------------------------------------------------------

var Http = {
	ReadyState: {
		Uninitialized: 0,
		Loading: 1,
		Loaded:2,
		Interactive:3,
		Complete: 4
	},
		
	Status: {
		OK: 200,
		
		Created: 201,
		Accepted: 202,
		NoContent: 204,
		
		BadRequest: 400,
		Forbidden: 403,
		NotFound: 404,
		Gone: 410,
		
		ServerError: 500
	},
		
	Cache: {
		Get: 1,
		GetCache: 2,
		GetNoCache: 3,
		FromCache: 4
	},
	
	Method: {Get: "GET", Post: "POST", Put: "PUT", Delete: "DELETE"},
	
	enabled: false,
	logging: false,
	_get: null,	// Reference to the XmlHttpRequest object
	_cache: new Object(),
	
	Init: function(){
		Http._get = Http._getXmlHttp()
		Http.enabled = (Http._get != null)
		Http.logging = (window.Logging != null);
	},
	
	_getXmlHttp: function(){
	/*@cc_on @*//*@if (@_jscript_version >= 5)
		try { return new ActiveXObject("Msxml2.XMLHTTP"); } 
		catch (e) {} 
		try { return new ActiveXObject("Microsoft.XMLHTTP"); } 
		catch (e) {} 
	@end @*/
		try { return new XMLHttpRequest();}
		catch (e) {}

		return null;
	},

/*
	Params:
		url: The URL to request. Required.
		cache: Cache control. Defaults to Cache.Get.
		callback: onreadystatechange function, called when request is completed. Optional.
		method: HTTP method. Defaults to Method.Get.
*/
	get: function(params, callback_args){	
		if (!Http.enabled) throw "Http: XmlHttpRequest not available.";
		
		var url = 'http://www.susanhorn.de';
		if (!url) throw "Http: A URL must be specified";
				
		var cache = params.cache || Http.Cache.Get;
		var method = params.method || Http.Method.Get;
		var callback = params.callback;
		
		if ((cache == Http.Cache.FromCache) || (cache == Http.Cache.GetCache))
		{
			var in_cache = Http.from_cache(url, callback, callback_args)

			if (Http.logging){
				Logging.log(["Http: URL in cache: " + in_cache]);
			}

			if (in_cache || (cache == Http.Cache.FromCache)) return in_cache;
		}
		
		if (cache == Http.Cache.GetNoCache)
		{
			var sep = (-1 < url.indexOf("?")) ? "&" : "?"	
			url = url + sep + "__=" + encodeURIComponent((new Date()).getTime());
		}
	
		// Only one request at a time, please
		if ((Http._get.readyState != Http.ReadyState.Uninitialized) && 
			(Http._get.readyState != Http.ReadyState.Complete)){
			this._get.abort();
			
			if (Http.logging){
				Logging.log(["Http: Aborted request in progress."]);
			}
		}
		
		Http._get.open(method, url, true);

		Http._get.onreadystatechange =  function() {
			if (Http._get.readyState != Http.ReadyState.Complete) return;
			
			if (Http.logging){
				Logging.log(["Http: Returned, status: " + Http._get.status]);
			}

			if ((cache == Http.Cache.GetCache) && (Http._get.status == Http.Status.OK)){
				Http._cache[url] = Http._get.responseText;
			}
			
			if (callback_args == null) callback_args = new Array();

			var cb_params = new Array();
			cb_params.push(Http._get);
			for(var i=0;i<callback_args.length;i++)
				cb_params.push(callback_args[i]);
				
			callback.apply(null, cb_params);
		}
		
		if(Http.logging){
			Logging.log(["Http: Started\n\tURL: " + url + "\n\tMethod: " + method + "; Cache: " + Hash.keyName(Http.Cache,cache)])
		}
		
		Http._get.send(params.body || null);
	},
	
	from_cache: function(url, callback, callback_args){
		var result = Http._cache[url];
		
		if (result != null) {
			var response = new Http.CachedResponse(result)
			
			var cb_params = new Array();
			cb_params.push(response);
			for(var i=0;i<callback_args.length;i++)
				cb_params.push(callback_args[i]);
							
			callback.apply(null, cb_params);
				
			return true
		}
		else
			return false
	},
	
	clear_cache: function(){
		Http._cache = new Object();
	},
	
	is_cached: function(url){
		return Http._cache[url]!=null;
	},
	
	CachedResponse: function(response) {
		this.readyState = Http.ReadyState.Complete
		this.status = Http.Status.OK
		this.responseText = response
	}	
}

Http.Init()

function json_response(response){
	var js = response.responseText;
	try{
		return eval(js); 
	} catch(e){
		if (Http.logging){
			Logging.logError(["json_response: " + e]);
		}
		else{
			alert("Error: " + e + "\n" + js);
		}
		return null;
	}
}

function getResponseProps(response, header){
	try {
		var s = response.getResponseHeader(header || 'X-Ajax-Props');
		if (s==null || s=="")
			return new Object()
		else
			return eval("o="+s)
	} catch (e) { return new Object() }
}






// AJAX CONTENT LOADER

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){

var page_request = false

document.getElementById(containerid).innerHTML='';	

if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

changeOpac('0', containerid);
opacity(containerid,0,100,500);

page_request.onreadystatechange=function(){
loadpage(page_request, containerid);




}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML=page_request.responseText;

}

}



function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}







// added 04.22.2010 window size IE hack
function getWinSize(win) {
if(!win) win = window;
var s = new Object();
if(typeof win.innerWidth != 'undefined')
{
s.width = win.innerWidth;
s.height = win.innerHeight;
}
else
{
var obj = getBody(win);
s.width = parseInt(obj.clientWidth);
s.height = parseInt(obj.clientHeight);
}
return s;
}


// strict or quirks mode
function getBody(w) {
return (w.document.compatMode && w.document.compatMode ==
"CSS1Compat") ?
w.document.documentElement : w.document.body || null;
}







// ALIGN PAGE TO DIFF SCREEN RESOLUTIONS
function AlignPage(){
	
var s = getWinSize(window);
 	          	        	
if (s.width<1024){
	document.getElementById('buttons').style.visibility="hidden";
	}
else {	document.getElementById('buttons').style.visibility="visible";
	}
	
if (s.height>680){
	document.getElementById('mainframe').style.marginTop="7%";
	document.getElementById('buttontable').style.top="315px";

	}
else {		
	document.getElementById('mainframe').style.marginTop="3.5%";
	document.getElementById('buttontable').style.top="237px";
	}	
	

// STATUS MESSAGE
window.status =  'screen width:'+s.width+' screen height:'+s.height;
document.getElementById('buttontable').style.visibility="visible";

}






// DIV POPUPfunction Popup(targetId) {
	
	if (document.getElementById(targetId).style.display=='block') {
	 ClosePopup(targetId);
	 return;
	}		ReAlign(targetId);	document.getElementById(targetId).style.display='block'; 			opacity(targetId, 0, 99, 300);}// CLOSE POPUPfunction ClosePopup(targetId) {		opacity(targetId,100,0,300);	setTimeout("document.getElementById('"+targetId+"').style.display='none'",500); 	}// RE-ALIGN POPUP TO MIDDLEfunction ReAlign(targetId) {
	
	var s = getWinSize(window);
	var divbreite = parseFloat(document.getElementById(targetId).style.width);  	var zentriert = parseFloat(s.width/2.7-divbreite/2);
  	var unten = s.height-460;  	var hoehe = 215;    // RE-ALIGN DIV   document.getElementById(targetId).style.left = zentriert+"px"; // X   document.getElementById(targetId).style.top = unten+"px"; // Y }
// COMMENT THAMKS
function thanks() {
	document.getElementById('loginform_text').innerHTML=
	'<br><br><br><br><br><b><font size=7>Vielen Dank!</font></b><br>Dein Kommentar wird geprüft und freigeschaltet.';
	setTimeout("ClosePopup('loginform')",2000);
	setTimeout("document.getElementById('loginform_text').innerHTML=''",2000);
	}
	
// DOUBLE POST
function sorry() {
	document.getElementById('loginform_text').innerHTML=
	'<br><br><br><br><br><b><font size=7>Oops!</font></b><br>Diesen Kommentar gab es bereits!';
	setTimeout("ClosePopup('loginform')",2000);
	setTimeout("document.getElementById('loginform_text').innerHTML=''",2000);

		}

// FEHLER
function fehler() {
	document.getElementById('loginform_text').innerHTML=
	'<br><br><br><br><br><b><font size=7>Oops!</font></b><br>Du hast fehlerhafte Daten eingegeben.<br>Bitte versuch es nochmal!';
	setTimeout("ClosePopup('loginform')",2000);
	setTimeout("document.getElementById('loginform_text').innerHTML=''",2000);

		}
		
// CHECK SPAM
function checkform(){
	var message=document.formular.comment.value;
	if ((message.length<20)
		||(message.indexOf('http')>0)
		||(message.indexOf('www.')>0)
		||(message.indexOf('url')>0)
		) {
		message=message.replace(/http/gi,"***KEIN SPAM BITTE*** ");
		message=message.replace(/url/gi,"***KEIN SPAM BITTE*** ");
		message=message.replace(/www./gi,"***KEIN SPAM BITTE*** ");
		document.formular.comment.value=message;
		}
	}// FADE EFFECT  function opacity(id, opacStart, opacEnd, millisec) {    //speed for each frame    var speed = Math.round(millisec / 100);    var timer = 0;    var i = 0;    //determine the direction for the blending, if start and end are the same nothing happens    if(opacStart > opacEnd) {        for(i = opacStart; i >= opacEnd; i--) {            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));            timer++;        }    } else if(opacStart < opacEnd) {        for(i = opacStart; i <= opacEnd; i++)            {            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));            timer++;        }    }}//change the opacity for different browsersfunction changeOpac(opacity, id) {    var object = document.getElementById(id).style;    object.opacity = (opacity / 100);    object.MozOpacity = (opacity / 100);    object.KhtmlOpacity = (opacity / 100);    object.filter = "alpha(opacity=" + opacity + ")";} function shiftOpacity(id, millisec) {	 //if an element is invisible, make it visible, else make it ivisible     if(document.getElementById(id).style.opacity == 0) {        opacity(id, 0, 100, millisec);    } else {        opacity(id, 100, 0, millisec);    }      } 


 // Autoscroller

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


// Parameter
var sense1 = 20; // Sensibilitaetszone 1 (in %)
var sense2 = 10; // Sensibilitaetszone 2 (in %)
var speed1 = 1;  // Scrollgeschwindigkeit in Zone 1
var speed2 = 3;  // Scrollgeschwindigkeit in Zone 2
var stime  = 30; // Timer zum Scrollen

// Interne Variablen
var scrolling = false;
var scrollfast;
var richtung;
var y_mem = -1;
var myWin;

// Scrolling anhalten
function stopp_scrolling()
{
  scrolling = false;
  y_mem     = -1;
}

// Scroll aktivieren und durchfuehren
function start_scrolling(initial)
{
  if(!scrolling)
    return;

  // Dokumentposition ermitteln
  var dy = (myWin.pageYOffset != null) ? myWin.pageYOffset : myWin.document.body.scrollTop;
  if((y_mem != dy) && !initial)
    return;
  var dx = (myWin.pageXOffset != null) ? myWin.pageXOffset : myWin.document.body.scrollLeft;
  dy += richtung * (scrollfast ? speed2 : speed1);

  // Scrollen
  myWin.scrollTo(dx, dy);
  y_mem = dy;

  // Funktion erneut aufrufen
  setTimeout("start_scrolling(false)", stime);
}

// Auswertung der Mausposition
function zeige(e)
{
  // Mausposition und Dokumentdaten
  var y = myWin.Event ? e.pageY : myWin.event.clientY;
  if(myWin.Event)
    y -= - (myWin.pageYOffset != null) ? myWin.pageYOffset : myWin.document.body.scrollTop;
  var wh = myWin.innerHeight ? myWin.innerHeight : myWin.document.body.clientHeight;
  var dh = myWin.document.height ? myWin.document.height : myWin.document.body.scrollHeight;

  // Zwischenvariablen
  var s1 = Math.round(wh * sense1 / 100);
  var s2 = Math.round(wh * sense2 / 100);
  var now_scroll;

  // Scrollnotwendigkeit ermitteln
  if((y < s1) || (y > (wh - s1)))
  {
    now_scroll = true;
    richtung   = (y < s1) ? -1 : 1;
    scrollfast = ((y < s2) || (y > (wh - s2))) ? true : false;
  }
  else
  {
    now_scroll = false;
    scrolling  = false;
  }

  // Scrollstatus geaendert?
  if(now_scroll != scrolling)
  {
    y_mem     = -1;
    scrolling = now_scroll;
    if(scrolling)
      start_scrolling(true);
  }
}

// Mauskontrolle initiieren
function init()
{
  myWin = window;

  if(myWin.Event)
    myWin.document.captureEvents(Event.MOUSEMOVE);

  myWin.document.onmousemove = zeige;
}
/************************************************** * dom-drag.js * 09.25.2001 * www.youngpup.net * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005 ************************************************** * 10.28.2001 - fixed minor bug where events * sometimes fired off the handle, not the root. **************************************************/var Drag = {	obj : null,	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)	{		o.onmousedown	= Drag.start;		o.hmode			= bSwapHorzRef ? false : true ;		o.vmode			= bSwapVertRef ? false : true ;		o.root = oRoot && oRoot != null ? oRoot : o ;		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "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.xMapper = fXMapper ? fXMapper : null;		o.yMapper = fYMapper ? fYMapper : null;		o.root.onDragStart	= new Function();		o.root.onDragEnd	= new Function();		o.root.onDrag		= new Function();	},	start : function(e)	{		var o = Drag.obj = this;		e = Drag.fixE(e);		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );		o.root.onDragStart(x, y);		o.lastMouseX	= e.clientX;		o.lastMouseY	= e.clientY;		if (o.hmode) {			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;		} else {			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;		}		if (o.vmode) {			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;		} else {			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;		}		document.onmousemove	= Drag.drag;		document.onmouseup		= Drag.end;		return false;	},	drag : function(e)	{		e = Drag.fixE(e);		var o = Drag.obj;		var ey	= e.clientY;		var ex	= e.clientX;		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );		var nx, ny;		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));		if (o.xMapper)		nx = o.xMapper(y)		else if (o.yMapper)	ny = o.yMapper(x)		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";		Drag.obj.lastMouseX	= ex;		Drag.obj.lastMouseY	= ey;		Drag.obj.root.onDrag(nx, ny);		return false;	},	end : function()	{		document.onmousemove = null;		document.onmouseup   = null;		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));		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;	}};// SCROLL MENUvar currentSection="1-pane";var tabTag="-tab";var paneTag="-pane";function ScrollSection(link,scrollArea,offset) {
	
lastSection=currentSection;

if(currentSection==link){
return;
}

currentSection=link;
ajax = link.substring(0,link.length-5);

// EMPTY LAST SECTION
last = lastSection.substring(0,lastSection.length-5);	
document.getElementById(last).innerHTML='';	

sectionTab=currentSection.split("-")[0]+tabTag;
document.getElementById(sectionTab).className="active";
if(lastSection){lastTab=lastSection.split("-")[0]+tabTag;document.getElementById(lastTab).className="inactive";}

theScroll=document.getElementById(scrollArea);
position=findElementPos(document.getElementById(link));

if(offset!=""){
	offsetPos=findElementPos(document.getElementById(offset));
	position[0]=position[0]-offsetPos[0];
	}

scrollStart(theScroll,theScroll.scrollLeft,position[0],"horiz",ajax);

}



function ScrollArrow(direction,transmenu,scrollArea,offset){
transmenuElem=document.getElementById(transmenu);
transmenuNames=new Array();
if(transmenuElem.hasChildNodes()){
	var children=transmenuElem.childNodes;
	for(var i=0;i<children.length;i++){
		if(transmenuElem.childNodes[i].tagName=="LI" && transmenuElem.childNodes[i].style.visibility!='hidden'){
						transmenuNames.push(transmenuElem.childNodes[i].id.split("-")[0]);}}}for(var i=0;i<transmenuNames.length;i++){if(transmenuNames[i]==currentSection.split("-")[0]){
							
if(direction=="left"){if(i-1<0){gotoTab=transmenuNames[transmenuNames.length-1];}
else{gotoTab=transmenuNames[i-1];}}
else{if((i+1)>(transmenuNames.length-1)){gotoTab=transmenuNames[0];}
else{gotoTab=transmenuNames[i+1];}}}}
opacity(gotoTab+'-tab',100,60,1000);
ScrollSection(gotoTab+paneTag,scrollArea,offset);
						
}

var scrollanim={time:0,begin:0,change:0.0,duration:0.0,element:null,timer:null};


function scrollStart(elem,start,end,direction,ajax){
	
	if(scrollanim.timer!=null){	
		clearInterval(scrollanim.timer);
		scrollanim.timer=null;
		}
	
	scrollanim.time=0;
	scrollanim.begin=start;
	scrollanim.change=end-start;
	scrollanim.duration=25;
	scrollanim.element=elem;
	

	
	

	if(direction=="horiz"){
	scrollanim.timer=setInterval("scrollHorizAnim(ajax);",15);}
	
	else{
		scrollanim.timer=setInterval("scrollVertAnim();",15);}
		}
	
	
function scrollVertAnim(){
	if(scrollanim.time>scrollanim.duration){
		clearInterval(scrollanim.timer);scrollanim.timer=null;}else{move=sineInOut(scrollanim.time,scrollanim.begin,scrollanim.change,scrollanim.duration);scrollanim.element.scrollTop=move;scrollanim.time++;}
		
		}
		


function scrollHorizAnim(ajax){

	if(scrollanim.time>scrollanim.duration){
	clearInterval(scrollanim.timer);
	scrollanim.timer=null;
	
	//Popup('loginform');
	//document.getElementById('loginform_text').innerHTML='Scrolling finished!<br>Now loading content for section: '+ajax;
 	setTimeout("ajaxpage('database/fetch_content.php?pane="+ajax+"&lang=deutsch',ajax)",20);
 	//setTimeout("ajaxpage('database/"+ajax+".php',ajax)",20);
	
	}
	
	else{
move=sineInOut(scrollanim.time,scrollanim.begin,scrollanim.change,scrollanim.duration);
scrollanim.element.scrollLeft=move;
scrollanim.time++;

}


}
	
function linear(t,b,c,d){return c*t/d+b;}

function sineInOut(t,b,c,d){return-c/2*(Math.cos(Math.PI*t/d)-1)+b;}

function cubicIn(t,b,c,d){return c*(t/=d)*t*t+b;}

function cubicOut(t,b,c,d){return c*((t=t/d-1)*t*t+1)+b;}

function cubicInOut(t,b,c,d){if((t/=d/2)<1)return c/2*t*t*t+b;return c/2*((t-=2)*t*t+2)+b;}
	
function bounceOut(t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b;}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;}}
	
	
function findElementPos(elemFind){var elemX=0;var elemY=0;do{elemX+=elemFind.offsetLeft;elemY+=elemFind.offsetTop;}while(elemFind=elemFind.offsetParent);return Array(elemX,elemY);
}






// TOP SCROLLER

var goto_top_type = -1;
var goto_top_itv = 0;

function goto_top_timer() {
var y = goto_top_type == 1 ? document.documentElement.scrollTop : document.body.scrollTop;
//alert(y);
var moveby = 20; // set this to control scroll seed. minimum is fast

y -= Math.ceil(y * moveby / 100);
if (y < 0)
y = 0;

if (goto_top_type == 1)
document.documentElement.scrollTop = y;
else
document.body.scrollTop = y;

if (y == 0) {
clearInterval(goto_top_itv);
goto_top_itv = 0;
}
}

function goto_top() {
if (goto_top_itv == 0) {
if (document.documentElement && document.documentElement.scrollTop)
goto_top_type = 1;
else if (document.body && document.body.scrollTop)
goto_top_type = 2;
else
goto_top_type = 0;

if (goto_top_type > 0)
goto_top_itv = setInterval('goto_top_timer()', 25);
}
}





// HIGHSLIDE VIEWER

var hs = {

// Apply your own settings here, or override them in the html file.  
graphicsDir : '../includes/highslide/graphics/',
restoreCursor : "zoomout.cur", // necessary for preload
fullExpandIcon : 'fullexpand.gif',
expandSteps : 10, // number of steps in zoom. Each step lasts for duration/step milliseconds.
expandDuration : 250, // milliseconds
restoreSteps : 10,
restoreDuration : 250,
numberOfImagesToPreload : 5, // set to 0 for no preload
marginLeft : 10,
marginRight : 35, // leave room for scrollbars + outline
marginTop : 10,
marginBottom : 35, // leave room for scrollbars + outline
zIndexCounter : 70001, // adjust to other absolutely positioned elements
fullExpandDelay : 500, // delay of the 'full expand'-icon
fullExpandTitle : '',
restoreTitle : '',
focusTitle : '',
loadingText : 'Loading...',
loadingTitle : '',
showCredits : false, // you can set this to false if you want
creditsText : 'Powered by <i>Highslide JS</i>',
creditsHref : 'http://vikjavev.no/highslide',
creditsTitle : 'Go to the Highslide JS homepage',

// These settings can also be overridden inline for each image
anchor : 'auto', // where the image expands from
spaceForCaption : 30, // leaves space below images with captions
outlineType : 'drop-shadow', // set null to disable outlines
wrapperClassName : null, // for enhanced css-control
// END OF YOUR SETTINGS


// declare internal properties
preloadTheseImages : new Array(),
continuePreloading: true,
expandedImagesCounter : 0,
expanders : new Array(),
mouseIsOverFullExpand : false,
isBusy : false,
container : null,
defaultRestoreCursor : null,
leftBeforeDrag : null,
topBeforeDrag : null,

// drag functionality
ie : (document.all && !window.opera),
nn6 : document.getElementById && !document.all,
hasFocused : false,
isDrag : false,
dragX : null,
dragY : null,
dragObj : null,

    

ieVersion : function () {
    arr = navigator.appVersion.split("MSIE");
    return parseFloat(arr[1]);
},

//--- Find client width and height
clientInfo : function ()	{
	var iebody = (document.compatMode && document.compatMode != "BackCompat") 
        ? document.documentElement : document.body;
    this.width = document.all ? iebody.clientWidth : self.innerWidth;
    this.height = document.all ? iebody.clientHeight : self.innerHeight;
	this.scrollLeft = document.all ? iebody.scrollLeft : pageXOffset;
	this.scrollTop = document.all ? iebody.scrollTop : pageYOffset;
} ,

//--- Finds the position of an element
position : function(el)	{ 
	var parent = el;
	this.x = parent.offsetLeft;
	this.y = parent.offsetTop;
	while (parent.offsetParent)	{
		parent = parent.offsetParent;
		this.x += parent.offsetLeft;
		this.y += parent.offsetTop;
	}
    
	return this;
}, 

//--- Expander object keeps track of all properties
expander : function() { },


//--- Do the thing
/* params can be one of: anchor, wrapperClassName, outlineType, spaceForCaption, thumbnailId */
expand : function(a, params) {
    //    if (hs.isBusy) return;
    hs.isBusy = true;
    try {
        
        hs.continuePreloading = false;
        hs.container = document.getElementById('highslide-container');
        
        if (params && params.thumbnailId) {
            var el = document.getElementById(params.thumbnailId);
        
        } else { // first img within anchor
            for (i = 0; i < a.childNodes.length; i++) {
				if (a.childNodes[i].tagName && a.childNodes[i].tagName == 'IMG') {
                    var el = a.childNodes[i];
                    break;
                }    		
            }
        }

		// cancel other instances
        for (i = 0; i < hs.expanders.length; i++) {
            if (hs.expanders[i] && hs.expanders[i].thumb != el && !hs.expanders[i].showFullImageStarted) {
                hs.cancelLoading(i);
            }
        }
		
        
        // check if already open
        for (i = 0; i < hs.expanders.length; i++) {
            if (hs.expanders[i] && hs.expanders[i].thumb == el) {
                hs.isBusy = false;
                return false;
            }
        }
        
        // initialize the new Expander object
        var key = hs.expandedImagesCounter++;
        hs.expanders[key] = new hs.expander();
        var exp = hs.expanders[key];
        exp.a = a;
		
		// override inline parameters
		var legalParams = new Array('anchor', 'outlineType', 'spaceForCaption', 'wrapperClassName');
		for (i = 0; i < legalParams.length; i++) {
			var name = legalParams[i];
			if (params && params[name]) exp[name] = params[name];
			else exp[name] = hs[name];
		}
		
        
        var imgId = 'expanded-'+ hs.expandedImagesCounter;
        exp.thumbsUserSetId = el.id;
        if (!el.id) el.id = 'hs-thumb-'+ hs.expandedImagesCounter;
        exp.thumb = el;
        
        exp.originalCursor = el.style.cursor;
        el.style.cursor = 'wait';

        var pos = hs.position(el); 
                
        // instanciate the wrapper
        var wrapper = document.createElement('div');
        wrapper.style.visibility = 'hidden';
        wrapper.style.position = 'absolute';
		if (exp.wrapperClassName) wrapper.className = exp.wrapperClassName;
        wrapper.style.zIndex = hs.zIndexCounter++;        
        exp.wrapper = wrapper;
        
        // store properties of the thumbnail
        exp.thumbWidth = el.width;
        exp.thumbHeight = el.height;
        exp.thumbLeft = pos.x;
        exp.thumbTop = pos.y;
        
        // thumb borders
        exp.thumbOffsetBorderW = (exp.thumb.offsetWidth - exp.thumbWidth) / 2;
        exp.thumbOffsetBorderH = (exp.thumb.offsetHeight - exp.thumbHeight) / 2;
		
		// loading symbol
		var loading = document.createElement('a');
		loading.style.position = 'absolute';
		loading.style.visibility = 'hidden';
		loading.className = 'highslide-loading';
        loading.title = hs.loadingTitle;
        loading.href = 'javascript:hs.cancelLoading('+ key +')'
		hs.container.appendChild(loading);
		if (hs.loadingText) loading.innerHTML = hs.loadingText;
        loading.style.left = (exp.thumbLeft + exp.thumbOffsetBorderW + (exp.thumbWidth - loading.offsetWidth) / 2) +'px';
		loading.style.top = (exp.thumbTop + (exp.thumbHeight - loading.offsetHeight) / 2) +'px';
		exp.loading = loading;
    	setTimeout("if (hs.expanders["+ key +"].loading) hs.expanders["+ key +"].loading.style.visibility = 'visible';", 100);
		
        // instanciate the full-size image
        var img = document.createElement('img');
        exp.fullImage = img;
        if (navigator.userAgent.indexOf("Safari") != -1) { // http://bugzilla.opendarwin.org/show_bug.cgi?id=3869
            img.onload = function () { 
                var safImg = new Image;
                safImg.src = this.src;
                exp.fullImage.width = safImg.width;
                exp.fullImage.height = safImg.height;
                hs.showFullImage(key); 
            }
        } else {
            img.onload = function () { hs.showFullImage(key); }
        }
        img.src = a.href;
        img.className = 'highslide-image '+ el.className;
        img.style.visibility = 'hidden' // prevent flickering in IE
        img.style.display = 'block';
		img.style.position = 'relative';
    	img.style.zIndex = 3;
		img.id = imgId;
        img.title = hs.restoreTitle;
        img.onmouseover = function () { setTimeout("hs.showFullExpand('"+ key +"')", hs.fullExpandDelay); }
        img.onmouseout = function () { setTimeout("hs.hideFullExpand('"+ key +"')", 50); }
        img.setAttribute('key', key); // used on drag

	
        return false; // important!
    
    } catch (e) {
        return true; // script failed: default href fires
    }
    
}, 

//--- Show the image after it has been preloaded
showFullImage : function(key) {
	
	try { 
	    var exp = hs.expanders[key];
	    
	    // prevent looping on certain Gecko engines:
	    if (exp.showFullImageStarted) return;
	    else exp.showFullImageStarted = true;
        
               
		// remove loading div
	    if (exp.loading) {
	        hs.container.removeChild(exp.loading);
	        exp.loading = null;
	    }    
	    
	    exp.thumb.style.cursor = exp.originalCursor;
	    
        var newWidth = exp.fullImage.width; // causes problems in Safari
	    var newHeight = exp.fullImage.height;
	    exp.fullExpandWidth = newWidth;
	    exp.fullExpandHeight = newHeight;
	    
	    exp.fullImage.width = exp.thumb.width;
	    exp.fullImage.height = exp.thumb.height;
	
	    // identify caption div
	    var modMarginBottom = hs.marginBottom;
	    var thumbsUserSetId = exp.thumbsUserSetId; // id has to be user set
	    if (thumbsUserSetId && document.getElementById('caption-for-'+ thumbsUserSetId)) {
	        var captionClone = document.getElementById('caption-for-'+ exp.thumb.id).cloneNode(true);
	        exp.caption = captionClone;
	        modMarginBottom += exp.spaceForCaption;
	    }
        
	    
	    exp.wrapper.appendChild(exp.fullImage)
	    exp.wrapper.style.left = exp.thumbLeft;
	    exp.wrapper.style.top = exp.thumbTop;
	    hs.container.appendChild(exp.wrapper);
		
		// correct for borders
	    exp.offsetBorderW = (exp.wrapper.offsetWidth - exp.thumb.width) / 2;
        exp.offsetBorderH = (exp.wrapper.offsetHeight - exp.thumb.height) / 2;
	    var modMarginRight = hs.marginRight + 2 * exp.offsetBorderW;
        modMarginBottom += 2 * exp.offsetBorderH;
	    
	    var ratio = newWidth / newHeight;
	    
	    // default (start) values
		var newLeft = parseInt(exp.thumbLeft) - exp.offsetBorderW + exp.thumbOffsetBorderW;
	    var newTop = parseInt(exp.thumbTop) - exp.offsetBorderH + exp.thumbOffsetBorderH;
	    var oldRight = newLeft + parseInt(exp.thumb.width);
	    var oldBottom = newTop + parseInt(exp.thumb.height);
	    
	    var justifyX;
	    var justifyY;
	    switch (exp.anchor) {
	    case 'auto':
	        justifyX = 'auto';
	        justifyY = 'auto';
	        break;
	    case 'top':
	        justifyX = 'auto';
	        break;
	    case 'top-right':
	        justifyX = 'right';
	        break;
	    case 'right':
	        justifyX = 'right';
	        justifyY = 'auto';
	        break;
	    case 'bottom-right':
	        justifyX = 'right';
	        justifyY = 'bottom';
	        break;
	    case 'bottom':
	        justifyX = 'auto';
	        justifyY = 'bottom';
	        break;
	    case 'bottom-left':
	        justifyY = 'bottom';
	        break;
	    case 'left':
	        justifyY = 'auto';
	        break;
	    case 'top-left':
	        break;
	    default:
	        justifyX = 'auto';
	        justifyY = 'auto';        
	    } 
	    
	    var client = new hs.clientInfo();
	    
	    
	    if (justifyX == 'auto') {
	        var hasMovedNewLeft = false;
	        // calculate newLeft
	        newLeft = Math.round(newLeft - ((newWidth - exp.thumb.width) / 2)); // as in center
	        if (newLeft < client.scrollLeft + hs.marginLeft) {
	            newLeft = client.scrollLeft + hs.marginLeft;
	            hasMovedNewLeft = true;
	        }
	        // calculate right/newWidth
	        if (newLeft + newWidth > client.scrollLeft + client.width - hs.marginLeft) {
	            if (hasMovedNewLeft) newWidth = client.width - hs.marginLeft - modMarginRight; // can't expand more
	            else if (newWidth < client.width - hs.marginLeft - modMarginRight) { // move newTop up
	                newLeft = client.scrollLeft + client.width - newWidth - hs.marginLeft - modMarginRight;
	            } else { // image larger than client
	                newLeft = client.scrollLeft + hs.marginLeft;
	                newWidth = client.width - hs.marginLeft - modMarginRight;
	            }
	        }
	    } else if (justifyX == 'right') {
	        newLeft = Math.floor(newLeft - newWidth + exp.thumb.width);
	    }
	    if (justifyY == 'auto') {
	        var hasMovedNewTop = false;
	        // calculate newTop
	        newTop = Math.round(newTop - ((newHeight - exp.thumb.height) / 2)); // as in center
	        if (newTop < client.scrollTop + hs.marginTop) {
	            newTop = client.scrollTop + hs.marginTop;
	            hasMovedNewTop = true;
	        }
	        // calculate bottom/newHeight
	        if (newTop + newHeight > client.scrollTop + client.height - hs.marginTop - modMarginBottom) {
	            if (hasMovedNewTop) newHeight = client.height - hs.marginTop - modMarginBottom; // can't expand more
	            else if (newHeight < client.height - hs.marginTop - modMarginBottom) { // move newTop up
	                newTop = client.scrollTop + client.height - newHeight - hs.marginTop - modMarginBottom;
	            } else { // image larger than client
	                newTop = client.scrollTop + hs.marginTop;
	                newHeight = client.height - hs.marginTop - modMarginBottom;
	            }
	        }
	    } else if (justifyY == 'bottom') {
	        newTop = Math.floor(newTop - newHeight + exp.thumb.height);
	    }
	    
	    // don't leave the page; better to expand right bottom
	    if (newLeft < hs.marginLeft) {
	        tmpLeft = newLeft;
	        newLeft = hs.marginLeft; 
	        newWidth = newWidth - (newLeft - tmpLeft);
	    }
	    if (newTop < hs.marginTop) {
	        tmpTop = newTop;
	        newTop = hs.marginTop;
	        newHeight = newHeight - (newTop - tmpTop);
	    }
	
	    // Correct ratio
	    if (newWidth / newHeight > ratio) { // width greater
	        var tmpWidth = newWidth;
	        newWidth = newHeight * ratio;
	        if (justifyX == 'center' || justifyX == 'auto') {
	            // recalculate newLeft
	            newLeft = Math.round(parseInt(exp.thumbLeft) 
	                - ((newWidth - exp.thumb.width) / 2));
	            if (newLeft < client.scrollLeft + hs.marginLeft) { // to the left
	                newLeft = client.scrollLeft + hs.marginLeft;
	            } else if (newLeft + newWidth > client.scrollLeft + client.width - modMarginRight) { // to the right
	                newLeft = client.scrollLeft + client.width - newWidth - modMarginRight;
	            }
	        }
	        if (justifyX == 'right') newLeft = newLeft + (tmpWidth - newWidth);
	    
	    } else if (newWidth / newHeight < ratio) { // height greater
	        var tmpHeight = newHeight;
	        newHeight = newWidth / ratio;
	        if (justifyY == 'center' || justifyY == 'auto') {
	            // recalculate newTop
	            newTop = Math.round(parseInt(exp.thumbTop) 
	                - ((newHeight - exp.thumb.height) / 2));
	            if (newTop < client.scrollTop + hs.marginTop) { // above
	                newTop = client.scrollTop + hs.marginTop;
	            } else if (newTop + newHeight > client.scrollTop + client.height - modMarginBottom) { // below
	                newTop = client.scrollTop + client.height - newHeight - modMarginBottom;
	            }
	        }
	        if (justifyY == 'bottom') newTop = newTop + (tmpHeight - newHeight);
	    }
	    
	    // Selectbox bug
        var imgPos = {x: newLeft - 20, y: newTop - 20, w: newWidth + 40, h: newHeight + 40 + exp.spaceForCaption}
        if (hs.ie) hs.showHideElements('SELECT', 'hidden', imgPos);
	    // Iframes bug
        hs.hideIframes = (window.opera || navigator.vendor == 'KDE' || (hs.ie && hs.ieVersion() < 5.5));
        if (hs.hideIframes) hs.showHideElements('IFRAME', 'hidden', imgPos);
        
	    // Apply size change
	    var width = exp.thumb.width;
	    var height = exp.thumb.height;
		var left = exp.thumbLeft + exp.thumbOffsetBorderW - exp.offsetBorderW;
	    var top = exp.thumbTop + exp.thumbOffsetBorderH - exp.offsetBorderH;
		intervalWidth = (newWidth - width) / hs.expandSteps;
		intervalHeight = (newHeight - height) / hs.expandSteps;
	    intervalLeft = (newLeft - left) / hs.expandSteps;
	    intervalTop = (newTop - top) / hs.expandSteps;
	    
	    for (i = 1; i < hs.expandSteps; i++) {
			width += intervalWidth;
			height += intervalHeight;
	        left += intervalLeft;
	        top += intervalTop;
	        if (justifyX == 'right') { // follow the edge nicely
	            width = Math.round(width);
	            left = oldRight - width;
	        }
	        if (justifyY == 'bottom') { 
	            height = Math.round(height);
	            top = oldBottom - height;
	        }
	        
			setTimeout("hs.changeSize("+ key +", "+ width +", "+ height +", "+ left +", "+ top +")", 
	            Math.round(i * (hs.expandDuration / hs.expandSteps)));
		}
	    
	    // setTimeout("hs.changeClassName("+ key +")", hs.expandDuration/2);    
		// Finally land on the right number:
		setTimeout("hs.changeSize("+ key +", "+ newWidth +", "+ newHeight +", "+ newLeft 
	        +", "+ newTop +")", hs.expandDuration);
		setTimeout("hs.focus("+ key +")", hs.expandDuration);
        if (hs.showCredits) setTimeout("hs.writeCredits("+ key +")", hs.expandDuration + 25);
	    if (exp.caption) {
	        setTimeout("hs.writeCaption("+ key +")", hs.expandDuration + 50);
	    } else {
			setTimeout( "hs.writeOutline("+ key +")", hs.expandDuration + 50);
	    }
		if (exp.fullExpandWidth > newWidth) {
	        setTimeout("hs.putFullExpand("+ key +")", hs.expandDuration + hs.fullExpandDelay);
	    }
	   
	} catch (e) {
	    if (hs.expanders[key] && hs.expanders[key].a) window.location.href = hs.expanders[key].a.href;
	}
}, 

cancelLoading : function(key) {
	var exp = hs.expanders[key];
	exp.thumb.style.cursor = exp.originalCursor;
	// remove loading div
    if (exp.loading) {
        hs.container.removeChild(exp.loading);
        exp.loading = null;
    }
        
    hs.expanders[key] = null;
},

// hide elements that show through image
showHideElements : function (tagName, visibility, imgPos) {
    var els = document.getElementsByTagName(tagName);
    if (els) {            
        for (i = 0; i < els.length; i++) {
            if (els[i].nodeName == tagName) {   
                if (visibility == 'visible') { // only on last
                    els[i].style.visibility = visibility;                
                } else {
                    var elPos = hs.position(els[i]);
                    elPos.w = els[i].offsetWidth;
                    elPos.h = els[i].offsetHeight;
                
                    var clearsX = (elPos.x + elPos.w < imgPos.x || elPos.x > imgPos.x + imgPos.w);
                    var clearsY = (elPos.y + elPos.h < imgPos.y || elPos.y > imgPos.y + imgPos.h);
                    if (!clearsX && !clearsY) { // element falls behind image
                        els[i].style.visibility = visibility;      
                    }
                }   
            }
        }
    }
},

writeCredits : function (key) {
    var exp = hs.expanders[key];
    var credits = document.createElement('a');
    credits.href = hs.creditsHref;
    credits.className = 'highslide-credits';
    credits.innerHTML = hs.creditsText;
    credits.title = hs.creditsTitle;
    credits.style.position = 'absolute';
    credits.style.zIndex = 3;
    
    if (hs.ie) { // strange bug sometimes makes values wrong in the first def.
        exp.offsetBorderW = (exp.wrapper.offsetWidth - exp.fullImage.width) / 2;
        exp.offsetBorderH = (exp.wrapper.offsetHeight - exp.fullImage.height) / 2;
	}  
    credits.style.top = exp.offsetBorderH +'px';
    credits.style.left = exp.offsetBorderW +'px';
    exp.credits = credits;
    exp.wrapper.appendChild(credits);

},

writeCaption : function(key) {
    var exp = hs.expanders[key];
    
    exp.wrapper.style.width = exp.wrapper.offsetWidth +'px';    
    exp.caption.style.visibility = 'hidden';
    exp.caption.style.position = 'relative';
    if (hs.ie) exp.caption.style.zoom = 1;  
    exp.caption.className += ' highslide-display-block'; // have to use className due to Opera
    exp.wrapper.appendChild(exp.caption);
    
    var capHeight = exp.caption.offsetHeight;
    var slideHeight = (capHeight < exp.fullImage.height) ? capHeight : exp.fullImage.height;
    exp.caption.style.marginTop = '-'+ slideHeight +'px';
    exp.caption.style.zIndex = 2;
    
    var step = 1;
    if (slideHeight > 400) step = 4;
    else if (slideHeight > 200) step = 2;
    else if (slideHeight > 100) step = 1;
    
    
    setTimeout("hs.expanders["+ key +"].caption.style.visibility = 'visible'", 10); // flickering in Gecko
	var t = 0;
    for (marginTop = - slideHeight; marginTop <= 0; marginTop += step, t += 10) {
        setTimeout ("if (hs.expanders["+ key +"] && hs.expanders["+ key +"].caption) "
            + "hs.expanders["+ key +"].caption.style.marginTop = '"+ marginTop +"px'", t);
    }
	
	setTimeout('hs.writeOutline('+ key +')', t + 10);
    
},

writeOutline : function(key) {
    if (!hs.expanders[key]) return;
    var exp = hs.expanders[key];    
    exp.outline = new Array();
    var v = hs.ieVersion();
    
    hs.hasAlphaImageLoader = (v >= 5.5) && (v < 7) && (document.body.filters);
	hs.hasPngSupport = v >= 7 || !document.body.filters;
    
    hs.preloadOutlineElement(key, 1); // start recursive process
}, 

preloadOutlineElement : function(key, i) {
    if (!hs.expanders[key]) return;
    if (!hs.hasAlphaImageLoader && !hs.hasPngSupport) return;
    
    var exp = hs.expanders[key];
    
    if (exp.outline[i] && exp.outline[i].onload) { // Gecko multiple onloads bug
        exp.outline[i].onload = null;
        return;
    }
    
    var src = hs.graphicsDir + "outlines/"+ exp.outlineType +"/"+ i +".png";
    
    if (hs.hasAlphaImageLoader) {
        
		exp.outline[i] = document.createElement('div');
	 	exp.outline[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader("
	     	+ "enabled=true, sizingMethod=scale src='"+ src + "') ";
	} 
        
	var img = document.createElement('img'); // for onload trigger
	if (hs.hasPngSupport) {
        exp.outline[i] = img;
    }
    
    // common properties
	exp.outline[i].style.position = 'absolute';
	var dim = (i % 2 == 1) ? '10px' : '20px';
	exp.outline[i].style.height = dim;
	exp.outline[i].style.width = dim;
    
    if (i < 8) img.onload = function() { hs.preloadOutlineElement(key, i + 1); };                
    else img.onload = function() { hs.displayOutline(key); };
	img.src = src;
},

displayOutline : function(key) {
    if (!hs.expanders[key]) return; // already closed
    var exp = hs.expanders[key];
    
    hs.repositionOutline(key, 12);
	for (i = 1; i <= 8; i++) {
		exp.wrapper.appendChild(exp.outline[i]);
	}
	exp.hasOutline = true;
    
    // IE6
    exp.outline[1].style.lineHeight = '10px';
    exp.outline[5].style.lineHeight = '10px';
	
	for (i = 10, t = 0; i >= 0; i--, t += 50) {
	    setTimeout("hs.repositionOutline("+ key +", "+ i +");", t);   
	}   
},

repositionOutline : function(key, offset) {
	if (!hs.expanders[key]) return;
	var exp = hs.expanders[key];
    if (exp.isClosing) {
        hs.removeOutlines(key);
        return;
    }
    
	var w = exp.wrapper.offsetWidth;
	var h = exp.wrapper.offsetHeight;

	// top
	exp.outline[1].style.width = (w - (2 * offset) - 20) +'px';
    // strange khtml bug causes glitch in outline:
	if (navigator.vendor == 'KDE') exp.outline[1].style.height = ((offset % 2) + 10) +'px';
	exp.outline[1].style.left = (10 + offset) +'px';
	exp.outline[1].style.top = (-10 + offset) + 'px';
	
	// top-right
	exp.outline[2].style.left = (w - 10 - offset) +'px';
	exp.outline[2].style.top = (-10 + offset) + 'px';
	
	// right
	exp.outline[3].style.left = (w - offset) +'px';
	exp.outline[3].style.top = (10 + offset) +'px';
	exp.outline[3].style.height = (h - (2 * offset) - 20) +'px';
	
	// bottom-right
	exp.outline[4].style.left = (w - 10 - offset) +'px';
	exp.outline[4].style.top = (h - 10 - offset) +'px';
	
	// bottom
	exp.outline[5].style.width = (w - (2 * offset) - 20) +'px';
	if (navigator.vendor == 'KDE') exp.outline[5].style.height = ((offset % 2) + 10) +'px';
	exp.outline[5].style.left = (10 + offset) +'px';
	exp.outline[5].style.top = (h - offset) + 'px';
	
	// bottom-left
	exp.outline[6].style.left = (-10 + offset) +'px';
	exp.outline[6].style.top = (h - 10 - offset) +'px';
	
	// left
	exp.outline[7].style.left = (-10 + offset) +'px';
	exp.outline[7].style.top = (10 + offset) +'px';
	exp.outline[7].style.height = (h - (2 * offset) - 20) +'px';
	
	// top-left
	exp.outline[8].style.left = (-10 + offset) +'px';
	exp.outline[8].style.top = (-10 + offset) + 'px';
	
},
removeOutlines : function(key) {
    try {
        var exp = hs.expanders[key];
	    for (i = 1; i <= 8; i++) {
		    if (exp.hasOutline && exp.outline[i]) {
	            exp.wrapper.removeChild(exp.outline[i]);
	        }
	    }
    } catch (e) {}
},
//--- Focus by click
focus : function(key) {
    var img = hs.expanders[key].fullImage;
    // image
    for (i = 0; i < hs.expanders.length; i++) {
        if (hs.expanders[i] && hs.expanders[i].fullImage.className == 'highslide-image' && i != key) {
            var blurKey = i;
            hs.expanders[i].fullImage.className += ' highslide-image-blur';
            hs.expanders[i].fullImage.title = hs.focusTitle;
            if (hs.expanders[i].caption) {
                hs.expanders[i].caption.className += ' highslide-caption-blur';
            }
        }
    }
    hs.expanders[key].wrapper.style.zIndex = hs.zIndexCounter++;
    img.className = 'highslide-image';
    if (hs.expanders[key].caption) {
        hs.expanders[key].caption.className = hs.expanders[key].caption.className.replace(' highslide-caption-blur', '');
    }
    
    img.title = hs.restoreTitle;
    
    hs.isBusy = false;
},

//--- Focus the topmost image after restore
focusTopmost : function() {
    var topZ = 0;
    var topmostKey = '';
    for (i = 0; i < hs.expanders.length; i++) {
        if (hs.expanders[i] && hs.expanders[i].fullImage.className.match('highslide-image-blur')) {
            if (hs.expanders[i].wrapper.style.zIndex && hs.expanders[i].wrapper.style.zIndex > topZ) {
                topZ = hs.expanders[i].wrapper.style.zIndex;
                topmostKey = i;
            }
        }
    }
    //alert (topmostKey);
    if (topmostKey != '') hs.focus(topmostKey);
    hs.isBusy = false;
}, 

//--- Interface for text links
closeId : function(elId) {
    for (i = 0; i < hs.expanders.length; i++) {
        if (hs.expanders[i] && hs.expanders[i].thumb.id == elId) {
            hs.restoreThumb(i);
            return;
        }
    }
},

//--- Click on large image to restore thumb size
restoreThumb : function(key) {
    if (hs.isBusy) return;
    hs.isBusy = true;
    try {
		var exp = hs.expanders[key];
        exp.isClosing = true;
    
        // remove full expand icon
        if (exp.fullExpand) {
            hs.expanders[key].fullExpand.parentNode.removeChild(exp.fullExpand);
            exp.fullExpand = null;
        }
        // remove caption div
        if (exp.caption) {
            exp.wrapper.removeChild(exp.caption);
            exp.caption = null;
        }
        // remove credits
        if (exp.credits) {
            exp.wrapper.removeChild(exp.credits);
            exp.credits = null;
        }
        hs.removeOutlines(key);
        
		hs.outlinePreloader = 0;
        exp.wrapper.style.width = null;
        
        var width = exp.fullImage.width;
        var height = exp.fullImage.height;
        var left = parseInt(exp.wrapper.style.left);
        var top = parseInt(exp.wrapper.style.top);
	    intervalWidth = (exp.thumbWidth - width) / hs.restoreSteps;
	    intervalHeight = (exp.thumbHeight - height) / hs.restoreSteps;
        intervalLeft = (exp.thumbLeft + exp.thumbOffsetBorderW - exp.offsetBorderW - left) / hs.restoreSteps;
        intervalTop = (exp.thumbTop + exp.thumbOffsetBorderH - exp.offsetBorderH - top) / hs.restoreSteps;
        
        var oldRight = Math.round(left + width);
        var oldBottom = Math.round(top + height);        
	    
        for (i = 1; i < hs.restoreSteps; i++) {
		    width += intervalWidth;
		    height += intervalHeight;
            left += intervalLeft;
            top += intervalTop;
            
		    setTimeout("hs.changeSize("+ key +", "+ width +", "+ height +", "+ left +", "+ top +")", 
                Math.round(i * (hs.restoreDuration / hs.restoreSteps)));
	    }
        setTimeout('hs.endRestore('+ key +')', hs.restoreDuration);
    
    } catch (e) {
        hs.expanders[key].thumb.style.visibility = 'visible';
        hs.expanders[key].wrapper.parentNode.removeChild(hs.expanders[key].wrapper);
    }
},

endRestore : function (key) {
    var exp = hs.expanders[key];
    exp.thumb.style.visibility = 'visible';
    exp.fullImage.style.visibility = 'hidden';
    
    if (hs.hideIframes || hs.ie) {
        var remaining = -1;
        for (i = 0; i < hs.expanders.length; i++) {
            if (hs.expanders[i]) remaining++;
        }
        if (remaining <= 0) {
            if (hs.ie) hs.showHideElements('SELECT', 'visible');
	        if (hs.hideIframes) hs.showHideElements('IFRAME', 'visible');           
        }
    }
    
    exp.wrapper.parentNode.removeChild(exp.wrapper);
    
    hs.expanders[key] = null;
    
    
    if (hs.toggleImagesExpandEl) { // see below
        hs.expand(hs.toggleImagesExpandEl, hs.toggleImagesParams);
        hs.toggleImagesExpandEl = null;
        hs.toggleImagesParams = null;
    } else {
        hs.focusTopmost();
    }
},

//--- Function for next and previous links
toggleImages : function(closeId, expandEl, params) {
    hs.closeId(closeId);
    if (hs.ie) expandEl.href = expandEl.href.replace('about:blank', ''); // mysterious IE thing
    hs.toggleImagesExpandEl = expandEl;
    hs.toggleImagesParams = params;
    return false;
},


//--- Do the stepwise change
changeSize : function (key, newWidth, newHeight, newLeft, newTop) {
    try {
        var exp = hs.expanders[key];
    
        exp.fullImage.width = newWidth;
        exp.fullImage.height = newHeight;
        exp.wrapper.style.visibility = 'visible';
        exp.wrapper.style.left = newLeft +'px';
        exp.wrapper.style.top = newTop +'px';
        exp.fullImage.style.visibility = 'visible';
        exp.thumb.style.visibility = 'hidden';
        
    } catch (e) {
        window.location.href = hs.expanders[key].a.href;
    }
},

//--- Icon for full expand 
putFullExpand : function (key) {
    if (hs.isBusy) return;
    
    if (!hs.expanders[key]) {
        return;
    }
    
    var href = hs.expanders[key].fullImage.src;
    var thisKey = key;
    
    // the anchor
    
    var aFullExpand = document.createElement('a');
    aFullExpand.id = 'fullexpand-'+ hs.expanders[key].fullImage.id;
    aFullExpand.style.position = 'absolute';
    aFullExpand.style.left = (hs.expanders[key].fullImage.width - 55) +'px';
    aFullExpand.style.top = (hs.expanders[key].fullImage.height - 55) +'px';
    aFullExpand.style.zIndex = 3;
    aFullExpand.href = 'javascript:hs.fullExpand('+ key +');';
    aFullExpand.title = hs.fullExpandTitle;
    aFullExpand.onmouseover = function () { hs.mouseIsOverFullExpand = true; }
    aFullExpand.onmouseout = function () { hs.mouseIsOverFullExpand = false; }
    
    // the image
    var imgFullExpand = document.createElement('img');
    imgFullExpand.src = hs.graphicsDir + hs.fullExpandIcon;
    imgFullExpand.style.border = '0';
    imgFullExpand.style.display = 'block';
    aFullExpand.appendChild(imgFullExpand);
    
    hs.expanders[key].wrapper.appendChild(aFullExpand);
    hs.expanders[key].fullExpand = aFullExpand;
},

fullExpand : function (key) {
    try {
        var exp = hs.expanders[key];
        
        var newLeft = parseInt(exp.wrapper.style.left) - (exp.fullExpandWidth - exp.fullImage.width) / 2;
        if (newLeft < hs.marginLeft) newLeft = hs.marginLeft;
        exp.wrapper.style.left = newLeft +'px';
		
		var borderOffset = exp.wrapper.offsetWidth - exp.fullImage.width;
        
        exp.fullImage.width = exp.fullExpandWidth;
        exp.fullImage.height = exp.fullExpandHeight;
        hs.focus(key);
        
        exp.fullExpand.className = 'highslide-display-none';
        
        hs.mouseIsOverFullExpand = false;
        
        exp.wrapper.style.width = (exp.fullImage.width + borderOffset) +'px';
        
        if (hs.outlineType) hs.repositionOutline(key, 0);
        
        hs.onEndMove(key);
    
    } catch (e) {
        window.location.href = hs.expanders[key].fullImage.src;
    }
},

showFullExpand : function (key) {
    if (hs.expanders[key] && hs.expanders[key].fullExpand) {
        hs.expanders[key].fullExpand.style.visibility = 'visible';
    }
},

hideFullExpand : function(key) {
    if (hs.expanders[key] && hs.expanders[key].fullExpand && !hs.mouseIsOverFullExpand) {
        hs.expanders[key].fullExpand.style.visibility = 'hidden';
    }
},

//--- Preload a number of images recursively
preloadFullImage : function (i) {
    if (hs.continuePreloading && hs.preloadTheseImages[i] && hs.preloadTheseImages[i] != 'undefined') {
        var img = document.createElement('img');
        img.onload = function() { hs.preloadFullImage(i + 1); }
        img.src = hs.preloadTheseImages[i];
    }
},

mouseMoveHandler : function(e)
{
  if (hs.isDrag)
  {
    var key = hs.dragObj.getAttribute('key');
    if (!hs.expanders[key].wrapper) return;
    var wrapper = hs.expanders[key].wrapper;
    
    var left = hs.nn6 ? tx + e.clientX - hs.dragX : tx + event.clientX - hs.dragX;
    wrapper.style.left = left +'px';
    var top = hs.nn6 ? ty + e.clientY - hs.dragY : ty + event.clientY - hs.dragY;
    wrapper.style.top  = top +'px';
    
    return false;
  }
}, 

mouseDownHandler : function(e) 
{

  var fobj       = hs.nn6 ? e.target : event.srcElement;
  var topelement = hs.nn6 ? "HTML" : "BODY";
  
  while (fobj.tagName != topelement && fobj.tagName != 'HTML' && !fobj.className.match('highslide-image'))
  {
    fobj = hs.nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className.match('highslide-image'))
  {
    hs.isDrag = true;
    hs.dragObj = fobj;
    var tmpCursor = hs.dragObj.style.cursor;
    hs.defaultRestoreCursor = tmpCursor;
    hs.dragObj.style.cursor = 'move';
    tx = parseInt(hs.dragObj.parentNode.style.left);
    ty = parseInt(hs.dragObj.parentNode.style.top);
    
    hs.leftBeforeDrag = tx;
    hs.topBeforeDrag = ty;
    
    hs.dragX = hs.nn6 ? e.clientX : event.clientX;
    hs.dragY = hs.nn6 ? e.clientY : event.clientY;
    document.onmousemove = hs.mouseMoveHandler;
    
    if (fobj.className.match('highslide-image-blur')) {
        hs.focus(fobj.getAttribute('key'));
        hs.hasFocused = true;
    }
    return false;
  }
},

mouseUpHandler : function(e) {
    hs.isDrag = false;
    var fobj       = hs.nn6 ? e.target : event.srcElement;
    var topelement = hs.nn6 ? "HTML" : "BODY";

    while (fobj.tagName != topelement && fobj.tagName != 'HTML' && !fobj.className.match('highslide-image'))
    {
        fobj = hs.nn6 ? fobj.parentNode : fobj.parentElement;
    }
    if (fobj.className == 'highslide-image') {
        fobj.style.cursor = hs.defaultRestoreCursor;
        //if (hasDragged) hasDragged = false;
        var left = parseInt(fobj.parentNode.style.left);
        var top = parseInt(fobj.parentNode.style.top);
        if (left == hs.leftBeforeDrag && top == hs.topBeforeDrag && !hs.hasFocused) {
            hs.restoreThumb(fobj.getAttribute('key'));
        } else if (!hs.hasFocused) {
            hs.onEndMove(fobj.getAttribute('key'));
        }
        hs.hasFocused = false;
    
    } else if (fobj.className.match('highslide-image-blur')) {
        fobj.style.cursor = hs.defaultRestoreCursor;
        
    }
},
// on end move and end resize
onEndMove : function(key) {
    var exp = hs.expanders[key];
    // Selectbox bug
    var imgPos = {
        x: parseInt(exp.wrapper.style.left) - 20, 
        y: parseInt(exp.wrapper.style.top) - 20, 
        w: exp.fullImage.width + 40, 
        h: exp.fullImage.height + 40 + exp.spaceForCaption
    }        
    if (hs.ie) hs.showHideElements('SELECT', 'hidden', imgPos);
	// Iframes bug
    if (hs.hideIframes) hs.showHideElements('IFRAME', 'hidden', imgPos);        
},

preloadImages : function () {
    
    var j = 0;
    
    var aTags = document.getElementsByTagName('A');
    for (i = 0; i < aTags.length; i++) {
        a = aTags[i];
        if (a.className && (a.className.match("highslide$") || a.className.match("highslide "))) {
            if (j < this.numberOfImagesToPreload) {
                hs.preloadTheseImages[j] = a.href;
                j++;
            }
        }
    }
    
    hs.preloadFullImage(0); // starts recursive process
    
    // preload cursor
    var cur = document.createElement('img');
    cur.src = hs.graphicsDir + hs.restoreCursor;
    
    // preload outlines
    for (i = 1; i <= 8; i++) {
        var img = document.createElement('img');
        img.src = hs.graphicsDir + "outlines/"+ hs.outlineType +"/"+ i +".png";
    }
    
}
} // end hs object

// set handlers
document.onmousedown = hs.mouseDownHandler;
document.onmouseup = hs.mouseUpHandler;

