﻿// extract the CSS rules object for a given sIFR-replaced selector
function cssRules(selector)
{
   var strSelector = ('.sIFR-active ' + selector).toLowerCase();
   var objResult = false;
   
   for (i=0; i<document.styleSheets.length; i++)
   {
      // ensure this is a screen media stylesheet
      if (document.styleSheets[i].media == 'screen' || document.styleSheets[i].media.mediaText == 'screen')
      {
         // test for CSS Rules object support
         if (document.styleSheets[i].cssRules) objRules = document.styleSheets[i].cssRules;
         else if (document.styleSheets[i].rules) objRules = document.styleSheets[i].rules;
         
         // iterate over all rules within this stylesheet
         for (j=0; j<objRules.length; j++)
         {
            if (objRules[j].selectorText.toLowerCase() == strSelector)
            {
               objResult = objRules[j];
            }
         }
      }
   }
   return objResult;
}

// method to convert an rgb(x,y,z) colour value to an #RRGGBB hex value
String.prototype.toHex = function()
{
   var rgb = this.replace(/^rgb\(([0-9]{1,3}),\s*([0-9]{1,3}),\s*([0-9]{1,3})\)/, '$1,$2,$3').split(',');
   var decimal = (65536 * rgb[0]) + (256 * rgb[1]) + (1 * rgb[2]);
   return '#' + decimal.toString(16).toUpperCase();
}

// method to convert an #RRGGBB hex value to an rgb(x,y,z) colour value
String.prototype.toRGB = function()
{
   var hex = this.replace(/^#(.*)/, '$1');
   return 'rgb(' + 
      parseInt(hex.substr(0,2), 16) + ',' + 
      parseInt(hex.substr(2,2), 16) + ',' + 
      parseInt(hex.substr(4,2), 16) + ')';
}