/*  BaseJQ JavaScript framework, version 3
 *  要jquery.js version 1.3.2
 *--------------------------------------------------------------------------*/ 

overImageClass= "overimage"; //ロールオーパー対象class
overImageClassFoot= "_on"; //ロールオーパーイメージ付加文字列
toggleImageFoot = "_on"; //トグル機能で現在のページを示す画像イメージ付加文字列

/*ロールオーバー・トグル*/

$(function(){
	var conf = {
		className : "." + overImageClass,
		overNode : overImageClassFoot,
		toggleNode : toggleImageFoot
	};
	//トグルエンジン実行

	if(typeof(PAGEID) != "undefined" ){	
		for(var i = 0; i < PAGEID.length; i++){
		var TGTID = PAGEID[i]
		var NODEID = "#" + TGTID
		$(NODEID).each(function(){
		this.oriSrc = this.src;
		this.cngSrc = this.oriSrc.replace(/(\.gif|\.jpg|\.png)/, conf.toggleNode+"$1");
		this.src = this.cngSrc;
		$(NODEID).removeClass(overImageClass);
		});
		};		
	};

	//ロールオーバーエンジン実行
	$(conf.className).each(function(){
		this.originalSrc = this.src;
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, conf.overNode+"$1");
		
		preloadImage(this.rolloverSrc);

		}).hover(function(){
			this.src = this.rolloverSrc;
		},function(){
			this.src = this.originalSrc;
		}).click(function(){
			this.src = this.originalSrc;
		});
	
});

/*汎用スクリプトここから*/


/*イメージプリロードエンジン*/

preloadedImages = [];
function preloadImage(url){
	var p = preloadedImages;
	var l = p.length;
	p[l] = new Image();
	p[l].src = url;
};

/*ポップアップウインドウエンジン*/
function openwin(theURL,winName,features) {
	window.open(theURL,winName,features);
};

/*インクルードエンジン*/
/*
  Ajax Code Display 
  written by Christian Heilmann (http://wait-till-i.com)
  license:http://creativecommons.org/licenses/by/3.0/
  requires on jQuery 1.2.2 or newer
*/
// when the web page is ready
$(document).ready(
  function(){
    // get all links with the class codeexample and apply a function
    $('a.codeexample').each(
      function(){
        // if the class 'dodisplay' is present
        if(this.className.indexOf('dodisplay') !==- 1){
          // add functionality to toggle the display of the output 
          $(this).toggle(
            // on the first click and subsequent odd clicks
            function(){
              // create an IFRAME after the element that shows the document 
              // the original link points to 
              $(this).after('<iframe class="codeexample" src='+this.href+'></iframe>');
              // store the original text in the link and change it to 'close'
              this.oldhtml = this.innerHTML;
              this.innerHTML = 'close';
            },
            // on the second and subsequent even clicks 
            function(){
              // remove the IFRAME and change the link text back to the old text
              this.parentNode.removeChild(this.nextSibling);
              this.innerHTML = this.oldhtml;
            }
          );
        }
        // store the link reference in 'link'
        var link = this;
        // are there any highlights to be done?
        var highlights = this.className.match(/highlight\[([^\]]+)/);
        // shall I only display a range of lines?
        var boundaries = this.className.match(/lines\[([^\]]+)/);
        // convert the ranges defined in classes to arrays
        // [1,5-7,12-15] => [1,5,6,7,12,13,14,15]
        var getrange = function(range){
          var elms = range.split(',');
          var range = [];
          for(var i=0,j=elms.length;i<j;i++){
             if(elms[i].indexOf('-')===-1){
              range.push(+elms[i]);
            } else {
              var s = +elms[i].split('-')[0];
              var e = +elms[i].split('-')[1];
              for(s;s<=e;s++){
                range.push(+s);
              };
            };
          };
          return range;
        };
        // convert code returned from the Ajax call
        var convert = function(code){
          // define output array
          var codeout = [];
          // replace HTML special chars
          // change tabs to spaces
          code = code.replace(/\t/g,'  ');
          // split code on newlines to get the lines
          var lines = code.split(/\r?\n/);
          // if there are highlights to be done 
          if(highlights){
            // get the full highlight range and loop over it
            var tohighlight = getrange(highlights[1]);
            for(var i=0,j=tohighlight.length;i<j;i++){
              // ger the appropriate line and add strong elements
              // around it
              var line = lines[tohighlight[i]-1];
              if(line){
                lines[tohighlight[i]-1] = '<strong>' + line + '</strong>';
              };
            };
          };
          // if there are only a few lines to be displayed
          if(boundaries){
            // get all the needed lines and loop over them
            var chunk = getrange(boundaries[1]);
            for(var i=0,j=chunk.length;i<j;i++){
              var line = lines[chunk[i]-1];
                // add spacers in between different line blocks
              if(i>0 && chunk[i] !== (chunk[i-1])+1){
                codeout.push('[...]');
              };
              // add a span with the line number, followed by a tab 
              if(line){
                var html = '<span>'+(chunk[i])+'</span>\t'+line;
                codeout.push(html);
              };
            };
          // if there are no boundaries just add line numbers to each line
          } else {
            for(var i=0,j=lines.length;i<j;i++){
              var html = lines[i];
              codeout.push(html);
            };
          };
          // create a pre with a code and the joined output after the link
          $(link).after(
            '<div class="codeexample"><span>' +
              codeout.join('\n') +
            '</span></div>'
          );
        };
        // do the ajax, timeout after 100 milliseconds if the 
        // document is not available
        $.ajax({
            url:this.href,
            timeout:500,
            success:convert
        });
      }
    );
  }
);

