var _maxLoop=0;

var listener = {
	'events' : {},
	'num' :0,
	'addListen' : function() {
		listener.num++;
		var id=listener.num++;;
		listener.events[id] = [];
		return id;
	},
	'addHandle' : function(id, ob) {
		if (!listener.events[id]) listener.events[id]=[];
		listener.events[id][listener.events[id].length] = ob;
	},
	'callEvent' : function(id, tp, ob, origOb) {
	  if (!listener.events[id]) return false;
		var i=listener.events[id].length;
		while(i--) {
			listener.events[id][i].listener(id, tp, ob, origOb);
		}
		i=null;
	},
	'remListen' : function(id) {
		delete listener.events[id];
	},
	'remHandle' : function(id, ob) {
		var i=listener.events[id].length;
		while(i--) {
			if (listener.events[id][i] == ob) {
				listener.events[id].splice(i, 1);
				break;
			}
		}
	},
	'getsrc' : function(e) {
		if (!e) e=window.event;
		var ob=(e.srcElement) ? e.srcElement : e.target;
		if (ob) {
			while(!ob.id) {
				ob=ob.parentNode;
				if(ob.nodeType != 1) break;
			}
		}
		return ob;
	},
	'onclick' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onclick", this, listener.getsrc(e));
		}
	},
	'onfocus' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onfocus", this, listener.getsrc(e));
		}
	},
	'onblur' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onblur", this, listener.getsrc(e));
		}
	},
	'onmouseover' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onmouseover", this, listener.getsrc(e));
		}
	},
	'onmouseout' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onmouseout", this, listener.getsrc(e));
		}
	},
	'onmousedown' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onmousedown", this, listener.getsrc(e));
		}
	},
	'onmouseup' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onmouseup", this, listener.getsrc(e));
		}
	},
	'onmousemove' : function(e) {
		if (listener.events[this.id]) {
			listener.callEvent(this.id, "onmousemove", this, listener.getsrc(e));
		}
	},
	'onchange' : function(e) {
		if (listener.events[ob.id]) {
			listener.callEvent(this.id, "onchange", this, listener.getsrc(e));
		}
	}
}


function effects(el, speed, dir, max) {
	  this.el=el;
	  this.speed=speed;
	  this.dir=dir;
	  this.max=max;
	  this.cancel;
	  this.listenid;
	  this.finalHandle;
	  this.timeoutid;
	  //register listener for closing handle
	  this.listenid=listener.addListen();
	}

	effects.prototype.fin = function() {
		listener.callEvent(this.listenid);
		listener.remListen(this.listenid);
	}
	
	effects.prototype.cancelEffect = function() {
		clearTimeout(this.timeoutid);
		this.cancel=true;
		this.fin();
	}

	effects.prototype.slide_horiz = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		//need to know starting point, end point, speed and direction
		var n=parseInt(_self.el.style.left);
		if (isNaN(n)) return false;
		n+=1 * _self.dir;
		_self.el.style.left=n + "px";
		if((_self.dir < 0 && n >_self.max) || (_self.dir > 0 &&  n < _self.max)) {
		  this.timeoutid=set.timeoutWithScope(_self, _self.slide_horiz, _self.speed);
		} else {
			_self.fin();
		}
		n=_self=null;
	}

	effects.prototype.slide_vert = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		var n=parseInt(_self.el.style.top);
		if (isNaN(n)) return false;
		n+=1 * _self.dir;
		_self.el.style.top=n + "px";
		if ((_self.dir < 0 && n >_self.max) || (_self.dir > 0 && n < _self.max)) {
			this.timeoutid=set.timeoutWithScope(_self, _self.slide_vert, _self.speed);
		} else {
			_self.fin();
		}
		n=null;
	}

	effects.prototype.scroll_vert = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		y = parseInt(_self.el.style.height);
		y += 1 * _self;
		_self.el.style.minHeight= y + "px";
	    if (y != _self.max) {
			this.timeoutid=set.timeoutWithScope(_self, _self.scroll_in_vert, _self.speed);
		} else {
			_self.fin();
		}
		y=null;
	}

	effects.prototype.scroll_horiz = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		x=parseInt(_self.el.style.width);
		x+=1 * _self.dir;
		_self.el.style.width = x + "px";
	    if (x != _self.max) {
			this.timeoutid=set.timeoutWithScope(_self, _self.scroll_in_horiz, _self.speed);
		} else {
			_self.fin();
		}
		x=null;
	}

	effects.prototype.scroll_out = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		x=parseInt(this.el.style.width);
		y = parseInt(this.el.style.height);
		this.el.style.overflow="hidden";
		if (x >0) x--;
		if (y>0) y--;
		this.el.style.width = x + "px";
		this.el.style.minHeight= y + "px";
		if (x > 0 || y > 0) {
			var _self=this;
			this.timeoutid=set.timeoutWithScope(_self, _self.scroll_out, _self.speed);
		    _self=null;
		}  else {
			_self.fin();
		}
	}

	effects.prototype.fade_in = function(_self){
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		var n=parseFloat(_self.el.style.opacity);
		if (isNaN(n)) n=0;
		else n += 0.01;
		_self.el.style.opacity=n;
		_self.el.style.filter="alpha(opacity='" + (n * 100) + "')";
		if (n < 1) {
			this.timeoutid=set.timeoutWithScope(_self, _self.fade_in, _self.speed);
		} else {
			_self.fin();
		}
	}

	effects.prototype.fade_out = function(_self) {
		_self=!_self?this:_self;
		if (_self.cancel) {
			_self.fin();
			return false;
		}
		var n=parseFloat(_self.el.style.opacity);
		if (isNaN(n)) n=1;
		else n = n - 0.01;
		_self.el.style.opacity=n;
		_self.el.style.filter="alpha(opacity='" + (n * 100) + "')";
		if (n > 0) {
			this.timeoutid=set.timeoutWithScope(_self, _self.fade_out, _self.speed);
		} else {
			_self.fin();
		}
	}

