if (!window.YUKU) var YUKU = {}

YUKU.styleSwitcher =
{
   getCookie : function (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 '';
   },

   setCookie : function (name, value)
   {
      var days = 32;
      var date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
      var expires = "; expires=" + date.toGMTString();

      document.cookie = name + "=" + value + expires + "; path=/";
   },

   setStyle : function (title)
   {
      for (i = 0; (a = get_by_tag("link")[i]); i++)
      {
         if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("href").indexOf("cssprofile") != -1
             && a.getAttribute("href").indexOf("global/1") == -1)
         {
            a.disabled = true;
            if (!a.getAttribute("title") && title == "")
               a.disabled = false;
            else if (a.getAttribute("title") == title)
               a.disabled = false;
         }
      }

      this.setCookie('style', title);
   },

   styleExists : function (style)
   {
      for (i = 0; (a = get_by_tag("link")[i]); i++)
      {
         if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("href").indexOf("cssprofile") != -1)
         {
            if (a.getAttribute("title") == style)
               return true;
         }
      }

      return false;
   },

   getPreferredStyle : function ()
   {
      var style = this.getCookie('style');
      if (style != "" && this.styleExists(style))
         this.setStyle(style);
   }
}

YUKU.styleSwitcher.getPreferredStyle();