// JavaScript Document
/**
* @param type		Browser type
*	1 : Internet Explorer
*	2 : Mozilla / Firefox
*	3 : Safari
*	4 : Opera
*
* @param version	Browser version 
*
* @param os 		Operation system. Default is Windows
*	1 : Linux
*	2 : MacOS
*/
function Browser (type, version, os) {
	this.type=type;
	this.version=version;
	this.os=os;
}

window.$browser = new Browser (0,0,null);

var ga = navigator.userAgent.toLowerCase();

if(ga.indexOf("opera")!=-1){
	$browser.type=4;
	if(ga.indexOf("opera/7")!=-1||ga.indexOf("opera 7")!=-1){
		$browser.version=7
	}
	else if(ga.indexOf("opera/8")!=-1||ga.indexOf("opera 8")!=-1){
		$browser.version=8
	}
}
else if(ga.indexOf("msie")!=-1&&document.all){
	$browser.type=1;
	if(ga.indexOf("msie 5")){
		$browser.version=5
	}
}
else if(ga.indexOf("safari")!=-1){
	$browser.type=3
}
else if(ga.indexOf("mozilla")!=-1){
	$browser.type=2
}

if(ga.indexOf("x11;")!=-1){
	$browser.os=1
}
else if(ga.indexOf("macintosh")!=-1){
	$browser.os=2
}



function el(i) {
	return document.getElementById(i);
}

function px(x) {
  return x + 'px';
}

function _falseFunction () {
	return false;
}

function _nullFunction () {
	return null;
}


function cursor (source, cursorType) {
	try {
		source.style.cursor=cursorType
	} catch(e) {
		if(cursorType=="pointer") { 
			cursor(source,"hand") 
		}
	}
}

function setUserData (source, key, value) {
	source["_ud__"+key] = value;
}

function getUserData (source, key) {
	return source["_ud__"+key];
}

function hasAncestor (source, object) {
	for (var n = source; n != document.body; n = n.parentNode) {
		if (n == object) return true;
	}
	return false;
}

function noUserSelect (source) {
	if ($browser.type == 1) {
		source.unselectable="on";
		source.onselectstart=_falseFunction;
	}
	else {
		source.style.MozUserSelect = "none";
	}
}


function createImage (src,width,height,left,top,zIndex,g,h,doc,k) {
	var n;doc=doc||document;
	if(!k){
		n=doc.createElement("img");
		if(src){n.src=src}
	}
	else{
		n=k(src,g,doc)
	}
	if(width&&height){
		n.style.width=px(width);
		n.style.height=px(height);
		n.width=width;
		n.height=height;
	}
	if(top||(left||(top==0||left==0))){
		n.style.position="absolute";
		n.style.left=px(left);
		n.style.top=px(top)
	}
	if(zIndex||zIndex==0){
		n.style.zIndex=zIndex
	}
	
	if($browser.type==1){
		n.unselectable="on";
		n.onselectstart=_falseFunction
	}
	else{
		n.style.MozUserSelect="none"
	}
	
	if($browser.type==1){
		n.galleryImg="no"
	}
	n.style.border="0";
	n.style.padding="0";
	n.style.margin="0";
	n.oncontextmenu=_falseFunction;
	if(h){
		Ba(n,h)
	}
	return n;
}

function Event(){}

Event.addListener=function(source,eventName,listenerFn) {
    var propertyName = Event.getPropertyName(eventName);
    if(source[propertyName]) {
        source[propertyName].push(listenerFn)
    }
    else{
        source[propertyName] = [listenerFn];
    }
    return new bc(source,propertyName,listenerFn)
}

Event.removeListener=function(listener){
    var b=listener.instance[listener.propertyName];
    for(var c=0;c<b.length;c++){
        if(b[c]==listener.listenerFn){
            b.splice(c,1);
            return
        }
    }
}

Event.clearListeners=function(source,eventName){
    var propertyName=Event.getPropertyName(eventName);
    source[propertyName]=null
}

Event.trigger=function(source,eventName){
    var propertyName=Event.getPropertyName(eventName);
    var listenerFuncs = source[propertyName];
    if(listenerFuncs && listenerFuncs.length>0) {
        
        var args=[];
        for(var f=2; f<arguments.length; f++){
            args.push(arguments[f])
        }
        
        for(var f=0; f<listenerFuncs.length; f++){
            var listenerFn = listenerFuncs[f];
            if(listenerFn) {
                //try {
                    listenerFn.apply(source,args)
//                } catch(e) {
//                    Log.dump(e)
//                }
            }
        }
    }
}

