<!--//
// MooTools functions

Element.extend({
 getText: function() {
 return this.innerText || this.textContent || this.innerHTML.replace(/<\/?[^>]+>/gi,'')
}
});

function changeText(objID, str){
 $(objID).set('text', str);
}

//End MooTools

// Pre load hovers
function preloadImages() //v3.0
{ 
  var d=document;
  if(d.images)
  {
    if(!d.MM_p)
    {
      d.MM_p = new Array();
      var i, j = d.MM_p.length, a = preloadImages.arguments;
      for(i = 0; i < a.length; i++)
      {
        if (a[i].indexOf("#")!=0)
        {
          d.MM_p[j] = new Image;
          d.MM_p[j++].src = a[i];
        }
      }
    }
  }
}

//pass url
function go(href)
{
  window.location = href;
  return false;
}
//status bar
function show(href)
{
  window.status = href;
  return false;
}
//For showing or hiding content
function showHide(objID)
{
  //check to see if its hidden
  //hidden = (document.getElementById(objID).style.display == 'none') ? true : false;
  hidden = ($(objID+'SH').getStyle('display') == 'none') ? true : false;

  if(hidden)
  {
    document.getElementById(objID+'SH').style.display = 'block';
    document.getElementById(objID).src = '../site_images/hide.jpg';
    changeText(objID+'ML', 'less...');
  }
  if(hidden == false)
  {
    document.getElementById(objID+'SH').style.display = 'none';
    document.getElementById(objID).src = '../site_images/show.jpg';
    changeText(objID+'ML', 'more...');
  }
}

function switchColor(objColor, targetObj)
{
  //Get background-color style value 
  if (document.getElementById(objColor).currentStyle) //IE
  {
    newColor = document.getElementById(objColor).currentStyle["backgroundColor"];
    //document.getElementById(targetId).style.backgroundColor = newColor;
    changeClassValue(targetObj, 'background-color', color);

    setCookie('color',color,365);
  }
  else if (window.getComputedStyle) //FF others
  {
    var objColorStyle = window.getComputedStyle(document.getElementById(objColor), "");
    color = objColorStyle.getPropertyValue("background-color");
    //document.getElementById(targetId).style.backgroundColor = color;
    changeClassValue(targetObj, 'background-color', color);

    setCookie('color',color,365);
  }
}

function changeClassValue(className, cssStyle, newValue) {
  var cssRules, sIndex, S, R;

  cssRules 
  if (document.all)
  {
    cssRules = 'rules';
  }
  else if (document.getElementById)
  {
    cssRules = 'cssRules';
  }

// Find the class index in the css rule set 
  var added = false;
  for (S = 0; S < document.styleSheets.length; S++)
  {
    for (R = 0; R < document.styleSheets[S][cssRules].length; R++)
    {
      if (document.styleSheets[S][cssRules][R].selectorText == className)
      {
        sIndex = S;

        if(document.styleSheets[S][cssRules][R].style[cssStyle])
        {
          document.styleSheets[S][cssRules][R].style[cssStyle] = newValue;
          added=true;
          break;
        }
        break;
      }
    }
  }
  if(!added)
  {
    if(document.styleSheets[sIndex].insertRule)// FF Others
    {
      document.styleSheets[sIndex].insertRule(className+' { '+cssStyle+' : '+newValue+'; }', document.styleSheets[sIndex][cssRules].length);
    }
    else if (document.styleSheets[sIndex].addRule)//IE
    {
      document.styleSheets[sIndex].addRule(className, cssStyle+' : '+newValue+';');
    }
  }
}

function setMood(mood, enabled)
{
  currMood = getCookie('mood'); // get current mood

  if (currMood != null && currMood != '') //mood has been set before
  {
    setCookie('mood',mood,365);
    if (document.all)  // IE
    {
      sheetId = 'ss'+ mood;
      currSheetId = 'ss'+ currMood;
      disable = false;

      document.getElementById(currSheetId).disabled = !disable;
      document.getElementById(sheetId).disabled = !enabled;
    }
    else if (document.getElementById) //FF others
    {
      sheetId = 'ss'+ mood;
      currSheetId = 'ss'+ currMood;
      disable = false;

      document.getElementById(currSheetId).disabled = !disable;
      document.getElementById(sheetId).disabled = !enabled;
    }
  }
  else if (currMood == null || currMood == '') //mood has NOT been set before
  {
  	mood = 'joppa'; //default
    setCookie('mood',mood,365);

    if (document.all)  // IE
    {
      sheetId = 'ss'+ mood;
      document.getElementById(sheetId).disabled = !enabled;
    }
    else if (document.getElementById) //FF others
    {
      sheetId = 'ss'+ mood;
      document.getElementById(sheetId).disabled = !enabled;
    }
  }
}

function showColor(objId)
{
  //we have to get the background-color style value 
  // IE
  if (document.getElementById(objId).currentStyle)
  {
    color = document.getElementById(objId).currentStyle["backgroundColor"];
    document.getElementById(objId).title = color;
  }
  else if (window.getComputedStyle) //FF others
  {
    var objColorStyle = window.getComputedStyle(document.getElementById(objId), "");
    color = objColorStyle.getPropertyValue("background-color");
    document.getElementById(objId).title = convertColor(color);
  }
}

//Personalization Color grids
function showCgrid(objId)
{
  // IE
  if (document.all)
  {
  	document.getElementById(objId).style.display = "block";
  }
  else if (document.getElementById) //FF others
  {
  	document.getElementById(objId).style.display = "block";
  }
}
function hideCgrid(objId)
{
  // IE
  if (document.all)
  {
  	document.getElementById(objId).style.display = "none";
  }
  else if (document.getElementById) //FF others
  {
  	document.getElementById(objId).style.display = "none";
  }
}

function convertColor(color)
{  
  var rgbColors=new Object();

  ///////////////////////////////////
  // Handle rgb(redValue, greenValue, blueValue) format
  //////////////////////////////////
  if (color[0]=='r')
  {
    // Find the index of the redValue.  Using subscring function to 
    // get rid off "rgb(" and ")" part.  
    // The indexOf function returns the index of the "(" and ")" which we 
    // then use to get inner content.  
    color=color.substring(color.indexOf('(')+1, color.indexOf(')'));
  
    // Notice here that we don't know how many digits are in each value,
    // but we know that every value is separated by a comma.
    // So split the three values using comma as the separator.
    // The split function returns an object.
    rgbColors=color.split(',', 3);

    // Convert redValue to integer
    rgbColors[0]=parseInt(rgbColors[0]);
    // Convert greenValue to integer
    rgbColors[1]=parseInt(rgbColors[1]);
    // Convert blueValue to integer
    rgbColors[2]=parseInt(rgbColors[2]);		
  }

  ////////////////////////////////
  // Handle the #RRGGBB' format
  ////////////////////////////////
  else if (color.substring(0,1)=="#")
  {
    // This is simples because we know that every values is two 
    // hexadecimal digits.
    rgbColors[0]=color.substring(1, 3);  // redValue
    rgbColors[1]=color.substring(3, 5);  // greenValue
    rgbColors[2]=color.substring(5, 7);  // blueValue

    // We need to convert the value into integers, 
    //   but the value is in hex (base 16)!
	// Fortunately, the parseInt function takes a second parameter 
    // signifying the base we're converting from.  
    rgbColors[0]=parseInt(rgbColors[0], 16);
    rgbColors[1]=parseInt(rgbColors[1], 16);
    rgbColors[2]=parseInt(rgbColors[2], 16);
	}
  return rgbColors;
}

//-->