effects.prototype.changeClass = function(origClass, newClass, like) {
	var cls=this.el.className?this.el.className.split(" "):[];
	var i=cls.length;
	var c=false;
	while(i--) {
		if ((like && cls[i].indexOf(origClass) > -1) || (!like && cls[i] == origClass)) {
			cls[i] = newClass;
			c=true;
			if (!like) break;
		}
	}
	if (!c) cls[cls.length] = newClass;
	var i=cls.length;
	while(i--) {
		if (!cls[i]) cls.splice(i, 1);
	}
	this.el.className=cls.join(" ");
}


function checkVal(res) {
  if (res.textContent) return res.textContent;
  else if (res.text) return res.text;
  else if (res.nodeValue) return res.nodeValue
  else if (res.firstChild) return res.firstChild.nodeValue;
  else return "";
}

function showHide(id, linkid, tp) {
	this.id=id;
	this.linkid=linkid;
	this.tp = tp;
    this.on=false;
}

showHide.prototype.hideLink = function() {
	if (this.tp == "show") return false;
	set.shDiv(this.linkid, false);
    this.on=false;
}

showHide.prototype.showLink = function() {
	if (this.tp=="hide") return false;
	set.shDiv(this.linkid, true);
    this.on=true;
}

showHide.prototype.listener = function() {
	if (this.tp=="show") this.showLink();
	else if (this.tp=="hide") this.hideLink();
	else {
	 if (this.on) this.hideLink();
	 else this.showLink();
	} 
}

var shows = {
	'obs' : {},
	'reg' : function(id, linkid, tp) {
		shows.obs[id] = new showHide(id, linkid, tp);
		hands.reg(id, "onclick", shows.obs[id]);
		_loadOb.shows = shows.hide;
	},
	'hide' : function() {
		for (var i in shows.obs) {
			shows.obs[i].hideLink();
		}
	}
}