function bc(instance,propertyName,listenerFn){
    this.instance=instance;
    this.propertyName=propertyName;
    this.listenerFn=listenerFn;
}

Event.getPropertyName=function(eventName){
    return"_e__"+eventName;
}

Event.addBuiltInListener=function(source,eventName,listenerFn)
{
	/**
	 * Synthesized event. fires when DOM is fully loaded, without waiting 
	 * off all multimedia content
	 */
    if (eventName == "contentloaded") {
    	if ($browser.type == 1) {
    		/** MSIE */
			var dummyId = "__id_onload" + Math.round(Math.random()*100000);
			document.write("<script id="+dummyId+" defer src=javascript:void(0)><\/script>");
			var script = document.getElementById(dummyId);
			script.onreadystatechange = function() {
    			if (this.readyState == "complete") {
        			listenerFn(); // call the onload handler
		    	}
			};
    	}
    	else if ($browser.type == 3) {
    		/** Safari */
			var _timer = setInterval(function() {
					if (/loaded|complete/.test(document.readyState)) {
						clearInterval(_timer);
						listenerFn();
					}
				}, 10);    		
    	}
    	else if ($browser.type == 4 && $browser.version < 9) {
    		/** Opera < 9 */
			var _timer = setInterval(function() {
					if (document.body) {
	            		clearInterval(_timer);
	            		listenerFn(); 
					}
    			}, 10);    	
    	} 
    	else if (source.addEventListener) {
    		/** FireFox & Opera 9 */
    		source.addEventListener("DOMContentLoaded", listenerFn, false);
    	}
    	else {
    		Event.addBuiltInListener(source, "load", listenerFn);
    	}
    	
    	return;
    }
    
    if ($browser.type == 2 && eventName == "mousewheel")  {
    	source.addEventListener("DOMMouseScroll", listenerFn, false);
    	return;
    }
	
    if($browser.type==3 && eventName=="dblclick"){
        source["on"+eventName]=c;return
    }
    
    if(source.addEventListener){
        source.addEventListener(eventName,listenerFn,false)
    }
    else if(source.attachEvent){
        source.attachEvent("on"+eventName,listenerFn)
    }
    else{
        source["on"+eventName]=listenerFn;
    }
}

Event.removeBuiltInListener=function(source,eventName,listenerFn){
    if(source.removeEventListener){
        source.removeEventListener(eventName,listenerFn,false)
    }
    else if(source.detachEvent){
        source.detachEvent("on"+eventName,listenerFn)
    }
    else{
        source["on"+eventName]=null
    }
}

Event.cancelEvent = function (ev) {
	if($browser.type==1) {
		window.event.cancelBubble=true;
		window.event.returnValue=false
	}
	else{
		ev.cancelBubble=true;
		ev.preventDefault();
		ev.stopPropagation()
	}
}

Event.cancelBubble = function (ev) {
	if($browser.type==1){
		window.event.cancelBubble=true;
	}
	else{ev.stopPropagation()}	
}

Event.bindDom = function(source,eventName,object,method) {
    var listentFn = Event.createAdapter(object,method);
    Event.addBuiltInListener(source,eventName,listentFn);
    return listentFn;
}

Event.bindClick=function(source,object,method){
    Event.bindDom(source,"click",object,method);
    if($browser.type==1){
        Event.bindDom(source,"dblclick",object,method)
    }
}

Event.bind=function(source,eventName,object,method){
    return Event.addListener(source, eventName, function(){ method.apply(object,arguments) });
}

Event.callback=function(object,method){
    var c=function(){return method.apply(object,arguments)}
    return c;
}

Event.createAdapter=function(object,method) {
    return function(ev) {
        if(!ev){
            ev=window.event
        }
        if(ev&&!ev.target){
            ev.target=ev.srcElement
        }
        method.call(object, ev)
    }
}


function XmlHttp(){}

/**
* @static
*/
XmlHttp.create = function() {
    if(typeof ActiveXObject!="undefined"){
        try {
            return new ActiveXObject("Microsoft.XMLHTTP")
        } catch(e) {}
    }
    if(typeof XMLHttpRequest!="undefined"){
        return new XMLHttpRequest();
    }
    return null;
}


