var RC = window.RC || {};
RC.Dom = function() {
	var $D = YAHOO.util.Dom;
	return {
      getStyle: function(el, property) {
         var f = function(el) {
            var value = null;
            var dv = document.defaultView;
            if (property == 'opacity' && el.filters) 
            {// IE opacity
               value = 1;
               try {
                  value = el.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100;
               } catch(e) {
                  try {
                     value = el.filters.item('alpha').opacity / 100;
                  } catch(e) {}
               }
            }
            else if (el.style[property]) 
            {
               value = el.style[property];
            }
            else if ( dv && dv.getComputedStyle )
            {  // convert camelCase to hyphen-case

               var converted = '';
               for(var i = 0, len = property.length;i < len; ++i) {
                  if (property.charAt(i) == property.charAt(i).toUpperCase()) 
                  {
                     converted = converted + '-' + property.charAt(i).toLowerCase();
                  } else {
                     converted = converted + property.charAt(i);
                  }
               }
              if (dv.getComputedStyle(el, '') && dv.getComputedStyle(el, '').getPropertyValue(converted)) {
                  value = dv.getComputedStyle(el, '').getPropertyValue(converted);
               }
            }
            else if (el.currentStyle && el.currentStyle[property]) {
				switch (el.currentStyle[property]) {
					case 'auto':
						switch (property) {
							case 'height':
								alert('offsetHeight: '+el.offsetHeight+', paddingTop: '+ el.currentStyle['paddingTop']+', paddingBottom: '+ el.currentStyle['paddingBottom']+', borderTopWidth: '+ el.currentStyle['borderTopWidth']+', borderBottomWidth: '+ el.currentStyle['borderBottomWidth']);
								value = el.offsetHeight+'px';
								break;
							case 'width':
								value = el.offsetWidth+'px';
								break;
							default:
								value = '0px';
						}
						break;
					case 'thin':
						value = '1px';
						break;
					case 'medium':
						value = '3px';
						break;
					case 'thick':
						value = '5px';
						break;
					default:
						value = el.currentStyle[property];
				}
            }
            return value;
         };
         return $D.batch(el, f, this, true);
      }
	}
}();
RC.Event = function() {
	return {
		attachLoadEvent: function(functionCall) {
			if (window.addEventListener) {
				window.addEventListener('load',functionCall, false);
			}
			else {
				var oldonload = window.onload;
				window.onload = function() {
					oldonload();
					functionCall();
				}
			}
		},
		schedule: function(objectID, functionCall, iteration)
		{
			if (iteration == null)
			{
			   iteration = 0;
			}

			if (objectID == "window")
			{
				RC.Event.attachLoadEvent(functionCall);
			}
			else if (document.getElementById(objectID))
			{
			   functionCall();
			}
			else if (iteration < 300)
			{
			   setTimeout(function(){RC.Event.schedule(objectID, functionCall, iteration + 1)}, 10);
			}

			return true;
		}
	}
}();
RC.Helpers = RC.Helpers || {};
RC.Helpers.Cookie = function() {
	return {
		get: function(name) {
			var start = document.cookie.indexOf( name + "=" );
			var len = start + name.length + 1;
			if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
			{
				return null;
			}
			if ( start == -1 ) return null;
			var end = document.cookie.indexOf( ";", len );
			if ( end == -1 ) end = document.cookie.length;
			return unescape( document.cookie.substring( len, end ) );
		},
		set: function( name, value, expires, path, domain, secure ) {
			var today = new Date();
			today.setTime( today.getTime() );
			if ( expires )
			{
				expires = expires * 1000 * 60 * 60 * 24;
			}
			var expires_date = new Date( today.getTime() + (expires) );
			document.cookie = name+"="+escape( value ) +
				( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
				( ( path ) ? ";path=" + path : "" ) +
				( ( domain ) ? ";domain=" + domain : "" ) +
				( ( secure ) ? ";secure" : "" );
		},
		remove: function ( name, path, domain ) {
			if ( this.get( name ) ) document.cookie = name + "=" +
					( ( path ) ? ";path=" + path : "") +
					( ( domain ) ? ";domain=" + domain : "" ) +
					";expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	}
}();
RC.Helpers.URL = function(sURL) {
	this.url = sURL.replace('&amp;','&');
	this.aURL = /^([^:]*:\/\/)?(([^:@]*)(:[^@]*)?@)?([^\/#\?]*)(\/[^?#]*)?(#[^\?]*)?(\?.*)?$/.exec(this.url);
	this.scheme = (this.aURL[1]!=undefined)? this.aURL[1].substring(0,this.aURL[1].length - 3) : '';
	this.user = (this.aURL[3]!=undefined)? this.aURL[3] : '';
	this.password = (this.aURL[4]!=undefined)? this.aURL[4].substring(1) : '';
	this.host = (this.aURL[5]!=undefined)? this.aURL[5] : '';
	if ( this.scheme == '' && this.host != '') {
		this.path = this.host;
		this.host = '';
	}
	else this.path = (this.aURL[6]!=undefined)? this.aURL[6] : '';
	this.fragment = (this.aURL[7]!=undefined)? this.aURL[7].substring(1) : '';
	this.queryString = (this.aURL[8]!=undefined)? this.aURL[8].substring(1) : '';
	if (this.queryString != '') {
		this.query = {};
		this.aQuery=this.queryString.split('&');
		for (var i in this.aQuery) {
			var array = /^([^=]*)(=(.*))?$/.exec(this.aQuery[i]);
			this.query[array[1]] = array[3];
		}
	}
};
RC.Helpers.stripUnits = function(unit) {
	if(value = unit.match(/([\d\.]*) *(.*)/)) {
		return {amount: parseInt(value[1]), unit: value[2] }
	}
	else {
		return false;
	}
};