/*commnad収納術高さ統一エンジン*/
jQuery.changeLetterSize = {
	handlers : [],
	interval : 1000,
	currentSize: 0
};

(function($) {

	var self = $.changeLetterSize;

	/* 文字の大きさを確認するためのins要素 */
	var ins = $('<ins>M</ins>').css({
		display: 'block',
		visibility: 'hidden',
		position: 'absolute',
		padding: '0',
		top: '0'
	});

	/* 文字の大きさが変わったか */
	var isChanged = function() {
		ins.appendTo('body');
		var size = ins[0].offsetHeight;
		ins.remove();
		if (self.currentSize == size) return false;
		self.currentSize = size;
		return true;
	};

	/* 文書を読み込んだ時点で
	   文字の大きさを確認しておく */
	$(isChanged);

	/* 文字の大きさが変わっていたら、
	   handlers中の関数を順に実行 */
	var observer = function() {
		if (!isChanged()) return;
		$.each(self.handlers, function(i, handler) {
			handler();
		});
	};

	/* ハンドラを登録し、
	   最初の登録であれば、定期処理を開始 */
	self.addHandler = function(func) {
		self.handlers.push(func);
		if (self.handlers.length == 1) {
			setInterval(observer, self.interval);
		}
	};

})(jQuery);

/*
======================================================================
	$(expr).flatHeights()
	$(expr)で選択した複数の要素について、それぞれ高さを
	一番高いものに揃える
======================================================================
*/

(function($) {

	/* 対象となる要素群の集合 */
	var sets = [];

	/* 高さ揃えの処理本体 */
	var flatHeights = function(set) {
		var maxHeight = 0;
		set.each(function(){
			var height = this.offsetHeight;
			if (height > maxHeight) maxHeight = height;
		});
		set.css('height', maxHeight + 'px');
	};

	/* 要素群の高さを揃え、setsに追加 */
	jQuery.fn.flatHeights = function() {
		if (this.length > 1) {
			flatHeights(this);
			sets.push(this);
		}
		return this;
	};

	/* 文字の大きさが変わった時に、
	   setsに含まれる各要素群に対して高さ揃えを実行 */
	$.changeLetterSize.addHandler(function() {
		$.each(sets, function() {
			this.height('auto');
			flatHeights(this);
		});
	});

})(jQuery);

$(function(){
    /* div要素を2つずつの組に分ける */
    var sets = [], temp = [];
    $('.introduceFrame > div').each(function(i) {
        temp.push(this);
        if (i % 2 == 1) {
            sets.push(temp);
            temp = [];
        }
    });
    if (temp.length) sets.push(temp);

    /* 各組ごとに高さ揃え */
    $.each(sets, function() {
        $(this).flatHeights();
    });
});


/*全製品一覧交互に背景エンジン*/
$(function(){
	$('div#commandList > ul > li:nth-child(odd)').css("background-color", "#FEF9E5");
	$('div#adhesiveList > ul > li:nth-child(odd)').css("background-color", "#FFEAEA");
	$('div#tapeList > ul > li:nth-child(odd)').css("background-color", "#EAF5FA");
	$('div#othersList > ul > li:nth-child(odd)').css("background-color", "#EFEAEF");
});
