﻿/* style switch */

var cookie = readCookie("style");
var title = cookie ? cookie: getPreferredStyleSheet();
setActiveStyleSheet(title);

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;
}

window.onload = function(e) {
    var cookie = readCookie("style");
    var title = cookie ? cookie: getPreferredStyleSheet();
    setActiveStyleSheet(title);
}

window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 365);
}

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() {
    var i,
    a;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i ++ ) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title"))
            return a.getAttribute("title");
    }
    return null;
}

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=/";
}

/* rollover */
function initRollOverImages() {
  var image_cache = new Object();
  $("img.swap").each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    $(this).hover(
      function() { this.src = imgsrc_on; },
      function() { this.src = imgsrc; });
  });
}

$(document).ready(initRollOverImages);

/* sidenavi-last-border */
jQuery(function($){
  $("ul li.third:last").css("border-bottom","1px solid #FFF");
  $("ul li.forth:last").css("border","none");
  $("ul li.forth:last + li.third").css("border-top","1px dotted #ddd");
  $("#mainarea ul.left li.forth:last + li.third").css("border","none");
  $("#mainarea ul.right li.forth:last + li.third").css("border","none");
  $("#mainarea ul.left li.third:last").css("border","none");
  $("#mainarea ul.right li.third:last").css("border","none");
});

jQuery(function($){
  $("table.union td:has(img)").css("text-align","center");
});

jQuery(function($){
  $("a[href^='http://']").addClass("outside");
});

jQuery(function($){
  $("table.union th:contains('名前')").css("width","130px");
  $("table.union th:contains('役職')").css("width","100px");
  $("table.union th:contains('専門')").css("width","150px");
  $("table.union th:contains('資格')").css("width","150px");
  $("div.categorynavi li:contains('医療技術部　リハビリテーション科')").css("letter-spacing","-1px");
  $("table.union th:contains('医療機関名')").css("width","350px");
  $("table.union td:contains('地区')").css("text-align","center");
  $("table.union th:contains('開設者')").css("width","150px");
  $("table.union th:contains('開院日')").css("width","150px");
  $("table.union th:contains('完成日')").css("width","150px");

});




