﻿
/*--------------------------------------------------------------------------
			popup
---------------------------------------------------------------------------*/

function openWindow(theURL, width, height, features, winName) { //v2.0
	if(typeof(width) == "undefined" || width == 0){
		width = 500;
	}
	
	if(typeof(height) == "undefined" || height == 0){
		height = 500;
	}
	
	if(typeof(features) == "undefined" || features == ""){
		features = "status=yes,menubar=no,scrollbars=yes,resizable=yes";
	}
	
	features = features + ', width = ' + width + ', height = ' + height;
	
  window.open(theURL,winName,features);
}



/*--------------------------------------------------------------------------
			img rollover
---------------------------------------------------------------------------*/
function imghover(){

$('img.hover').hover(
function(){
$(this).attr('src', $(this).attr('src').replace(/_on\.(gif|jpg|png)/i,'.$1').replace(/\.(gif|jpg|png)/i,'_on.$1'));
},
function(){
$(this).attr('src', $(this).attr('src').replace(/_on\.(gif|jpg|png)/i,'.$1'));
}
);

}



$(document).ready(function(){
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
  imghover();
});

function complete(){
  imghover();	
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  createCookie("style", title, 365);
	
  $("#include a.inc").click(function(){
  /*$('#include').load($(this).attr("href"),{},	function(){ complete();	});*/
		$('#include').html('<script src="'+$(this).attr('href')+'" type="text/javascript"></script>');
		return false;
	});

}


/*--------------------------------------------------------------------------
			style switcher
---------------------------------------------------------------------------*/
function init_size(){
	var cookie = readCookie("style");
 var title = cookie ? cookie : getPreferredStyleSheet();
 setActiveStyleSheet(title);
	return null;
}


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;
    }
  }
		createCookie("style", title, 365);
}

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 = "";
  //host 
  //var host = location.host;
  var host = location.host;
 	host = host.replace(/^[^\.]+\.([^\.]+.(jp|com))/, '$1');

  document.cookie = name+"="+value+expires+"; path=/;domain="+host;
}

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.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}