var set = {
	'lpId' : function(id) {
          var lp="";
	   if (id.indexOf("_loop") > -1) {
		var ids=id.split("_loop");
		lp = "_loop" + ids.pop();
		id=ids.join("_loop");
	   }
	   return [id,lp];
	},		
	'cCase' : function(key, type) {
		type = type || "-";
		var finkey="",keys;
		keys = key.split(type);
		for (var i=0,l=keys.length; i<l; i++) {
			if (finkey=="") finkey = keys[i];
			else {
				finkey+=keys[i].charAt(0).toUpperCase() + keys[i].substring(1,keys[i].length);
			}
		}
		type=keys=key=null;
		return finkey;
	},
	//? Please comment this functions, is this copying from the hidden to actual text editor?
	'copyOb' : function (cob) {
	   var ob={};
		for (var i in cob) {
		    if (cob[i] === null || typeof cob[i] === "undefined") ob[i] = null;
		    else if (typeof cob[i] === "string") ob[i] = cob[i];
		    else if (typeof cob[i].length != "undefined") ob[i]=set.copyArr(cob[i]);
			else if (typeof cob[i] === "object") ob[i]=set.copyOb(cob[i]);
			else ob[i]=cob[i];
		}
	  return ob;
	},
	'copyArr' : function(cob) {
		var ob=[];
		for (var i=0,n=cob.length; i<n; i++) {
		    if (cob[i] === null || typeof cob[i] === "undefined") ob[i]=null;
		    else if (typeof cob[i] == "string") ob[i] = cob[i];
		    else if (typeof cob[i].length != "undefined") ob[i]=set.copyArr(cob[i]);
			else if (typeof cob[i] === "object") ob[i]=set.copyOb(cob[i]);
			else ob[i]=cob[i];
		}
	  return ob;	
	},
	'compStyle' : function(el, style) {
	   if (!el || !el.style) return "";
	   else if (el.style[set.cCase(style)]) return el.style[set.cCase(style)];
	   else if (document.defaultView) return document.defaultView.getComputedStyle(el, null).getPropertyValue(style);
	   else if( window.getComputedStyle ) return window.getComputedStyle(el,null)[style];
	   else if( el.currentStyle ) return el.currentStyle[set.cCase(style)];
	},
	'compOb' : function(ob1, ob2, ign) {
	   var aS=true,cp={},x,i;
	   if (!ob2) return false;
   		for(var x in ob1) {
   		  if (x==="id" || x===ign || !ob1[x]) continue;
   		   if (typeof ob1[x] == "object" && typeof ob1[x].length !== "undefined") aS=set.compArr(ob1[x], ob2[x]);
		   else if (typeof ob1[x] == "object") aS=set.compOb(ob1[x], ob2[x]);
		   else aS=(ob1[x]==ob2[x])?true:false;
		   cp[x]=true;
		 if (!aS) return false;
		}
		for (var i in ob2) {
		  if (i=="id" || i==ign) continue;
		  if (!cp[i]) {
			  aS=cp=x=i=ob1=ob2=ign=null;
			  return false;
		  }
		}
		aS=cp=x=i=ob1=ob2=ign=null;
      return true;
	},
	'compArr' : function(arr1, arr2) {
	  var aS=true;
	  for (var i=0,n=arr1.length; i<n; i++) {
	    if (typeof ob1[x] !== "string" && ob1[x].length) aS=set.compArr(arr1[i], arr2[i]);
		else if (typeof arr1[i] ==="object") aS=set.compOb(arr1[i], arr2[i]);
		else aS = arr1[i] == arr2[i];
		if (!aS) {
		  break;
		}  
	  }
	  i=arr1=arr2=null;
	  return aS;	
	},
	'scrSize' : function() {
	  var sWid,sHe;
	  if( typeof(window.innerWidth) === 'number' ) {
       sWid = window.innerWidth;
       sHe = window.innerHeight;
      } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
       sWid  = document.documentElement.clientWidth;
       sHe = document.documentElement.clientHeight;
     } else if(document.body && (document.body.clientWidth || document.body.clientHeight )) {
      sWid  = document.body.clientWidth;
      sHe = document.body.clientHeight;
     }
     return[sWid,sHe];
	},
	'stopBub' : function(e) {
	   if (!e) var e = window.event; e.cancelBubble=true;if(e.stopPropagation)e.stopPropagation();return e;
	},
	'remEl' : function(id) {
		var el = document.getElementById(id);
		if (el) el.parentNode.removeChild(el);
		el=id=null;
	},
	'offset' : function(el, lessPar) {
	  if (!el) return false;
		var wid = el.offsetWidth;
		var height=el.offsetHeight;
		var top=left=ptop=pleft=x=0;
		do {
		  if (x > 0) {
			ptop+=el.offsetTop;
			pleft+=el.offsetLeft;
		  }
		  x++
		  left += el.offsetLeft;
		  top += el.offsetTop;
		} while (el=el.offsetParent);
	  if (lessPar) {
		left= left - pleft;
		top = top - ptop;
	  }
	  pleft=ptop=null;
 	  return [top, left, wid, height];
	},
	'shDiv' : function(id, type) {
	  var el=(typeof id == "string") ? document.getElementById(id) : id;
	  if (el) {
		if (type) {
			el.style.visibility="visible";
			el.style.display="block";
		} else {
			el.style.visibility="hidden";
			el.style.display="none";
		}
	     el=null;
	     return true;
	  } else return false;
	},
	'timeoutWithScope' : function(ob, func, delay, params) {
	  var id;
	  if (typeof func !== "function") {
	  }else id=setTimeout(function() {func(ob);}, delay);
	  return id;
	}
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };



function Ajax() {
  this.req = null;
  this.url = null;
  this.method = 'GET';
  this.async = true;
  this.status = null;
  this.statusText = '';
  this.postData = null;
  this.readyState = null;
  this.responseText = null;
  this.responseXML = null;
  this.handleResp = null;
  this.responseFormat = 'text', // 'text', 'xml' or object
  this.innerID = null;
  this.logout = null;
  this.tries=0;
  this.maxtries=2;
}

Ajax.prototype.init = function() {
    if (!this.req) {
       try {
         //Try to create object for firefox / safari etc
         this.req = new XMLHttpRequest();
        }
        catch (e) {
         try {
           //try to create object for later versions of IE
           this.req = new ActiveXObject("MSXML2.XMLHTTP");
         }
         catch(e) {
            try {
             //try to create object for earlier versions of IE
             this.req = new ActiveObject('Microsoft.XMLHTTP');
          } catch (e) {
            //could not create the object so return false
            return false;
         }
       }
    }
  }
  return this.req;
}

