
var _=function(root, query){
	if(!root) return undefined;
	
	if(JJ.type(root, "Function")) return JJ.onloadFunctions[JJ.onloadFunctions.length]=root;
	
	if(JJ.type(root, "Event")) return new Event(root);
	
	if(JJ.type(root, "String")){
		var el;
		if(/^#?[a-z0-9_]+$/i.test(root)) el=document.getElementById(root.replace(/#/,"")); //root as id
		if(el) root=el;
		else{query=root; root=document;} //root as query
	}
		
	if(!query && root._extended) return root;
	var els=root;
	if(query) els=JJ.getElements.parse(query, root);
	
	if(!els) els=""; //if no element return empty string
	
	JJ.extend(els, JJ.element); //exend one element
	
	if(JJ.type(els, "Array")) JJ.foreach(els, function(){ JJ.extend(this, JJ.element)}); //exend elements group (array object)
	
	return els;
};



//-------------------------------------------- JJ ------------------------------------------------
var JJ={};

	
JJ.onloadFunctions=[];
JJ.onload=function(){
	if(document.attachEvent && document.readyState!=="complete" ) return false;

	if(arguments.callee.inited) return false;
	else arguments.callee.inited=1;
	//alert((new Date).getTime()-ttt1)
	//alert(document.body)
	if(!JJ.onloadFunctions.length) return false;
	else for(var i=0, l=JJ.onloadFunctions.length; i<l; i++) JJ.onloadFunctions[i](); 
};

if(document.addEventListener){
	document.addEventListener("DOMContentLoaded", JJ.onload, false);
	window.addEventListener( "load", JJ.onload, false );
}else if(document.attachEvent){
	//document.write('<script type="text/javascript" defer="defer">setTimeout(function(){JJ.onload()},10)</'+'script>');
	document.attachEvent("onreadystatechange", JJ.onload);
	window.attachEvent("onload", JJ.onload);
}


_.type=JJ.type=function(obj, _type){
	var t=typeof obj;
	if(!_type) return t;
	if(obj==undefined) return _type==undefined;
	_type=_type.toLowerCase();
	switch(_type){
		case "object":   return obj.constructor==Object;
		case "array":    return obj.constructor==Array; //t=="object" && obj.length; 
		case "number":   return t=="number" || !isNaN(obj);
		case "element":  return t=="object" && obj.nodeType==1;
		case "date":     return obj.constructor==Date;
		case "string":     return obj.constructor==String;
		case "boolean":     return obj.constructor==Boolean;
		case "event":     return obj.srcElement || (obj.target &&  obj.bubbles!=undefined);
		case "function":     return t=="function";
		default: return t==_type; 
	}
};
JJ.foreach=function(obj, func){
	if(!JJ.type(obj, "Array")) return func.call(obj);
	for(var i=0, arr=[], l=obj.length; i<l; i++)
		arr.push(func.call(obj[i], i));
	return arr;
};
JJ.extend=function(obj, methods){
	var call=function(obj, name, args){
		if(!JJ.type(obj, "Array") || name=="repeat"){
			return methods[name].exec(obj, args[0], args[1], args[2], args[3]);
		}
		else{
			//execute functions and return elements
			var res=JJ.foreach(obj, function(){ return methods[name].exec(this, args[0], args[1], args[2], args[3])});
			if(res[0]){
				if(res[0]._extended) JJ.extend(res, methods); //re-extend root element
				
				//play elements group events (overload result with functions)
				if(JJ.type(res[0], "Function") && name=="event"){ 
					var _res=res; 
					res=function(){
						for(var i=0, l=_res.length; i<l; i++) 
							if(_res[i]) 
								_res[i].apply(obj[i], arguments); 
					};
				}
			}
			return res;
		}
	};
	var attach=function(obj, name){
		//attach property to element or to elements group
		obj[name]=function(){return call(this, name, arguments)};
	};
	
	if(obj._extended) return false;
	obj._extended=true;
	for(var i in methods) attach(obj, i);
	
	return obj;
};

//wait for loading needed function or from other file
JJ.wait=function(func){
	try{ func() }catch(e){ setTimeout(func,10) }
};

_.create=JJ.create=function(tag){
	return JJ.extend(document.createElement(tag), JJ.element);
};


/*
Find Elements in DOM
	"*"                   //any tags
	"h1"                  //all <h1>
	"p a"                 //all nesting childs A <p><b><a>
	"p>a"                 //all siblings A <p><a>
	"p>*"                 //all siblings
	"p a, div a"          //multiply selection
	"#id"                 //id="id"
	".classname"          //class="classname"
	"[attr]"              //has this attr
	"[!attr]"             //hasn't this attr
	"[attr=value]"        //attr=value
	"[attr!=value]"       //attr!=value
	":^" ":0"             //first child
	":$"                  //last child
	":4"                  //child in position 4 (from 0)
	"<"                   //parent node
	"<div.classname"      //search div parent node with className
	"<:1"                 //return second parent node
	"+a"                  //next sibling element
	"+a:2"                //next (nearest with position) sibling element
	"-.classname"         //previous sibling element
	"()"                  //groups...
	["p a"]               //return array of <a> (even if one element found)
*/
JJ.getElements={
	parse:function(query, root){
		var return_array_reqired=false;
		if(JJ.type(query, "array")){
			query=query[0];
			return_array_reqired=true;
		}
		query=query.replace(/((^)|([ ><+\-,]))(([#.:\[,])|($))/g, "$1*$4")+" "; //set * for any tag
		root=root || document;
		
		var sep=" ><+-,", //levels separations
			breakset=" ><+-,:[", // breakset for conditions
			cond={"#":  breakset, ".":  breakset, ":":  breakset, "[":  "]"}, //out of fit condition
			prop={"#":"id", ".":"className", ":":"pos", "[":"attr", "<":"parentNode", "+":"nextSibling", "-":"previousSibling"}, //operations

			i=-1, c, fit, match, root_arr=[root], multi_arr=[], len=query.length;
		while(c=query.charAt(++i)){
			if(fit){
				if(cond[fit].indexOf(c)!=-1){ //out from fit
					fit=null;
					if(c=="]") match.attr=this.attr2struct(match.attr); //parse attribute
					else i--;
					continue;
				}
				match[prop[fit]]+=c; //add filter chars if in fit
			}
			else{
				if(sep.indexOf(c)!=-1){//if find separator
					if(match){
						this.init_match(match);
						root_arr=this.walk(match, root_arr); //search previous match
					}
					if(c==","){ //set next matches set
						multi_arr=multi_arr.concat(root_arr);
						root_arr=[root];
						match=null; 
						continue;
					}
					if(i==len-1) break; //exit if this is last instruction
					match={tag:"", child:c!=" ", move_to:prop[c]}; //init match if first sep
					continue;
				}
				if(!match){ //init match if first tag
					match={tag:c, child:false};
					continue;
				}
				if(c in cond){ //find filter fit
					match[prop[fit=c]]=""; //init current filter & set current prop
					continue;
				}
				match.tag+=c;
			}
		}
		if(multi_arr.length) root_arr=multi_arr.concat(root_arr);
			////alert(MATCH_DEBUG+"\n"+(root_arr.length==1?root_arr[0]:root_arr));
		return root_arr.length==1 && !return_array_reqired?root_arr[0]:(root_arr[0]?root_arr:undefined); //element or array
	},
	walk:function(match, root_arr){
			////MATCH_DEBUG.push(match);
		var root_el, i=0, new_arr=[];
		while(root_el=root_arr[i++]){
			var el, j=0, match_arr=[];
			if(match.only_id){
				if(el=document.getElementById(match.id)) new_arr[new_arr.length]=el;
				continue;
			}
			if(match.move_to){
				if(el=this.move(match, root_el)) new_arr[new_arr.length]=el;
				continue;
			}
			var nodes=match.child?root_el.childNodes:root_el.getElementsByTagName(match.tag); //get elements
			//filter nodes
			while(el=nodes[j++]){
				if(match.single_tag || this.check_filters(match, el))
					match_arr[match_arr.length]=el;
			}
			//position filter 
			if(match.pos){
				if(el=this.pos(match, match_arr)) new_arr[new_arr.length]=el;
				continue;
			}
			new_arr=new_arr.concat(match_arr); //add all mathes to array
		}
		return new_arr;
	},
	init_match:function(match){
		match.tag=match.tag.toUpperCase();
		if(match.tag=="*" && match.id && !match.className && !match.attr) match.only_id=1;
		if(!match.id && !match.className && !match.attr) match.no_prop=1;
		if(!match.child && match.no_prop) match.single_tag=1;
	},
	check_filters:function(match, el){
		if(match.child && (el.nodeType!=1 || (match.tag!="*" && match.tag!=el.tagName))) return false;
		if(match.no_prop) return true; //fast instruction [no_prop]
		if(match.id && match.id!=el.id) return false;
		if(match.className && !JJ.element.classname.exist(el, match.className)) return false;
		if(match.attr){
			var attr=JJ.element.attr.get(el, match.attr.key, 1);
			if(match.attr.equal==false && attr!=match.attr.value) return false;
			if(match.attr.equal==true && attr==match.attr.value) return false;
		}
		return true;
	},
	attr2struct:function(expr){
		var equal;
		if(expr.indexOf("!")==0){ expr=[expr.substr(1)]; equal=false;}
		else if(expr.indexOf("!")>0){ expr=expr.split("!="); equal=true;}
		else if(expr.indexOf("=")!=-1){ expr=expr.split("="); equal=false;}
		else {expr=[expr]; equal=true;}
		return {key:expr[0], value:expr[1], equal:equal};
	},
	pos:function(match, match_arr){ //return element by some position
		var pos;
		if(match.pos=="^") pos=0;
		else if(match.pos=="$") pos=match_arr.length-1;
		else if(JJ.type(match.pos, "Number")) pos=Number(match.pos);
		if(pos!=undefined && pos<match_arr.length) return match_arr[pos]; //match element
		return;
	},
	move:function(match, el){ //go to parentNode||nextSibling||previousSibling
		var pos=0;
		while(el=el[match.move_to])
			if(this.check_filters(match, el))
				if(Number(match.pos||0)==pos++) 
					break;
		return el;
	}
};

//Base methods for elements-----------------------------------------------------------------
JJ.element={};


/*
*Element foreach function
*(function(){})
*/
JJ.element.repeat={
	exec:function(obj, func){
		if(JJ.type(obj, "String")) return obj; //check obj for compatibility
		JJ.foreach(obj, func);
		return obj;
	}
};



/*
*Element attributes functions
*("id")                         //get attribute  #String
*(["id", "name", "href"])       //get attributes  #Hash
*("id", "ppp")                  //set attribute "id"="ppp"  #Element
*({name:"abc", param:1})        //set attributes from hash  #Element
*/
JJ.element.attr={
	exec:function(obj, name, value){
		if(JJ.type(obj, "String")) return obj; //check obj for compatibility
		if(JJ.type(name, "String")){
			if(value!=undefined) return this.set(obj, name, value);
			else return this.get(obj, name);
		}
		else if(JJ.type(name, "Object")){
			for(var i in name)
				this.set(obj, i, name[i]);
			return obj;
		}
		else if(JJ.type(name, "Array")){
			var hash={};
			for(var i=0, l=name.length; i<l; i++)
				hash[name[i]]=this.get(obj, name[i]);
			return hash;
		}
	},
	get:function(obj, name, only_tag_attr){
		var attr=obj.getAttribute?obj.getAttribute(name):undefined;
		if(attr==undefined && !only_tag_attr) attr=obj[name];
		if(attr=='' && obj.attributes && obj.attributes[name] && !obj.attributes[name].specified) attr=undefined; //for IE 
		return attr;
	},
	set:function(obj, name, value){
		if(obj.setAttribute && !JJ.type(value, "Function")) obj.setAttribute(name, value);
		obj[name]=value;
		return obj;
	}
};


/*
*Element events functions
*("onclick", function(){})                      //set event  #Element
*("onclick", "alert(1)")                        //set event  #Element
*({onclick:function(){}, onblur:"alert(1)"})    //set event set  #Element
*("onclick", null)                              //remove event  #Element
*("oncomplete")                                 //return event  #Function [default]
*("oncomplete(arg1, arg2,... )")            //return event and init arguments  #Function [default]
*("oncomplete(:Array)")                         //return all event entries  #Array of functions
*("oncomplete(:String)")                        //return event body  #String
*(["onclick","oncomplete"])                     //return set of events in Array #Array of functions [default]
*/
JJ.element.event={
	exec:function(obj, name, value){
		if(!obj) return value!==undefined?obj:function(){};
		//if(!obj.attachEvent && !obj.addEventListener) return value!==undefined?obj:function(){}; //check obj for compatibility
		
		if(JJ.type(name, "String")){
			if(value!==undefined) return this.set(obj, name, value);
			else return this.get(obj, name); 
		}
		else if(JJ.type(name, "Object")){
			for(var i in name)
				this.set(obj, i, name[i]);
			return obj;
		}
		else if(JJ.type(name, "Array")){
			var hash={};
			for(var i=0, l=name.length; i<l; i++)
				hash[name[i]]=this.get(obj, name[i]);
			return hash;
		}
	},
	set:function(obj, ev, func){
		if(func===null) return this.remove(obj, ev);
		var prev_func=this.get(obj, ev);
		func=this.toFunc(func, obj);
		var call=function(_this, args){
			if(prev_func) prev_func.apply(_this, args);
			return func.apply(_this, args);
		};
		this.rec(obj, ev, func); //write event to data array _onevent_=[]
		obj[ev]=function(){return call(this, arguments)}; //reinit element event
		if(ev=='onmousewheel' && obj.addEventListener){
			obj.addEventListener('DOMMouseScroll', obj[ev], false);
			obj.removeEventListener('DOMMouseScroll', prev_func, false);
		}
		return obj;
	},
	get:function(obj, ev){
		if(ev.indexOf("(")!=-1){
			var param=ev.split("(");
			ev=param[0];
			var _return=param[1].substr(0, param[1].length-1);
			var args="";
			switch(_return){
				case ":String": return this.toStr(obj["_"+ev+"_"]);
				case ":Array": return obj["_"+ev+"_"];
				default: args=_return;
			}
		}
		var attr=JJ.element.attr.get(obj, ev);
		var func=this.toFunc(attr, obj, args);
		return func;
	},
	remove:function(obj, ev){
		obj[ev]=function(){};
		return obj;
	},
	toFunc:function(attr, obj, args){
		var func;
		if(!attr) return function(){};
		if(JJ.type(attr, "String")) func=new Function(args, attr);
		else func=attr;
		return function(){return func.apply(obj, arguments)};
	},
	toStr:function(_evs){
		if(!_evs) return '';
		var str='';
		for(var i=0, l=_evs.length; i<l; i++){
			var s=_evs[i].toString();
			s=s.replace(/^function[^{]*\{(.*)/gi,"$1");
			s=s.substr(0, s.length-2);
			str+=s+"\n";
		}
		str=str.replace(/;([^\n])/gi,";\n$1");
		return str;
	},
	rec:function(obj, ev, func){

		var _ev="_"+ev+"_";
		if(!obj[_ev]){
			obj[_ev]=[];
			var prev_func=this.get(obj, ev);
			if(prev_func) obj[_ev].push(prev_func);
		}
		obj[_ev].push(func);
	}
};


/*
*Element styles functions (with isNaN check)
*("top")                           //get: "top"  #String or #Number
*(["top", "left"])                 //get: ["top", "left"]  #Hash     
*(["marginLeft", "height"], true)  //get all not empty: ["height"]  #Hash     
*("top", "20")                     //set: "top"="20px"  #Element
*("display", "none", "block")      //toogle: if(display==none) display=block  #Element
*({top:100,left:50})               //set: {top:"20px", left:"10px"}  #Element
*/
JJ.element.css={
	exec:function(obj, name, value, value2){
		if(!JJ.type(obj, "Element")) return obj; //check obj for compatibility
		if(JJ.type(name, "String")){
			if(value!=undefined){
				if(value2!=undefined && this.get(obj, name)==value) value=value2;
				return this.set(obj, name, value);
			}
			else return this.get(obj, name); 
		}
		else if(JJ.type(name, "Object")){
			for(var i in name)
				this.set(obj, i, name[i]);
			return obj;
		}
		else if(JJ.type(name, "Array")){
			var hash={};
			for(var i=0, l=name.length; i<l; i++){
				var val=this.get(obj, name[i]);
				if(!val && value) continue; //if (["top", "left"], true) - return only not empty values 
				hash[name[i]]=val;
			}
			return hash;
		}
	},
	//convert js style property to css property (zIndex -> z-index)
	js2css:function(prop){
		return prop.replace(/([A-Z])/g,"-$1").toLowerCase();
	},
	//get style
	get:function(obj, name){
		var value;
		if(obj.currentStyle) value=obj.currentStyle[name]; //IE, opera
		else if(window.getComputedStyle) value=window.getComputedStyle(obj, null).getPropertyValue(this.js2css(name)); //other Gesco
		else value=obj.style[name]; //other
		if(/^[0-9]+px/.test(value)) value=parseInt(value); //remove "px" [default] from number
		return value;
	},
	//set style 
	set:function(obj, name, value){
		var is_unsigned={"width":1, "height":1};
		if(name in is_unsigned && value<0) value=0; 
		var no_px={"zIndex":1, "opacity":1};
		if(value && JJ.type(value, "Number") && !(name in no_px)) value+="px"; //add "px" [default] to number
		if(name=="opacity" && BROWSER.ie){
			name="filter";
			value=(value==1?"":"Alpha(opacity="+(value*100)+")");
		}
		if(name=="float") name=BROWSER.ie?"styleFloat":"cssFloat";
		try{obj.style[name]=value;}catch(e){throw "element.css.set() -> obj.style."+name+"="+value; };
		return obj;
	},
	//check style
	check:function(obj, name){
		return true;
	}
};


/*
*Element className functions
*()             //get className  #String
*("*")          //get all defined names in className  #Array
*("^")          //get first name  #String
*("$")          //get last name  #String
*("+name")      //add name to className  #Element
*("-name")      //remove name from className  #Element
*("!name")      //toogle name  #Element
*("?name")      //check name existing  #Boolean
*("name")       //set className  #Element
*("")           //clear className  #Element
*/
JJ.element.classname={
	exec:function(obj, query, b){
		if(obj.className==undefined) return obj; //check obj for compatibility
		if(query==null) return obj.className;
		if(b!=undefined) query=(b?"+":"-")+query;
		var c=query.charAt(0);
		var name=query.substr(1);
		with(this){
			switch(c){
				case "*": return all(obj);
				case "^": return get(obj, 0);
				case "$": return get(obj, 1);
				case "+": add(obj, name); break;
				case "-": remove(obj, name); break;
				case "!": toogle(obj, name); break;
				case "?": return exist(obj, name);
				default:  set(obj, query);
			}
		}
		return obj;
	},
	empty:function(obj){
		return obj.className.replace(/\s/g,"")==""?true:false;
	},
	exist:function(obj, name){
		return (new RegExp('((^)|(\\s))'+name+'((\\s)|($))')).test(obj.className);
	},
	all:function(obj){
		return !this.empty(obj)?obj.className.split(/\s+/):[];
	},
	get:function(obj, pos){
		var arr=this.all(obj);
		if(!arr.length) return "";
		pos=pos?arr.length-1:0;
		return arr[pos];
	},
	set:function(obj, name){
		obj.className=name;
	},
	add:function(obj, name){
		this.remove(obj, name);
		obj.className+=obj.className?' '+name:name;
	},
	remove:function(obj, name){
		obj.className=obj.className.replace(new RegExp("((^)|(\\s))"+name+"((\\s)|($))"),"$3");
	},
	toogle:function(obj, name){
		this.exist(obj, name) ? this.remove(obj, name) : this.add(obj, name);
	}
};


/*
*Element insert functions
*("span")                       //append <span>
*("span:^")("span:0")           //insert <span> before first element
*("span:2")                     //insert <span> before second sibling
*("span", beforeElement)        //insert <span> before beforeElement
*("input", {type:"submit"})     //insert <input> and set attribute "type" before insert
*/
JJ.element.insert={
	exec:function(obj, tag, opt){
		if(!obj.appendChild) return obj; //check obj for compatibility
		var elem=tag;
		var beforeElement;
		if(JJ.type(tag, "String")){
			if(tag.indexOf(":")!=-1){
				var params=tag.split(":");
				tag=params[0];
				beforeElement=JJ.getElements.parse(">:"+params[1], obj);
			}
			elem=document.createElement(tag);
		}
		
		if(JJ.type(opt, "Object") && !opt.nodeType) JJ.element.attr.exec(elem, opt); //set element attributes before insert
		else beforeElement=opt; 
		
		beforeElement ? obj.insertBefore(elem, beforeElement) : obj.appendChild(elem);
		return _(elem);
	}
};

/*
*Element inner html
*("code")             //set innerHTML
*()                   //get innerHTML
*/
JJ.element.html={
	exec:function(obj, str){
		if(obj.innerHTML==undefined) return obj; //check obj for compatibility
		if(str==undefined) return obj.innerHTML;
		obj.innerHTML=str;
		return obj;
	}
};

/*
*Element remove function
*()                   //remove current element & return parent
*(child_el)           //remove child element & return current element
*/
JJ.element.remove={
	exec:function(obj, child_el){
		if(!obj.removeChild) return obj; //check obj for compatibility
		if(child_el==undefined){
			var par=obj.parentNode;
			par.removeChild(obj);
			return null;
		}
		else{
			var el=_(child_el);
			obj.removeChild(el);
			return obj;
		}
	}
};


/*
*Element activate or activate child (set classname="act")
*()                   //activate current element
*(2)                  //activate specified child element 
*/
JJ.element.act={
	exec:function(obj, num){
		var _this=this;
		if(!obj || !obj.tagName || !obj.parentNode) return false;
		if(obj.attr("noact")!=undefined) return false;
		var par=_(obj, "<");
		if(par.tagName=="LI" || par.tagName=="DT") par=_(par, "<");
		if(num!=undefined){
			par=obj; 
			obj=_(par, '>a:'+num);
		}
		if(!par.deact) par.deact=function(){_this.deact(this)}; //init funtion [set]
		if(par.cur==obj) return false;
		this.act(par, obj);
		obj.event("onact")(); //call [onact] event
		return obj;
	},
	
	act:function(par, obj){
		if(!par.cur) par.cur=_(par, ">a.act"); // if no [cur] try to find it
		if(par.cur) par.cur.classname("-act");
		obj.classname("+act");
		par.cur=obj;
		return par;
	},
	deact:function(par){
		if(!par.cur) return false;
		par.cur.classname("-act");
		par.cur=null; 
		return par;
	}
};


JJ.element.offset={
	exec:function(obj){
		var left=0, top=0;
		if(obj.getBoundingClientRect){
			var box=obj.getBoundingClientRect();
			left=box.left+Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
			top=box.top+Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		}
		else{
			
		}
		return {left:left, top:top};
	}
};



JJ.element.display={
	exec:function(obj, b, sender){
		var no_display=(obj.css("display")=="none");
		var no_visibility=(obj.css("visibility")=="hidden");
		if(!obj.display_default) obj.display_default=no_display?"block":obj.css("display");
		var b=(b==undefined?(no_display||no_visibility?1:0):b);
		obj.css({display:b?obj.display_default:"none"});
		return obj;
	}	
};

//element effects--------------------
JJ.element.slide={
	exec:function(obj, b, opt){
		if(!window.EFX) return JJ.element.display.exec(obj, b);
		var no_display=(obj.css("display")=="none");
		b=(b==undefined?(no_display?1:0):b);
		if(no_display==b) obj._slide=EFX.slide(obj, b, opt);
		//fade effect for Gesco
		if(obj._fade || obj.css("visibility")=="hidden"){
			if(!BROWSER.ie && !BROWSER.opera) obj.fade(b, opt);
			else obj.css({visibility:"visible"});
		}
		return obj;
	}
};
JJ.element.fade={
	exec:function(obj, b, opt){
		if(!window.EFX) return JJ.element.display.exec(obj, b);
		var no_visibility=(obj.css("visibility")=="hidden");
		b=(b==undefined?(no_visibility?1:0):b);
		if(no_visibility==b) obj._fade=EFX.fade(obj, b, opt || {dynamic:5});
		return obj;
	}
};
//---------------------------------------




//DOM extends
if(!String.prototype._extend) JJ.extend(String.prototype, JJ.element);




//Externals-----------------------------------------------------------

var BROWSER={
	ie:(document.all && !window.opera)?true:false,
	ie6:navigator.appVersion.indexOf("MSIE 6")!=-1,
	ie7:navigator.appVersion.indexOf("MSIE 7")!=-1,
	chrome:navigator.appVersion.indexOf("Chrome")!=-1,
	safari:navigator.appVersion.indexOf("Safari")!=-1 && navigator.appVersion.indexOf("Chrome")==-1,
	opera:window.opera
};



var Class=function(proto){
	var obj=function(){this.init.apply(this, arguments)};
	obj.prototype=proto;
	obj.prototype.constructor=obj;
	return obj;
};



var Event=Class({
	init:function(e){
		this.e=window.event?window.event:e;
	},
	key:function(key){
		if(typeof key=="string"){
			var sysKey={ctrl:1, shift:1, alt:1};
			var customKey={enter:13, escape:27, space:32, tab:9, left:37, up:38, right:39, down:40};
			if(key in sysKey) return this.e[key+"Key"];
			else if(key in customKey) key=customKey[key];
			else key=key.charCodeAt(0);
		}
		var code=window.event?this.e.keyCode:this.e.which; 
		return key!=undefined?code==key:code;
	},
	target:function(){
		var target=window.event?this.e.srcElement:this.e.target; 
		return target;
	},
	mouse:function(v){ 
		var c={
			x:window.event?this.e.clientX+document.documentElement.scrollLeft:this.e.pageX, 
			y:window.event?this.e.clientY+document.documentElement.scrollTop:this.e.pageY
		};
		return v!=undefined?c[v]:c;
	},
	prevent:function(){ 
		if(window.event){ this.e.cancelBubble=true; this.e.returnValue=false;} 
		else if(this.e.preventDefault) this.e.preventDefault();
		return false;
	},
	stop:function(){ 
		if(window.event){ this.e.cancelBubble=true; this.e.returnValue=false;} 
		else if(this.e.stopPropagation) this.e.stopPropagation();
		return false;
	}
});



var COOKIE={
	set:function(name, value, expire, path) {
		if(expire){
			var d=new Date();
			d.setTime(d.getTime()+expire*1000);
			expire="; expires="+d.toUTCString();
		}
		else expire="";
		var base=document.getElementsByTagName("base")[0];
		var base_path=base?base.href.replace(/https?:\/\/[^\/]+/, ""):"/";
		path=path||base_path;
		document.cookie=name+"="+escape(value)+expire+"; path="+path;
	},
	get:function(name) {
		if(document.cookie.length==0) return false;
		var offset=document.cookie.indexOf(name+"=");
		if(offset!=-1) { 
			offset+=name.length+1;
			var end=document.cookie.indexOf(";", offset);
			if (end==-1) end=document.cookie.length;
			return unescape(document.cookie.substring(offset, end)) 
		}
		return false;
	},
	all:function(arr){
		arr=arr || [];
		var i, cookieArray = document.cookie.split(';'), caLength = cookieArray.length, c, eqIndex, name, value;
		for (i = 0; i < caLength; i++) {
			c = cookieArray[i];
			
			// Left Trim spaces
			while (c.charAt(0) === " ") {
					c = c.substring(1, c.length);
			}
			eqIndex = c.indexOf("=");
			if (eqIndex > 0) {
					name = c.substring(0, eqIndex);
					value = c.substring(eqIndex + 1);
					arr[name] = value;
			}
		}
		return arr;
	}
};





//fix ie6 png & css :hover state
function ie6_fixes(root, prop){
	var base=_("base:^").href;
	_(root, "*").repeat(function(){
		if(!this || ! this.currentStyle) return;
		if(prop.png && this.currentStyle[prop.png]){
			var src=base+(window.GLOBAL_PATH?GLOBAL_PATH:"")+this.currentStyle[prop.png].replace(/url\(['"]?([^'"]*)['"]?\)$/i,"$1");
			this.css({filter:'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="'+src+'",sizingMethod='+'crop'+')', background:"none"});
		}
		if(prop.hover && this.currentStyle[prop.hover]) {
			this.event("onmouseover", function(){ Style(this).add(this.currentStyle[prop.hover]); });
			this.event("onmouseout", function(){ Style(this).remove(this.currentStyle[prop.hover]); });
		}
	});
};


function flashDetect(){
	if(typeof navigator.plugins!=undefined && typeof navigator.plugins["Shockwave Flash"]=="object"){
		var d=navigator.plugins["Shockwave Flash"].description;
		if (d && !(typeof navigator.mimeTypes!=undefined && navigator.mimeTypes["application/x-shockwave-flash"] && !navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin)){
			return true;
		}
	}
	else if(typeof window.ActiveXObject!=undefined) {
		try{
			var a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");  //return null when ActiveX is disabled
			if(a){
				var d=a.GetVariable("$version");
				if(d){
					return true;
				}
			}
		}
		catch(e){}
	}
	return false;
}


function ie_embed(obj){
	if(!BROWSER.ie) return false;
	var code='<object id="'+obj.name+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+obj.width+'" height="'+obj.height+'">';
	for(var i in obj.attributes){
		var item=obj.attributes[i];
		if(!item || !item.specified || (obj[item.name] && typeof obj[item.name]!="string" && typeof obj[item.name]!="boolean")) continue;
		if(item.name=="_extended" || item.name=="width" || item.name=="height" || item.name=="pluginspage" || item.name=="type") continue;
		var name=item.name=="src"?"movie":item.name;
		code+='<param name="'+name+'" value="'+item.value+'" />';
	}
	code+=obj.outerHTML;
	code+='</object>';
	obj.outerHTML=code;
};

function _uid(){
	return (new Date()).getTime()+Math.round(Math.random()*1000);
}



//debug output for Array & Hash objects
var o2s = function(o) {
	if(o.constructor == String) return o;
	var cont = [];
	var addslashes=function(s){return s.split('\\').join('\\\\').split('"').join('\\"');};
	for (var k in o) { 
		if (cont.length) cont[cont.length-1] += ",";
		var v = o[k];
		var vs = ''; 
		if (v.constructor == Object || v.constructor == Array) vs=o2s(v);
		else if (v.constructor == String) vs = '"' + addslashes(v) + '"';
		else  vs = v;
		cont[cont.length]=k + ": " + vs;
	}
	cont = "	" + cont.join("\n").split("\n").join("\n	");
	var s = cont;
	if (o.constructor == Object) s = "{\n"+cont+"\n}";
	if (o.constructor == Array) s = "[\n"+cont+"\n]";
	return s;
};


_alert=function(str){alert(o2s(str))};// GLOBAL PARAMETERS

var LANG="ua"; //default language

var APP_PATH="app/";
var GLOBAL_PATH="template/";
var IMGS_PATH=GLOBAL_PATH+"imgs/";

var AJAX_HANDLER=APP_PATH+"index.php?_ajax";
var CACHE_DEFAULT=60;  //default ajax cache [in minutes]
var DEBUGGER_ENABLED=1;

//© <stipuha /> development (2008)
//> AJAX
//-------------------------------- 
//  ___example#1___
//  (req=new Ajax()).onready=function(response){ready_func(response)};
//	req.file="index.php";
//	req.query="abc=123&def=456";
//	req.send();
//
//  ___example#2___
//	new Ajax({
//		file:"index.php", 
//		query:"abc=123&def=456",
//		onready:function(response){ready_func(response)},
//		send:1
//	});


var AJAX=Class({
	
	CACHE:{},
	
	init:function(opt){
		opt=opt || {};
		this.method=opt.method || "http";
		this.file=opt.file || "";
		this.query=opt.query || "";
		this.caching=opt.caching || false;
		this.hash=opt.hash || {};
		this.onready=opt.onready || function(){};
		if(opt.onready) this.send();
	},
		
	send:function(){
		//add hash to query
		this.query+=this.json2query(this.hash);
		//if cache==true > call data from cache & return
		try{if(this.caching && this.CACHE[this.query]) return this.ondata(this.CACHE[this.query]);}catch(e){};
		
		var _this=this;
		var request, response;
		var SID=(new Date()).getTime()+Math.round(Math.random()*1000);
		
		switch(this.method){
			case "http":
				request=window.XMLHttpRequest?new XMLHttpRequest():(new ActiveXObject("Msxml2.XMLHTTP") || null); // ||"Microsoft.XMLHTTP" - ie5x
				if(request){
					request.open('POST', this.file, true);
					request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // $_POST[] || $_REQUEST[]
					request.onreadystatechange=function(){
						if(request.readyState==4){
							try{
								if(request.getResponseHeader('Content-Type') && request.getResponseHeader('Content-Type').indexOf("/xml")!=-1) 
									response=_this.xml2json(request); //xml
								else 
									response=(new Function('return '+request.responseText))(); //json
							}
							catch(e){_this.onerror(request.responseText)}
							_this.ondata(response);
						}
					};
					request.send(this.query); //request send 
					break;
				}
				
			case "script":
				request=document.createElement("script");
				if(request){
					request.id=SID;
					var src=this.file+"?"+"_scriptID_="+request.id+"&"+this.query;
					if(BROWSER.ie) request.src=src.substr(0,2048); //MAX msie:2kb
					else{request.src=src; request.src=request.src.substr(0,4096)}; //MAX gesko:4Kb
					request.onreadystatechange=function(response){
						if(response && !response.initEvent){
							_this.ondata(response);
							setTimeout(function(){request.parentNode.removeChild(request)},13);
						}
					};
					document.body.appendChild(request); //request send 
					break;
				}
				
			case "form":
				var request=document.createElement(BROWSER.ie?"<iframe name="+this.form.name+">":"iframe");
				if(request){
					request.name=this.form.name;
					request.style.position="absolute";
					request.style.visibility="hidden";
					request.onreadystatechange=request.onload=function(response){
						if(!request.readyState || request.readyState=="complete"){
							_this.ondata((new Function('return '+request.contentWindow.document.body.innerHTML))());
							setTimeout(function(){request.parentNode.removeChild(request)},13);
						}
					};
					this.form.appendChild(request);
					this.form.submit(); //request send 
					break;
				}
				
			default: return request;
		}
	},
	
	ondata:function(response){
		if(this.caching || this.CACHE[this.query]) this.CACHE[this.query]=response; //cache response data
		this.response=response;
		this.onready(response);
	},
	
	json2query:function(hash, pref){
		var query="";
		for(var i in hash){
			if(!i) continue;
			var key=(pref?pref+"["+i+"]":i);
			query+=(typeof hash[i]=="object" ? this.json2query(hash[i],key) : "&"+key+"="+hash[i].toString().replace(/&/g, "%26").replace(/\+/g, "%2B"));
		}
		return query;
	},
	
	xml2json:function(request){
		var parseXML=function(node){
			if(node.childNodes.length==1 && (node.firstChild.nodeType==3 || node.firstChild.nodeType==4)) return node.firstChild.data; //if text node
			var hash={};
			for(var i=0, childs=node.childNodes, l=childs.length; i<l; i++)
				if(childs[i].nodeType==1)
					if(hash[childs[i].tagName]){ //if node has array type
						if(typeof hash[childs[i].tagName]=="string" || (typeof hash[childs[i].tagName]=="object" && !hash[childs[i].tagName].length)) 
							hash[childs[i].tagName]=[hash[childs[i].tagName]]; //reinit node (set array type)
						hash[childs[i].tagName][hash[childs[i].tagName].length]=parseXML(childs[i]);
						}
					else hash[childs[i].tagName]=parseXML(childs[i]);
			return hash;
		};
		var doc=BROWSER.ie?request.responseXML:(new DOMParser()).parseFromString(request.responseText, "text/xml"); //get XML content
		var response={obj:{}, text:''};
		if(doc && doc.documentElement) response.obj=parseXML(doc);
		return response;
	},
	
	onerror:function(message){alert("Server output error...\n"+message)}
});//<stipuha /> development (2008)
//--------------------------------
//CLIENT CONFIGURATION
//--------------------
// define aref="?key1=value&key2=(this.value)&key3=(func())" (get query)
// define target="uid123" (unique tag id for ajax content)
// define autoload (automatic send get query on load content)
// define onstarting="func()" (event calling before ajax sending)
// define oncomplete="func()" (event calling when content already loaded)

//SERVER CONFIGURATION
//--------------------
// define $RESPONSE["complete"]=1 (condition for execute oncomplete function after POST query)
// define $RESPONSE["alert"]="message message message" (condition for open system information popup)



//> HTMLAJAX functionality
//----------------------------------
var HTMLAJAX=Class({
	
	init:function(obj, ev){
		var _this=this;
		this.obj=_(obj);
		this.ev=ev;
		//init target
		var target=_(this.obj.attr("target"));
		if(target=="_self") this.target=this.obj;
		else if(target=="_parent") this.target=_(this.obj.parentNode);
		else this.target=_(target);
		//init vars
		this.append=this.obj.attr("append");
		this.indicatorShow=this.target?this.target.attr("indicator"):0;
		this.onstarting=this.obj.event("onstarting(event, request)");
		this.oncomplete=this.obj.event("oncomplete(response)");
		this.onfailure=this.obj.event("onfailure(response)");	

		//init ajax
		(this.req=new AJAX()).onready=function(response){_this.onready(response)};
		this.cache_time=this.obj.attr("cache");
		return this;
	},
	exec:function(){
		if(this.target) this.target.call_func=this.constructor.lastCall; //attach call ajax on target
		
		//execute sender callback function
		if(this.onstarting(this.ev, this.req.hash)==false) return false; //break if onstarting event return false
		
		//execute predefined basic operations
		if(this.constructor.onrequest(this.req.hash, this)==false) return false; //break if onbeforesend function  return false
		
		
		
		//try to set cache
		if(this.cache_time) this.constructor.cache.set(this.cache_time, this.req, this.obj); 
		
		this.indicator(1);
		
		if(this.obj.in_process) return false;
		this.obj.in_process=true;
		
		this.req.send();
		return false;
	},
	onready:function(response){
		if(window.DEBUGGER_ENABLED)
			this.constructor.debug.add(response?"[target=\""+this.obj.target+"\"]\n"+"[ref=\""+this.req.query+"\"]\n"+"\n----------\n"+o2s(response.obj)+"\n----------\n"+response.text:"\nNO RESPONSE!\n");
		
		this.failure=!response || response.obj.failure;
		this.complete=!this.failure && (response.obj.complete==undefined || (!isNaN(response.obj.complete) && Number(response.obj.complete))); 

		if(this.target && !this.failure){
			var holder=this.target;
			if(this.append)	holder=this.target.insert(this.append);
			holder.html(response.text); //if echo -- write innerHTML
			if(response.obj) this.targetProp(this.target, response.obj.target); //if target properties in response exist set properties to target
			if(window.init_content) init_content(holder);
		}
		
		this.indicator(0);
		this.obj.in_process=false;
		
		if(!this.failure) this.obj.act();
		
		//execute predefined basic operations
		this.constructor.onresponse(response, this);
		
		//execute sender callback function
		if(this.complete) this.oncomplete(response);
		else if(this.failure) this.onfailure(response);
		
	},
	targetProp:function(target, props){
		if(props)
			for(var i in props)
				target[i]=props[i];
	},
	//show global ajax loading icon
	indicator:function(b){
		if(this.constructor.loader) _(this.constructor.loader).css({display:b?"block":"none"});
		if(this.target){
			if(this.indicatorShow){
				if(!isNaN(this.indicatorShow)){
					if(!this.modal && window.Modal) this.modal=new Modal({opacity:this.indicatorShow, bgcolor:"#fff", loader:""});
					if(this.modal) this.modal.showhide(b);
				}
				else{
					if(b) this.target.defaultHeight=this.target.css("height") || "auto";
					this.target.css("height", b?this.target.clientHeight:this.target.defaultHeight);
					if(b) this.target.html(this.indicatorShow);
				}
			}
			else this.target.css({opacity:b?0.5:1});
		}
		return false;
	},
	//parse ajax referer link (ARL=aref)
	url2query:function(url){
		if(!url) return "";
		var file=url.replace(/([^?]*\/)*([^?]*)\??.*/,"$2"); //get file name
		if(file) this.req.file=file; //overwrite ajax handler file name
		url=url.replace(/[^?]*\??/,""); //get query [a=1&b=2&c=3]
		if(!url) return "";
		url=this.func2query(url); //check & try to execute function in query
		return url;
	},
	//parse form fields & create hash params
	form2query:function(form){
		if(!form.elements) return {};
		var hash={};
		for(var i=0;i<form.elements.length;i++){
			if(!form.elements[i]) continue;	
			if(form.elements[i].tagName=="FIELDSET" || form.elements[i].tagName=="OBJECT") continue;			
			//if(form.elements[i].type=="checkbox") hash[form.elements[i].name]=(form.elements[i].checked?1:0);
			if(form.elements[i].type=="checkbox"){ if(form.elements[i].checked) hash[form.elements[i].name]=form.elements[i].value || "on";}
			else if(form.elements[i].type=="radio"){ if(form.elements[i].checked) hash[form.elements[i].name]=form.elements[i].value;}
			else if(form.elements[i].type=="file") hash[form.elements[i].name]=form.elements[i];
			else hash[form.elements[i].name]=form.elements[i].isDefault?"":form.elements[i].value; //handle Forms.Default status 
		}
		return hash;
	},
	//for function in query (dynamic executeble query)
	func2query:function(url){
		var dyn=url.match(/&?[a-z0-9_]+=\(%?[^&]+\)/gi);
		if(dyn && dyn.length){
			for(var i=0,a,l=dyn.length;i<l;i++){
				a=dyn[i].split(/=/);
				var ue=false;
				if(ue=/^\(%/.test(a[1]))a[1]=a[1].replace(/^\(%/, "("); //unescape definition
				var hash={};
				var key=a[0].replace(/&/,"");
				var value=(new Function('return '+a[1])).apply(this.obj);
				hash[key]=value;
				var res="";
				res=this.req.json2query(hash);
				if(ue && typeof res=="string") res=unescape(res);
				url=url.replace(/&?[a-z0-9_]+=\(%?[^&]+\)/i, res); //add value to query
			}
		}
		return url;
	}
});

//HTMLAJAX CACHE control functionality
HTMLAJAX.cache={
	MULTIPLIER:60*1000, // set cache in [minutes]
	from:(new Date()).getTime(),
	init:function(cache_time){
		var cache_param={};
		var ts=(new Date()).getTime();
		cache_param.period=Number(cache_time=="*"?(window.CACHE_DEFAULT?CACHE_DEFAULT:60):cache_time);
		cache_param.start=ts;
		cache_param.end=ts+cache_param.period*this.MULTIPLIER;
		return cache_param;
	},
	expire:function(cache_param){ //check cache time out
		var ts=(new Date()).getTime();
		if(cache_param.end<ts || cache_param.start<this.from){ //if cache time out replace cache params (start & end)
			cache_param.start=ts;
			cache_param.end=this.init(cache_param.period).end;
			return true;
		}
		return false;
	},
	set:function(cache_time, ajax, cache_obj){
		// from tag:  cache="5" (5 minutes cache) || cache="*" (default cache)
		if(cache_time && cache_obj){
			if(!cache_obj.cache_param) cache_obj.cache_param=this.init(cache_time);
			if(!this.expire(cache_obj.cache_param) && !cache_obj.nocaching) ajax.caching=true;
		}
	},
	reset:function(){this.from=(new Date()).getTime()}
};



//>-------------------------------
//> AJAX debugger console
//> Calling: ctrl+shift+q
HTMLAJAX.debug={
	win:null,
	data:'',
	limit:100*1024, //bytes [100Kb]
	init:function(){
		var _this=this;
		//attach debugger window call on key combination
		_(document).event("onkeyup", function(e){
			var ev=e?e:window.event;
			var key=ev.keyCode?ev.keyCode:ev.which;  
			//alert(ev.ctrlKey+","+ev.shiftKey+","+ev.altKey+","+key);	//ctrl+shift+q
			if(ev.ctrlKey  && ev.shiftKey  && (key==113 || key==81 || key==17) ) _this.winopen();
		});
		this.inited=1;
	},
	winopen:function(){
		this.win=window.open('', 'debug', 'scrollbars=no,status=yes,resizable=yes,width=780,height=560');
		this.load();
	},
	
	load:function(){
		this.win.document.open();
		this.win.document.write("<title>AJAX debugger</title><input type='button' value='refresh' onclick='window.opener.HTMLAJAX.debug.load()' /><div style='width:100%;height:95%;overflow-y:auto; border:1px solid #555; font:12px \"Courier New\"'>"+this.data+"</div>");
		this.win.document.close();
	},
	
	add:function(txt){
		if(!this.inited) this.init();
		if(this.data.length>this.limit) this.data=this.data.substr(-this.limit, this.limit).replace(/^.*<hr \/>/m, "...<br />"); //data limit
		txt=txt.replace(/={20,}/g,"");
		txt=txt.replace(/</g,"&lt;");
		txt=txt.replace(/>/g,"&gt;");
		txt=txt.replace(/\t/g,"&nbsp; ");
		txt=txt.replace(/\n/g,"<br />");
		var now=new Date();
		this.data+="<hr />";
		this.data+="["+this._0(now.getHours())+":"+this._0(now.getMinutes())+":"+this._0(now.getSeconds())+"]<br />";
		this.data+=txt+"<br /><br /><br />";
	},
	
	_0:function(num){return (num<10?"0"+num:num)}
};


HTMLAJAX.loader=null; //ajax loader icon
HTMLAJAX.lastCall=null; //last request which call ajax
HTMLAJAX.onrequest=function(request, htmlajax){}; //function is called before request sended
HTMLAJAX.onresponse=function(response, htmlajax){}; //function is called when response complete

//attach ajax handler for element (FORM or A)
HTMLAJAX.attach=function(obj){
	if(obj.attr("aref").indexOf("?")==-1) return false;
	if(obj.tagName=="FORM"){
		var func_submit=obj.onsubmit ? obj.event("onsubmit") : null;
		obj.onsubmit=function(e){if(!func_submit || (func_submit && func_submit())) GET(this, e); return false};
		if(obj.attr("autoload")!=undefined) obj.onsubmit();
	}
	else{
		if(obj.tagName=="A" && !obj.href) obj.href="#"; //set empty href value <a href="#"> (for non IE)
		if(!obj.onclick) obj.event("onclick", function(e){ return GET(this, e)});
		if(obj.attr("autoload")!=undefined) obj.onclick();
	}
};

// main handler
function GET(obj, event){
	if(!window.AJAX_HANDLER) return false;
	//HTMLAJAX.lastCall=function(e){window["GET"](obj,e)};
	obj=_(obj);
	var htmlajax=new HTMLAJAX(obj, event); /*init parent class*/
	obj.req=htmlajax.req;
	htmlajax.req.file=AJAX_HANDLER;
	htmlajax.req.query=htmlajax.url2query(obj.ref||obj.aref||obj.attr("aref")||obj.attr("href")||obj.attr("action")); //set query params
	if(obj.tagName=="FORM") htmlajax.req.hash=htmlajax.form2query(obj);
	if(obj.nodeType!=1 && obj.params) htmlajax.req.hash=obj.params;
	if(!htmlajax.req.query && !obj.params) return false; //exit if no parameters
	return htmlajax.exec();
};



var MAP={
	init:function(id, params){
		var _this=this;
		
		if (!GBrowserIsCompatible()) return;
		JJ.element.event.exec(window, "onunload", GUnload);
		
		this.block=_(id);
		this.map = new GMap2(this.block);
		
		geocoder = new GClientGeocoder();
		
        var customUI = this.map.getDefaultUI();
        customUI.controls.largemapcontrol3d = false;
        customUI.controls.smallzoomcontrol3d = true;
		customUI.controls.menumaptypecontrol = true;
        this.map.setUI(customUI);

		this.map.enableContinuousZoom();
		this.map.disableInfoWindow();
		
		GEvent.addListener(this.map, "click", function(marker, point){
			if(point){
				GET({ref:"?task=getElevation&lat="+point.lat()+"&lng="+point.lng(), oncomplete:function(response){
					var r=((new Function('return '+response.text))()).results[0];
					_('map_point_output').html(r.location.lat+", "+r.location.lng+", "+r.elevation);
				}});
			}
			//alert(o2s(MAP.getViewPort())+" "+MAP.map.getCenter().lng()+ " "+MAP.map.getCenter().lat()+ " "+MAP.map.getZoom());
		});
		
		this.isScrollWheelZoom=1;
		GEvent.addListener(this.map, "mousemove", function(marker, point){
			if(!_this.isScrollWheelZoom){
				_this.map.enableScrollWheelZoom();
				_this.isScrollWheelZoom=1;
			}
		});
		
		GEvent.addListener(this.map, "mouseover", function(marker, point){
			_this.map.disableScrollWheelZoom();
			_this.isScrollWheelZoom=0;
		});


		this.icon=[];
		this.icon["marker_1"]=this.initIcon("marker_1.png", "marker_1_sh.png", 40, 38, 40, 38, 8, 38);
		this.icon["s1"]=this.initIcon("marker_s1.png", "marker_s_shad.png", 34, 34, 38, 43, 14, 38);
		this.icon["s2"]=this.initIcon("marker_s1.png", "marker_s_shad.png", 34, 34, 38, 43, 14, 38);
		this.icon["s3"]=this.initIcon("marker_s1.png", "marker_s_shad.png", 34, 34, 38, 43, 14, 38);
		
		params=params || {};
		this.setType(params.type || 3);
		
		var route_points=this.route.init(params.polylines);
		
		if(route_points.length) this.setViewPort(route_points);
		else this.map.setCenter(new GLatLng(params.lat || 49.85067, params.lng || 24.01704), params.zoom || 11);
		
		
	},
	
	//create single marker and attach event on it
	createMarker:function(point){
		var opts = {
			"icon": this.icon[point.icon || point.marker],	
			"clickable": true,
			"draggable": true
		};
		var latlng=point.latlng || new GLatLng(point.lat, point.lng);
		var marker = new GMarker(latlng, opts);
		
		for(var i in point) marker[i]=point[i]; //copy properties
			
		if(point.href){
			GEvent.addListener(marker, "click", function() {
				location.href=marker.href;
			});
		}
		
		if(point.title){
			GEvent.addListener(marker, "mouseover", function() {
				MAP.tooltip.show(marker);
			});
			GEvent.addListener(marker, "mouseout", function() {
				MAP.tooltip.hide(marker);
			});
		}
		return marker;
	},
	
	// draw/redraw markers on the map
	drawMarkers:function(points, center){
		this.clear();
		var markers=[];
		for(var i in points){
			var marker=this.createMarker(points[i]);
			markers.push(marker);
			if(!this.clustering) this.map.addOverlay(marker);
		}
		if(this.clustering) this.createCluster(markers);
		
		//if(center) mapa.setCenter(new GLatLng(center.lat, center.lng), center.zoom);
		//else 
		this.setViewPort(points);
	},
	
	clear:function clearMarkers(){
		if(this.map) this.map.clearOverlays();
	},
			
	createCluster:function(markers){
		var ClustererStyles=[
			{url:IMGS_PATH+"m1.png", height:57, width:53},
			{url:IMGS_PATH+"m2.png", height:58, width:55},
			{url:IMGS_PATH+"m3.png", height:65, width:66},
			{url:IMGS_PATH+"m4.png", height:65, width:66},
			{url:IMGS_PATH+"m5.png", height:65, width:66},
		];
		return new MarkerClusterer(this.map, markers, {styles: ClustererStyles, gridSize: 70});
		
	},
	
	setType:function(num){
		switch(Number(num)){
			case 0:this.map.setMapType(G_NORMAL_MAP);break;
			case 1:this.map.setMapType(G_SATELLITE_MAP);break;
			case 2:this.map.setMapType(G_HYBRID_MAP);break;
			case 3:this.map.setMapType(G_PHYSICAL_MAP);break;
			default:;
		}
	},
	
	getViewPort:function(){
		var bounds = this.boundsNormalize(this.map.getBounds());
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		return {n:{lng:northEast.lng(),lat:northEast.lat()},s:{lng:southWest.lng(),lat:southWest.lat()}};
	},
	
	setViewPort:function(points){
		//get markers view zone on map, return rectangle bounds
		if(!points || !points.length) return false;
		var exists, n_lng, n_lat, s_lng, s_lat;
		var G_mode=points[0].lat()?1:0;
		for(var i=0; i<points.length; i++){
			var lat=G_mode?points[i].lat():lat;
			var lng=G_mode?points[i].lng():lng;
			n_lng=!exists || (exists && lng>n_lng)?lng:n_lng;
			n_lat=!exists || (exists && lat>n_lat)?lat:n_lat;
			s_lng=!exists || (exists && lng<s_lng)?lng:s_lng;
			s_lat=!exists || (exists && lat<s_lat)?lat:s_lat;
			exists=true;
		}
		if(!exists) return false;
		var bounds=new GLatLngBounds(new GLatLng(s_lat,  s_lng), new GLatLng(n_lat, n_lng));	
		//bounds=boundsNormalize(bounds);

		//set move/zoom map to ViewPort
		this.map.setCenter(bounds.getCenter(), this.map.getBoundsZoomLevel(bounds));
	},
	
	boundsNormalize:function(bounds){
		var southWest = bounds.getSouthWest();
		var cc=this.map.fromLatLngToDivPixel(southWest);
		southWest=this.map.fromDivPixelToLatLng(new GPoint(cc.x+15, cc.y-40));
		var northEast = bounds.getNorthEast();
		var cc=this.map.fromLatLngToDivPixel(northEast);
		northEast=this.map.fromDivPixelToLatLng(new GPoint(cc.x-15, cc.y+40));
		return new GLatLngBounds(southWest, northEast);
	},
	
	initIcon:function(img, shad, icW, icH, shW, shH, anW, AnH){
		var icon=new GIcon();
		icon.image=IMGS_PATH+img;
		//icon.over=over?IMGS_PATH+over:null;
		icon.iconSize=new GSize(icW, icH);
		icon.shadow=IMGS_PATH+shad;
		icon.shadowSize=new GSize(shW, shH);
		icon.iconAnchor=new GPoint(anW, AnH);
		icon.infoWindowAnchor=new GPoint(0, 0);
		return icon;
	},
	
	set:function(id, sett){
		if(!this.map) this.init(id, sett);
		var marker=this.createMarker(sett);
		this.map.addOverlay(marker);
	},
	
	preload:function(id, sett){
		this.start_params={id:id, sett:sett};
	},
	
	execute:function(start_params){
		var start_params=start_params || this.start_params;
		if(!start_params) return false;
		var _this=this;
		if(!this.inPreload){
			this.inPreload=true;
			this.load_core(start_params.sett.key);
			if(start_params.sett.clustering) this.load_clustering();
			var tm=setInterval(function(){if(window.GMap2){ clearInterval(tm); _this.init(start_params.id, start_params.sett);} }, 100);
		}
		this.start_params=null;
	},
	
	load_core:function(key){
		document.write('<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;hl=uk&amp;key='+key+'"><'+'/script>');
	},
	
	load_clustering:function(){
		document.write('<script type="text/javascript" defer="defer" src="'+GLOBAL_PATH+'js/markerclusterer_packed.js"></'+'script>');
		this.clustering=true;
	}
};

//http://maps.google.com/maps/api/elevation/json?locations=49.85067,24.01704|49.84067,23.90704&sensor=false
//http://maps.google.com/maps/api/elevation/json?path=49.85067,24.01704|49.84067,23.90704|49.81067,23.95704&samples=6&sensor=false


MAP.tooltip={
	init:function(){
		var _this=this;
		this.tooltip=JJ.create("div").attr({id:'tooltip'});
		this.tooltip.event({onmouseover:function(){_this.show(_this.currentMarker)}, onmouseout:function(){_this.hide(_this.currentMarker)}});
		this.tooltip.content=this.tooltip.insert("a");
		_(MAP.block, "<").insert(this.tooltip);
		this.inited=1;
	},
	show:function(marker){
		var _this=this;
		if(this.currentMarker!=marker && this.currentMarker) this.hideDelay(this.currentMarker);
		this.currentMarker=marker;
		marker.isOver=1;
		clearTimeout(this.tm);
		this.tm=setTimeout(function(){_this.showDelay(marker)}, 200);
	},
	hide:function(marker){
		var _this=this;
		marker.isOver=0;
		clearTimeout(this.tm);
		this.tm=setTimeout(function(){_this.hideDelay(marker)}, 200);
	},
	showDelay:function(marker){
		if(marker.isOver && marker.isShow) return false;
		if(!this.inited) this.init();
		var cc=MAP.map.fromLatLngToContainerPixel(marker.getLatLng());
		this.tooltip.content.html(marker.title);
		if(marker.href) this.tooltip.content.href=marker.href;
		this.tooltip.css({top:cc.y, left:cc.x}).fade(1);
		marker.isShow=1;
	},
	hideDelay:function(marker){
		if(marker.isOver || !marker.isShow) return false;
		this.tooltip.fade(0);
		marker.isShow=0;
	}
};



MAP.route={
	_colors:{
		route:["#ff0000", "#0000ff"],
		walk:["#00ff00", "#ffff00"]
	},
	init:function(polylines_points){
		var _this=this;
		this.mode="view";
		this.polylines={};
		
		var points_route=this.buildPolylines(polylines_points, "route");
		var points_walk=this.buildPolylines(polylines_points, "walk");
		
		if(AUTH){ 
			//onCreate polyline handler
			GEvent.addListener(MAP.map, "click", function(overlay, point){
				if(_this.mode=="create"){
					var new_id=_this.polylines[_this.line_type].length;
					var line=new MAP.polyline([point], {type:_this.line_type, id:new_id, editable:true, color:_this._colors[_this.line_type]});
					line.mode_edit(1);
					line.onCreateEnd=function(){
						_this.cur_but.classname("-act"); 
						_this.polylines[_this.line_type].push(line);
						_this.mode="view"; 
						this.onCreateEnd=null;
					};
					_this.mode="draw"; 
				}
			});
		}
		return points_route;
	},
	
	buildPolylines:function(polylines_points, line_type){
		var points=[];
		var current_polylines_points=polylines_points[line_type];
		this.polylines[line_type]=[];
		
		if(current_polylines_points && current_polylines_points.length){
			if(!AUTH && line_type=="route"){
				current_polylines_points=[current_polylines_points.join("|").replace(/\|{2,}/g,"|")];
			}
			for(var i=0; i<current_polylines_points.length; i++){
				if(current_polylines_points[i]){
					this.polylines[line_type][i]=new MAP.polyline(current_polylines_points[i], {type:line_type, id:i, editable:AUTH, color:this._colors[line_type]});
					points=points.concat(this.polylines[line_type][i].get_points("latlng"));
				}
				else {
					this.polylines[line_type][i]="";
				}
			}
		}
		return points;
	},
	
	addPolyline:function(obj, line_type){
		this.mode="create";
		this.line_type=line_type;
		if(this.cur_but) this.cur_but.classname("-act");
		this.cur_but=obj;
		obj.classname("+act");
	},
	
	getLength:function(line_type){
		var total=0;
		for(var i=0; i<this.polylines[line_type].length; i++){
			if(this.polylines[i])
				total+=this.polylines[line_type][i].line.getLength();
		}
		return total;
	}
}



MAP.polyline=Class({
	init:function(result, opts){
		var _this=this;
		
		opts=opts||{};
		this.type=opts.type || "";
		this.id=opts.id || 0;
		this.isEditable=opts.editable || false;
		this.color=opts.color || ["#ff0000", "#0000ff"];
		this.weight=opts.weight || 5;
		this.opacity=opts.opacity || 0.5;
		
		this.mode="view";
		this.edited=false;
		this.lineupdate==true;
		
		this.create(result);
	},
	
	create:function(result){
		var _this=this;
		
		
		if(/^\d/.test(result) || _.type(result, "array")){ //separated points or array
			var points=_.type(result, "array")?result:this.toLatLng(result);
			this.line = new GPolyline(points, this.color[0], this.weight, this.opacity);
		}else{ //encoded points
			this.line = new GPolyline.fromEncoded({color:this.color[0],  weight:this.weight,  opacity:this.opacity, points:result, levels: "?", zoomFactor:0, numLevels:0});
		}
		

		MAP.map.addOverlay(this.line);
		
		if(!this.isEditable) return false;
		
		GEvent.addListener(this.line, "click", function(){
			if(_this.mode=="view") _this.mode_edit();
		}); 
		
		GEvent.addListener(this.line, "mouseover", function(){
			if(_this.mode=="view") _this.hover(1);
		}); 
		
		GEvent.addListener(this.line, "mouseout", function(){
			if(_this.mode=="view") _this.hover(0);
		}); 
		
		GEvent.addListener(this.line, "lineupdated", function(){
			if(!_this.lineupdate) return _this.lineupdate=true;
			_this.edited=true;
		}); 
		
		GEvent.addListener(this.line, "endline", function(){
			_this.onCreateEnd()
			_this.mode_view();
		}); 
		
		GEvent.addListener(MAP.map, "singlerightclick", function(point, src, overlay){
			if(_this.mode=="edit" && overlay.index!==undefined){
				if(_this.line.getVertexCount()==2){
					MAP.map.removeOverlay(_this.line);
					_this.line=null;
					return _this.save();
				}
				_this.line.deleteVertex(overlay.index);
			}
		}); 
		GEvent.addListener(MAP.map, "click", function(overlay, point){
			if(_this.mode=="edit" && !overlay){
				_this.mode_view();
			}
		}); 
		
	},
	
	mode_view:function(){
		//alert(this.line.getVertexCount());
		if(this.edited) return this.save();
		this.mode="view";
		this.hover(0);
		if(this.line) this.line.disableEditing();
	},
	
	mode_edit:function(drawMode){
		if(!this.line) return false;
		this.hover(1);
		if(drawMode){
			this.mode="draw"; 
			this.line.enableDrawing();
		}
		else{
			this.mode="edit"; 
			this.line.disableEditing();
			this.line.enableEditing();	
		}
	},
	
	hover:function(n){
		this.lineupdate=false;
		if(this.line) this.line.setStrokeStyle({color:this.color[n]});
	},
	
	save:function(){
		var _this=this;
		//if(this.but_save.classname("?but_save_active")){
			GET({line:this, ref:"?task=polyline&type="+this.type+"&id="+this.id+"&action=save&points_data=(this.line.get_points('path'))", oncomplete:function(response){
				_this.edited=false;
				_this.mode_view();
			}});
		//}
	},
	
	get_points:function(type){
		if(!this.line) return "";
		var path="";
		var points=[];
		var count=this.line.getVertexCount();
		if(count>1){
			for(var i=0; i<count; i++){
				var item=this.line.getVertex(i);
				if(type=="latlng") points[i]=item;
				else if(type=="array" || type=="encoded") points[i]=[item.lat(), item.lng()];
				else path+=(path?"|":"")+item.lat()+","+item.lng();
			}
		}
		if(type=="latlng" || type=="array") return points;
		else if(type=="encoded") return this.points_encode(points);
		else return path;
	},
	
	points_encode:function(points, precision){
	
		var encodeNumber=function(num){
			var num = num << 1;
			if (num < 0) {
			  num = ~(num);
			}
			var encoded = '';
			while (num >= 0x20) {
			  encoded += String.fromCharCode((0x20 | (num & 0x1f)) + 63);
			  num >>= 5;
			}
			encoded += String.fromCharCode(num + 63);
			return encoded;   
		}
		
		var oldLat = 0, oldLng = 0, len = points.length, index = 0;
		var encoded = '';
		precision = Math.pow(10, precision||5);
		while (index < len) {
		  //  Round to N decimal places
		  var lat = Math.round(points[index][0] * precision);
		  var lng = Math.round(points[index][1] * precision);
		  index++;
		
		  //  Encode the differences between the points
		  encoded += encodeNumber(lat - oldLat);
		  encoded += encodeNumber(lng - oldLng);
		  
		  oldLat = lat;
		  oldLng = lng;
		}
		return encoded;
		
	},
	
	toLatLng:function(path){
		var points=[];
		var coords=path.split("|");
		for(var i=0; i<coords.length; i++){
			var latlng=coords[i].split(",");
			points[i]=new GLatLng(latlng[0], latlng[1]);
		}
		return points;
	},
	
	onCreateEnd:function(){}
});
//> Move html objects control
//--------------------------------
//> INITIALIZE
//  obj.move=new Move(obj, {x:[0,100], y:[10,50], disabled:true, parent:obj.parentNode.parentNode});
//  obj.move.onmove=function(per){this.obj.inp.value=Math.round(this.obj.range*per);};

var Move=Class({
	init:function(obj, opt){
		var _this=this;
		//options
		var opt=opt?opt:{};
		this.disabled=opt.disable!=undefined ? opt.disable : false;
		this.parent=opt.parent ? opt.parent : obj.parentNode; //used for detection parent bounds
		
		if(opt.x) this.x=[opt.x[0]!=undefined?opt.x[0]:0, opt.x[1]!=undefined?opt.x[1]:this.parent.offsetWidth-obj.offsetWidth];
		if(opt.y) this.y=[opt.y[0]!=undefined?opt.y[0]:0, opt.y[1]!=undefined?opt.y[1]:this.parent.offsetHeight-obj.offsetHeight];
		//global
		this.obj=obj;
		this.isDraging=false;
		this.defaultCursor=this.obj.style.cursor;
		this.range={x:(this.x?this.x[1]-this.x[0]:0), y:(this.y?this.y[1]-this.y[0]:0)};
		
		//attach
		this.obj.onmousedown=function(e){_this.start(e)};
		//this.parent.onclick=function(e){_this.start(e)};
	},
	start:function(e){
		if(this.disabled) return false;
		var _this=this;
		this.onstart();
		_(e).prevent();
		this.obj.style.cursor=this.x && this.y ? "move" : (this.y ? "n-resize" : (this.x ? "e-resize" : "pointer") );
		this.obj.style.margin="0px";
		this.offset={x:_(e).mouse("x")-this.obj.offsetLeft, y:_(e).mouse("y")-this.obj.offsetTop};
		this.isDraging=true;
		document.onmousemove=function(e){ _this.move(e)};
		document.onmouseup=function(e){ _this.end(e)};
	},
	move:function(e){
		if(this.isDraging){
			_(e).prevent();
			this.pos({x:_(e).mouse("x")-this.offset.x, y:_(e).mouse("y")-this.offset.y}); //set position
		}
	},
	pos:function(pos, disable_callback){
		var _this=this;
		var per={}; // obj shift in float persent
		this.value={};
		if(this.x){
			this.value.x=this.checkBound(pos,"x");
			this.obj.style["left"]=this.value.x+"px";
			per.x=(this.value.x-this.x[0])/this.range.x;
		}
		if(this.y){
			this.value.y=this.checkBound(pos,"y");
			this.obj.style["top"]=this.value.y+"px";
			per.y=(this.value.y-this.y[0])/this.range.y;
		}
		if(disable_callback) return;
		this.onmove(this.x&&this.y?per:(this.x?per.x:per.y));
		clearTimeout(this.tm);
		this.tm=setTimeout(function(){_this.onpause()},500);
	},
	end:function(e){
		if(this.isDraging){
			this.isDraging=false;
			this.obj.style.cursor=this.defaultCursor;
			document.onmousemove=null;
			document.onmouseup=null;
			clearTimeout(this.tm);
			this.onend();
		}
	},
	set:function(val, disable_callback){
		var pos={};
		if(this.x) pos.x=(this.range.x*(val.constructor==Array?val[0]:val)+this.x[0]);
		if(this.y) pos.y=(this.range.y*(val.constructor==Array?val[1]:val)+this.y[0]);
		this.pos(pos, disable_callback);
		return false;
	},
	checkBound:function(pos, xy){
		return this[xy][0]>pos[xy] ? this[xy][0] : (this[xy][1]<pos[xy] ? this[xy][1] : pos[xy]);
	},
	onstart:function(){},
	onpause:function(){},
	onmove:function(){},
	onend:function(){}
});


/*
----------------------------------------------------------------------
EXAMPLE:

smooth=new Smooth({dynamic:5, duration:500, algoritm:300});
smooth.onplay=function(values){obj.style.left=values.left+"px"; obj.style.top=values.top+"px"; };
smooth.onend=function(d){ obj.style.display=d>0?"block":"none"; };

----------------------------------------------------------------------
opt={
	dynamic:   [-10..+10]                                //dynamic koeficient (default:0)
	duration:  [ms]                                      //play duration  (default:1000)
	algoritm:  [fade | ball | [-n..+n] | function]       //play algoritm  (default:"fade")
	onstart: function(){};
	onplay:  function(value){};
	onend:   function(){};
}
methods={	
	start:   function(range){};
}
range=[a,b] | {left:[a,b], top:[a,b], width:[a,b], ...}

----------------------------------------------------------------------
*/

var Smooth=new Class({
	dynamic:0,
	duration:1000,
	fps:50,
	algoritm:"fade",
	inPlay:null,
	init:function(opt, range){
		opt=opt||{};
		this.dynamic=(opt.dynamic!=undefined?opt.dynamic:0) || 0.1;
		this.duration=opt.duration || this.duration;
		this.algoritm=opt.algoritm || this.algoritm;
		this.onstart=opt.onstart || this.onstart;
		this.onplay=opt.onplay || this.onplay;
		this.onend=opt.onend || this.onend;
		if(range) this.start(range);
	},
	start:function(range, to){
		var _this=this;
		
		if(this.inPlay) this.end();
		
		var algoritm="";
		if(this.algoritm.constructor==Array) algoritm="custom";
		else if(typeof this.algoritm=="function") algoritm="function";
		else algoritm=this.algoritm;
		
		var interval=1000/this.fps;
		this.steps=Math.round(this.duration/interval);
		
		//custom values
		this.half=this.steps/2;
		this.dynamic_abs=Math.abs(this.dynamic);
		this.dynamic_reverse_flag=(this.dynamic<0?this.dynamic:0);
		
		var algoritm_values=[];
		var max, min;
		for(var i=0;i<=this.steps;i++){
			algoritm_values[i]=this.get_algoritm(algoritm, i);
			if(!i || max<algoritm_values[i]) max=algoritm_values[i];
			if(!i || min>algoritm_values[i]) min=algoritm_values[i];
		}
		
		//create values
		if(range==undefined) range=[0, 100];
		else if(range.constructor==Number && to!=undefined) range=[range, to];
		
		if(range.constructor==Array) range={_base:range};
		var length={};
		for(var key in range) 
			length[key]=range[key][1]-range[key][0]; //length of each diapazons
		
		var percent;
		/**/var algoritm_percents=[];
		this.val=[];
		for(var i=0;i<=this.steps;i++){
			this.val[i]={};
			percent=(algoritm_values[i]-min)/(max-min);
			/**/algoritm_percents[i]=percent;
			for(var key in range){ //for each param
				this.val[i][key]=range[key][0]+length[key]*percent; //if multi params
				if(range._base) this.val[i]=this.val[i][key]; //if single params
			}
		}
		
		/**/if(window.debug && window.debug==1){ debug=0; return alert(o2s(algoritm_values));}
		/**/if(window.debug && window.debug==2){ debug=0; return alert(o2s(algoritm_percents));}
		/**/if(window.debug && window.debug==3){ debug=0; return alert(o2s(this.val));}
		
		this.cur=0;
		this.onstart();
		this.play();
		this.tm=setInterval(function(){_this.play()}, interval); 
		this.inPlay=true;
	},
	get_algoritm:function(alg, i){
		switch(alg){
			case "fade": return Math.atan((this.dynamic_abs/this.steps*i)+this.dynamic_reverse_flag);
			case "ball": return Math.atan(this.dynamic_abs/this.half*(i-this.half));
			case "custom": return this.algoritm[i];
			case "function": return this.algoritm(i, this.steps, this.dynamic);
			default: return i;
		}
	},
	play:function(){
		this.onplay(this.val[this.cur]);
		this.cur++;
		if(this.cur>this.steps) return this.end();
	},
	end:function(){
		clearInterval(this.tm);
		this.tm=null;
		this.inPlay=false;
		this.onend();
		return false;
	},
	onstart:function(d){},
	onplay:function(val){},
	onend:function(d){}
});



var EFX={
	slide:function(obj, b, opt){
		if(!obj._slide){
			opt=opt || {};
			opt.dynamic=opt.dynamic!=undefined?opt.dynamic:7;
			opt.duration=opt.duration!=undefined?opt.duration:350;
			opt.onstart=function(){ };
			opt.onplay=function(pos){ obj.css({height:pos});};
			opt.onend=function(){ obj.css(obj._slide.css);  if(!this.isVisible) obj.css({display:"none"});};
			obj._slide=new Smooth(opt);
		}
		if(obj._slide.inPlay) obj._slide.end();
		
		obj._slide.css=obj.css(["overflow", "position", "paddingTop", "paddingBottom", "height"]); //save default css values
		obj.css({position:"absolute"}); //for height init
		obj.css({display:"block"});
		
		obj._slide.css.absHeight=obj.offsetHeight-obj._slide.css.paddingTop;
		
		obj.css({overflow:"hidden", paddingBottom:0, paddingTop:b?0:obj._slide.css.paddingTop, position:obj._slide.css.position});
		obj._slide.start(b?0:obj._slide.css.absHeight, b?obj._slide.css.absHeight:0);
		obj._slide.isVisible=b;
		
		return obj._slide;
	},
	fade:function(obj, b, opt){
		if(!obj._fade){
			opt=opt || {};
			opt.dynamic=opt.dynamic!=undefined?opt.dynamic:7;
			opt.duration=opt.duration!=undefined?opt.duration:500;
			opt.onstart=function(){obj.css({visibility:"visible"}); };
			opt.onplay=function(pos){obj.css({opacity:pos/100}); };
			opt.onend=function(){if(!this.isVisible) obj.css({visibility:"hidden"});};
			obj._fade=new Smooth(opt);
		}
		if(obj._fade.inPlay) obj._fade.end();
		
		var end=100;
		obj._fade.start(b?0:end, b?end:0);
		obj._fade.isVisible=b;
		return obj._fade;
	}
};


var Popup=Class({
	init:function(content_obj){
		var _this=this;
		this.block=_(document.body).insert("div").classname("popup");
		this.but_close=this.block.insert("a").classname("popup_close").event("onclick", function(){_this.hide()});
		this.buts=this.block.insert("div").classname("popup_buts");
		this.but_ok=this.buts.insert("a").classname("popup_ok").html("OK").event("onclick", function(){_this.hide()});
		this.block.insert("div").classname("popup_top");
		this.body=this.block.insert("div").classname("popup_body");
		this.block.insert("div").classname("popup_bottom");
		_(document).event("onkeydown", function(e){
			if((_(e).key("escape") || (_(e).key("enter") && _this.but_ok.isShown)) && _this.isOpen) return _this.hide();
		});
		if(content_obj){
			this.body.appendChild(content_obj);
			this.haveContent=true;
		}
		this.modal=new Modal();
		this.inited=1;
	},
	showhide:function(b){
		this.modal.showhide(b);
		this.block.css({visibility:b?"visible":"hidden"});
		this.isOpen=b;
	},
	show:function(content, buts){
		var _this=this;
		if(!this.inited) this.init();
		this.ok_showhide(buts?1:0);
		if(!this.haveContent) this.body.html(content);
		if(window.init_content) init_content(this.body);
		this.block.css({marginTop:-Math.round(this.block.offsetHeight/2)});
		this.showhide(1);
		return false;
	},
	hide:function(){
		this.showhide(0);
		if(!this.haveContent) this.body.html("");
		return false;
	},
	alert:function(content){
		return this.show(content, 1);
	},
	confirm:function(content){
		return this.show(content);
	},
	win:function(content){
		return this.show(content);
	},
	ok_showhide:function(b){
		this.but_ok.isShown=b;
		this.buts.css({display:b?"block":"none"});
		if(!this.body.paddingBottom) this.body.paddingBottom=this.body.css("paddingBottom");
		this.body.css({paddingBottom:this.body.paddingBottom+(b?this.buts.offsetHeight:0)});
	}
});


var Modal=Class({
	init:function(opt){
		this.block=_(document.body).insert("div").classname("modal");
		this.layer=this.block.insert("span");
		opt=opt||{};
		if(opt.loader!=undefined) this.block.insert("div").classname("loader").html(opt.loader).insert("div");
		if(opt.opacity!=undefined) this.layer.css({opacity:opt.opacity});
		if(opt.bgcolor){ this.layer.css({background:opt.bgcolor});}
		this.inited=1;
	},
	showhide:function(b){
		this.block.css({display:b?"block":"none"});
		this.isOpen=b;	
	},
	show:function(opt){
		this.showhide(1);
	},
	hide:function(){
		this.showhide(0);	
	}
});
//> created by <stipuha />
//> Custom forms controls

var Forms={};


// reset form fields
Forms.reset=function(root){
	_(root, "input, select, textarea").repeat(function(){
		if(!this || this.attr("reset")=="false") return false;
		if(this.type=="file") this.parentNode.innerHTML=this.parentNode.innerHTML;
		if(this.type=="checkbox" || this.type=="radio") this.checked=false;//this.getAttribute("checked");
		if(this.type=="text" || this.type=="password" || this.tagName=="TEXTAREA") this.value="";
		if(typeof this.reset=="function") this.reset(); //for custom select
		if(this.event("onreset")) this.event("onreset")(); //start onreset event
	});
	return false;
};


//fix textarea length
Forms.maxlength=function(obj){
	obj.maxlength=obj.attr("maxlength");
	var func=function(){if(this.value.length>this.maxlength) this.value=this.value.substr(0, this.maxlength)};
	obj.event({onkeyup:func, onkeypress:func});
};



Forms.autocomplete=Class({
	init:function(obj, classname){
		if(obj.autocomplete) return false;
		obj.autocomplete=this;
		var _this=this;
		this.list=_(obj.parentNode).insert("div", _(obj, "+")).classname(classname || "autocomplete").css({display:"none"});
		this.input=_(obj).event({
					  onkeyup:function(e){_this.onkeyup(e)},
					  onfocus:function(e){_this.onkeyup(e); _this.inFocus=true; },
					  onblur:function(e){_this.close(); _this.inFocus=false; },
					  oncomplete:function(e){ if(_this.inFocus){ _this.showhide(1); _this.initItems();}}
					});
		this.input.target=this.list;
		this.input._value=this.input.value;
		this.inFocus=true;
	},
	onkeyup:function(e){
		if(this.isOpen && (_(e).key("up") || _(e).key("down"))) return this.act(e);
		if(!this.isOpen && _(e).key("down")) return this.showhide(1); 
		if(_(e).key("enter")) return this.exec();
		if(this.input._value==this.input.value) return true;
		if(this.curItem && this.curItem.html()==this.input.value) return true;
		this.input._value=this.input.value; 
		if(this.input.value) GET(this.input);
		else this.close();
		
	},
	exec:function(){
		 if(this.curActIndex) this.input._value=this.input.value;
		 return this.go();		
	},
	initItems:function(){
		var _this=this;
		this.curActIndex=-1;
		this.items=_(this.list, "a").event({
					onmousedown:function(){_this.lock=true},
					onmouseup:function(){_this.lock=false},
					onclick:function(){_this.input.value=this.innerHTML; return _this.go(); }
					});
		if(!this.items.length && this.items.tagName!="A") return this.showhide(0);
	},
	close:function(){
		var _this=this;
		if(!this.lock) setTimeout(function(){_this.showhide(0);},100);
	},
	showhide:function(b){
		this.list.slide(b);
		this.isOpen=b;
	},
	act:function(e){
		if(!this.items || !this.items.length) return false;
		if(this.curItem) this.curItem.classname("-act");
		this.curActIndex+=_(e).key("down")?1:-1;
		if(this.curActIndex<-1) this.curActIndex=-1;
		if(this.curActIndex>=this.items.length) this.curActIndex=0;
		if(this.curActIndex==-1){
			this.input.value=this.input._value;
			return this.showhide(0);
		}
		this.curItem=this.items[this.curActIndex];
		this.input.value=this.curItem.html();
		this.curItem.classname("+act");
		return false;
	},
	go:function(){
		 this.showhide(0); 
		 if(this.input.event("onenter")) this.input.event("onenter")();
		 return false;
	}
});



Forms.Default=Class({
	init:function(obj, classname){
		var _this=this;
		this.obj=_(obj);
		this.text=obj.attr("alt") || obj.attr("default") || "";
		this.classname=classname || "default";
		obj.event({
			onfocus:function(){_this.set(0)},
			onblur:function(){_this.set(1)}
		});
		this.set(1);
	},
	set:function(b){
		if(b && this.obj.value && this.obj.value!=this.text) b=0;
		this.obj.value=b?this.text:(this.obj.value==this.text?"":this.obj.value);
		this.obj.classname((b?"+":"-")+this.classname);
		this.obj.isDefault=b;
	}
});



//Custom select control
//--------------------------------
//> INITIALIZE
//  new Forms.Select(select_obj)

Forms.select=Class({
	init:function(obj, active_classname){
		var _this=this;
		
		this.obj=_(obj);
		this.active_classname=active_classname || "select_active";
		
		this.root=JJ.create("span").classname("select "+obj.classname());
		this.root.event({
			onclick:function(){ if(!_this.renderComlete) _this.showhide(); _this.input.focus(); }, 
			onmousedown:function(){_this.lockBlur=1}, 
			onmouseup:function(){_this.lockBlur=0}
			});
		this.field=this.root.insert("span").classname("field").event({onclick: function(){if(_this.renderComlete) _this.showhide()}});
			
		//create hidden input element for submit
		this.input=this.field.insert("input", {type:"text"});
		this.input.attr({
			value:obj.value,
			tabindex:obj.attr("tabindex")
		});
		this.input.attr({
			update:function(){_this.update()},
			reset:function(){_this.set(_this.input.options[0])},//_this.input.defaultElement)},
			disable:function(b){_this.disable(b)}
		});
		//external events
		this.input.event({
			onchange:obj.onchange,
			onfocus:obj.onfocus,
			onblur:obj.onblur
		});
		this.input.event({
			onfocus:function(){ _this.active(1); },
			onblur:function(){if(!_this.lockBlur) _this.active(0)},
			onkeydown: function(e){ return _this.onkey(e)}
		});
		//copy all inline external attributes from select to input
		for(var i in obj.attributes){
			var item=obj.attributes[i];
			if(!item || !item.specified || (obj[item.name] && typeof obj[item.name]!="string" && typeof obj[item.name]!="boolean")) continue;
			this.input[item.name]=item.value;
		}
		this.holder=this.field.insert("span").classname("holder").attr({classdef:"holder"}).html("&nbsp;");
		this.arrow=this.field.insert("span").classname("arrow");
		this.dropdown=this.root.insert("span").classname("dropdown");
		
		this.root.input=this.input;
		this.input.root=this.root;
		
		this.input.options=_([]);
		if(obj.options.length)
			for(var i=0; i<obj.options.length; i++) {
				var el=_(obj.options[i]);
				var a=this.dropdown.insert("a")
					.classname(el.classname())
					.attr({value:el.value, i:i})
					.html(el.html()?el.html():"&nbsp;")
					.event({onclick:function(){return _this.set(this)}})
					;
				this.input.options.push(a);
				if(el.selected || obj.value==a.value) this.input.selected=this.input.defaultElement=a;
				if(el.attr("image")) a.insert("img", a.firstChild).attr({src:el.attr("image")});
			}
		
		//rendering ------------------------------------------------------------------------------
		this.obj.css({display:"none"});
		this.inherit={
			width:this.obj.css("width"),
			margin:this.obj.css(["marginTop", "marginRight", "marginBottom", "marginLeft"], true)
		};
		this.obj.parentNode.replaceChild(this.root, this.obj);
		
		if(!this.constructor.array) this.constructor.array=[];
		this.constructor.array.push(this.root); //add to constructor array (Forms.select.array)
		
		if(this.input.options.length) this.set(this.input.selected?this.input.selected:this.input.options[0]); //set default or act
		
		this.preRender(); //css rendering
		
		if(this.input.disabled) this.disable(1);
		this.isCreated=true;
	},
	
	preRender:function(){
		this.root.inherit={
			line:this.root.css("lineHeight"),
			paddingTB:this.root.css("borderTopWidth")+this.root.css("borderBottomWidth"),
			paddingLR:this.root.css("borderLeftWidth")+this.root.css("borderRightWidth")
		};
		this.root.inherit.height=this.root.inherit.line+this.root.inherit.paddingTB;
		if(this.root.css("position")=="static") this.root.css({position:"relative"});
		if(this.root.css("display")=="inline") this.root.css({display:"inline-block"});
		if(this.inherit.width && !isNaN(this.inherit.width)) this.root.css({width:this.inherit.width}); //set inherit width if exist
		this.root.css(this.inherit.margin); //set inherit not empty margins
		this.root.css({height:this.root.inherit.height});//swap height
		if(BROWSER.ie) _([this.root, _(this.root, "<")]).css({zIndex:100-this.constructor.array.length}); //fix z-index for IE
		this.input.css({position:"absolute", border:0, padding:0/*});*/, width:1, height:1, opacity:0, marginLeft:-2});/**/
		this.field.css({display:"block", whiteSpace:"nowrap", cursor:"default"});
		this.dropdown.css({position:"relative", visibility:"hidden", overflowX:"hidden", overflowY:"auto", zIndex:2});
		if(BROWSER.opera) this.dropdown.css({display:"table-row-group"});
		this.input.options.css({display:"block", whiteSpace:"nowrap", textDecoration:"none"});
		this.arrow.css({position:"absolute", display:"block", top:this.field.css("borderTopWidth"), right:this.field.css("borderRightWidth"), cursor:"pointer", height:this.root.inherit.line});
		if(this.root.offsetWidth) this.postRender(); //render if element is visible
	},
	
	postRender:function(){
		var field_width=this.root.clientWidth-this.field.css("borderLeftWidth")-this.field.css("borderRightWidth")-this.field.css("marginRight")-this.field.css("marginLeft");
		this.root.css({width:this.root.offsetWidth-this.root.inherit.paddingLR, height:"auto"}); //fix width
		this.field.css({width:field_width, overflow:"hidden"});
		this.dropdown.css({position:"absolute"});
		this.dropdown.css({top:this.root.clientHeight, left:-this.root.css("borderLeftWidth"), width:this.root.clientWidth});
		if(BROWSER.ie6 && this.dropdown.currentStyle["max-height"] && this.dropdown.clientHeight>this.dropdown.currentStyle["max-height"]) this.dropdown.css({height:this.dropdown.currentStyle["max-height"]}); //fix for ie6
		this.renderComlete=true;
	},
	
	showhide:function(d){
		if(this.input.disabled) return false;
		if(d==undefined) d=this.dropdown.css("visibility")!="visible";
		this.dropdown.css({visibility:d?"visible":"hidden"});
		this.isOpen=d;
		return false;
	},
	
	set:function(obj, lock_hide){
		var _this=this;
		this.input.prevValue=this.input.value;
		this.input.value=obj.value;
		this.input.selected=obj;
		
		if(BROWSER.opera) setTimeout(function(){_this.holder.html(obj.html())},0);  //setTimeout for opera inline select
		else _this.holder.html(obj.html());
		this.holder.classname(this.holder.classdef+" "+obj.classname());
		
		if(!lock_hide && this.isCreated) this.showhide(0);
		
		if((this.isCreated && this.input.prevValue!=this.input.value) || (!this.isCreated && this.input.autoload!=undefined)){
			if(this.input.aref) GET(this.input); //call ajax
			if(this.input.onchange) this.input.onchange(); //call onchange event
		}
		
		//act element in dropdown
		if(this.cur) this.cur.classname("-act");
		this.cur=obj;
		this.cur.classname("+act");
		
		return false;
	},
	
	update:function(){
		for(var i=0; i<this.input.options.length; i++) {
			if(this.input.options[i].value==this.input.value){
				this.set(this.input.options[i]);
				break;	
			}				
		}
	},
	
	disable:function(b){
		this.input.disabled=b;
		this.root.css({opacity:b?0.5:1});
	},
	
	active:function(b){
		if(!this.renderComlete) this.postRender();
		this.root.classname((b?"+":"-")+this.active_classname);
		if(!b && this.isOpen) this.showhide(0); //hide dropdown if select blur
	},
	
	onkey:function(e){
		if(_(e).key("tab") || _(e).key("ctrl") || _(e).key("alt") || (_(e).key()>111 && _(e).key()<124)) return true;
		if(_(e).key("up") && this.cur.i) this.set(this.input.options[this.cur.i-1], true);
		if(_(e).key("down") && this.cur.i<this.input.options.length-1) this.set(this.input.options[this.cur.i+1], true);
		if(_(e).key("enter") || _(e).key("space")) this.showhide(this.isOpen?0:1);
		if(_(e).key("escape") && this.isOpen) this.showhide(0);
		return false;
	}
	
});





Forms.validate=Class({
	init:function(form, opt){
		var _this=this;
		opt=opt || {};
		this.cn_err_field=opt.err_field || "err";
		this.cn_err_block=opt.err_block ||"err_block";
		this.cn_err_mess=opt.err_mess ||"err_mess";
		
		this.err_block=_(form, "."+this.cn_err_block);
		this.form=form.event({onsubmit:function(){return _this.onsubmit()}});
		this.fields=_(form, "input[req], textarea[req]");
		this.fields.repeat(function(){
			this.cn_err=_this.cn_err_field;
			this.req=this.attr("req");
			this.target=_(this, "+."+_this.cn_err_mess);
			var ev="onkeyup";
			if(this.req=="checked") ev="onchange";
			this.event(ev, function(){ _this.verify(this)});
			if(this.attr("aref")){
				this.event({
					onblur:function(){GET(this)}, 
					onstarting:function(){return _this.verify(this)}, 
					oncomplete:function(response){this.ajax_err=!_this.set(this, response.obj.err?0:1, response.obj.err!="0"?response.obj.err:"")}
				});
			}
			else if(ev=="onkeyup"){
				this.event({
					onblur:function(){_this.verify(this)}
				});
			}
			if(this.classname("?"+this.cn_err)) _this.set(this, 0);
		});
		this.check_err_block(); //try to open err_block if err found
	},
	check:function(obj){
		if(/\(\)$/.test(obj.req)){ //custom function handler
			var func=window[obj.req.replace(/\(\)$/, "")];
			return func?func.apply(obj):true;
		}
		var b=true;
		var val=this.trim(obj.value);
		switch(obj.req){
			case "empty": b=(val!=""); break;
			case "email": b=(/^([a-z0-9\-._]+)@([a-z0-9\-._]+)\.([a-z0-9]{2,3})$/i.test(val)); break;
			case "checked": b=(obj.checked); break;
			default://field is equal specified in "req" field 
				var f2=this.form.elements[obj.req];
				b=(f2 && this.trim(f2.value)==val);
		}
		return b;
	},
	trim:function(str){
		return (str||"").replace(/^\s*|\s*$/g,"");
	},
	set:function(obj, b, ajax_title){
		obj.classname((b?"-":"+")+obj.cn_err);
		obj.target.css({display:b?"none":"block"}).html(ajax_title || obj.target.title);
		if(this.err_block.isVisible) this.check_err_block(); //try to close err_block
		return b;
	},
	verify:function(obj){
		return this.set(obj, this.check(obj));
	},
	check_err_block:function(b){
		b=b!=undefined?b:(_(this.form, "input."+this.cn_err_field+", textarea."+this.cn_err_field)?1:0);
		this.err_block.css({display:b?"block":"none"}).html(this.err_block.title);
		this.err_block.isVisible=b;
	},
	onsubmit:function(){
		var _this=this;
		var b=true;
		this.fields.repeat(function(){
			b=_this.verify(this)?b:false;
			if(this.ajax_err) b=false;			
		});
		if(!b) this.check_err_block(1);
		return b;
	}
});var Selector=Class({
	init:function(root){
		var _this=this;
		this.root=root;
		this.link=_(root, "a:0");
		this.list=_(root, "ul");
		this.items=_(this.list, "a");
		
		this.items.repeat(function(i){this.i=i});
		this.default_index=this.getCurrent();
		
		this.root.event({onclick:function(){_this.link.focus()}});
		this.link.css({width:this.items[0].offsetWidth-this.items[0].css("paddingLeft")-this.items[0].css("paddingRight")-3});
		this.link.event({
			onfocus:function(){_this.showhide(1)}, 
			onblur:function(){_this.showhide(0)}, 
			onclick:function(){return false}
		});
		
		this.list.event({onmousewheel:function(e){_this.wheel(e)}});
		
		this.items.event({onmousedown:function(){_this.skip=true;}, onclick:function(e){return _this.apply(this, e)}});
		this.items[0].css({borderTopColor:this.items[0].css("borderLeftColor")});
		this.items[this.items.length-1].css({borderBottomColor:this.items[0].css("borderLeftColor")});
		
	},
	showhide:function(b){
		if(this.skip) return false;
		this.root.classname((b?"+":"-")+"selector_open");
		if(b){
			this.setCurrent(this.default_index);
			this.list.fade(b);
		}
		else{
			this.list.css({visibility:"hidden", top:-1000});
		}

	},
	getCurrent:function(){
		var cur;
		for(var i=0; i<this.items.length; i++){
			if(this.items[i].href==this.link.href){
				cur=this.items[i];
				break;
			}
		}
		return cur.i;
	},
	setCurrent:function(index){
		if(index<0 || index>=this.items.length) return false;
		var obj=this.items[index];
		if(this.current_index && index!=this.current_index){
			this.items[this.current_index].classname("-active");
		}
		obj.classname("+active");
		this.list.css({top:obj?-obj.offsetTop-1:this.root.offsetHeight-2});
		this.current_index=index;
		this.opacity(index);
	},
	apply:function(obj, e){
		_(e).stop();
		this.skip=false;
		this.showhide(0);
		if(this.link.href==obj.href) return false;
		this.link.href=obj.href;
		this.link.html(obj.html());
		this.root.classname("+selector_loading");
		location.href=obj.href;
		return false;
	},
	wheel:function(e){
		e = e ? e : window.event;
		_(e).prevent();
  		var wheelDirection = e.detail ? e.detail :  e.wheelDelta / -120; ///down:1 up:-1
		this.setCurrent(this.current_index+wheelDirection);
	},
	opacity:function(index){
		var step, value;
		for(var i=0; i<this.items.length; i++){
			step=100/((i<index?index+1:this.items.length-index));
			value=100-step*Math.abs(index-i);
			this.items[i].css({opacity:value/100});
		}
	}
});var COOKIES_EXPIRES=60*60*24*365;

function init_mail(obj) {
	var mail=obj.innerHTML+"@"+obj.rel;
	obj.href="mailto:"+mail;
	obj.innerHTML=mail;
};



var Tabs=Class({
	_active_classname:"act",
	_effect:"slide",
	
	init:function(obj){
		var _this=this;
		this.root=obj;
		this._effect=this.root.attr("effect") || this._effect;
		this.items=_(obj, ["dt"]);
		this.blocks=_(obj, ["dd"]);
		if(this.items.length<=1 || this.blocks.length<=1) return false;
		this.items.repeat(function(i){this.i=i});
		var event_name=this.items[0].attr("aref")?"oncomplete":"onclick";
		var ev={};
		ev[event_name]=function(){_this.set(this.i)};
		this.items.event(ev);
		this.blocks.css({display:"none"});
		this.cur=_(obj, "dt.act").i || 0; //get default active tab
		this.act(this.cur);
		this.blocks[this.cur].css({display:"block"});
	},
	set:function(num){
		if(this.cur==num) return false;
		this.blocks[this.cur][this._effect](0);
		this.act(num, this.cur);
		this.blocks[num][this._effect](1);
		this.cur=num;
	},
	act:function(cur, old){
		_([this.items[cur], _(this.items[cur], "<")]).classname("+"+this._active_classname);
		if(old!=undefined) _([this.items[old], _(this.items[old], "<")]).classname("-"+this._active_classname);
	}
});

function init_calc(){
	var inp=document.forms.calc.getElementsByTagName("input");
	for(var i=0; i<inp.length; i++)
		inp[i].onchange=inp[i].onclick=function(){calc_form()};
	calc_form();
};


function calc_form(){
	var sum=0;
	var inp=document.forms.calc.getElementsByTagName("input");
	for(var i=0; i<inp.length; i++){
		if((inp[i].className=="chb" || inp[i].className=="rad") && inp[i].checked){
			if(inp[i].lang)  sum+=Number(inp[i].value*_(inp[i].lang).value);
			else sum+=Number(inp[i].value);
		}
	}
	_("total_price").innerHTML=sum+"$";
};


function calc_call(){
	if(!window._popup){ _popup=new Popup(_('calculator')); init_calc();} 
	_popup.show();
	return false;
}
if(window.GOOGLE_ANALYTICS){
	document.write('<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></'+'script>');
	var _gaq;
	_(function(){
		_gaq = _gaq || [];
		_gaq.push(['_setAccount', GOOGLE_ANALYTICS]);
		_gaq.push(['_setDomainName', 'ukrinsoft.com']);
		_gaq.push(['_setDomainName', 'ukrinsoft.com.ua']);
		//_gaq.push(['_setDomainName', 'ukrinsoft.de']);
		_gaq.push(['_setDomainName', 'ukrinsoft.ru']);
	    _gaq.push(['_setAllowLinker', true]);
		_gaq.push(['_trackPageview']);
	});
}



//if(window.GOOGLE_MAP_KEY) MAP.load_core(GOOGLE_MAP_KEY);

_(function(){
	init_content(document);
	if(location.hash=="#calculator") calc_call();

});



//AJAX response listeners
HTMLAJAX.onresponse=function(response, htmlajax){
	if(!response || !response.obj) return;
	if(response.obj.alert) alert(response.obj.alert);
	//if(response.obj.alert) Popup.show(response.obj.alert);
	if(response.obj.redirect!=undefined) location.href=response.obj.redirect;
	if(response.obj.reload) location.reload();
};



//initialize output content
function init_content(root){	
	
	if(root!=document){
		_(root, "script").repeat(function(){
			var func=(new Function(this?this.innerHTML:""));
			if(!this.src) func.apply(this); //normal script execution
		});
	}
	
	if(window.Editor){
		
		_(root, "div[aref]").event({ondblclick:function(){this.target=this; return GET(this);}});
		
		_(root, "textarea[editor]").repeat(function(){
			var id=Editor.init(this);
			_(this.form).event({onsubmit:function(){return Editor.save(id)}});
		});
	}

	_(root, "a[aref], form[aref]").repeat(function(){
		HTMLAJAX.attach(this);
	});
	
	_(root, "a[rev=mailto:]").repeat(function(){
		init_mail(this);
	});
		
	_(root, "dl.tabs").repeat(function(){
		var first=_(this, "dt:0");
		if(!first.attr("href") || first.attr("aref")) new Tabs(this);
	});
	
	_(root, "input[calendar]").event({onfocus:function(){
		JSCal.show(this);
	}});

	_(root, "input[alt], textarea[alt]").repeat(function(){
		new Forms.Default(this);
	});
	
	_(root, "select").repeat(function(){
		new Forms.select(this);
	});
	
	_(root, "input[autocomplete]").event("onfocus", function(){
		new Forms.autocomplete(this);
	});
	
	_(root, "a[swfupload]").event("onmouseover", function(){
		new Upload(this, window.UPLOAD_HANDLER, this.attr("swfupload"), "image");
	});
	
	
	_(".selector").repeat(function(){new Selector(this)});

	
	
};


