// Popups via class="popup"
// Source: http://adactio.com/atmedia2005/
function doPopups() {
  if (!document.getElementsByTagName)
    return false;
  var links = document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("tc_popup")) {
      links[i].onclick = function() {
        var win = window.open(this.href, "tc_popup", "width=350,height=452,scrollbars=no,resizable=no");
        if (window.focus)
          win.focus();
        return false;
      }
    }
    else if (links[i].className.match("popup")) {
      links[i].onclick = function() {
        var win = window.open(this.href, "popup", "width=600,height=485,scrollbars=yes,resizable=yes");
        if (window.focus)
          win.focus();
        return false;
      }
    }
  }
}

// dropdown digg, etc widgets via class="share", cw 2006-06-21

function initShare() {
  if (!document.getElementsByTagName)
    return false;
  var lis = document.getElementsByTagName("li");
  for (var i=0; i < lis.length; i++) {
    if (lis[i].className.match("share")) {
	  lis[i].onmouseover = function() {
	    this.className += " sfhover";
	  }
	  lis[i].onmouseout = function() {
        this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
	  }
	}
  }
}

// Font size switching via S/S+/S++ widget
function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'S' : 
      setActiveStyleSheet('S+');
      break;
    case 'S+' : 
      setActiveStyleSheet('S++');
      break;
    case 'S++' : 
      break;
    default :
      setActiveStyleSheet('S');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {

    case 'S+' : 
      setActiveStyleSheet('S');
      break;
    case 'S++' : 
      setActiveStyleSheet('S+');
      break;
    case 'S' : 
      break;
    default :
      setActiveStyleSheet('S');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");

  }
  return null;
}

function getPreferredStyleSheet() {
  return ('S');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

var cookie = readCookie("SalonFontSize");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);


/**
 * This function reads all thinks from a container and sets
 * their targets to open in a new window if the domain is non-salon.
 *
 * This behavior can be forced if you use the following class names on a link:
 *   <a class="target_self"></a> or <a class="target_new"></a>
 */

function setLinkTargets(container_name) {

        // make sure we have ability to move forward
        if (!document.getElementById || !document.getElementsByTagName) return true;
        if (!document.getElementById(container_name)) return true;


        // we will only re-target links in outer_container (i.e. excludes header & footer)
        var container = document.getElementById(container_name);

        // get all links
        var links = container.getElementsByTagName('a');

        var ct = links.length;
        for (var i=0; i<ct; i++) {
                // skip link with target attribute set
                if (links[i].target) {
                	if (links[i].target == 'new') {
                        	// change 'new' to '_blank'
                        	links[i].target = '_blank';
                	}
                }

                // check for manual over-ride
                else if (/\s?target_new\s?/.test(links[i].className)) {
                        links[i].target = '_blank';
                }
                else if (/\s?target_self\s?/.test(links[i].className)) {
                        // do nothing
                }

                // otherwise process href and choose target
                else {
                        // if url doesn't contain :// or url contains salon.com in domain name. fantastic
                        if (/^\w+:\/\//.test(links[i].href)==false || /^\w+:\/\/(\w+\.)*salon.com\//i.test(links[i].href)) {
                                // salon, do nothing
                        } else {
                                links[i].target = '_blank';
                        }
                }
        }
}


window.onload = function(e) {
  var cookie = readCookie("SalonFontSize");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  doPopups();
  initShare();
  setLinkTargets('outer_container');
  setLinkTargets('yui-main');
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("SalonFontSize", title, 365);
}


































