Ajax.prototype.doReq = function() {
  if (!this.init()) {
    alert("Could not create XMLHttp Object");
    return;
  }
 this.req.open(this.method, this.url, this.async);
  if (this.method == "POST") {
    this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this.req.setRequestHeader("Content-length", this.postData.length);
    this.req.setRequestHeader("Connection", "close");
  }
  var self = this;
  this.req.onreadystatechange = function() {
    var resp;
    if (self.req.readyState == 4) {
        switch(self.responseFormat) {
            case 'text':
                resp = self.req.responseText;
                break;
            case 'xml':
                resp = self.req.responseXML;
                break;
            case 'object':
                resp = req;
                break;
       }
        if (self.req.status >= 200 && self.req.status <= 299) {
            //find out what status resp is
            if (self.logout) {
               if (self.responseFormat=="xml") {
				var tgs = resp.getElementsByTagName("_logout_");
				 if (tgs.length > 1) {
					tgs=null;
					href.location = self.logout;
				 } 
			   } else if (resp.indexOf("_logout_=true ") > -1) {
				href.location=self.logout;
			   }
			  return false;  
	      }	   
	  if (self.innerID) {
	    document.getElementById(self.innerID).innerHTML = resp;
	  } 
	  if (typeof self.handleResp === 'function') self.handleResp(resp);
	  else if (self.handleResp==="alert") alert(resp);
     } else self.handleErr(resp);
    }
    resp=null;
  };
  try {
    this.req.send(this.postData);
    } catch (e) {
    }
    resp=null;
}

Ajax.prototype.handleErr = function(str) {
  if (this.tries < this.maxtries) {
	this.tries++;
	this.abort();
	this.doReq();
 } else {
    alert ('An error has occured, Status code: ' + this.req.status + '\n Status description: ' + this.req.statusText + ' URL: ' + this.url);
  }
}

Ajax.prototype.abort = function() {
  if (this.req) {
    this.req.onreadystatechange = function () {};
    this.req.abort();
    this.req = null;
  }
}

Ajax.prototype.doGet = function(url, hand, format, innerID, logout) {
  this.url=url;
  this.handleResp=hand;
  this.innerID=innerID;
  this.logout=logout;
  this.responseFormat = format || 'text';
  this.doReq();
}


var hands = {
	'st' : [],
	'setHd' : function(el, ob, set) {
	  if (set) {
		  listener.addHandle(el.id, ob.ob, ob.type);
		  el[ob.type] = listener[ob.type];
		} else el[ob.type] = null;
		if (ob.type==="onclick") el.style.cursor="pointer";
	  el=ob=set=null;
	},
	'set' : function(set) {
	  var iob, el, y;
	  var i=hands.st.length;
	  while(i--) {
		iob=hands.st[i];
		el=document.getElementById(iob.id);
		if (el) hands.setHd(el, iob, set);
	  }
	  scrl.loadOb();
	  iob=el=y=null;	
	},
	'reg' : function(id, type, ob) {
	   if (typeof ob === "function") {
		   var f=ob;
		   ob = new handOb(id, f);
		   f=null;
	   }
	   hands.st[hands.st.length] = {'id':id,'type':type,'ob':ob};
	},
	'dynamic_reg' : function(id, type, ob, el, loop) {
		   var ob = {'id':id,'type':type,'ob':ob,'loop':loop};
		   hands.setHd(el, ob, true);
		   var nm=hands.st.length;
		   hands.st[nm] = ob;
		   ob=null;
		   return nm;
	},
	'listener' : function(id, tp, origOb) {
		if (hands.rgs[id]) hands.rgs[id]();
	}
}

function handOb(id, func) {
	this.id=id;
	this.func=func;
}

handOb.prototype.listener = function() {
	this.func();
}

