/*
styledJS v0.7
Coded by Rustam Khodjaev.
This code is the part of copyrighted content and not for public use.
If you want to use anything from here, please contact an author.
*/

var firstRun=true,popUpWin=false,rTimer,tTimer,cTimer
var Mozilla=navigator.appName=='Netscape'
var IE=navigator.appName.indexOf('Microsoft')!=-1
var IE6=typeof document.addEventListener != 'function'
var Opera=!!window.opera
var elementStyles = {
	left: '@px', top: '@px', bottom: '@px', right: '@px',
	width: '@px', height: '@px', maxWidth: '@px', maxHeight: '@px', minWidth: '@px', minHeight: '@px',
	backgroundColor: 'rgb(@, @, @)', backgroundPosition: '@px @px', color: 'rgb(@, @, @)',
	fontSize: '@px', letterSpacing: '@px', lineHeight: '@px', clip: 'rect(@px @px @px @px)',
	margin: '@px @px @px @px', padding: '@px @px @px @px', border: '@px @ rgb(@, @, @) @px @ rgb(@, @, @) @px @ rgb(@, @, @)',
	borderWidth: '@px @px @px @px', borderStyle: '@ @ @ @', borderColor: 'rgb(@, @, @) rgb(@, @, @) rgb(@, @, @) rgb(@, @, @)',
	zIndex: '@', 'zoom': '@', fontWeight: '@', textIndent: '@px', opacity: '@'
}

function addEvent(obj,type,fn) {
	if (obj.addEventListener) obj.addEventListener(type,fn,false)
	else if (obj.attachEvent) {
		obj["e"+type+fn]=fn
		obj.attachEvent("on"+type,function() { obj["e"+type+fn]() } )
	}
}

function insertHTML(elem,html) {
	if(Mozilla) {
		var adjHTML,range=elem.ownerDocument.createRange()
		range.selectNodeContents(elem)
		range.collapse(false)
		adjHTML=range.createContextualFragment(html)
		elem.appendChild(adjHTML)
    } else {
		elem.innerHTML=html
    }
}

function get(elem) {
	if(document.getElementById(elem)) return document.getElementById(elem)
}

function getByTag(elemid,name,index) {
	elem=typeof elemid=='object'?elemid:get(elemid)
	collection=elem.getElementsByTagName(name)
	return (index==undefined)?collection:collection[index]
} 

function redirect(to,timeout) {
	timedAction(function(){location.href=(to==''?'index.php':to)},timeout)
}

function timedAction(callback,timeout) {
	if(!timeout||timeout==0||timeout==undefined) {
		callback()
		if(tTimer) clearInterval(tTimer)
	} else {
		tTimer=setInterval(function(){timedAction(callback)},timeout*1000)
	}
}

function decodeUrl(coded,extended,hideQm) {
	var url=''
	if(extended) {
		var index=0
		var str=new Array()
		temp=coded.toString().split('')
		for(i=0;i<temp.length;i++) {
			if(!str[index]) str[index]=''
			str[index]+=temp[i]
			if(str[index].toString().length>=3) index++
		}
		var cArray=str
	} else cArray=coded.split('%')
	for(i=0;i < cArray.length;i++) {
		if(extended) {
			url+=String.fromCharCode(parseInt(cArray[i].replace('%',''))+13)
		} else {
			innerArray=cArray[i].split(',')
			for(a=0; a<innerArray.length; a++) url+=String.fromCharCode(parseInt(innerArray[a])+13)
			if(i != (cArray.length-1)) url+='&'
		}
	}
	return (extended?'':(hideQm?'':'?'))+url
}

function randNum() {return Math.round(Math.random()*100000)}

function setContent(text,elem) {
	elem=typeof elem=='object'?elem:get(elem)
	setStyle(elem,'display','block')
	elem.innerHTML=text
}

function getPosition(obj) {
	var oleft=otop=0
	if(obj.offsetParent) {
		oleft=obj.offsetLeft
		otop =obj.offsetTop
		while(obj=obj.offsetParent) {
			oleft+=obj.offsetLeft
			otop +=obj.offsetTop
		}
	}
	return [oleft,otop]
}

function newWindow(URLStr, left, top, width, height) {
	if(popUpWin && !popUpWin.closed) popUpWin.close()
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'')
}

function checkKeycode(e) {
	e = e||window.event
	var keyCode=e.keyCode
	if(e.ctrlKey && keyCode==83) return false
}

function locate(elem,elemto,act,acl) {
	var coords=getPosition(elemto)
	setStyles(elem,{
		'left':coords[0]+(acl==undefined?0:acl),
		'top':coords[1]+(act==undefined?0:act)
	})
}

function catchResult(fn) {
	return fn()
}

function setOpacity(elem,value) {
	if(IE) elem.style.filter='alpha(opacity='+value+')'
	else elem.style.opacity=value/100
	return true
}

function setStyle(elem,property,value) {
	if(property=='opacity') return setOpacity(elem,value)
	if(property=='float') property=(IE)?'styleFloat':'cssFloat'
	value=catchResult(function() {
			if(typeof value != 'string') {
				return (typeof value == 'number') ? elementStyles[property].replace('@', Math.round(value)) : value;
			}
			return value;
	})
	elem.style[property]=value
}

function setStyles(elem, properties) {
	for (var style in properties) setStyle(elem,style,properties[style])
}

function appendElement(elementName,appendTo,styles) {
	temp=document.createElement(elementName)
	setStyles(temp,styles)
	appendTo.appendChild(temp)
	return temp
}
