function Class(){};

Class.prototype.construct = function(){};

Class.extend = function(def){

    var classDef = function(){

        if (arguments[0] !== Class){

		this.construct.apply(this, arguments);
	};  
    };

    var proto = new this(Class);    
    var superClass = this.prototype;

    for (var n in def){

        var item = def[n];

        if (item instanceof Function){

		item.$ = superClass;

	} else classDef[n] = item;

        proto[n] = item;
    };

    classDef.prototype = proto;
    classDef.extend = this.extend;

    return classDef;
};

function getEventTarget(e){

    var e = e || window.event;

    var targ = e.target || e.srcElement;

    return targ;
};

function makeRequest(url, parameters, onComplete, obj){

    var http_request = false;

    try{

        http_request = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1){
       
	try {
            http_request= new ActiveXObject("Microsoft.XMLHTTP");

        } catch (e2){

            http_request = new XMLHttpRequest();
        };
    };

    if (!http_request){

      alert('Cannot create XMLHTTP instance');

      return false;
    };

    completeListener = function(){

        if (http_request.readyState == 4){

            if (http_request.status == 200){

                onComplete(http_request, obj);
            };
        };
    };

    var salt = Math.random();

    http_request.onreadystatechange = completeListener;

    http_request.open('GET', url + "?" + parameters + "&salt=" + salt, true);
    http_request.send(null);
};

var USER_DATA = {

    Browser:{

        KHTML: /Konqueror|KHTML/.test(navigator.userAgent) && !/Apple/.test(navigator.userAgent),
        Safari: /KHTML/.test(navigator.userAgent) && /Apple/.test(navigator.userAgent),
        Opera: !!window.opera, 
	MSIE: !!(window.attachEvent && !window.opera),
        Gecko: /Gecko/.test(navigator.userAgent) && !/Konqueror|KHTML/.test(navigator.userAgent)
    },

    OS:{

        Windows: navigator.platform.indexOf("Win") > -1,
        Mac: navigator.platform.indexOf("Mac") > -1,
        Linux: navigator.platform.indexOf("Linux") > -1
    }
};

Array.prototype.inArray = function (value){
      
	var i;
        for (i=0; i < this.length; i++){

                if (this[i] === value){

                        return true;
                };
        };

        return false;
};


Number.prototype.NaN0=function(){return isNaN(this)?0:this;};

var IS_IE = USER_DATA['Browser'].MSIE;

function getPosition(e){

    var left = 0;
    var top  = 0; 

    while (e.offsetParent){

        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0); 

        top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

        e = e.offsetParent;
    };

    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0); 

    top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0(): 0);

    return {x:left, y:top};
};

function getAlignedPosition(e) {

    var left = 0;
    var top  = 0;

    while (e.offsetParent){

        left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);

        top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

        e  = e.offsetParent;

        if(e.scrollLeft){

		left -= e.scrollLeft;
	};

        if(e.scrollTop){

		top  -= e.scrollTop;

	};
    };

    var docBody = document.documentElement ? document.documentElement : document.body;

    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0) +
        (IS_IE ? (parseInt(docBody.scrollLeft)).NaN0() : 0) - (parseInt(docBody.clientLeft)).NaN0();

    top  += e.offsetTop  + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0) +
        (IS_IE ? (parseInt(docBody.scrollTop)).NaN0() : 0) - (parseInt(docBody.clientTop)).NaN0();

    return {x:left, y:top};
};

function findOffsetHeight(e){

    var res = 0;

    while ((res == 0) && e.parentNode){

        e = e.parentNode;
        res = e.offsetHeight;
    };

    return res;
};

var IS_SAFARI = USER_DATA['Browser'].Safari;
var NS_SYMB = '_';

function getElmAttr(elm, attrName, ns){ 

    var elmValue = null;

    try{
        elmValue = (elm.getAttribute
                    ? elm.getAttribute((ns ? (ns + NS_SYMB) : '')
                    + attrName) : null);

    } catch (e){ 

	return null; 
    }

    if (!elmValue && IS_SAFARI){

        elmValue = (elm.getAttributeNS
                    ? elm.getAttributeNS(ns, attrName)
                    : null);
    };

    return elmValue;
};

function setElmAttr(elm, attrName, value, ns){

    if (!IS_SAFARI || !ns){

        return (elm.setAttribute ? elm.setAttribute((ns ? (ns + NS_SYMB) : '') + attrName, value) : null);

    } else {

        return (elm.setAttributeNS
                    ? elm.setAttributeNS(ns, attrName, value)
                    : null);
    };
};

function $(elementId){

	if(document.layers){
		
		if(typeof elementId == "string"){
			
			return document.layers(elementId);

		} else {
		
			return elementId;
		};
	};
	
	if(document.all){

		if(typeof elementId == "string"){
			
			if(document.all(elementId) != null){
					
				return document.all(elementId);
					
			} else {

				return null;
			};
		
		} else { 
				
			return elementId;
		};
	};
		
	if(document.getElementById){

		if(typeof elementId == "string"){

			return document.getElementById(elementId);
			
		} else {

			return elementId;
		};
	};

		return null;
}

function show(element){

    element.style.display = 'block';
};