function DocumentTransport(){
    this.xmlhttp = XmlHttp.create();
}

DocumentTransport.prototype.continueWith=function(url,b){
    Log.writeURL(url);
    if ($browser.type == 1) {
		url = url + '&__microtime__=' + (new Date()).getTime();
    }
    var xmlhttp=this.xmlhttp;
    xmlhttp.open("GET",url,true);
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4) {
            b(xmlhttp.responseText);
            xmlhttp.onreadystatechange=_nullFunction;
        }
    }
    xmlhttp.send(null);
}


if (! Array.prototype.indexOf) {
	/**
	* @param searchElement
	* @param fromIndex?
	*/ 
	Array.prototype.indexOf = function (searchElement, fromIndex) {
		var n = fromIndex ? fromIndex : 0;
		for (var i=n; i<this.length; i++) {
			if (this[i] == searchElement) {
				return i;
			}
		}
		return -1;
	}
}


// Escape XML special markup chracters: tag delimiter < > and entity
// reference start delimiter &. The escaped string can be used in XML
// text portions (i.e. between tags).
function xmlEscapeText(s) {
  return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

// Escape XML special markup characters: tag delimiter < > entity
// reference start delimiter & and quotes ". The escaped string can be
// used in double quoted XML attribute value portions (i.e. in
// attributes within start tags).
function xmlEscapeAttr(s) {
  return xmlEscapeText(s).replace(/\"/g, '&quot;');
}

// Escape markup in XML text, but don't touch entity references. The
// escaped string can be used as XML text (i.e. between tags).
function xmlEscapeTags(s) {
  return s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

var $logging = false;

function Log() {};

Log.lines = [];

Log.write = function(s) {
  if ($logging) {
    this.lines.push(xmlEscapeText(s));
    this.show();
  }
};

// Writes the given XML with every tag on a new line.
Log.writeXML = function(xml) {
  if ($logging) {
    var s0 = xml.replace(/</g, '\n<');
    var s1 = xmlEscapeText(s0);
    var s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
    this.lines.push(s2);
    this.show();
  }
}

// Writes without any escaping
Log.writeRaw = function(s) {
  if ($logging) {
    this.lines.push(s);
    this.show();
  }
}

Log.writeURL = function (url) {
	if ($logging) {
		this.lines.push("<a href="+url+">"+url+"</a>");
		this.show();
	}
}

Log.clear = function() {
  if ($logging) {
    var l = this.div();
    l.innerHTML = '';
    this.lines = [];
  }
}

Log.show = function() {
  var l = this.div();
  l.innerHTML += this.lines.join('<br/>') + '<br/>';
  this.lines = [];
  l.scrollTop = l.scrollHeight;
}

Log.div = function() {
  var l = document.getElementById('log');
  if (!l) {
    l = document.createElement('div');
    l.id = 'log';
    l.style.position = 'fixed';
    l.style.right = '5px';
    l.style.top = '5px';
    l.style.width = '250px';
    l.style.height = '150px';
    l.style.overflow = 'auto';
	l.style.color = '#000000';
    l.style.backgroundColor = '#f0f0f0';
    l.style.border = '1px solid gray';
    l.style.fontSize = '10px';
    l.style.padding = '5px';
    document.body.appendChild(l);
  }
  return l;
}


function Sa(a){
	var b={"x":0,"y":0};
	while(a){
		b.x+=a.offsetLeft;
		b.y+=a.offsetTop;
		a=a.offsetParent;
	}
	return b
}

function nd(a,b){
	var c={"x":0,"y":0};
	c.toString = function () {
		return "(x: "+c.x+"; y: "+c.y+")";
	};
	
	while(a&&a!=b){
		c.x+=a.offsetLeft;
		c.y+=a.offsetTop;
		a=a.offsetParent;
	}
	return c
}


function postRequest(url, args) {
	var form = document.createElement("form");
	form.method = "POST";
	form.action = url;
	
	for (var n in args) {
		var v = args[n];
		var i = document.createElement("input");
		i.type = "hidden";
		i.name = n;
		i.value = v;
		form.appendChild(i);
	}
	
	document.body.appendChild(form);
	form.submit();
}