var ie=document.all && !window.opera;
var IE6=navigator.appVersion.indexOf("MSIE 6")!=-1;

var _=function(obj,route){
	if(!obj) return null;
	if(typeof obj=="string" && document.getElementById) obj=document.getElementById(obj);
	if(obj) return route?_DOM(obj,route):obj;
	else return null;
}



//Linguistic DOM objects search functionality
// ">" - next sibling tag
// "<" - prefious sibling tag
// "^" - first child tag
// "$" - last child tag
// "/" - parent node
// "~" - search  in child nodes
// "@" - return array matches
// "." - className property
// ":" - id property
// "#" - name property
// ----- RegExp to search _\(\'?\"?[a-zA-Z0-9_]+\'?\"?,
function _DOM(obj,route){
	route=route.replace(/[^<>\^$\/~a-z0-9_@.:# ]/gi,""); //clear uncorrect instructions
	route=route.replace(/(^[a-z@.:#].*)/i,"^$1"); //normalize inctructions (start with firstChild)
	route=route.replace(/((\<+)|(\>+)|(\^)|(\$)|(\/)|(\~)|(\@))/g,"$1*").replace(/\*([a-z0-9_@.:# ])/gi,"$1"); //add "any tag" (*) pointer
	var tags=route.toUpperCase().match(/([a-z0-9_*.:# ]+)/gi) || []; //create tags array
	var pointer=route.replace(/[^<>\^$\/~@]+/g,"+"); //split inctructions
	
	//alert(route+" ||| "+tags+" ||| "+pointer+" ||| ")
	var fit={
		">":"nextSibling",
		"<":"previousSibling",
		"^":"firstChild",
		"$":"lastChild",
		"/":"parentNode",
		".":ie?"className":"class",
		":":"id",
		"#":"name"
	}
	var tagPos=0, childPos=0;
	var char, tag, tagName, propKey, propValue, found, childNodes;
	var matches=[];

	while((char=pointer.charAt(0))){
		if(char=="+"){//change filter by "tag"
			if(tags[tagPos+1]) tagPos++;
			pointer=pointer.substr(1);
			continue;
		}
		
		tagName=tags[tagPos];
		propKey="";
		
		//if property exist
		if(tagName && (/[.:#]/.test(tagName))){
			propKey=fit[tagName.replace(/[^.:#]/g,"")];
			tag=tagName.match(/([a-z1-6_]*)[.:#]([a-z0-9_ ]*)/i);
			tagName=tag[1] || "*";
			propValue=tag[2];
			//alert(tagName+" "+propKey+" "+propValue)
		}
		
		//search in child nodes
		if(char=="~"){
			if(!childNodes) childNodes=obj.getElementsByTagName(tagName);
			else childPos++;
		}
		else if(childNodes){
			childNodes=null;
			childPos=0;
		}
		
		if(!(obj=obj[fit[char]] || (childNodes && childNodes[childPos]))) return matches.length?matches:null; //set next object
		found=!(obj.nodeType!=1 || (tagName!="*" && obj.tagName!=tagName) || (propKey && (!obj.getAttribute(propKey) || typeof obj.getAttribute(propKey)!="string" || obj.getAttribute(propKey).toUpperCase()!=propValue)));
		if(found) pointer=pointer.substr(1);
		
		//if first/last child not found in first step
		if((char=="^" || char=="$") && !found){
			pointer=pointer.replace(/./,(char=="^"?">":"<"));
		}
		
		//if matches symbol was found (return array of matches)
		if(pointer.charAt(0)=="@"){
			if(char=="^" && found) char=">";
			pointer=char+pointer;
			matches[matches.length]=obj;
		}
	}
	return obj;
}


function addEvent(el, evname, func) {
	if(!el["on"+evname] && el!=window && el!=document) return el["on"+evname]=func;
	if(el.attachEvent) el.attachEvent("on"+evname, func); // IE
	else if(el.addEventListener) el.addEventListener(evname, func, true); // Gecko / W3C
	else el["on"+evname]=func;
};

//get tag Attribute
function _ATTR(obj,attr){
	obj=_(obj);
	if(!obj || !attr) return null;
	return obj.getAttribute && obj.getAttribute(attr)!=undefined ? obj.getAttribute(attr) : (obj[attr]!=undefined ? obj[attr] : null);
}


var COOKIE={
	set:function(name, value, expire) {
		if(expire){
			var d=new Date();
			d.setTime(d.getTime()+expire*1000);
			expire="; expires="+d.toUTCString();
		}
		else expire="";
		document.cookie=name+"="+escape(value)+expire+"; 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;
	}
}


// element className & style functions
var CSS=function(obj){
	return {
		empty:function(){
			return obj.className.replace(/\s/g,"")==""?true:false;
		},
		all:function(name){
			return !this.empty()?obj.className.split(/\s+/):[];
		},
		exist:function(name){
			for(var i=0, c=this.all(name), l=c.length; i<l; i++)
				if(c[i]==name) 
					return true;
			return false;
		},
		set:function(name){
			obj.className=name;
		},
		add:function(name){
			this.remove(name);
			obj.className+=' '+name;
			return true;
		},
		remove:function(name){
			obj.className=obj.className.replace(new RegExp("((^)|(\\s))"+name+"((\\s)|($))"),"$3");
			return false;
		},
		invert:function(name){
			return this.exist(name) ? this.remove(name) : this.add(name);
		},
		clear:function(){
			obj.className='';
		}
	}
}

//js include
function include(src){
	if(!document.files) document.files={};
	if(document.files[src]) return false;
	document.files[src]=1;
	src=(/^https?:\/\/.+/.test(src)?src:GLOBAL_PATH+src);
	if(src.indexOf(".css")==-1) document.write('<'+'script type="text/javascript" src="'+src+'"><'+'/script>');
	else document.write('<link type="text/css" rel="stylesheet" href="'+src+'" />');

}


//init png in IE6
function initPNG(root){
	//return false;
	if(!IE6) return false;
	var all=root.getElementsByTagName("*");
	var src;
	for(var i=0, l=all.length; i<l; i++){
		if(all[i].currentStyle && all[i].currentStyle["backgroundAttachment"]!="fixed"){
			var src=all[i].tagName.toLowerCase()=="img" ? all[i].src : all[i].currentStyle["backgroundImage"];
			if( !(/\.png/i).test(src)) continue;
			if(all[i].tagName.toLowerCase()=="img"){
				all[i].style.width=all[i].offsetWidth;
				all[i].style.height=all[i].offsetHeight;
				all[i].src=IMGS_PATH+"dot.gif"; 
			}
			else src=src.replace(/url\(\"(.*)\"\)$/i,"$1");
			
			var sizing=all[i].currentStyle["backgroundRepeat"]=="no-repeat"?"crop":"scale";
			all[i].style["filter"]="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"',sizingMethod="+sizing+")";
			all[i].style["backgroundImage"]="none";
			all[i].style["backgroundPosition"]="-1000px -1000px";
		}
	}
}

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