/* デジタルカタログ */

var catalogViewWnd;
function CatalogViewOpenAction(url){
catalogViewWnd = window.open(url, 'CatalogView', 'toolbar=no, location=no, status=no, scrollbars=no, menubar=no, width=1024,height=700, resizable=yes');
catalogViewWnd.focus();
}

/* 画像切り替えスクリプト（110623） */
function setImg(v_img,h_img1,h_img2)
{
	var visi1=document.getElementById(v_img);
	var hide1=document.getElementById(h_img1);
	var hide2=document.getElementById(h_img2);

	visi1.className="visi";
/*	hide1.className="hide";
	hide2.className="hide"; */
	
	if(hide1==null){
		return true;
	}
	else{
	hide1.className="hide";
	}
	if(hide2==null){
		return true;
	}
	else{
	hide2.className="hide";
	}
	
	return;
}

function setImg_com(v_img,h_img1,h_img2,h_img3,h_img4)
{
	var visi1=document.getElementById(v_img);
	var hide1=document.getElementById(h_img1);
	var hide2=document.getElementById(h_img2);
	var hide3=document.getElementById(h_img3);
	var hide4=document.getElementById(h_img4);

	visi1.className="visi";
	
	if(hide1==null){
		return true;
	}
	else{
	hide1.className="hide";
	}
	
	if(hide2==null){
		return true;
	}
	else{
	hide2.className="hide";
	}
	
	if(hide3==null){
		return true;
	}
	else{
	hide3.className="hide";
	}

	if(hide4==null){
		return true;
	}
	else{
	hide4.className="hide";
	}

	return;
}

/* 画像切り替えスクリプト */

function imgchange(id,l_url,imgid1,imgurl1,imgid2,imgurl2,imgid3,imgurl3)
{
	var l_img=document.getElementById(id);
	var thumb=document.getElementById(imgid1);
	var thumb2=document.getElementById(imgid2);
	var thumb3=document.getElementById(imgid3);

	l_img.src=l_url;
	
	if(thumb==null){
		return true;
	}
	else{
	thumb.src=imgurl1;
	}
	
	if(thumb2==null){
		return true;
	}
	else{
	thumb2.src=imgurl2;
	}
	
	if(thumb3==null)
	{
		return true;
	}
	else
	{
	thumb3.src=imgurl3;
	}

	return;
}

function imgchange_com(id,l_url,imgid1,imgurl1,imgid2,imgurl2,imgid3,imgurl3,imgid4,imgurl4,imgid5,imgurl5)
{
	var l_img=document.getElementById(id);
	var thumb=document.getElementById(imgid1);
	var thumb2=document.getElementById(imgid2);
	var thumb3=document.getElementById(imgid3);
	var thumb4=document.getElementById(imgid4);
	var thumb5=document.getElementById(imgid5);

	l_img.src=l_url;
	
	if(thumb==null){
		return true;
	}
	else{
	thumb.src=imgurl1;
	}
	
	if(thumb2==null){
		return true;
	}
	else{
	thumb2.src=imgurl2;
	}
	
	if(thumb3==null)
	{
		return true;
	}
	else
	{
	thumb3.src=imgurl3;
	}

	if(thumb4==null)
	{
		return true;
	}
	else
	{
	thumb4.src=imgurl4;
	}

	if(thumb5==null)
	{
		return true;
	}
	else
	{
	thumb5.src=imgurl5;
	}

	return;
}

//tab1//
function setTab(tab)
{
	var on_tab=document.getElementById(tab);
	
	var tab01=document.getElementById('fact01');
	var tab02=document.getElementById('fact02');
	var tab03=document.getElementById('fact03');
	var tab04=document.getElementById('fact04');
	var tab05=document.getElementById('fact05');
	var tab06=document.getElementById('fact06');

	if(on_tab == tab01)
	{
		tab01.className="visi";
		tab02.className="hide";
		tab03.className="hide";
		tab04.className="hide";
		tab05.className="hide";
		tab06.className="hide";
	}
	else if(on_tab == tab02)
	{
		tab01.className="hide";
		tab02.className="visi";
		tab03.className="hide";
		tab04.className="hide";
		tab05.className="hide";
		tab06.className="hide";
	}
	else if(on_tab == tab03)
	{
		tab01.className="hide";
		tab02.className="hide";
		tab03.className="visi";
		tab04.className="hide";
		tab05.className="hide";
		tab06.className="hide";
	}
	else if(on_tab == tab04)
	{
		tab01.className="hide";
		tab02.className="hide";
		tab03.className="hide";
		tab04.className="visi";
		tab05.className="hide";
		tab06.className="hide";
	}
	else if(on_tab == tab05)
	{
		tab01.className="hide";
		tab02.className="hide";
		tab03.className="hide";
		tab04.className="hide";
		tab05.className="visi";
		tab06.className="hide";
	}
	else if(on_tab == tab06)
	{
		tab01.className="hide";
		tab02.className="hide";
		tab03.className="hide";
		tab04.className="hide";
		tab05.className="hide";
		tab06.className="visi";
	}
	else{ return true; }
	
	return;
}

//tab1//
function setFAQ(tab)
{
	var on_tab=document.getElementById(tab);
	
	var tab01=document.getElementById('faq01');
	var tab02=document.getElementById('faq02');
	var tab03=document.getElementById('faq03');

	if(on_tab == tab01)
	{
		tab01.className="visi";
		tab02.className="hide";
		tab03.className="hide";
	}
	else if(on_tab == tab02)
	{
		tab01.className="hide";
		tab02.className="visi";
		tab03.className="hide";
	}
	else if(on_tab == tab03)
	{
		tab01.className="hide";
		tab02.className="hide";
		tab03.className="visi";
	}
	else{ return true; }
	
	return;
}



