//JS.js
String.prototype.trim = function () {
    var s = this.replace(/^\s*/, "");
    return s.replace(/\s*$/, "");    
}
String.prototype.replaceString = function(find, replace) {
	var str = this;
	var pos = str.indexOf(find);
	while (pos >= 0) {
		var buf = new StringBuffer();
		buf.append(str.substring(0, pos));
		buf.append(replace);
		buf.append(str.substring(pos + find.length));
		str = buf.toString();
		pos = str.indexOf(find, pos + 1);
	}
	return str;
}
function Array_addElement(a, element) { a[a.length] = element; }
function Array_contains(a, element) { 
	for (var t = 0; t < a.length; t++)
		if (a[t] == element)
			return true; 
	return false;
}
function Array_indexOf(a, element) { 
	for (var t = 0; t < a.length; t++)
		if (a[t] == element)
			return t; 
	return -1;
}
function Array_removeElement(a, element) { 
	var pos = Arrray_indexOf(a, element);
	if (pos == -1)
		return;
	for (var t = pos; t < a.length - 1; t++)
		a[t] = a[t + 1];
	a.length--;
}


// event and function binding enhancements
//  from http://www.brockman.se/writing/method-references.html.utf8
function entries(collection) {
    var result = [];  // This is our real duck.

    for (var i = 0; i < collection.length; i++)
        result.push(collection[i]);

    return result;
}

Function.prototype.bind = function (object) {
    var method = this;
    var oldArguments = entries(arguments).slice(1);
    return function () {
        var newArguments = entries(arguments);
        return method.apply(object, oldArguments.concat(newArguments));
    };
}

Function.prototype.bindEventListener = function (object) {
    var method = this;
    var oldArguments = entries(arguments);//.slice(1);
    return function (event) {
    	if (event) {
	    	oldArguments[0] = event;
    		return method.apply(object, oldArguments);
        } else {
	        oldArguments[0] = window.event;
        	return method.apply(object, oldArguments);
	    }    
        //return method.apply(object, event || window.event, oldArguments);
    };
}

//Windowing.js
function Browser() {
}
	Browser.UserAgent = navigator.userAgent.toLowerCase();
	if (window.opera) {
	    var i=Browser.UserAgent.indexOf('opera');
	    if (i!=-1) {
	        var v=parseInt(Browser.UserAgent.charAt(i+6));
	        Browser.Op7Up=v>=7;
	        Browser.Op6Dn=v<7;
	    }
	} else if(navigator.vendor!='KDE' && document.all && Browser.UserAgent.indexOf('msie')!=-1) {
	    Browser.IE4Up=parseFloat(navigator.appVersion)>=4;
	    Browser.IE4=Browser.UserAgent.indexOf('msie 4')!=-1;
	    Browser.IE5=Browser.UserAgent.indexOf('msie 5')!=-1;
	} else if(document.layers) {
	    Browser.NN4=true;
	}
	Browser.Mac=Browser.UserAgent.indexOf('mac')!=-1;

function Utility() {
}
	Utility.IsString = function(s){
	    for(var i=0; i<arguments.length; ++i){
	        if(typeof(arguments[i])!='string') 
	             return false;
	    }
	    return true;
	}
	Utility.IsDefined = function(){
	    for(var i=0; i<arguments.length; ++i) {
	        if(typeof(arguments[i])=='undefined') 
	            return false;
	    }
	    return true;
	}
	Utility.IsNumber = function(){
	    for(var i=0; i<arguments.length; ++i) {
	        if(isNaN(arguments[i]) || typeof(arguments[i])!='number') 
	            return false;
	    }
	    return true;
	}

