window.onload = function ini(){
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	if(title=="null") title="default";
	setActiveStyleSheet(title);

	onloadFunction ();

}
function onloadFunction () {
// onloadイベントここから

	if(document.getElementById("ctwrap") && document.getElementById("sn")){
		var ctH = document.getElementById("ctwrap").offsetHeight;
		var snH = document.getElementById("sn").offsetHeight;
		if(snH<ctH) {
			//ctH = ctH-30+15;
			ctH = ctH;
			document.getElementById("sn").style.height = ctH+"px";
		}
	}
// onloadイベントここまで
}

//styleswitcher.js

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;
	 // alert("title="+title+"/"+a.getAttribute("title")+"/"+a.disabled);
    }
  }
}

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=/";
}

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;
}

function initRollOvers() {
    if (!document.getElementById){
        return;
    }
   
    var preLoads = new Array();
    var allImages = document.getElementsByTagName('img');
 
    for (var i = 0; i < allImages.length; i++) {       
        if (allImages[i].className == 'rollover') {
            var src = allImages[i].getAttribute('src');
            var ftype = src.substring(src.lastIndexOf('.'), src.length);
            var oSrc = src.replace(ftype, 'o'+ftype);
 
            allImages[i].setAttribute('pSrc', src);
            allImages[i].setAttribute('oSrc', oSrc);
 
            preLoads[i] = new Image();
            preLoads[i].src = oSrc;
 
            allImages[i].onmouseover = function() {
                this.setAttribute('src', this.getAttribute('oSrc'));
            }
            allImages[i].onmouseout = function() {
                this.setAttribute('src', this.getAttribute('pSrc'));
            }
        }
    }
}
function addOnload(func){
    if ( typeof window.addEventListener != "undefined" ){
        window.addEventListener( "load", func, false );
    }else if ( typeof window.attachEvent != "undefined" ) {
        window.attachEvent( "onload", func );
    }else{
        if ( window.onload != null ){
            var oldOnload = window.onload;
            window.onload = function ( e ) {
            oldOnload( e );
            window[func]();
        };
    }else
        window.onload = func;
    }
}
addOnload(initRollOvers);

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

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if(title=="null") title="default";
setActiveStyleSheet(title);



