

red.prototype.css = {
	
	get : function ( elem, name ) {
		var cName = red.prototype.util.camelize(name);
		var value = "";

		if (red.prototype.browser == "IE" && name == "float") {
			return elem.currentStyle["styleFloat"];
		} 
		else if (red.prototype.browser != "IE" && name == "float") {
			return document.defaultView.getComputedStyle(elem, "").getPropertyValue("float");
		}
		if (elem.style[cName]) {
			return elem.style[cName];
		}
		else  if (elem.currentStyle) {
			value = elem.currentStyle[cName];
		}
		else if (document.defaultView && document.defaultView.getComputedStyle) {
			value = document.defaultView.getComputedStyle(elem, "").getPropertyValue(name);
		}
		if (/^\s*rgb\s*\(/.test(value)) {
			value = red.prototype.util.rgbtohex(value);
		}
		if (red.prototype.browser == "Safari" && document.defaultView.getComputedStyle(elem, "").getPropertyValue("display") == "none") {
			red.prototype.css.set(elem, "display: block");
			value = document.defaultView.getComputedStyle(elem, "").getPropertyValue(name);
			red.prototype.css.set(elem, "display: none");
		}
		
		if(isNaN(value)){
			value = 0;
		}
				
		return value;
	},
		
	set : function ( elem, css, overwrite ) {
		overwrite ? elem.style.cssText = css : elem.style.cssText += css;
	},
	
	get1 : function ( elem, css) {
		return elem.style[css];
	},
		
	set1 : function ( elem, css, value ) {
		elem.style[css] = value;
	},
		
	reset : function ( elem ) {
		elem.style.cssText = "";
	},
	
	fullsizexy : function ( elem ) {
		if (red.prototype.css.get(elem, "display") != "none") {
			return [elem.offsetWidth,elem.offsetHeight];
		} 
		else{
			var p = red.prototype.css.get(elem, "position");
			var v = red.prototype.css.get(elem, "visibility");
			var d = red.prototype.css.get(elem, "display");
			var oldCSS = "position:" + p + "; visibility:" + v + "; display:" + d + ";";
			var newCSS = "position: relative; visibility: hidden; display : block;";
			red.prototype.css.set(elem, newCSS);
			var oh = elem.offsetHeight;
			var ow = elem.offsetWidth;
			red.prototype.css.set(elem, oldCSS);
			return [ow,oh];
		}
	},

	getsizexy : function ( elem ) {
		var s = red.prototype.css.fullsizexy( elem );
				
		var bp = parseInt(red.prototype.css.get(elem, "border-left-width"));
		bp += parseInt(red.prototype.css.get(elem, "border-right-width"));
		bp += parseInt(red.prototype.css.get(elem, "padding-left"));
		bp += parseInt(red.prototype.css.get(elem, "padding-right"));
		var w = s[0] - bp;
				
		var bp = parseInt(red.prototype.css.get(elem, "border-top-width"));
		bp += parseInt(red.prototype.css.get(elem, "border-bottom-width"));
		bp += parseInt(red.prototype.css.get(elem, "padding-top"));
		bp += parseInt(red.prototype.css.get(elem, "padding-bottom"));
		
		var h = s[1] - bp;
		return [w,h];
	},
	
	setsizexy : function (elem , sizearray){
		//red.prototype.css.set(elem,"width:"+sizearray[0]+"px;height:"+sizearray[1]+"px;",true);
		elem.style.width 	= sizearray[0]+'px';
		elem.style.height 	= sizearray[1]+'px';
		
	},
	
	getxy : function ( elem ){
		var posx = 0;
		var posy = 0;
		while ( elem.offsetParent ) {
			posx += elem.offsetLeft;
			posy += elem.offsetTop;
			elem = elem.offsetParent;
		}
		posx = posx + document.body.offsetLeft;
		posy = posy + document.body.offsetTop;
		return [posx,posy];
	},
			
	setxy : function ( elem, xyarray, position ) {
		if(position == null){
			position = 'relative';
		}
		
		if (red.prototype.css.get(elem, "position") == "absolute" ||
		red.prototype.css.get(elem, "position") == "relative") {
			elem.style.left = xyarray[0] + "px";
			elem.style.top 	= xyarray[1] + "px";
		} 
		else {
			red.prototype.css.set1(elem, "position",position);
			elem.style.left = xyarray[0] + "px";
			elem.style.top 	= xyarray[1] + "px";
		}
	},
	
	relxy : function ( elem ) {
		var xy 			= red.prototype.css.getxy(elem);
		var parentxy 	= red.prototype.css.getxy(elem.parentNode);
		
		var x = elem.parentNode == elem.offsetParent ? elem.offsetLeft : 
		xy[0] - parentxy[0];
		
		var y = elem.parentNode == elem.offsetParent ? elem.offsetTop : 
		xy[1] - parentxy[1];
		
		return [x,y];
	},
	
	setopacity : function ( elem, amount ) {
		if ( red.prototype.browser == "IE" ) {
			elem.style.zoom = 1;
			var o = "alpha(opacity=" + amount + ")";
			elem.style.filter = o;
		}
		else{
			amount = amount / 100;
			elem.style.opacity = amount;
		}
	},
	
	/* static, absolute, relative, fixed, Inherit */
	
	position : function(elem,position){
		if(position == null){
			position = 'absolute';
		}
		//var xy = red.prototype.css.getxy(elem);
		//red.prototype.css.setxy(elem,xy,position);
		elem.style.position = position;
	},
	
	has_position : function(elem){
		if(red.prototype.css.get(elem, "position") == "absolute" ||
			red.prototype.css.get(elem, "position") == "relative"){
			return true;
		}
		else{
			return false;
		}
	}

};