var $ = function(id,parent){
	if(parent == null) parent = document;
	var o = parent.getElementById(id);
	return o;
}

/**************************************************************************/

var Stardust = function(){
	var parent = this;
	
	/* ****************************** DOM ****************************** */

	parent.$ = function(id, parent)
	{
		if(parent == null) parent = document;
		var o = parent.getElementById(id);
		return o;
	}
	
	parent.childNodeIndex = function(o, type, back)
	{
		var tmp = o.parentNode;
		for(i=0;i<back;i++) tmp = tmp.parentNode;
		if(type!='') var childs = tmp.getElementsByTagName(type);
		else var childs = tmp.childNodes;
		for(i=0;i<childs.length;i++)
		{
			if(childs[i]==o) return i;
		}
	}
	
	parent.insertAfter = function(node, referenceNode, parentEl)
	{
		parentEl.insertBefore(node, referenceNode.nextSibling.nextSibling);
	}
	
	parent.nextSibling = function( str, prev )
	{
		var next = prev.nextSibling;
		if( next.tagName!=undefined && next.tagName.toUpperCase()==str.toUpperCase() ) return next;
		else return nextSibling(str, next );		
	}
	
	parent.previousSibling = function( str, next )
	{
		var next = next.previousSibling;
		if( next.tagName!=undefined && next.tagName.toUpperCase()==str.toUpperCase() ) return next;
		else return parent.previousSibling(str, next );		
	}
	
	parent.getParentByTagName = function(o, tag)
	{
		var p = o.parentNode;
		if(!p){
			return false;
		}else{
			if(p.tagName.toLowerCase()==tag) return p;
			else return getParentByTagName(p,tag);
		}
	}

	parent.getElementsByClassName = function(str,type,child)
	{
		if(!child) child = document;
		str = str.replace(/\-/g, "\\-");
		var regexp = new RegExp("(^|\\s)" + str + "(\\s|$)");
		var tmp = new Array();
		var o = child.getElementsByTagName(type);
		for(var i=0;i<o.length;i++){
			if(regexp.test( o[i].className )) tmp.push(o[i]);
		}
		return tmp;
	}
	
	parent.getElementsByName = function(str, type, child)
	{
		if(!child) child = document;
		str = str.replace(/\-/g, "\\-");
		//var regexp = new RegExp("(^|\\s)" + str + "(\\s|$)");
		var regexp = new RegExp("" + str + "");
		var tmp = new Array();
		var o = child.getElementsByTagName(type);
		for(var i=0;i<o.length;i++){
			if(regexp.test( o[i].getAttribute('name') )) tmp.push(o[i]);
		}
		return tmp;
	}
	
	parent.getElementsByTagName = function(str, o){
		if(!o) o = document;
		list = o.getElementsByTagName(str);
		res = new Array();
		for(k=0;k<list.length;k++) res.push(list[k]);
		return res;
	}
	
	parent.createTag = function(type, params)
	{
		if(type){
			switch(type){
				case 'img':
					var o = new Image();
					break;
				case 'text':
					//if(key=='innerHTML') o.innerHTML = params[key];
					var o = document.createTextNode( (key=='innerHTML')? params[key]:'' );
					break;
				default:
					var o = document.createElement(type);
					break;
			}
			for(var key in params){
				if(key=='id') o.setAttribute('id',params[key]);
				else if(key=='name') o.setAttribute('name',params[key]);
				else if(key=='type') o.setAttribute('type',params[key]);
				else if(key=='href') o.setAttribute('href',params[key]);
				else if(key=='usemap') o.setAttribute('usemap',params[key],0);
				else if(key=='shape') o.setAttribute('shape',params[key]);
				else if(key=='coords') o.setAttribute('coords',params[key]);
				else if(key=='className') o.className = params[key];
				else if(key=='src') o.src = params[key];
				else if(key=='value') o.value = params[key];
				else if(key=='innerHTML') o.innerHTML = params[key];
				else if(key=='opacity') parent.opacity(o, params[key]);
				else o.style[key] = params[key];
			}
			return o;
		}
		return false;
	}
	
	/* ****************************** EVENT ****************************** */

	parent.addEvent = function( obj, type, fn , follow)
	{
		if (obj.addEventListener)
			obj.addEventListener( type, fn, follow );
		else if (obj.attachEvent)
		{
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
			obj.attachEvent( "on"+type, obj[type+fn] );
		}
	}
	
	parent.removeEvent = function( obj, type, fn )
	{
		if (obj.removeEventListener)
			obj.removeEventListener( type, fn, false );
		else if (obj.detachEvent)
		{
			obj.detachEvent( "on"+type, obj[type+fn] );
			obj[type+fn] = null;
			obj["e"+type+fn] = null;
		}
	}
	
	parent.addLoadEvent = function(func)
	{
		var oldonload = window.onload;
		if (typeof window.onload != 'function'){
			window.onload = func;
		}else{
			window.onload = function(){
				oldonload();
				func();
			}
		}
	}

	/* ****************************** AJAX ****************************** */
	
	parent.ajax = function(url, synch)
	{ 
	    var xmlHttpReq = false;
	    var self = this;
	    this.res;
	    if (window.XMLHttpRequest) self.xmlHttpReq = new XMLHttpRequest(); // Mozilla/Safari
	    else if (window.ActiveXObject) self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); // IE
	    
	    self.xmlHttpReq.open('GET', url, synch);
	    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    self.xmlHttpReq.onreadystatechange = function() {
        	if(self.xmlHttpReq.readyState == 4) {
				self.res = self.xmlHttpReq.responseText;
	        }
	    }
		self.xmlHttpReq.send(url);
		return this.res;
		    
	}
	
	/* ****************************** STYLE ****************************** */
	
	parent.width = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.width);
			o.style.width = value + 'px';
			return true;
		}
	}
	parent.height = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.height);
			o.style.height = value + 'px';
			return true;
		}
	}
	parent.left = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.left);
			o.style.left = value + 'px';
			return true;
		}
	}
	parent.top = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.top);
			o.style.top = value + 'px';
			return true;
		}
	}
	parent.right = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.right);
			o.style.right = value + 'px';
			return true;
		}
	}
	parent.bottom = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parseInt(o.style.bottom);
			o.style.bottom = value + 'px';
			return true;
		}
	}
	
	parent.margin = function(o, array)
	{
		if( parent.isObject(o) ){
			if( typeof array == 'array' ){
				if( array[0]!=null) o.style.marginTop = array[0];
				if( array[1]!=null) o.style.marginRight = array[1];
				if( array[2]!=null) o.style.marginBottom = array[2];
				if( array[3]!=null) o.style.marginLeft = array[3];
				return true;
			}
			if( !isNaN(array) ){
				o.style.marginTop = o.style.marginRight = o.style.marginBottom = o.style.marginLeft = array;
				return true;
			}
			if( array===undefined ) return [parseInt(o.style.marginTop),parseInt(o.style.marginRight),parseInt(o.style.marginBottom),parseInt(o.style.marginLeft)];
		}
	}
	
	parent.padding = function(o, array)
	{
		if( parent.isObject(o) ){
			//alert(array);
			if( isArray(array) ){
				if( array[0]!=null) o.style.paddingTop = array[0];
				if( array[1]!=null) o.style.paddingRight = array[1];
				if( array[2]!=null) o.style.paddingBottom = array[2];
				if( array[3]!=null) o.style.paddingLeft = array[3];
				return true;
			}
			if( !isNaN(array) ){
				o.style.paddingTop = o.style.paddingRight = o.style.paddingBottom = o.style.paddingLeft = array;
				return true;
			}
			if( array===undefined ) return [parseInt(o.style.paddingTop),parseInt(o.style.paddingRight),parseInt(o.style.paddingBottom),parseInt(o.style.paddingLeft)];
		}
	}
	
	parent.opacity = function(o, value)
	{
		if( parent.isObject(o) ){
			if( value===undefined ) return parent.isIE()? o.filters.alpha.opacity/100 : o.style.opacity*1;
			//o.style.filter = isIE()? 'progid:DXImageTransform.Microsoft.Alpha(Opacity='+(value*100)+')' : o.style.opacity = value
			if(parent.isIE()) o.style.filter = 'Alpha(Opacity='+(value*100)+')'; else o.style.opacity = value;
			//if( isIE() && value==1 ) o.style.filter = '';
			return true;
		}
	}
	
	parent.crop = function(o, p1, p2, p3, p4)
	{
		if( o.clip ) {
			o.clip.left = p4; o.clip.top = p1; o.clip.right = p2; o.clip.bottom = p3;
		}else{
			//o.style.clip = 'rect('+p1+'px,'+p2+'px,'+p3+'px,'+p4+'px)';
			o.style.clip = 'rect('+p1+','+p2+','+p3+','+p4+')';
		}
	}
	
	parent.display = function(o, state)
	{
		o.style.display = state? '':'none';
	}
	
	/* ****************************** SCREEN ****************************** */
	
	parent.bodysize = function()
	{
		var w, h;
		var scrolls = parent.viewsize();
		if(window.innerHeight && window.scrollMaxY){
			w = document.body.scrollWidth;
			h = window.innerHeight + window.scrollMaxY;
		}else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){ //IE 6+ in 'standards compliant mode'
		    w = document.documentElement.clientWidth;
		    h = document.documentElement.clientHeight;
		}else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){ //IE 4 compatible
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			w = document.body.offsetWidth;
			h = document.body.offsetHeight;
		}
		return [ (w<scrolls[0])? scrolls[0]:w, (h<scrolls[1])? scrolls[1]:h ];
	}
	
	parent.viewsize = function()
	{
		if(window.innerHeight && window.scrollMaxY){
			return [ document.body.scrollWidth, window.innerHeight + window.scrollMaxY ];
		}else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			return [ document.body.scrollWidth, document.body.scrollHeight ];
		}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			return [ document.body.offsetWidth, document.body.offsetHeight ];
		}
		return null;
	}
	
	parent.scrollX = function()
	{
		if(self.pageXOffset){
			return self.pageXOffset;
		}else if(document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
			return document.documentElement.scrollLeft;
		}else if(document.body){// all other Explorers
			return document.body.scrollLeft;
		}
		return null;
	}
	
	parent.scrollY = function()
	{
		if(self.pageYOffset){
			return self.pageYOffset;
		}else if(document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			return document.documentElement.scrollTop;
		}else if(document.body){// all other Explorers
			return document.body.scrollTop;
		}
		return null;
	}
	
	parent.elementPosition = function(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while( obj=obj.offsetParent )
			{
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		}
		return [curleft, curtop];
	}
	
	parent.mouseAbsolute = function(e){
		if(e.pageX) return [e.pageX,e.pageY];
		else if(e.clientX) return [e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft:document.body.scrollLeft), e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop:document.body.scrollTop)];
		else return null;
	}
	
	parent.getMousePosition = function(e)
	{
		return [
			parent.isIE()? event.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft:e.pageX,
			parent.isIE()? event.clientY + document.body.scrollTop + document.documentElement.scrollTop:e.pageY
			];
	}
	
	/* ****************************** OTHER ****************************** */
	
	parent.isFF = function()
	{
		return (navigator.appName.indexOf("Netscape")!=-1)? true:false;
	}
	
	parent.isIE = function()
	{
		return (navigator.appName.indexOf("Microsoft")!=-1)? true:false;
	}
	
	parent.isOP = function()
	{
		return (navigator.appName.indexOf("Opera")!=-1)? true:false;
	}
	
	
	
	parent.isArray = function(o)
	{
		if(o.constructor.toString().indexOf("Array") == -1) return false;
		return true;
	}
	
	parent.isObject = function(a)
	{
		return (a && typeof a == 'object') || isFunction(a);
	}
	
	parent.isFunction = function(a)
	{
		return typeof a == 'function';
	}
	
	parent.stripHTML = function(t)
	{
		return t.replace(/(<([^>]+)>)/ig,"");
	}
	
	parent.str_pad = function(str, len, pad, dir)
	{
		if (typeof(len) == "undefined") { var len = 0; }
		if (typeof(pad) == "undefined") { var pad = ' '; }
		if (typeof(dir) == "undefined") { var dir = 1; }
		str = str.toString();
		if (len + 1 >= str.length) {
			switch (dir){
				case 1:
					str = Array(len + 1 - str.length).join(pad) + str;
					break;
				case 2:
					var right = Math.ceil((padlen = len - str.length) / 2);
					var left = padlen - right;
					str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
					break;
				default:
					str = str + Array(len + 1 - str.length).join(pad);
					break;
			}
		}
		return str;
	}
	
	
	parent.viewsize = function()
	{
		if( self.innerHeight ){ // all except Explorer
			return [ self.innerWidth, self.innerHeight];
		}else if( document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode
			return [ document.documentElement.clientWidth, document.documentElement.clientHeight ];
		}else if( document.body ){ // other Explorers
			return [ document.body.clientWidth, document.body.clientHeight ];
		}	
		return null;
	}
	
	parent.scrollY = function()
	{
		if(self.pageYOffset){
			return self.pageYOffset;
		}else if(document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			return document.documentElement.scrollTop;
		}else if(document.body){// all other Explorers
			return document.body.scrollTop;
		}
		return null;
	}
	
}
var stardust = new Stardust();

/**************************************************************************/