var win = {
   'wins' : {},
	'open' : function() {
	  var ob=win.wins[this.id];
		window.open(ob.src, "view_photo", "toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=" + b.width + ",height=" + ob.height + ",top=100,left=50");
		ob=null;
    return false;
	},
	'reg' : function(id, src, width, height) {
		win.wins[id] = {'src':src,'width':width,'height':height};
	},
	'popOver' : function(id) {
	  var id = (typeof id === "string") ? id : this.id;
      var ob=win.wins[id];
	  win.closePopOver();
	  var dv = document.createElement("div");
	 dv.setAttribute("id", "popover");
	 dv.onclick=win.closePopOver;
	 dv.style.cssText="width:100%;height:100%;position:fixed;margin:0px;padding:0px;top:0px;left:0px;background-image:url(/img/grey_popup_fade.png);background-repeat:repeat;z-index:6000;";
    var href= (ob.src.indexOf("?") > -1) ? ob.src + "&popover=true" : ob.src + "?popover=true";
	dv.innerHTML="<iframe id='popovercontent' src='" + href + "' FRAMEBORDER=0 style='position:absolute;margin:0px;padding:0px;top:10px;left:0px;border:0px;visibility:hidden;'></iframe></div>";
	document.body.appendChild(dv);
	dv=null;
	return false;
  },
  'resizePop' : function() {
    var arr=set.scrSize();
    var wid=0,he=0,l=0,t=0;
    var ob=document.getElementById("popovercontent");
  	if (!ob) return false;
  	var sWid=arr[0],sHe=arr[1];
	var bd=(ob.contentWindow) ?ob.contentWindow.document.body : ob.contentDocument.body;
	var tgs=bd.getElementsByTagName("*");
	var i=tgs.length;
	var he=0,wid=0;
	var off=set.offset(bd);
	he=off[0] + off[3];
	wid=off[1] + off[2];
	while(i--) {
		off=set.offset(tgs[i]);
		if (off[0] + off[3] > he) he=off[0] + off[3];
		if (off[1] + off[2] > wid) wid=off[1] + off[2];
	}
	var sc=false;
  	if (he > (arr[1] * 0.9)) {
	    he = arr[1] * 0.9;
	    sc=true;
	}
	if(sc) {
  	  var bdwid=bd.clientWidth;
  	  bd.style.overflow="scroll";
  	  bdwid -= bd.clientWidth;
  	  if (!bdwid) bdwid = bd.offsetWidth - bd.clientWidth;
  	  bd.style.overflow='auto';
  	  if (bdwid + wid < sWid * 0.9) wid += bdwid;
  	}
  	bd=null;
  	ob.style.left=((sWid / 2) - (wid / 2)) + "px";
    ob.style.top=((sHe / 2) - (he / 2)) + "px";
    ob.style.width=(wid + 3) + "px";
    ob.style.height=(he + 3) +  "px";
    ob.style.visibility="visible";
    sHe=sWid=ob=wid=he=l=t=null;
  },
  'closePopOver' : function() {
     var ob=document.getElementById("popover");
     if (ob) {
    	 ob.onclick=null;
    	 document.body.removeChild(ob);
     }
     ob=null;
   },
   'setZero' : function() {
    var bd;
    for (var i=0,n=document.body.childNodes.length; i<n; i++) {
    bd=document.body.childNodes[i];
    if (bd.nodeType==1 && bd.nodeName.toLowerCase() == "div") {
      bd.style.top="0px";
      bd.style.left="0px";
      break;
    }
  }
  bd=null;
  }

}

function popOver(ob) {
 	win.reg(ob.id, ob.href);
	win.popOver(ob.id);
	ob=null;
	return false;
}

function closePopOver() {
	win.closePopOver();
}

function dropEl(elid, dropelid, effect, align, level, delay, direction, fade, fadespeed) {
	this.elid=elid;
	this.dropelid=dropelid;
	this.effect=effect;
	this.el;
	this.dropel;
	this.status=0;
	this.align=align;
	this.level=level;
	this.delay=delay;
	this.direction=direction;
	this.fade=fade;
	this.fadespeed=fadespeed;
	this.lastmod;
}

dropEl.prototype.loadDrop = function() {
	set.shDiv(this.dropel, true);
    if (this.align) {
         //get the offset of the parent and then the child node
         var off=set.offset(this.el);
         this.dropel.style.left = (off[1] + this.align[0]) + "px";
         this.dropel.style.top = (off[0] + this.align[1]) + "px";
         off=null;
    }
    this.status=1;
}

dropEl.prototype.unloadDrop = function() {
	set.shDiv(this.dropel, false);
	this.status=0;
	this.dropel.onmousemove=null;
}

dropEl.prototype.checkTime = function(_self) {
   if (_self.status==2) { 
	  if (new Date().getTime() - _self.statuschanged > _self.delay) {
		  _self.unloadDrop();
		  _self.status=0;
	  } else set.timeoutWithScope(_self, _self.checkTime, 100);
   }
}

dropEl.prototype.startClose = function() {
	this.status=2;
	this.statuschanged = new Date().getTime();
	set.timeoutWithScope(this, this.checkTime, 200);
}

dropEl.prototype.startOpen = function() {
	this.status=1;
	if (!this.el) {
	    this.el=document.getElementById(this.elid);
		this.dropel=document.getElementById(this.dropelid);
	}
	var eff;
	if (this.effect=="fade") {
	  this.dropel.style.opacity="0px";
	  eff = new effects(this.dropel, this.speed, 1, 1);
      eff.fade_in();
	} else if (this.effect=="scroll_down") {
	  set.shDiv(this.el, true);
	  var he=this.dropel.offsetHeight;
	  this.dropel.style.height="0px";
	  eff=new effects(this.dropel, this.speed, he);
	  eff.scroll_down();
	  he=null;
	} else if (this.effect=="scroll_right") {
	  set.shDiv(this.dropel, true);
	  var wid=this.dropel.offsetWidth;
	  this.dropel.style.width="0px";
	  eff=new effects(this.dropel, this.speed, wid);
	  eff.scroll_right();
	  wid=null;
	} else {
		set.shDiv(this.dropel, true);
	}
	eff=null;
	this.statuschanged=new Date().getTime();
	this.loadDrop();
}

dropEl.prototype.resetStatus = function() {
	this.status=1;
}

dropEl.prototype.listener = function(id, typ) {
	if (id.indexOf("dropdown") > -1) {
		if (typ=="onmouseover") this.resetStatus();
		else if (typ=="onmouseout") this.startClose();
	} else {
		if (typ=="onmouseover") this.startOpen();
		else if (typ==="onmouseout") this.startClose();
	}
}

