// $Id: jquery.pagestyle.js,v 1.1.2.3 2009/02/16 15:02:35 christianzwahlen Exp $

if (Drupal.jsEnabled) {
  $(document).ready(function(){
    var ps_val = $("#edit-pagestyle-select").val();
    var str = "pagestyle[" + ps_val + "]";
    $("a.ps_white_black").attr({ href: "#" });
    $("a.ps_black_white").attr({ href: "#" });
    $("a.ps_yellow_blue").attr({ href: "#" });
    $("a.ps_standard").attr({ href: "#" });
    function removeBC(){
      $("body").removeClass("pagestyle_black_white");
      $("body").removeClass("pagestyle_white_black");
      $("body").removeClass("pagestyle_yellow_blue");
      $("body").removeClass("pagestyle_standard");
      $("link.ps_white_black").attr({ rel: "alternate stylesheet" });
      $("link.ps_black_white").attr({ rel: "alternate stylesheet" });
      $("link.ps_yellow_blue").attr({ rel: "alternate stylesheet" });
      $("link.ps_standard").attr({ rel: "alternate stylesheet" });
    };
    function editLink(link_href){
      if (link_href = "standard") {
        $("link.ps_" + pagestyle_current).attr({ href: pagestyle_path + "/css/style_standard.css" });
      }
      else if (link_href = "current") {
        $("link.ps_" + pagestyle_current).attr({ href: pagestyle_path + "/css/style_" + pagestyle_current + ".css" });
      }
      $("link.ps_" + ps_val).attr({ href: pagestyle_path + "/css/style_" + ps_val + ".css" });
    }
    $("a.ps_black_white[href=#]").click(
      function(){
        removeBC();
        editLink(link_href = "current");
        $.cookie('pagestyle', "black_white", { expires: 52, path: '/'});
        $("#pagestyle_current").empty();
        $("#pagestyle_current").append(Drupal.t('Black') + '/'+ Drupal.t('White'));
        $("body").addClass("pagestyle_black_white");
      }
    );
  if ($.cookie("pagestyle")) {
    $("a.ps_white_black[href=#]").click(
    function (){
        removeBC();
        editLink(link_href = "current");
        $.cookie('pagestyle', "white_black", { expires: 52, path: '/'});
        $("#pagestyle_current").empty();
        $("#pagestyle_current").append(Drupal.t('White') + '/' + Drupal.t('Black'));
        $("body").addClass("pagestyle_white_black");
      }
    );
    $("a.ps_yellow_blue[href=#]").click(
      function(){
        removeBC();
        editLink(link_href = "current");
        $.cookie('pagestyle', "yellow_blue", { expires: 52, path: '/'});
        $("#pagestyle_current").empty();
        $("#pagestyle_current").append(Drupal.t('Yellow') + '/' + Drupal.t('Blue'));
        $("body").addClass("pagestyle_yellow_blue");
      }
    );
    $("a.ps_standard[href=#]").click(
      function(){
        removeBC();
        editLink(link_href = "standard");
        $.cookie('pagestyle', "standard", { expires: 52, path: '/'});
        $("#pagestyle_current").empty();
        $("#pagestyle_current").append(Drupal.t('Standard'));
        $("body").addClass("pagestyle_standard");
      }
    );
  }
    function pagestyleVals() {
        removeBC();
        editLink(link_href = "standard");
        $.cookie('pagestyle', ps_val, { expires: 52, path: '/'});
        $("body").addClass("pagestyle_" + ps_val);
        $("select.pagestyle option:selected").each(function () {
          $("#pagestyle_current").empty();
          $("#pagestyle_current").append( $(this).text() );
          }
        );
        $("body").addClass('pagestyle_' + ps_val);
        $("link.ps_" + ps_val).attr({ rel: "stylesheet" });
    }
    $("#edit-pagestyle-select").change(pagestyleVals);
    $("#edit-pagestyle-submit").hide();
    $(".rollover").hover(
      function(){
        if($(this).attr("src").indexOf("_hover") == -1) {
          var newSrc = $(this).attr("src").replace(".gif","_hover.gif#hover");
          $(this).attr("src",newSrc);
        }
      },
      function(){
        if($(this).attr("src").indexOf("_hover.gif#hover") != -1) {
          var oldSrc = $(this).attr("src").replace("_hover.gif#hover",".gif");
          $(this).attr("src",oldSrc);
        }
      }
    );
  });
}
