/*nanpeidai.js
  BOstudio JavaScript Library ver0.2
*/

/*ディレクトリ取得*/
function GetDir(){
	var scriptSrc = document.getElementsByTagName('script')[0].getAttribute('src');
	var commonJS = 'js/jquery.js';
	var path = scriptSrc.replace(commonJS, '');
	return path;
}


$(function(){
//    PageBack();
    PopUpSet();
//	ReadCookie();
//	FontSizeClick();
	RollOverSet();
});


/*PageBack*/
function PageBack(){
	$("a",".pageback").click(function(){
    history.back();
	return false;
	});
}

/*PopUp*/
function PopUpSet(){
	PopUp("a.popup_contact","https://www.s-db.jp/entry?k=4d682a8b40dbd8c5e57f7b80cfc84a4117D%2CDI","contactw",900,800);
	PopUp("a.popup_mm","https://www.s-db.jp/entry?k=53264d3af87d44be0824179ec8a2c85517D%2CD4","mmw",900,800);
	PopUp("a.popup_entry","https://www.s-db.jp/entry?k=4ad05821a0f6d9704cf134bdb6cddafe17D%2CDA","entryw",900,800);
	PopUp("a.popup_mailmag","https://www.s-db.jp/entry?k=53264d3af87d44be0824179ec8a2c85517D%2CD4","mailmagw",900,800);
	PopUp_blank("a.popup3","sample1-1.html");
}
function PopUp(classname,url,wname,w,h){
	$(classname).click(function(){
	window.open(url,wname,'width='+w+',height='+h+'left=0,top=0,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,favorites=no,resizable=yes');
	return false;
	});
}
function PopUp_blank(classname,url){
	$(classname).click(function(){
	window.open(url,"_blank");
	return false;
	});
}

function CloseWin(){
    window.close();
}


/* fontsizechange */
/*function setFontsize(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;
	  setCookie("style", title, 365);

      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  fontsizeimg(title);
}

function getFontsize() {
  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 getPreFontsize() {
  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 setCookie(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 getCookie(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 ReadCookie() {
  var cookie = getCookie("style");
  var title = cookie ? cookie : getPreFontsize();
  setFontsize(title);
}

window.onunload = function(e) {
  var title = getFontsize();
  setCookie("style", title, 365);
}

var cookie = getCookie("style");
var title = cookie ? cookie : getPreFontsize();
setFontsize(title);

function fontsizeimg(title){
  var thispath = GetDir();
  var currentstyle = title;
  var area = document.getElementById("fsizechange");
  if (area){
  var imgtag = area.getElementsByTagName("img");
  var s = imgtag[1];
  var m = imgtag[2];
  var l = imgtag[3];
  var fname = thispath + "imgs/b_style_";
  switch(currentstyle)
  {
  case "default":
      l.src=fname+"l.gif";
      m.src=fname+"m.gif";
      s.src=fname+"s_on.gif";
      break;
  case "medium":
      l.src=fname+"l.gif";
      m.src=fname+"m_on.gif";
      s.src=fname+"s.gif";
      break;
  case "large":
      l.src=fname+"l_on.gif";
      m.src=fname+"m.gif";
      s.src=fname+"s.gif";
      break;
  default:
      l.src=fname+"l.gif";
      m.src=fname+"m.gif";
      s.src=fname+"s_on.gif";
      break;
  }
  }

}

function FontSizeClick(){
	$("dd.fontL").click(function(){
    setFontsize("large");
	return false;
	});
	$("dd.fontM").click(function(){
    setFontsize("medium");
	return false;
	});
	$("dd.fontS").click(function(){
    setFontsize("default");
	return false;
	});
}
*/
/*rollover*/
function RollOverSet(){
	RollOver(".gn_normal");
	RollOver(".b_select");
	RollOver(".b_select_l");
	RollOver(".b_contact");
	RollOver(".b_ccon");
	RollOver(".b_back");
	RollOver(".b_submit");
	RollOver(".b_confirm");
	RollOver(".b_complete");
	RollOver(".b_cm");
}

function RollOver(target){
	$target = $(target);
	$("img", $target).each(function(){
		$(this).mouseover(function(){
			this.setAttribute("src", this.getAttribute("src").replace(".jpg", "_on.jpg"));
        })
		$(this).mouseout(function(){
			this.setAttribute("src", this.getAttribute("src").replace("_on.jpg", ".jpg"));
        })
		$(".stay").unbind();
	});
}