function hide(element){

    if (element.style.display != 'none'){

       element.style.display  = 'none';
    };
};var ListScroll = Class.extend({

	construct:function(conteinerId, lineId, control){

		var conteiner = $(conteinerId);
		this.cHeight = conteiner.offsetHeight;
	
		this.line = $(lineId);
		this.control = control;	
		
		var controlEl = $(control.id);
		var obj = this;
		
		this.interval = null;
		
		var down = $(this.control.down);
		down.className = 'd-disabled';
		
		this.d_act = false;
		this.t_act = false;		
		
		if(this.line.offsetHeight <= this.cHeight){

			var top = $(this.control.top);			
			top.className = 't-disabled';
		
		} else {
		
			controlEl.onmousedown = function(e){obj.move(e)};
			controlEl.onmouseup = function(){obj.stop()};
			controlEl.onmouseout = function(){obj.stop()};
		}
	},
		
	move:function(e){
			
		var target = getEventTarget(e);
		
		if(!target){
		
			return;
		} 
		
		if(target.id == this.control.top){
		
			this._top();
				
		} else if(target.id == this.control.down){
		
			this._down();
		}
		
	},

	stop:function(){
	
		clearInterval(this.interval);
		this.interval = null;
		
		if(this.t_act){
			
			var top  = $(this.control.top);
			top.className = 't';
		}

		if(this.d_act){
			
			var down  = $(this.control.down);
			down.className = 'd';
		}		
	},
	
	_down:function(){

		var offset = this.line.offsetHeight + this.line.offsetTop;
		
		if(offset >= this.line.offsetHeight){
		
			this.d_act = false;
		
			this.stop();
			
			var down = $(this.control.down);			
			down.className = 'd-disabled';
			
			return;
		}
	
		this.line.style.top = this.line.offsetTop + 4 + 'px';
		
		if(!this.interval){
		
			this.d_act = true;
			
			var down = $(this.control.down);			
			down.className = 'd-current';			
		
			var top = $(this.control.top);			
			top.className = 't';
		
			var obj = this;
			
			this.interval = setInterval(function(){obj._down()}, 10);
		}
	},
	
	_top:function(){
	
		var offset = this.line.offsetHeight + this.line.offsetTop;

		if(this.cHeight >= offset){
		
			this.t_act = false;
		
			this.stop();
			
			var top = $(this.control.top);			
			top.className = 't-disabled';
			
			return;
		}
	
		this.line.style.top = this.line.offsetTop - 4 + 'px';
		
		if(!this.interval){
		
			this.t_act = true;
			
			var top = $(this.control.top);
			top.className = 't-current';
			
			var down = $(this.control.down);			
			down.className = 'd';
		
			var obj = this;
			
			this.interval = setInterval(function(){obj._top()}, 10);
		}
	}

});var SendForm = Class.extend({

	construct:function(formId, alerts){
	
		this.form = $(formId);
		this.alerts = alerts;
		
		var obj = this;
		
		this.form.control.onclick = function(){obj.send()};	
	},

	send:function(){
		
		makeRequest("/ajax/send_form/", 
						"name=" + this.form.name.value + 
						"&email=" + this.form.email.value + 
						"&subject=" + this.form.subject.value +
						"&body=" + this.form.body.value +
						"&captcha=" + this.form.captcha.value, this.result, this);
	
		this.form.name.disabled = true;
		this.form.email.disabled = true;
		this.form.subject.disabled = true;
		this.form.body.disabled = true;
		this.form.captcha.disabled = true;
		this.form.control.disabled = true;
	},
	
	result:function(res, obj){

		obj.form.name.disabled = false;
		obj.form.email.disabled = false;
		obj.form.subject.disabled = false;
		obj.form.body.disabled = false;
		obj.form.captcha.disabled = false;
		obj.form.control.disabled = false;
	
		var error = $(obj.alerts.error);
		var sent = $(obj.alerts.sent);
	
		if(res.responseText != "ok"){
		
			hide(sent);
			show(error);
			
			error.innerHTML = res.responseText;
		
		} else {
		
			obj.form.name.value = "";
			obj.form.email.value = "";
			obj.form.subject.value = "";
			obj.form.body.value = "";
			obj.form.captcha.value = "";
		
			hide(error);
			show(sent);
		}
	}
});function fixPNG(element)
{
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
	{
		var src;
		
		if (element.tagName=='IMG')
		{
			if (/\.png$/.test(element.src))
			{
				src = element.src;
				element.src = "/img/site/blank.gif";
			}
		}
		else
		{
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src)
			{
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	};
};var MenuCloseOpen = Class.extend({

	construct:function(containerId, controlId, controlledId, old){

		var obj = this;
		var conteiner = $(containerId);

		this.containerId = containerId;
		this.controlId = controlId;
		this.controlledId = controlledId;
				
		this.oldControlled = old;				


		conteiner.onclick = function(e){obj.click(e)};
	},

	click:function(e){

		
		var target = getEventTarget(e);

		if(this.controlId == target.id.substr(0, this.controlId.length)){

			var id = target.id.substr(this.controlId.length);
			var control = $(this.controlledId + id);

			if(id == this.oldControlled && control.style.display == 'none'){

				show(control);

			} else if(id == this.oldControlled && control.style.display == 'block'){


				hide(control);
			
			} else {


				hide($(this.controlledId + this.oldControlled));
				show(control);
			}

			this.oldControlled = id;
					
		}
	}
});