// FreeStyler Library // Copyright 2009 Ian Porter

var fsError = new Object();
fsError.debug = false;
fsError.log = function(message)
{
    if(fsError.debug)
        alert("FS library: " + message);
}


function fsGetRuleStyle(ruleName)
{
    for (var i=0; i<document.styleSheets.length; i++)
    {
        var sheet = document.styleSheets[i];
        var rules = sheet.cssRules ? sheet.cssRules : sheet.rules;
        for (var j=0; j<rules.length; j++)
            if(rules[j].selectorText && rules[j].selectorText==ruleName)
                return rules[j].style;      // returns first one found
    }
    return null;
}

function fsGetComputedStyle(element, strCssRule)
{
	var result = "";
	if(document.defaultView && document.defaultView.getComputedStyle)
		result = document.defaultView.getComputedStyle(element, "").getPropertyValue(strCssRule);
	else if(element.currentStyle)
	{
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); } );
		result = element.currentStyle[strCssRule];
	}
	return result;
}


// all rollover with preload
// assumes rollover is same size and has '_over' appended
function ipRollover(img)
{
    if(img.src && !img.ipOrigSrc)
    {
        var pos = img.src.lastIndexOf(".");    
        if(pos>0) {
            img.ipOrigSrc = img.src;
            img.ipOver = new Image;
            img.ipOver.src = img.src.substr(0,pos) + "_over" + img.src.substr(pos);
            //alert(img.ipOver.src);
            img.onmouseover = function() { this.src = this.ipOver.src; };
            img.onmouseout = function() { this.src = this.ipOrigSrc; };
        }
    }
 }
 
 
 function addLoadEvent(func) 
 {
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
    window.onload = func;
  else 
  {
    window.onload = function() 
    {
      if (oldonload)
        oldonload();
      func();
    }
  }
}

 