Windowing.RootDiv = document.documentElement
function Windowing() {
}
    Windowing.CreateElement = function(type, id, className, attributes) {
		var ele;
        if (Browser.IE4Up) {
        	var txt = "<" + type;
        	if (id != null)
        		txt += " id='" + id + "'";
        	if (className != null)
        		txt += "class='" + className + "'";
        	if (attributes) {
        		for (var t = 0; t < attributes.size(); t++) {
        			var key = attributes.keyAt(t);
        			var value = attributes.get(key);
        			txt += " " + key + "='" + value + "'";
        		}
        	}
        	txt += ">";
            ele = document.createElement(txt);
        } else {
            ele = document.createElement(type);
        	if (id != null)
	            ele.setAttribute("id", id);
        	if (className != null)
			    ele.setAttribute("class", className);
        	if (attributes) {
        		for (var t = 0; t < attributes.size(); t++) {
        			var key = attributes.keyAt(t);
        			var value = attributes.get(key);
        			ele.setAttribute(key, value);
        		}
        	}
		}
		return ele;
	}	
	Windowing.Background = function(e,c,i) {
	    if(!(e=Windowing.GetElement(e))) 
	        return '';
	    var bg='';
	    if(e.style) {
	        if(Utility.IsString(c)) {
	            if(!Browser.Op6Dn) 
	                e.style.backgroundColor=c;
	            else 
	                e.style.background=c;
	        }
	        if(Utility.IsString(i)) 
	            e.style.backgroundImage=(i!='')? 'url('+i+')' : null;
	            if(!Browser.Op6Dn) 
	                bg=e.style.backgroundColor;
	            else 
	                bg=e.style.background;
	    }
	    return bg;
	}
	Windowing.GetElement = function(e){
	    if(typeof(e)!='string') 
	        return e;
	    if(document.getElementById) 
	        e=document.getElementById(e);
	    else if(document.all) 
	        e=document.all[e];
	    else 
	        e=null;
	    return e;
	}
	Windowing.ClientHeight = function(){
	    var h=0;
	    if(Browser.Op6Dn) 
	        h=window.innerHeight;
	    else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
	        h=document.documentElement.clientHeight;
	    else if(document.body && document.body.clientHeight)
	        h=document.body.clientHeight;
	    else 
	        if(Utility.IsDefined(window.innerWidth,window.innerHeight,document.width)) {
	            h=window.innerHeight;
	            if(document.width>window.innerWidth) 
	                h-=16;
	        }
	        return h;
	}
	Windowing.ClientWidth = function() {
	    var w=0;
	    if(Browser.Op6Dn) 
	        w=window.innerWidth;
	    else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
	        w=document.documentElement.clientWidth;
	    else if(document.body && document.body.clientWidth)
	        w=document.body.clientWidth;
	    else if(Utility.IsDefined(window.innerWidth,window.innerHeight,document.height)) {
	        w=window.innerWidth;
	        if(document.height>window.innerHeight) 
	            w-=16;
	    }
	    return w;
	}
	Windowing.Clip = function(e,t,r,b,l) {
	    if(!(e=Windowing.GetElement(e))) 
	        return;
	    if(e.style) {
	        if (Utility.IsNumber(l)) 
	            e.style.clip='rect('+t+'px '+r+'px '+b+'px '+l+'px)';
	        else 
	            e.style.clip='rect(0 '+parseInt(e.style.width)+'px '+parseInt(e.style.height)+'px 0)';
	    }
	}
	Windowing.Color = function(e,s) {
	    if(!(e=Windowing.GetElement(e))) 
	        return '';
	    var c='';
	    if(e.style && Utility.IsDefined(e.style.color)) {
	        if(Utility.IsString(s)) 
	            e.style.color=s;
	        c=e.style.color;
	    }
	    return c;
	}

	Windowing.Display = function(e,s) {
	    if(!(e=Windowing.GetElement(e))) 
	        return null;
	    if(e.style && Utility.IsDefined(e.style.display)) {
	        if (Utility.IsString(s)) 
	            e.style.display = s;
	        return e.style.display;
	    }
	    return null;
	}
	Windowing.GetComputedStyle = function(oEle, sProp, bInt) {
	    var s, p = 'undefined';
	    var dv = document.defaultView;
	    if(dv && dv.getComputedStyle) {
	        s = dv.getComputedStyle(oEle,'');
	        if (s) 
	            p = s.getPropertyValue(sProp);
	    } else if(oEle.currentStyle) {
	        var a = sProp.split('-');
	        sProp = a[0];
	        for (var i=1; i<a.length; ++i) {
	            c = a[i].charAt(0);
	            sProp += a[i].replace(c, c.toUpperCase());
	        }
	        p = oEle.currentStyle[sProp];
	    } else 
	        return null;
	    return bInt ? (parseInt(p) || 0) : p;
	}
	Windowing.HasPoint = function(e,x,y,t,r,b,l) {
	    if (!Utility.IsNumber(t)){
	        t=r=b=l=0;
	    } else if (!Utility.IsNumber(r)) {
	        r=b=l=t;
	    } else if (!Utility.IsNumber(b)) {
	        l=r; b=t;
	    }
	    var eX = xPageX(e), eY = xPageY(e);
	    return (x >= eX + l && x <= eX + xWidth(e) - r &&y >= eY + t && y <= eY + xHeight(e) - b );
	}
	Windowing.Height = function(e,h) {
	    if(!(e=Windowing.GetElement(e))) 
	        return 0;
	    if (Utility.IsNumber(h)) {
	        if (h<0) 
	            h = 0;
	        else 
	            h=Math.round(h);
	    } else 
	        h=-1;
	    var css=Utility.IsDefined(e.style);
	    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	        h = xClientHeight();
	    }else if(css && Utility.IsDefined(e.offsetHeight) && Utility.IsString(e.style.height)) {
	        if(h>=0) {
	            var pt=0,pb=0,bt=0,bb=0;
	            if (document.compatMode=='CSS1Compat') {
	                var gcs = Windowing.GetComputedStyle;
	                pt=gcs(e,'padding-top',1);
	                if (pt !== null) {
	                    pb=gcs(e,'padding-bottom',1);
	                    bt=gcs(e,'border-top-width',1);
	                    bb=gcs(e,'border-bottom-width',1);
	                } else if(Utility.IsDefined(e.offsetHeight,e.style.height)) {
	                    e.style.height=h+'px';
	                    pt=e.offsetHeight-h;
	                }
	            }
	            h-=(pt+pb+bt+bb);
	            if(isNaN(h)||h<0) 
	                return;
	            else 
	                e.style.height=h+'px';
	        }
	        h=e.offsetHeight;
	    } else if(css && Utility.IsDefined(e.style.pixelHeight)) {
	        if(h>=0) 
	            e.style.pixelHeight=h;
	        h=e.style.pixelHeight;
	    }
	    return h;
	}
	Windowing.Width = function(e,w){
	    if(!(e=Windowing.GetElement(e))) 
	        return 0;
	    if (Utility.IsNumber(w)) {
	        if (w<0) 
	            w = 0;
	        else 
	            w=Math.round(w);
	    }else 
	        w=-1;
	    var css=Utility.IsDefined(e.style);
	    if (e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	        w = xClientWidth();
	    }else if(css && Utility.IsDefined(e.offsetWidth) && Utility.IsString(e.style.width)) {
	        if(w>=0) {
	            var pl=0,pr=0,bl=0,br=0;
	            if (document.compatMode=='CSS1Compat') {
	                var gcs = Windowing.GetComputedStyle;
	                pl=gcs(e,'padding-left',1);
	                if (pl !== null) {
	                    pr=gcs(e,'padding-right',1);
	                    bl=gcs(e,'border-left-width',1);
	                    br=gcs(e,'border-right-width',1);
	                }else if(Utility.IsDefined(e.offsetWidth,e.style.width)){
	                    e.style.width=w+'px';
	                    pl=e.offsetWidth-w;
	                }
	            }
	            w-=(pl+pr+bl+br);
	            if(isNaN(w)||w<0) 
	                return;
	            else 
	                e.style.width=w+'px';
	        }
	        w=e.offsetWidth;
	    }else if(css && Utility.IsDefined(e.style.pixelWidth)) {
	        if(w>=0) 
	            e.style.pixelWidth=w;
	        w=e.style.pixelWidth;
	    }
	    return w;
	}
	Windowing.Left = function(e, iX) {
	    if(!(e=Windowing.GetElement(e))) 
	        return 0;
	    var css=Utility.IsDefined(e.style);
	    if (css && Utility.IsString(e.style.left)) {
	        if(Utility.IsNumber(iX)) 
	            e.style.left=iX+'px';
	        else {
	            iX=parseInt(e.style.left);
	            if(isNaN(iX)) iX=0;
	        }
	    } else if(css && Utility.IsDefined(e.style.pixelLeft)) {
	        if(Utility.IsNumber(iX)) 
	            e.style.pixelLeft=iX;
	        else 
	            iX=e.style.pixelLeft;
	    }
	    return iX;
	}
	Windowing.Top = function(e, iY){
	    if(!(e=Windowing.GetElement(e))) 
	        return 0;
	    var css=Utility.IsDefined(e.style);
	    if(css && Utility.IsString(e.style.top)) {
	        if(Utility.IsNumber(iY)) 
	            e.style.top=iY+'px';
	        else {
	            iY=parseInt(e.style.top);
	            if(isNaN(iY)) 
	                iY=0;
	        }
	    }else if(css && Utility.IsDefined(e.style.pixelTop)) {
	        if(Utility.IsNumber(iY)) 
	            e.style.pixelTop=iY;
	        else 
	            iY=e.style.pixelTop;
	    }
	    return iY;
	}
	Windowing.Hide = function(e) {
	    return xVisibility(e,0);
	}
	Windowing.Move = function(e,x,y) {
	    Windowing.Left(e,x);
	    Windowing.Top(e,y);
	}
	Windowing.OffsetLeft = function(e) {
	    if (!(e=Windowing.GetElement(e))) 
	        return 0;
	    if (Utility.IsDefined(e.offsetLeft)) 
	        return e.offsetLeft;
	    else 
	        return 0;
	}
	Windowing.OffsetTop = function(e) {
	    if (!(e=Windowing.GetElement(e))) 
	        return 0;
	    if (Utility.IsDefined(e.offsetTop)) 
	        return e.offsetTop;
	    else 
	        return 0;
	}
	Windowing.PageX = function(e) {
	    if (!(e=Windowing.GetElement(e))) 
	        return 0;
	    var x = 0;
	    while (e) {
	        if (Utility.IsDefined(e.offsetLeft)) 
	            x += e.offsetLeft;
	        e = Utility.IsDefined(e.offsetParent) ? e.offsetParent : null;
	    }
	    return x;
	}
	Windowing.PageY = function(e) {
	    if (!(e=Windowing.GetElement(e))) 
	        return 0;
	    var y = 0;
	    while (e) {
	        if (Utility.IsDefined(e.offsetTop)) 
	            y += e.offsetTop;
	        e = Utility.IsDefined(e.offsetParent) ? e.offsetParent : null;
	    }
	    return y;
	}
	Windowing.Parent = function(e, bNode) {
	    if (!(e=Windowing.GetElement(e))) 
	        return null;
	    var p=null;
	    if (!bNode && Utility.IsDefined(e.offsetParent)) 
	        p=e.offsetParent;
	    else if (Utility.IsDefined(e.parentNode)) 
	        p=e.parentNode;
	    else if (Utility.IsDefined(e.parentElement)) 
	        p=e.parentElement;
	    return p;
	}
	Windowing.Resize = function(e,w,h){
	    Windowing.Width(e,w);
	    Windowing.Height(e,h);
	}
	Windowing.ScrollLeft = function(e, bWin){
	    var offset=0;
	    if (!Utility.IsDefined(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	        var w = window;
	        if (bWin && e) 
	            w = e;
	        if(w.document.documentElement && w.document.documentElement.scrollLeft) 
	            offset=w.document.documentElement.scrollLeft;
	        else if(w.document.body && Utility.IsDefined(w.document.body.scrollLeft)) 
	            offset=w.document.body.scrollLeft;
	    } else {
	        e = Windowing.GetElement(e);
	        if (e && Utility.IsNumber(e.scrollLeft)) 
	            offset = e.scrollLeft;
	    }
	    return offset;
	}
	Windowing.ScrollTop = function(e, bWin){
	    var offset=0;
	    if (!Utility.IsDefined(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	        var w = window;
	        if (bWin && e) 
	            w = e;
	        if(w.document.documentElement && w.document.documentElement.scrollTop) 
	            offset=w.document.documentElement.scrollTop;
	        else if(w.document.body && Utility.IsDefined(w.document.body.scrollTop)) 
	            offset=w.document.body.scrollTop;
	    }else {
	        e = Windowing.GetElement(e);
	        if (e && Utility.IsNumber(e.scrollTop)) 
	            offset = e.scrollTop;
	    }
	    return offset;
	}
	Windowing.Show = function(e) {
	    return Windowing.Visibility(e,1);
	}
	Windowing.Visibility = function(e, bShow){
	    if(!(e=Windowing.GetElement(e))) 
	        return null;
	    if(e.style && Utility.IsDefined(e.style.visibility)) {
	        if (Utility.IsDefined(bShow)) 
	            e.style.visibility = bShow ? 'visible' : 'hidden';
	        return e.style.visibility;
	    }
	    return null;
	}
	Windowing.ZIndex = function(e,uZ){
	    if(!(e=Windowing.GetElement(e))) 
	        return 0;
	    if(e.style && Utility.IsDefined(e.style.zIndex)) {
	        if(Utility.IsNumber(uZ)) 
	            e.style.zIndex=uZ;
	        uZ=parseInt(e.style.zIndex);
	    }
	    return uZ;
	}
	Windowing.Attribute = function(e, att, val) {
		if (Browser.IE4Up) {
			for (var t = 0; t < e.attributes.length; t++) {
				if (e.attributes[t].nodeName == att) {
					if (val)
						e.attributes[t].value = val;
					return e.attributes[t].value;
				}
			}
		}
		e.setAttribute(att, val);
	}
	Windowing.SetAttribute = function(e, att, val) {
		if (Browser.IE4Up) {
			for (var t = 0; t < e.attributes.length; t++) {
				if (e.attributes[t].nodeName == att) {
					e.attributes[t].value = val;
					return;
				}
			}
		}
		e.setAttribute(att, val);
	}
	   
function Events() {
var x=1;
}
	Events.AddListener = function(e,eT,eL,cap) {
	    if(!(e = Windowing.GetElement(e))) 
	        return;
	    eT = eT.toLowerCase();
	    if ((!Browser.IE4Up && !Browser.xOp7Up) && e==window) {
	        if (eT=='resize') { 
	            window.xPCW=Windowing.ClientWidth(); 
	            window.xPCH=Windowing.ClientHeight(); 
	            window.xREL=eL; 
	            Events.ResizeEvent(); 
	            return; 
	        }
	        if (eT=='scroll') { 
	            window.xPSL=Windowing.ScrollLeft(); 
	            window.xPST=Windowing.ScrollTop(); 
	            window.xSEL=eL; 
	            Events.ScrollEvent(); 
	            return; 
	        }
	    }
	    var eh='e.on'+eT+'=eL';
	    if (e.addEventListener) 
	        e.addEventListener(eT,eL,cap);
	    else if(e.attachEvent) 
	        e.attachEvent('on'+eT,eL);
	    else 
	        eval(eh);
	}
	Events.ResizeEvent = function() {
	    if (window.xREL) 
	        setTimeout('Events.ResizeEvent()', 250);
	    var cw = Windowing.ClientWidth(), ch = Windowing.ClientHeight();
	    if (window.xPCW != cw || window.xPCH != ch) { 
	        window.xPCW = cw; 
	        window.xPCH = ch; 
	        if (window.xREL) 
	            window.xREL(); 
	    }
	}
	Events.ScrollEvent = function(){
	    if (window.xSEL) 
	        setTimeout('Events.ScrollEvent()', 250);
	    var sl = Windowing.ScrollLeft(), st = Windowing.ScrollTop();
	    if (window.xPSL != sl || window.xPST != st) { 
	        window.xPSL = sl; 
	        window.xPST = st; 
	        if (window.xSEL) 
	            window.xSEL(); 
	    }
	}
	Events.Event = function(evt) {
	    var e = evt || window.event;
	    if (!e) 
	        return;
	    if (e.type) 
	        this.type = e.type;
	    if(e.target) 
	        this.target = e.target;
	    else if(e.srcElement) 
	        this.target = e.srcElement;
	    if (e.relatedTarget) 
	        this.relatedTarget = e.relatedTarget;
	    else if (e.type == 'mouseover' && e.fromElement) 
	        this.relatedTarget = e.fromElement;
	    else if (e.type == 'mouseout') 
	        this.relatedTarget = e.toElement;
	    if (Browser.Op6Dn) { 
	        this.pageX = e.clientX; 
	        this.pageY = e.clientY; 
	    } else if (Utility.IsDefined(e.pageX, e.pageY)) { 
	        this.pageX = e.pageX; 
	        this.pageY = e.pageY; 
	    } else if (Utility.IsDefined(e.clientX, e.clientY)) { 
	        this.pageX = e.clientX + Windowing.ScrollLeft(); 
	        this.pageY = e.clientY + Windowing.ScrollTop(); 
	    }
	    if (Utility.IsDefined(e.offsetX, e.offsetY)) {
	        this.offsetX = e.offsetX;
	        this.offsetY = e.offsetY;
	    } else if (Utility.IsDefined(e.layerX,e.layerY)) {
	        this.offsetX = e.layerX;
	        this.offsetY = e.layerY;
	    } else {
	        this.offsetX = this.pageX - Windowing.PageX(this.target);
	        this.offsetY = this.pageY - Windowing.PageY(this.target);
	    } 
	    if (e.keyCode) { 
	        this.keyCode = e.keyCode; 
	    } else if (Utility.IsDefined(e.which) && e.type.indexOf('key')!=-1) { 
	        this.keyCode = e.which; 
	    }
	    this.shiftKey = e.shiftKey;
	    this.ctrlKey = e.ctrlKey;
	    this.altKey = e.altKey;
	}
	Events.PreventDefault = function(e) {
	    if (e && e.preventDefault) 
	        e.preventDefault();
	    else if (window.event) 
	        window.event.returnValue = false;
	}
	Events.RemoveListener = function(e,eT,eL,cap) {
	    if (!(e=Windowing.GetElement(e))) 
	        return;
	    eT = eT.toLowerCase();
	    if ((!Browser.IE4Up && !Browser.Op7Up) && e==window) {
	        if (eT=='resize') { 
	            window.xREL=null; 
	            return; 
	        }
	        if (eT=='scroll') { 
	            window.xSEL=null; 
	            return; 
	        }
	    }
	    var eh = 'e.on'+eT+'=null';
	    if (e.removeEventListener) 
	        e.removeEventListener(eT,eL,cap);
	    else if(e.detachEvent) 
	        e.detachEvent('on'+eT,eL);
	    else 
	        eval(eh);
	}
	Events.StopPropagation = function(evt) {
	    if (evt && evt.stopPropagation) 
	        evt.stopPropagation();
	    else if (window.event) 
	        window.event.cancelBubble = true;
	}	   
	   	   
	Events.DragManager = { ele:null, mm:false };
	Events.DisableDrag = function(id, last){
	    if (!Events.DragManager) 
	        return;
	    var ele = Windowing.GetElement(id);
	    ele.xDraggable = false;
	    ele.xODS = null;
	    ele.xOD = null;
	    ele.xODE = null;
	    xRemoveEventListener(ele, 'mousedown', Events.HandleMouseDown, false);
	    if (Events.DragManager.mm && last) {
	        Events.DragManager.mm = false;
	        Events.RemoveEventListener(document, 'mousemove', Events.HandleMouseMoved, false);
	    }
	}

	Events.EnableDrag = function(id,fS,fD,fE){
	    var ele = Windowing.GetElement(id);
	    ele.xDraggable = true;
	    ele.xODS = fS;
	    ele.xOD = fD;
	    ele.xODE = fE;
	    Events.AddListener(ele, 'mousedown', Events.HandleMouseDown, false);
	    if (!Events.DragManager.mm) {
	        Events.DragManager.mm = true;
	        Events.AddListener(document, 'mousemove', Events.HandleMouseMoved, false);
	    }
	}
	Events.HandleMouseDown = function(e) {
	    var evt = new Events.Event(e);
	    var ele = evt.target;
	    while(ele && !ele.xDraggable) {
	        ele = Windowing.Parent(ele);
	    }
	    if (ele) {
	        Events.PreventDefault(e);
	        ele.xDPX = evt.pageX;
	        ele.xDPY = evt.pageY;
	        Events.DragManager.ele = ele;
	        Events.AddListener(document, 'mouseup', Events.HandleMouseUp, false);
	        if (ele.xODS) {
	            ele.xODS(ele, evt.pageX, evt.pageY);
	        }
	    }
	}
	Events.HandleMouseMoved = function (e) {
	    var evt = new Events.Event(e);
	    if (Events.DragManager.ele) {
	        Events.PreventDefault(e);
	        var ele = Events.DragManager.ele;
	        var dx = evt.pageX - ele.xDPX;
	        var dy = evt.pageY - ele.xDPY;
	        ele.xDPX = evt.pageX;
	        ele.xDPY = evt.pageY;
	        if (ele.xOD) {
	            ele.xOD(ele, dx, dy);
	        } else {
	            Windowing.Move(ele, xLeft(ele) + dx, xTop(ele) + dy);
	        }
	    }
	}
	Events.HandleMouseUp = function (e) {
	    if (Events.DragManager.ele) {
	        Events.PreventDefault(e);
	        Events.RemoveListener(document, 'mouseup', Events.HandleMouseUp, false);
	        if (Events.DragManager.ele.xODE) {
	            var evt = new Events.Event(e);
	            Events.DragManager.ele.xODE(Events.DragManager.ele, evt.pageX, evt.pageY);
	        } 
	        Events.DragManager.ele = null;
	    }
	}
	
//FlowAlbum.js
//Class ImageTile
var ImageTile = function(){}
	ImageTile.prototype = new ImageTile;
	ImageTile.prototype.construct = function(imageList, name, date, w, h, size) {
		this.imageList = imageList;
		this.name = name;
		this.height = h;
		this.width = w;
		this.loaded = false;
		this.loading = false;
		this.selected = false;
		this.div       = Windowing.CreateElement("div", name, "ImageTile");
		this.image     = Windowing.CreateElement("img", name + "_Image", "Image");
		this.lastClickX = -1;
		this.lastClickY = -1;
		this.lastClickTime = -1;
		this.showPopup = true;
	
		var imgwidth, imgheight;
		var ratio = w/h;
		imgheight = height/10.1;  
		imgwidth = imgheight * ratio;
		this.image.setAttribute("width", imgwidth);
		this.image.setAttribute("height", imgheight);
		this.image.setAttribute("src", "thumbs/thumb_" + name);
		this.image.setAttribute("title", this.name + " - " + "" + this.parseDate(date) + " - (" + size + "KB)");
		this.div.appendChild(this.image);
		imageList.div.appendChild(this.div);
		this.div.onmousedown = this.eventImageClick.bindEventListener(this);

		this.setSize(imgwidth, imgheight);
	}
	ImageTile.prototype.resize = function(w, h, holdWidthConstant, showPopup) { 
		var imgwidth, imgheight;
		var ratio = this.width/this.height;
		if (holdWidthConstant) {
			imgwidth = w;
			imgheight = imgwidth / ratio;
		} else {
			imgheight = h;  
			imgwidth = imgheight * ratio;
		}
		this.setSize(imgwidth, imgheight);
		this.showPopup = showPopup;
	}
	ImageTile.prototype.reflectState = function() { 
		if (this.loading) 
			Windowing.SetAttribute(this.image, "class", "ImageLoading");
		else if (this.selected) {
			Windowing.SetAttribute(this.image, "class", this.loaded ? "ImageLoadedSelected": "ImageSelected");
		} else {
			Windowing.SetAttribute(this.image, "class", this.loaded ? "ImageLoaded": "Image");
		}
	}
	ImageTile.prototype.setSelected = function(value) { 
		this.selected = value;
		this.reflectState();
	}
	ImageTile.prototype.setLoading = function(value) { 
		this.loading = value;
		if (!this.loading)
			this.loaded = true;
		this.reflectState();
	}	
	ImageTile.prototype.setSize = function(w, h) { Windowing.Resize(this.image, w, h); }
	ImageTile.prototype.parseDate = function(date) { 
		var format = [4, 5, "-", 6, 7, "-", 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16];
		var newDate = "";
		for (var t = 0; t< format.length; t++) {
			if (isNaN(format[t]))
				newDate += format[t];
			else
				newDate += date.charAt(format[t])
		}
		return newDate;	
	}	

	ImageTile.prototype.eventImageClick = function(event) { 
		this.imageList.setSelected(this);
		if (this.loaded) {
			// show the popup
			this.load(false, function() { 
					this.image.setAttribute("src", "thumbs/large_" + this.name);
					if (this.showPopup) {
						var imageFrame = new ImageFrame();
						imageFrame.construct(Windowing.RootDiv, "Zoom", this.width, this.height);
						imageFrame.display(this);
					}
				}.bind(this));
		} else if (!this.loading) {
			this.load(false, function() { 
					this.image.setAttribute("src", "thumbs/large_" + this.name);
				}.bind(this));
		}
	}
	
	ImageTile.prototype.load = function(blockSimultaneous, funcToCall) {
		if (this.loaded) {
			if (funcToCall)
				funcToCall(this);
		} else if ((!working || !blockSimultaneous)) {
			if (Windowing.GetElement("HiddenImage" + this.name) == null) {
				this.setLoading(true);
				if (!working)
					working = blockSimultaneous;
				this.hiddenImage = Windowing.CreateElement("img", "HiddenImage" + this.name, "Hidden");
				this.hiddenImage.setAttribute("src", "thumbs/large_" + this.name);
				this.hiddenImage.onload = this.loadComplete.bind(this, funcToCall, blockSimultaneous);
				this.imageList.hidden.appendChild(this.hiddenImage);
			} else if (!this.loaded) {
				this.checkLoaded(funcToCall);
			} else {
				if (funcToCall)
					funcToCall(this);
			}
		}
	}
	ImageTile.prototype.checkLoaded = function(funcToCall) {
		if (!this.loaded) {
			setTimeout(function() { 
				this.checkLoaded(funcToCall);
			}.bind(this), 500);
		} else {
			funcToCall();
		}
	}
	ImageTile.prototype.loadComplete = function(funcToCall, blockSimultaneous) {
		this.setLoading(false);
		if (blockSimultaneous)
			working = false;
		try {
			this.imageList.hidden.removeChild(this.hiddenImage);
		} catch (e) {}
		this.hiddenImage = null
		if (funcToCall)
			funcToCall(this);
	}
	ImageTile.prototype.onunload = function() {
		try {
			this.imageList.div.removeChild(this.div);
		} catch (e) { }
		try {
			this.div.removeChild(this.image);
		} catch (e) { }
		this.div.onmousedown = null;
		this.div = this.image = this.width = this.height = null;
		this.imageList = this.name = this.loaded = this.loading = null;
		this.selected = this.lastClickX = this.lastClickY = this.lastClickTime = this.showPopup = null;
	}
	
// Class ImageList
var ImageList = function(){}
	ImageList.prototype = new ImageList;
	ImageList.prototype.construct = function(parent, id) {
		this.parent = parent;
	    this.id = id;
		this.images = new Array();
	
	    this.div = Windowing.CreateElement("div", this.id, "ImageList")
	    this.buttonBar = Windowing.CreateElement("div", this.id, "ButtonBar")
	    this.div.appendChild(this.buttonBar);
	
		var sizes   = [ 10.1, 8.1, 6.1, 4.1, 3.1, 2.1, 1, 1];
		var bywidth = [    0,   0,   0,   0,   0,   0, 0, 1];
		var popup   = [    1,   1,   1,   1,   1,   1, 0, 0];
		this.buttonCount = sizes.length;
		for (var t = 0; t < sizes.length; t++) {
			var button = Windowing.CreateElement("input", this.id + "Button" + t, "Button");
		    button.setAttribute("type", "button");
		    button.value = "" + (t + 1);
			button.onclick = this.buttonSizerPressed.bind(this, sizes[t], bywidth[t]==1, popup[t]==1);
			this.buttonBar.appendChild(button);
		}			
	    this.parent.appendChild(this.div);
	}
	ImageList.prototype.onunload = function() {
		try {
			this.parent.removeChild(this.div);
		} catch (e) { }
		try {
			this.div.removeChild(this.hidden);
		} catch (e) { }
		for (var i = 0; i < this.buttonCount.length; i++) {
			try {
				this.div.removeChild(Windowing.GetElement(this.id + "Button" + i));
			} catch (e) { }
		}
		for (var i = 0; i < this.images.length; i++) {
			var image = this.images[i];
			image.onunload();
			this.images[i] = image = null;
		}
		this.images.length = 0;
		this.parent = this.id = this.images = this.buttonCount = null;
	}
	
	ImageList.prototype.addImage = function(theImageData) {
		var image = new ImageTile();
		image.construct(this, theImageData[0], theImageData[1], theImageData[2], theImageData[3], theImageData[4]);
		Array_addElement(this.images, image);
	}
	ImageList.prototype.loadImageData = function(imageData) {
		for (var i = 0; i < imgData.length; i++) {
			imageList.addImage(imgData[i]);
		}
	}
	
	ImageList.prototype.getID         = function()     { return this.id; }
	ImageList.prototype.getHeight     = function()     { return Windowing.Height(this.div); }
	ImageList.prototype.setHeight     = function(h)    { Windowing.Height(this.div, h); return this;}
	ImageList.prototype.getWidth      = function()     { return Windowing.Width(this.div); }
	ImageList.prototype.setLocation   = function(x, y) { Windowing.Move(this.div, x, y); }
	ImageList.prototype.setSize       = function(w, h) { Windowing.Resize(this.div, w, h); }
	ImageList.prototype.setBackground = function(backcolor) { 
		Windowing.Background(this.div, backcolor); 
	}
	ImageList.prototype.setVisible = function(visible) { Windowing.Visibility(this.div, visible); }
	ImageList.prototype.setSelected = function(imageTile) {
		for (var i = 0; i < this.images.length; i++) {
			var image = this.images[i];
			image.setSelected(image == imageTile);
		}
		this.hidden = Windowing.CreateElement("div", this.id + "_Hidden", "Hidden")
	    this.div.appendChild(this.hidden);
	}

	ImageList.prototype.buttonSizerPressed = function(size, holdWidthConstant, showPopup) {
		var w = width/size;
		var h = height/size;
		this.resizeImages(w, h, holdWidthConstant, showPopup);
	}

	ImageList.prototype.resizeImages = function(w, h, holdWidthConstant, showPopup) {
		for (var i = 0; i < this.images.length; i++) {
			var image = this.images[i];
			image.resize(w, h, holdWidthConstant, showPopup);
		}
	
	}
	ImageList.prototype.eventImageClick = function(image) {
	}


// Class ImageFrame
var ImageFrame = function(){}
	ImageFrame.prototype = new ImageTile;
	ImageFrame.prototype.construct = function(parent, id, imageWidth, imageHeight) {
		this.parent = parent;
		this.id = id;
		this.div = Windowing.CreateElement("div", name,  "ImageFrame")
	    this.setVisible(false);
	    this.image = Windowing.CreateElement("img", name + "Image",  "Image")
	    this.image.setAttribute("width", width);
	    this.image.setAttribute("height", height);
		this.div.appendChild(this.image);
		this.parent.appendChild(this.div);

		var pageX = Windowing.ScrollLeft(document);
		var pageY = Windowing.ScrollTop(document);
		var pageW = Windowing.ClientWidth();
		var pageH = Windowing.ClientHeight();
		
		this.left = pageX;
		this.top = pageY;
		this.width = pageW;
		this.height = pageH;
		
		this.desiredWidth = this.width - 30;
		this.desiredHeight = this.height - 60;
		
		this.div.onmousedown = this.eventMouseDown.bind(this);
	    this.setVisible(false);
	}
	ImageFrame.prototype.onunload = function() {
		try {
			this.parent.removeChild(this.div);
		} catch (e) {}
		try {
			this.div.removeChild(this.image);
		} catch (e) {}
		this.div.onmousedown = null;
		this.parent = this.id = this.div = this.image = null;
		this.left = this.top = this.width = this.height = this.desiredWidth = this.desiredHeight = null;
	}
	ImageFrame.prototype.setLocation = function(x, y) {
		Windowing.Move(this.div, x, y);
	}
	ImageFrame.prototype.setSize = function(w, h) {
		Windowing.Resize(this.div, w, h);
	}
	ImageFrame.prototype.setVisible = function(visible) {
		Windowing.Visibility(this.div, visible);
	}
	ImageFrame.prototype.eventMouseDown = function(e) {
		this.setVisible(false);
		this.onunload();
	}
	ImageFrame.prototype.center = function(imageWidth, imageHeight) {
		this.setLocation((this.width - imageWidth) / 2 + this.left, 
				         (this.height - imageHeight) / 2 + this.top);
	}
	ImageFrame.prototype.display = function(image) {
		var ratio = image.width/image.height;
	    var ratio2 = this.desiredWidth/this.desiredHeight;
		var imgwidth, imgheight;
		if (ratio > ratio2) {
			imgwidth = this.desiredWidth;
			imgheight = imgwidth / ratio;
		} else {
			imgheight = this.desiredHeight; 
			imgwidth = imgheight * ratio;
		}
		try {
			this.div.removeChild(this.image);
		} catch (e) { }
		this.image = Windowing.CreateElement("img", name + "Image",  "Image")
		this.image.setAttribute("src", "thumbs/large_" + image.name);
		this.image.setAttribute("width", imgwidth);
		this.image.setAttribute("height", imgheight);
		this.center(imgwidth, imgheight);		
		this.div.appendChild(this.image);
		this.setVisible(true);
	}
	


var width = Windowing.ClientWidth() - 40;
var height = Windowing.ClientHeight() - 40;
var working = false;
document.write('<DIV id="RootDiv"></DIV>');

Windowing.RootDiv = Windowing.GetElement("RootDiv");

var imageList = new ImageList();
imageList.construct(Windowing.RootDiv, "ImageList");
imageList.loadImageData(imgData);

	