var drop = {
  'drops' : {},
  'regDrop' : function(id, type, level, delay, align, direction, fade, fadespeed) {
   if (!delay) delay=0;
	var ob = new dropEl(id, id + '_dropdown', align, level, delay, direction, fade, fadespeed);
	hands.reg(id, "onmouseover", ob);
	hands.reg(id, "onmouseout", ob);
	hands.reg(id + "_dropdown", "onmouseover", ob);
	hands.reg(id + "_dropdown", "onmouseout", ob);
	drop.drops[id] = ob;
  }
}

function obState(id, normalSrc, hoverSrc, activeSrc, visitedSrc) {
	this.id=id;
	this.normalSrc=normalSrc;
	this.hoverSrc=hoverSrc;
	this.activeSrc=activeSrc;
	this.visitedSrc=visitedSrc;
	this.activeState;
	this.visitedState;
}

obState.prototype.active = function(ob) {
	this.activeState=true;
	if (!ob) ob=document.getElementById(this.id);
	if (this.activeSrc) ob.src=this.activeSrc;
	else {
	 var cls=ob.className;
	 if (cls) {
		cls=cls.trim();
		var cls=cls.split(" ");
		cls=cls[0];
		ob.className = cls + " " + cls + "_active";
	 }
	 cls=null;
	}
	ob=null;
}

obState.prototype.hover = function(ob) {
	if (!ob) ob=document.getElementById(this.id);
	if (this.hoverSrc) ob.src = this.hoverSrc;
	else {
	 var cls=ob.className;
	 if (cls) {
		cls=cls.trim();
		var cls=cls.split(" ");
		cls=cls[0];
		ob.className = cls + " " + cls + "_hover";
	 }
	 cls=null;
	}
	ob=null;
}

obState.prototype.unhover = function(ob) {
	if (ob && location.href.indexOf(ob.parentNode.href) == -1) {
	if (this.activeState) this.active(ob);
	else if (this.visitedState) this.visited(ob);
	else this.normal(ob);
	}
}

obState.prototype.inactive = function(ob) {
	if (location.href.indexOf(ob.parentNode.href) == -1) {
		this.activeState=false;
	    if (!ob) ob=document.getElementById(this.id);
	    if (this.visitedOb) this.visited(ob);
	    else this.normal(ob);
	}
}

obState.prototype.visited = function(ob) {
	this.visitedState=true;
	if (!ob) ob=document.getElementById(this.id);
	if (this.visitedSrc) ob.src=this.visitedSrc;
	else {
	  var cls=ob.className;
	  if (cls) {
		cls=cls.trim();
		var cls=cls.split(" ");
		cls=cls[0];
		ob.className = cls + " " + cls + "_visited";
	  }
	}
	ob=cls=null;
}

obState.prototype.normal = function(ob) {
	if (!ob) ob=document.getElementById(this.id);
	if (this.normalSrc) ob.src=this.normalSrc;
	else {
	 var cls=ob.className;
	 if (cls) {
		cls=cls.trim();
		var cls=cls.split(" ");
		cls=cls[0];
		ob.className = cls;
	 }
	}
	ob=null;
}

obState.prototype.listener = function(id, tp, ob) {
	if (tp==="onmouseover") this.hover(ob);
	else if (tp==="onmouseout") this.unhover(ob);
	else if (tp=="onclick" || tp=="onfocus") {
		state.unhighlight(ob.id);
		this.active(ob);
	} else if (tp=="onblur") this.inactive(ob);
}

var state = {
   'obs' : {},
   'els' : {},
   'grps' : {},
   'reg' : function(id, group, normalSrc, hoverSrc, activeSrc, visitedSrc) {
	   state.obs[id] = new obState(id, normalSrc, hoverSrc, activeSrc, visitedSrc);
	   //state.els[elid] = ob;
	   if (group) state.grps[id]=group;
	   hands.reg(id, 'onmouseover', state.obs[id]);
	   hands.reg(id, 'onclick', state.obs[id]);
	   hands.reg(id, 'onmouseout', state.obs[id]);
	   return id;
   },
   'unhighlight' : function(id) {
	   if (state.grps[id]) {
		   for (var i in state.grps) {
			   if (i==id) continue;
			   if (state.grps[i] == state.grps[id]) state.inactive(i);
		   }
	   }
   },
   'active' : function(id) {
	   //first check any others in this group
	   state.unhighlight(id);
	   if (state.obs[id]) state.obs[id].active();
   },
   'inactive' : function(id) {
	   if (state.obs[id]) state.obs[id].inactive(document.getElementById(id));
   },
   'change' : function(ob) {
	   state.unhighlight(ob.id);
	   if (state.obs[ob.id]) state.obs[ob.id].active(document.getElementById(id));
	   //if (state.els[ob.id]) state.els[ob.id].activateFromLink(ob.id);
	   return false;
	}	
}

