// JavaScript Document

/* r-de.net stylesheets
 *
 * update: 2008.01.26
 * code by Hidetake Kurihara
 * copyright (c)2008 R-design. all rights reserved.
 */


SiteURL="http://www.datsumou-site.com/";


/*------------------------------------------------------------------------------------------
	SWAP IMAGE
------------------------------------------------------------------------------------------*/
function swapImg(str,num){
	document.images[str].src = SiteURL+'imgs/'+num;
}


/*------------------------------------------------------------------------------------------
	SWAP BACKGROUND COLOR
------------------------------------------------------------------------------------------*/
function swapBgOver(str){
	str.style.background="#E7E7E7";
	str.style.color="#666";
}
function swapBgOut(str){
	str.style.background="#FFF";
	str.style.color="#666";
}


/*------------------------------------------------------------------------------------------
	ZEBRA EFFECT
------------------------------------------------------------------------------------------*/
function zebra(idName,tagName,addClassName) {
	if (!document.getElementById(idName)) { return false; }
	var zebraRows = document.getElementById(idName).getElementsByTagName(tagName);
	for (var i=0; i<zebraRows.length; i++) {
		if (i%2) {
			zebraRows[i].className = addClassName;
		}
	}
}


/*------------------------------------------------------------------------------------------
	SEARCH BOX FORCUS
------------------------------------------------------------------------------------------*/
function FormFocus() {
  document.SearchArea.query.focus();
}


/*------------------------------------------------------------------------------------------
	SUB MENU SHOW and HIDDEN
------------------------------------------------------------------------------------------*/
function toggle( targetId ){
	if (document.getElementById){
		target = document.getElementById( targetId );
		if(target.style.display == "none"){target.style.display = "";
		}else{target.style.display = "none";}
	}
}


/*------------------------------------------------------------------------------------------
	WINDOW OPEN
------------------------------------------------------------------------------------------*/
function openWin(tgtU,wdt,hgt){
	subWin=window.open(tgtU,"subWin","width=" + wgt,"height=" + hgt);
	subWin.moveTo(0,0);
	subWin.focus;
}


/*------------------------------------------------------------------------------------------
	WINDOW CLOSE
------------------------------------------------------------------------------------------*/
function insertCloseBtn(){
	document.write('<a href="javascript:window.close()">閉じる</a>');
}
/* <script type="text/javascript">insertCloseBtn();</script>で呼び出し */


/*------------------------------------------------------------------------------------------
	SMOOTH SCROLL with prototype.js + effects.js
------------------------------------------------------------------------------------------*/

Event.observe(window, 'load', function() {
	// smooth scroll
	$$('a[href^=#]:not([href=#])').each(function(element) {
		element.observe('click', function(event) {
			new Effect.ScrollTo(this.hash.substr(1));
			Event.stop(event);
		}.bindAsEventListener(element))
	});
});



/*------------------------------------------------------------------------------------------
	Flash MOVIE READ
------------------------------------------------------------------------------------------*/
function includeFlash( url, width, height, title, quality ){
	document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width + '" height="' + height + '" title="' + title + '">' );
	document.write( '<param name="movie" value="' + url + '" />' );
	document.write( '<param name="quality" value="' + quality + '" />' );
	document.write( '<embed src="' + url + '" quality="' + quality + '" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed>' );
	document.write( '</object>' );
}
/* <script type="text/javascript" language="javascript">includeFlash( 'flash/main.swf', 750, 180, 'ホームページ制作 R-design WEBサイト', 'high' );</script>で呼び出し */


/*------------------------------------------------------------------------------------------
	styleswitcher.js （http://www.alistapart.com/stories/alternate/）*Font size read
------------------------------------------------------------------------------------------*/
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
   if(a.getAttribute("rel") && 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") && 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") && 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;
}

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

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


/*------------------------------------------------------------------------------------------
	Favorite registration　（ONLY WindowsIE）
------------------------------------------------------------------------------------------*/
function myFavorite(){
	var agent=navigator.userAgent;
	var ie=agent.indexOf("MSIE");
	var iever=parseInt(agent.substring(ie+5, ie+6));
	var os=agent.indexOf("Windows");

	if((ie > 0) && (iever >= 5) && (os > 0) && !window.opera){
		var bookmarkURL=self.location; /* window.location.hrefでもOK */
		var bookmarkTITLE=document.title;
		window.external.AddFavorite(bookmarkURL, bookmarkTITLE);
	}else{
		alert("Internet Explorer のみのサポートとなります");
	}
}
