/*  Prototype JavaScript framework
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
/*--------------------------------------------------------------------------*/

//note: modified & stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
	var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhiteSpace: function(element) {
		element = $(element);
		$c(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	},

	find: function(element, what) {
		element = $(element)[what];
		while (element.nodeType != 1) element = element[what];
		return element;
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = [];
	$c(children).each(function(child){
		if (Element.hasClassName(child, className)) elements.push(child);
	});  
	return elements;
}

//useful array functions
Array.prototype.each = function(func){
	for(var i=0;ob=this[i];i++) func(ob, i);
}

function $c(array){
	var nArray = [];
	for (i=0;el=array[i];i++) nArray.push(el);
	return nArray;
}

panel = Class.create();
panel.prototype = {
        initialize: function(id, options){
                this.panelId = id;
                this.panelTitle = options.title;
                this.panelX = options.X || 0;
                this.panelY = options.Y || 200;
                this.panelW = options.W || 200;
                this.panelH = options.H || 200;
                this.handle = 'hId'+Math.random();
                this.follow = ((options.follow==null)?Offset.Y():0);
                this.align = options.align || 'center';
                this.bodyWidth = Offset.W();
                switch (this.align){
                	case 'center': this.panelX += (this.bodyWidth/2)-(this.panelW/2);break;	
                	case 'right': this.panelX += (this.bodyWidth)-(this.panelW)-20;break;
                }
                this.overFlow = options.overFlow || "auto";
                this.newAjax = options.call || null;
                this.panelContent = options.content || '';
                this.draw();
        },

        draw: function(){
                if(!$(this.panelId)){
                        var total = '<div class="panel" id="' + this.panelId + '" style="position:absolute;left: ' +  this.panelX + 'px; top: ' +  (this.panelY+this.follow)  + 'px;width:' + this.panelW + 'px;">';
                                total += '<div id="'+this.handle+'" onmouseover="this.style.cursor=\'pointer\'"><div class="panelTitle">' + this.panelTitle ;
                                        total += '<div style="position:absolute;left:0;top:2px;"><div onClick="panelController.close(\''+this.panelId+'\');" class="panelIcon">x</div></div>'; //<img class="panelIcon"  src="images/cross.gif" />
                                total += '</div></div>';

                                total += '<div class="panelBody"><div class="panelText" id="' + this.panelId + 'Content" style="height:' + this.panelH + 'px;overflow:' + this.overFlow + ';">' + this.panelContent + '</div></div>';
                        total += '</div>';
                        var createElement = document.createElement("div");
                        createElement.innerHTML =total;
                        createElement.position = "absolute";
                        document.body.appendChild(createElement);
                        Drag.init($(this.handle),$(this.panelId));
                        if(this.newAjax)
                         setTimeout(function(){this.newAjax();}.bind(this), 10);
                }
                else{
                        panelController.close(this.panelId);
                }
        }
}

var panelController = {
        close: function(id){
                 $(id).parentNode.removeChild($(id));
        }
}

var getMouse = {
	X:function (event) {
	if (event.pageX) return event.pageX;
	else if (event.clientX)
	   return event.clientX + Offset.X();
	else return null;
	},
	Y: function (event) {
	if (event.pageY) return event.pageY;
	else if (event.clientY)
	   return event.clientY + Offset.Y();
	else return null;
	}	
}
var Offset = {
	X: function (){
	         if (window.innerWidth)
	                  return window.pageXOffset;
	         else if (document.documentElement && document.documentElement.scrollLeft)
	                 return document.documentElement.scrollLeft;
	         else
	                 return document.body.scrollLeft;
	},
	Y: function (){
	         if (window.innerHeight)
	                  return window.pageYOffset;
	         else if (document.documentElement && document.documentElement.scrollTop)
	                 return document.documentElement.scrollTop;
	         else
	                 return document.body.scrollTop
	},
	W: function (){
	         if (window.innerWidth)
	                  return window.innerWidth;
	         else
	                 return document.body.offsetWidth;
	},
	H: function (){
	         if (window.innerHeight)
	                  return window.innerHeight;
	         else
	                 return document.body.offsetHeight;
	}
}
/**************************************************
 * 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;
        }
};





ajax = Class.create();
ajax.prototype = {
        initialize: function(url, options){
                this.trigger = options.trigger || null;
                if(this.trigger) setTimeout(function(){this.trigger();}.bind(this), 10);
                this.transport = this.getTransport();
                this.form = options.form || null;
                this.args = options.args || (this.form!=null?this.getFormData($(this.form)):'');
                this.type = options.type || '';
                this.method = options.method || 'post';
                this.onComplete = options.onComplete || null;
                this.update=this.type=='script'?this.newScript():$(options.update) || null;
                this.request(url);
        },request: function(url){
                var args=this.method=='get'?'&'+this.args:'';
                this.transport.open(this.method, url+args, true);
                this.transport.onreadystatechange = this.onStateChange.bind(this);
                if (this.method == 'post') {
                        this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
                        if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
                }this.transport.send(this.args);
        },onStateChange: function(){
                if (this.transport.readyState == 4 && this.transport.status == 200) {
                        if (this.update){
                                var rT=this.transport.responseText;
                                setTimeout(function(){this.type=='script'? this.update.text=rT:this.update.innerHTML=rT;}.bind(this), 10);
                        }
                        if (this.onComplete)
                                setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
                        this.transport.onreadystatechange = function(){};
                }
        },getTransport: function() {
                if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
                else if (window.XMLHttpRequest) return new XMLHttpRequest();
                else return false;
        },newScript: function(){
                 var js = document.createElement('script');
                 js.type = 'text/javascript';
                 document.body.appendChild(js);
                 return js;
        },getFormData: function(frm) {
                  var args='';
                  var formEls=['input','textarea','select'];
                  for(var j=0;j<formEls.length;j++){
                           var el = frm.getElementsByTagName(formEls[j]);
                           for(var i=0;i<el.length;i++) {
                                 if((el[i].type!='radio' && el[i].type!='checkbox') || el[i].checked)
                                    args+=el[i].name+'='+this.urlEncode(el[i].value)+'&';
                           }
                  }return args+'unCache='+Math.random();
        },urlEncode: function(s) {
                  return s.replace(/\r\n|\r/g, '%5Cn').replace(/&/g,'%26');
        }
};

function menuHover(id,act){
	$('bgImage').style.display='none';
	for(i=0;i<menu.length;i++)
		if($(menu[i]))
			$(menu[i]).style.display='none';
	if(act==undefined){
		$('bgImage').style.display='block';
		$('bgImage').style.zIndex = 15;
		$(id).style.zIndex = 20;
		$(id).style.display='block';
	}
}