var mAjax = {
	'obs' : {},
	'addOb' : function(id, name, src, srcid, method, func, data, logout, time) {
		mAjax.obs[id] = {'src':src,'srcid':srcid,'name':name,'method':method,'func':func,'data':data,'logout':logout,'time':time};
	},
	'regLink' : function(id, srcid, args) {
		mAjax.obs[id] = {'id' : id,'srcid':srcid,'data':args,'listener':mAjax.listener};
		hands.reg(id, 'onclick', mAjax.obs[id]);
	},
	'run' : function(id, data) {
		var id=(typeof id === "string") ? id : this.id;
		var cob=mAjax.obs[id];
		if (!cob) return false;
	    var ob=document.getElementById(cob.srcid);
		if (ob) ob.innerHTML = "loading... ";
		ob=null;
		var ajax = new Ajax();
		var src=cob.src + "?ajaxid=" + id;
		if (cob.method==="POST") ajax.postData = data;
		else src += "&" + cob.name + "=true&" + data;
		if (cob.data) src += "&" + cob.data;
		ajax.method=cob.method;
		ajax.doGet(src, cob.func, "text", cob.srcid, cob.logout);
		if (!isNaN(parseInt(cob.time))) window.setTimeout("mAjax('" + id + "');");
	    id=cob=src=ajax=null;
	},
	'listener' : function(id, tp, ob) {
	  if (tp==="onclick") {
		var cob=mAjax.obs[id];
		if (!cob) return false;
	    var ob=document.getElementById(cob.srcid);
		if (ob) ob.innerHTML = "loading... ";
		ob=null;
		var ajax = new Ajax();
		var src=location.href + "?ajaxid=" + cob.srcid;
		if (cob.data) src += "&" + cob.data;
		ajax.doGet(src, null, "text", cob.srcid);
		//if (!isNaN(parseInt(cob.time))) window.setTimeout("mAjax('" + id + "');");
	    id=cob=ajax=null;
	  }
	}
}

var scrl = {
	'obs':{},
	'scr' : function(id) {
	  var obs=scrl.obs[id];
	    if(!obs.pause) {
			obs.vl=obs.vl <= 0 - parseInt(obs.ob.firstChild.style.height)? obs.st : obs.vl - 1;
			obs.ob.firstChild.style[obs.style] = obs.vl + "px";
		}	
		window.setTimeout("scrl.scr('" + id + "')", obs.speed);
	  obs=null;
	},
	'stpscr' : function() {
		scrl.obs[this.id].pause=true;
	},
	'setscr' : function() {
		scrl.obs[this.id].pause=false;
	},
	'regOb' : function(id, speed, style) {
		scrl.obs[id] = {'speed' : speed, 'id' :id, 'style' : style};
	},
	'loadOb' : function() {
	  var style,ob,dv;
		for (var id in scrl.obs) {
		ob=document.getElementById(id);
		scrl.obs[id].ob = ob;
		style=scrl.obs[id].style;
		dv=document.createElement("div");
		dv.className = ob.className;
		dv.style.overflow="hidden";
		dv.style.top=0;
		dv.style.left=0;
		dv.style.position="relative"; 
		dv.style.padding=0;
		dv.innerHTML=ob.innerHTML;
		ob.innerHTML="";
		ob.style.overflow="hidden";
		ob.appendChild(dv);
		window.setTimeout("scrl.scr('" + id + "')", scrl.obs[id].speed / 10);
	var h = set.offset(dv.lastChild, true);
	if (style==="left") {
			scrl.obs[id].size=scrl.obs[id].vl=ob.offsetWidth;
			dv.style.width = (h[1] + h[2] + 5) + "px";
		} else {
			scrl.obs[id].size=scrl.obs[id].vl=ob.offsetHeight;			
			dv.style.height = (h[0] + h[3] + 5) + "px";
		}
	
	scrl.obs[id].st=scrl.obs[id].vl;
	}
      dv=ob=style=h=null;	
	}
}

var tree = {
 'obs' : {},
 'show':function() {
       var ids=set.lpId(this.id);
       var id=ids[0];
       var lp=ids[1];
        if (tree.obs[id]) {
		//is this on or off
          var cob=tree.obs[id];
	  var on;
	  if (lp != "") {
		cob[lp] = (cob[lp]) ? false : true;
	        on=cob[lp];
	  } else {
		cob.on = (cob.on) ? false : true;
	        on=cob.on;
          }
	  set.shDiv(cob.block_id + lp, on);
	  if (on) {
		//var re = new RegExp(cob.onval, 'i');
		var wit = cob.offval;
	  } else {
	    //    var re = new RegExp(cob.offval, 'i');
		var wit = cob.onval;
          }
        // this.innerHTML = this.innerHTML.replace(re, wit);
	re=wit=cob=id=lp=null;
    }
  },
  'reg' : function(id, blockid, onval, offval, loop) {
	tree.obs[id] = {'on':false,'block_id':blockid,'onval':onval,'offval':offval,'loop':true};
	hands.reg(id, 'onclick', tree.show);
        if (loop) {
	   hands.st[id].loop=true;
	   var i=0;
  	   while(set.shDiv(blockid + "_loop" + i, false)) {
		i++;
           }
        } else set.shDiv(blockid, false);
  }
}