/* スタイルスイッチスクリプト */
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=/";
}

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);


/* テキストボックス拡大スクリプト */
var ElementResizer = {
   moveNode: false,

   add: function(elm) {
      var obj = new this._ChildElement(this, elm);

      addEvent(elm, 'mousedown', function (e) {
         if(obj.resizePoint(e)) {
            ElementResizer.moveNode = obj;
         }
      });

      return obj;
   },

   start: function() {
      var self = this;
      addEvent(document.body, 'mouseup', function (e) {
         if(self.moveNode) self.moveNode = false;
      });

      addEvent(document.body, 'mousemove', function (e) {
         if(self.moveNode) self.moveNode.doResize(e);
      });
   },

   resizePoint: function(e, elm) {
      var offset = Position.offset(elm);
      var page   = Position.page(e);

      offset.y += elm.offsetHeight;
      offset.x += elm.offsetWidth;

      if(offset.y - 32 < page.y && page.y < offset.y &&
         offset.x - 32 < page.x && page.x < offset.x - 8) {
         return true;
      }
   },

   doResize: function(e, elm) {
      var offset = Position.offset(elm);
      var page   = Position.page(e);

      var width  = page.x - offset.x + 24;
      var height = page.y - offset.y + 16;
      if (width  < 50) width  = 50;
      if (height < 50) height = 50;

      elm.style.height = height + 'px';
      /* elm.style.width  = width  + 'px'; */
	  
   }
}

ElementResizer._ChildElement = function() {
   this.initialize.apply(this, arguments);
}

ElementResizer._ChildElement.prototype = {
   initialize: function(base, elm) {
      this.base = base;
      this.elm  = elm;
   },

   resizePoint: function(e) {
      return this.base.resizePoint(e, this.elm);
   },

   doResize: function(e) {
      return this.base.doResize(e, this.elm);
   }
}

var Position = {
   offset: function(elm) {
      var pos = {};
      pos.x = this.getOffset('Left', elm);
      pos.y = this.getOffset('Top', elm);
      return pos;
   },

   getOffset: function(prop, el) {
      if(!el.offsetParent || el.offsetParent.tagName.toLowerCase() == "body")
         return el['offset'+prop];
      else
         return el['offset'+prop]+ this.getOffset(prop, el.offsetParent);
   },

   page: (document.all) ?
      (function() {
         var pos = {};
         pos.x = event.x + (document.body.scrollLeft || document.documentElement.scrollLeft);
         pos.y = event.y + (document.body.scrollTop  || document.documentElement.scrollTop);
         return pos;
      })
      :
      (function(e) {
         var pos = {};
         pos.x = e.pageX;
         pos.y = e.pageY;
         return pos;
      })
}

var addEvent = (window.addEventListener) ?
   (function(elm, type, event) {
      elm.addEventListener(type, event, false);
   }) : (window.attachEvent) ?
   (function(elm, type, event) {
      elm.attachEvent('on'+type, event);
   }) :
   (function(elm, type, event) {
      elm['on'+type] = event;
   }) ;

addEvent(window, 'load', function() {
   var textareas = document.getElementsByTagName('textarea');

   for(var i = 0;elm = textareas[i];i++) {
      (function(elm) {
         var obj = ElementResizer.add(elm);
         var cursor = false;

         addEvent(elm, 'mousemove', function (e) {
            if(!cursor && obj.resizePoint(e)) {
               elm.style.cursor = 'se-resize';
               cursor = true;
            } else if(cursor && !obj.resizePoint(e)) {
               elm.style.cursor = 'default';
               cursor = false;
            }
         });
      })(elm);
   }

   ElementResizer.start();
});

/* スムーススクロール */
/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 20;

ss.addEvent(window,"load",ss.fixAllLinks);



/* ボックスリンクスクリプト */
/*
 
Folks, addLoadEvent is a function made by Simon Willison that serves as a manageable window.onload replacement.  Jeremy Keith gave it a thumbs up in his book, DOM Scripting, and it's difficult to walk away from that book without incorporating it into every project.
 
*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
 
 
/*
	Copyright Robert Nyman, http://www.robertnyman.com
	Free to use if this text is included
	
	
Here's the function that allows us to retrieve elements by their class name, something that everyone wishes were part of JavaScript to begin with.  To read more about it, visit Robert Nyman's site.
 
 
*/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}
 
/*
 
Below are the functions that let me add and remove classes, which I'm using to get the hover effect.  "hovering" is the class that is added or removed, and you can see in the style sheet how .hovering is defined.
 
 
*/
 
function addClassName(oElm, strClassName){
	var strCurrentClass = oElm.className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		oElm.className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}
 
 
function removeClassName(oElm, strClassName){
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	oElm.className = oElm.className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}
 
 
/*
 
Here's the part I wrote that uses the functions above to create our "link boxes".
 
*/
 
 
function prepareBoxes() {
	var boxes = getElementsByClassName(document, "div", "linkbox");
	for (var i=0; i<boxes.length; i++){
		var fullstories = getElementsByClassName(document, "p", "fullstory");
		for (var k=0; k<fullstories.length; k++){
			fullstories[k].parentNode.tabIndex = k+1;
			fullstories[k].style.display = "none";
			fullstories[k].parentNode.onmouseover = function() {
				addClassName(this, "hovering");
			}
			fullstories[k].parentNode.onmouseout = function() {
				removeClassName(this, "hovering");
			}
			fullstories[k].parentNode.onclick = function() {
				var destin = this.getElementsByTagName("a");
				window.location = destin[0].href;
			}
			fullstories[k].parentNode.onkeypress = fullstories[k].parentNode.onclick;
		}
	}
}
addLoadEvent(prepareBoxes);