var _cln = {
//id, par, num, cln
  '_obs' : {},
  'setEl' : function(el) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
	var nm;
    	while (i--) {
	 nm=tgs[i].nodeName.toLowerCase();
	  if ((nm==="input" && tgs[i].type != "submit") || nm==="select" || nm==="textarea") {
             if (tgs[i].name.indexOf("[") == -1) tgs[i].name = tgs[i].name + "[0]";
          }
        }
	el=tgs=nm=num=null;
   },
 'rsNum' : function(cln, num) {
 	var tgs=cln.getElementsByTagName("*");
	var i=tgs.length;
	var nm;
    	while (i--) {
	 nm=tgs[i].nodeName.toLowerCase();
	  if ((nm==="input" && tgs[i].type != "submit") || nm==="select" || nm==="textarea") {
	    var exp=tgs[i].name.split("[");
	    tgs[i].name = exp[0] + "[" + num + "]";

          }
        }
	cln=num=tgs=null;
 },
 '_clone' : function() {
	var id,ob,cln,q;
	id=this.id;
 	ob=_cln._obs[id];
	ob.num++;
	cln = ob.cln.cloneNode(true);
	_cln.rsNum(cln, ob.num);
	_cln.rsIds(cln, ob.num);
	ob.par.appendChild(cln);
	q=document.getElementById(ob.q);
	q.value=parseInt(q.value) + 1;
	if (ob.func) {
	try {
	  ob.func();
        } catch(e){}
        }
	id=ob=cln=q=null;
  },
  'rsIds' : function(el, num) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
	while (i--) {
	  if (tgs[i].id && tgs[i].id.indexOf("_0_") > -1) tgs[i].id = tgs[i].id.replace("_0_", "_" + num + "_");
	   if (tgs[i].value) tgs[i].value="";
	}
	tgs=i=null;
  },	
  'rem' : function() {
	//how to remove this one?
  },
  'reset' : function(el) {
	var tgs=el.getElementsByTagName("*");
	var i=tgs.length;
    	while (i--) {
	  if ((tgs[i].nodeName==="input" && tgs[i].type != "submit") || tgs[i].nodeName==="select" || tgs[i].nodeName==="textarea") {
             if (tgs[i].name.indexOf("[") == -1) tgs[i].name = tgs[i].name + "[0]";
          }
        }
       i=tgs=null;
   },
   'reg' : function(id, clon, q, func) {
	_cln.setEl(clon);
	var par=clon.parentNode;
	var _clone = clon.cloneNode(true);
	_cln._obs[id] = {'cln':_clone,'par':par,'q':q,'num':0,'func':func};
	hands.reg(id, "onclick", _cln._clone);
	par=_clone=null;
   }
}

var sts = {
		 'clicks' : [],
	        'stT' : new Date(),
	        'load' : new Date(),
	        'setXY' : function(e) {
	                if (!e) var e = window.event;
	                var orig = (e.srcElement) ? e.srcElement : e.target;
	                while (orig) {
	                  if (orig.id || orig.nodeType !== 1) break;
	                  orig=orig.parentNode;
	                }
	                var id=(orig)?orig.id:0;
	                sts.clicks[sts.clicks.length] = {'x' : e.clientX, 'y' : e.clientY, 'srcId' : id};
	                id=orig=null;
	        },
	        'endPage' : function() {
	                var clstr='', endtime, sttime,n;
			n=sts.clicks.length > 25?10:sts.clicks.length;
	                for (var i=0; i<n; i++) {
	                 clstr += "&link_" + i + "_x=" + sts.clicks[i].x;
	                 clstr += "&link_" + i + "_y=" + sts.clicks[i].y;
	                 clstr += "&link_" + i + "_srcid=" + encodeURI(sts.clicks[i].srcId);
	            }
	            endtime = new Date().getTime() - sts.load.getTime();
	            sttime = sts.load.getTime() - sts.stT.getTime();
	         var arr=set.scrSize();
	         clstr = "starttime=" + sttime + "&endtime=" + endtime + "&wid=" + arr[0] + "&he=" + arr[1]  + clstr;
	         var ajax = new Ajax();
	         ajax.async=false;
	         ajax.doGet("/webwam/function/setstats.php?" + clstr);
	         ajax=endtime=clstr=arr=sttime=ajax=n=null;
	        }		
}

document.onclick = sts.setXY;

window.onbeforeunload = function() {
	sts.endPage();
     hands.set(false);
}

var _loadOb = {};

window.onload=function(){
   if (parent.location != window.location) {
    set.shDiv("topmenu1", false);
    set.shDiv("topmenu", false);
   }
   for (var i in _loadOb) {
	   _loadOb[i]();
   }
   _loadOb=null;
   sts.load=new Date();
   if(typeof onFunc=="function") onFunc();
   hands.set(true);
   if (parent.win.resizePop) {
    parent.win.resizePop();
    win.setZero();
   }
}
