﻿
/*-----------------------------mozira [array.indexOf] extention -----------------------------*/
/*
*https://developer.mozilla.org/ja/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf
*/
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

/*-----------------------------配列シャッフル-----------------------------*/
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]
shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};


/*-----------------------------ブラウザ判別-----------------------------*/
 var ua_name = null;
 var re_version = null;
 var ua;
 
 $.each
  (
   $.browser,
   function(key, val)
    {
     if(key == "version"){re_version = val;}
     else if(val){ua_name = key;}
     if(ua_name && re_version){ua = ua_name + re_version;}
    }
  );

/*-----------------------------画像ナチュラルサイズ取得-----------------------------*/
function getNaturalSize(imgJqObj,src)
{
 if(ua_name == "msie")
  {
   var imgObj = new Image();
   imgObj.src = src;
   var w = imgObj.width;
   var h = imgObj.height;
  }
 else
  {
   imgObj = imgJqObj.get(0);  //jQueryオブジェクト配列→標準エレメント
   w = imgObj.naturalWidth;
   h = imgObj.naturalHeight;
  }

 return {width: w, height: h}
}

/*-----------------------------スクローラー-----------------------------*/
function setScroller(trigger,target,over_y){
 $(trigger).mousedown(function(){toggleScroller(trigger,target,over_y)});
}

function toggleScroller(trigger,target,over_y){
 var y = $(window).scrollTop();
 if(y > over_y || y <= 0){$.scrollTo($(target), {speed:750,axis:'y', offset: scrollOffset, queue: false});}
 else{$.scrollTo($("body"), {speed:750,axis:'y', queue: false});}
}


/*----------------------------------------------------------------------------*/
/*--                                  egBridge                              --*/
/*----------------------------------------------------------------------------*/

function egBridge(ini){

 this.setEgBridge = function()
  {
   var jan_e = $(ini.jan_e);
   var url_e = $(ini.url_e);
   var price_e = $(ini.price_e);
   var stock_e = $(ini.stock_e);

   var x = jan_e.size();

   var self = this;
   this.p_code = new Array(x); jan_e.each(function(i){self.p_code[i] = ($(this).html() + "").substr(7,5);});
   if(url_e.size() == x){this.url = new Array(x); url_e.each(function(i){self.url[i] = $(this).attr("href");});}
   if(price_e.size() == x){this.price = new Array(x); price_e.each(function(i){self.price[i] = $(this).html();});}
   if(stock_e.size() == x){this.stock = new Array(x); stock_e.each(function(i){self.stock[i] = $(this).html();});}
 
   this.setEachValue();
  }

 this.setEachValue = function()
  {
   var e = $('[egbridge^="c"]');
   var self = this;
   e.each
    (
     function()
      {
	   var t = $(this);
	   var v = t.attr("egbridge");
	   var c = v.substr(1,5);
	   var j = (self.p_code).indexOf(c);
	   var o = v.substr(6,1);
	   switch(o){
                  case "p": self.insertPrice(t,j); break;
                  case "s": self.insertStock(t,j); break;
                  case "u": self.insertUrl(t,j); break;
                  default: break;
	             }
	  }
	);
  }

 this.insertPrice = function(t,j){
   if(this.price[j]){t.html(this.price[j]);}
  }

 this.insertStock = function(t,j)
  {
   if(this.stock[j])
    {
     if(this.stock[j].indexOf("input") == -1){var a = 0;}
     else{a = 1;}
	 this.stock_flag = a;
	 var str = ini.stock_display[a].str; var style = ini.stock_display[a].style;
     t.css(style).html(str);
	}
  }

 this.insertUrl = function(t,j){
   var a = this.stock_flag;
   var link_style = ini.stock_display[a].link_style;
   if(this.url[j]){t.css(link_style).attr("href",this.url[j]);}
  }
 
 
}


/*----------------------------------------------------------------------------*/
/*--                                  egFilter                              --*/
/*----------------------------------------------------------------------------*/

function egFilter(ini){

 this.c_box = $(ini.root + " > ul.tab_contents_box");
 this.current_sort = "null";
 this.tabBlock = 1;

 this.setEgFilter = function()
  {
   this.setFilter();
   this.setSortControl();
  }
  
 this.setSortControl = function()
  {
   var keys = ini.sort_keys;
   $(ini.root + " > " + ini.sort_control_root).append("<p>並べ替え : </p><ul></ul>");
   var box = $(ini.root + " > " + ini.sort_control_root + " > ul");
   var self = this;
   var keys_len = keys.length;
   if(ua_name == "msie"){keys_len = 1;}
   for(var i = 0; i < keys_len; i++)
    {
	 var key = keys[i];
	 box.append("<li>" + key.str[0] + "</li>");
	 key.sort_selector;

     this.setSortAttr(i);
     this.bindSortControl(i);
    }
   $(ini.root + " > " + ini.sort_control_root + " > ul > li").css(ini.sort_key_style[0]).css({cursor: "pointer"});
  }

 this.bindSortControl = function(i){
   var self = this;
   $(ini.root + " > " + ini.sort_control_root + " li:eq(" + i + ")").click(function(){self.beforeSortCheck(i);});
  }
  
 this.setSortAttr = function(a)
  {
   var keys = ini.sort_keys;
   var attr = keys[a].attr;
   var selector = keys[a].sort_selector;
   var remover = keys[a].remover;
   var type = keys[a].type;

   for(var i = 0; i < this.contents_count; i++)
    {
     var e = $(ini.root + " > ul.tab_contents_box > li:eq(" + i + ") " + selector);
     var e_len = e.size();
     if(e_len > 1)
      {
       var inListVals = new Array(e_len);
	   var self = this;
       e.each(
              function(j)
			   {
			    var str = $(this).html();
				str = self.strRemover(str,remover);
				if(type == "num"){str = self.removeComma(str); str = str-0;}
				             else{str = self.removeTag(str);}
                inListVals[j] = str;
               }
             );

       if(type == "num"){inListVals.sort(function(a,b){return(a-b);});}
	   else{inListVals.sort();}
	   var v = inListVals[0];
      }
	 else
	  {
	   v = e.html();
	   if(type == "num"){v = this.removeComma(v); v = this.strRemover(v,remover); v = v-0;}
	                else{v = this.removeTag(v);}
	  }

     $(ini.root + " > ul.tab_contents_box > li:eq(" + i + ")").attr(attr,v);
    }
  }
  
 this.setFilter = function()
  {
   var tabs = $(ini.root + " > ul.tab_box > li");
   this.contents = $(ini.root + " > ul.tab_contents_box > li");
   this.contents_count = this.contents.size();
   this.clearContents();

   var self = this;
   tabs.each(function(i){$(this).click(function(){self.clickTab(i);});});
   this.contents.each(function(i){$(this).attr({def_i: i, fav: 0});});
   this.tabBlock = 0;
   this.clickTab(ini.def_tab);
  }

 this.clickTab = function(i)
  {
   if(this.tabBlock == 0)
    {
     if(ini.tab_bind_event)
      {
	   if(ini.tab_bind_event() == true){this.afterClickTab(i);}
	  }
     else{this.afterClickTab(i);}
	}
  }

 this.afterClickTab = function(i)
  {
   this.changeTab(i);
   this.clearContents();
   this.contentsFilter(i).css({display: "block"});
   this.c_box.css({height: "auto"});
  }
  
 this.clearContents = function(){
   var h = this.c_box.height();
   this.c_box.height(h);
   this.contents.css({display: "none"});
  }

 this.changeTab = function(i){
   $(ini.root + " > ul.tab_box > li " + ini.tab_parts).css(ini.tab_off);
   $(ini.root + " > ul.tab_box > li:eq(" + i + ") " + ini.tab_parts).css(ini.tab_on);
  }

 this.contentsFilter = function(i){
   var k = $(ini.root + " > ul.tab_box > li:eq(" + i + ") " + ini.tab_title).html();
   var c = $(ini.root + " > ul.tab_contents_box > li[egkey*=" + k + "]");
   return c;
  }

 this.beforeSortCheck = function(a)
  {
   if(this.current_sort != a)
    {
	 this.tabBlock = 1;
     if(ini.before_sort_event)
      {
	   if(ini.before_sort_event() == true)
        {
		 this.sortList(a);
        }
	  }
     else{this.sortList(a);}
	}
  }
  
 this.sortList = function(a)
  {
   this.changeSortButton(a);
   var keys = ini.sort_keys;
   var attr = keys[a].attr;
   var selector = keys[a].sort_selector;
   var type = keys[a].type;

   var tempArr = new Array(this.contents_count);
   var self = this;

   this.contents.each(
                       function(i)
                        {
                         var v = $(this).attr(attr);
                         tempArr[i] = {index: i, key: v}
                        }
                      );

   tempArr.sort(function(b1, b2){return b1["key"] > b2["key"] ? 1 : -1;});

   for(var i=0; i<tempArr.length; i++)
    {
     var old_i = tempArr[i].index;
     $(ini.root + " > ul.tab_contents_box > li:eq(" + old_i + ")").clone().appendTo(this.c_box);
	 if(i+1 == tempArr.length){this.afterSort();}
    }

  }
  
 this.afterSort = function()
  {
   $(ini.root + " > ul.tab_contents_box > li:lt(" + this.contents.size() + ")").remove();
   this.contents = $(ini.root + " > ul.tab_contents_box > li");
   var self = this;
   ini.after_sort_event(); self.tabBlock = 0;
  }
  
 this.changeSortButton = function(a)
  {
   if(this.current_sort != "null")
    {
	 var x = this.current_sort;
	 var c = $(ini.root + " > " + ini.sort_control_root + " > ul > li:eq(" + x + ")");
	 c.html(ini.sort_keys[x].str[0]).css(ini.sort_key_style[0]);
	}

   this.current_sort = a;
   var e = $(ini.root + " > " + ini.sort_control_root + " > ul > li:eq(" + a + ")");
   e.html(ini.sort_keys[a].str[1]).css(ini.sort_key_style[1]);
  }

 this.strRemover = function(str,remover){
   str = str + "";
   str = str.replace(remover,"");
   return str;
  }
  
 this.removeComma = function(str){
   str = str + "";
   str = str.replace(/,/g,"");
   return str;
  }
  
 this.removeTag = function(str){
   str = str + "";
   str = str.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g,"");
   str = str.replace(/&nbsp;/g,"");
   str = str.replace(/&amp;/g,"");
   str = str.replace(/&quot;/g,"");
   return str;
  }

}

/*------------------------------------------------------------------------*/
/*--                                 egList                             --*/
/*------------------------------------------------------------------------*/

function egList(ini){

this.ul_id = ini.ul_id;
this.li_width_offset = ini.li_width_offset;
this.eg_list_tab_on = ini.eg_list_tab_on;
this.eg_list_tab_off = ini.eg_list_tab_off;
this.gallery_on = ini.gallery_on;
this.gallery_off = ini.gallery_off;

this.li_width;

this.modal = false;
this.modal0 = false;
this.modal1 = false;


 this.setEgList = function()
  {
   $(this.ul_id + " div.eg_list_tab_pg").css({display: "none"});
   $(this.ul_id + " div.main_view_caption").css({display: "none"});
   this.li_width = $(this.ul_id + " > li:eq(0)").width();

   var self = this;
   var fn = function()
    {
     //$.scrollTo( $(self.ul_id), {speed:750,axis:'y', offset: scrollOffset, queue: false});
     $(self.ul_id + " > li .main_view img").after("<img class='full_size' src='' />");
     $(self.ul_id + " img.full_size").css({display: "none"});
     self.setEachList();
	};
   $(this.ul_id + " > li .main_view").onImagesLoad({selectorCallback: fn});
  }
  
 this.setEachList = function()
  {
   this.close_i = "null";
   this.open_i = "null";
   this.tab_i = "null";
   this.img_i = "null"; 
   var self = this;
   $(this.ul_id + " > li").each
    (
     function(i)
      {
       self.setEachListTab(i);
	   self.setEachListImage(i);
       $(self.ul_id + " > li:eq(" + i + ") .main_view").unbind().mousedown(function(){self.onListEvent(i,"preview");});
      }
    );
  }
  
 this.setEachListTab = function(i)
  {
   var self = this;
   $(this.ul_id + " > li:eq(" + i + ") ul.eg_list_tab li").each
    (
     function(j)
      {
       $(this).unbind().mousedown(function(){self.onListEvent(i,j);});
      }
    );
  }

 this.setEachListImage = function(i)
  {
   var self = this;
   $(this.ul_id + " > li:eq(" + i + ") div.eg_list_tab_pg img").each
    (
     function(j)
      {
       if($(this).attr("full_size_src") != "")
	    {
		 $(this).css({cursor: "pointer"});
         $(this).unbind().mousedown(function(){self.changeMainView(i,j);});
		}
      }
    );
  }

/*-----------------------------モーダルコントロール-----------------------------*/
 this.modalOn = function(){
   this.modal = true; this.modal0 = true; this.modal1 = true;
  }
  
 this.modalOff = function(){
   this.modal = false; this.modal0 = false; this.modal1 = false;
  }

 this.modalOffAnd = function(){
   if(this.modal0 == false && this.modal1 == false){this.modal = false;}
  }

/*-----------------------------マウスダウンイベント-----------------------------*/
 this.onListEvent = function(list_i, trigger)
  {
   if(this.modal == false)
    {
     if(trigger == "preview"){this.tab_i = "null";}else{this.tab_i = trigger - 0};

     if(this.open_i != list_i)
	  {
       this.modalOn();
       this.close_i = this.open_i;
       this.open_i = list_i;
	   this.openList(); this.closeList();
	  }
     else
	  {
	   if(trigger == "preview") //onlyクローズ処理
	    {
         this.modalOn();
         this.open_i = "null";
         this.close_i = list_i;
         this.closeList();
		}
       else{this.downListTab(this.tab_i); this.modal = false;}
      }
    }
  }

/*-----------------------------リスト内タブアクション-----------------------------*/
 this.downListTab = function(tab_i){
   var list_i = this.open_i - 0;
   this.ChangeListTabStyle(list_i, tab_i);
   this.ChangeListTabPage(list_i, tab_i);
  }

 this.ChangeListTabStyle = function(list_i,tab_i){
   $(this.ul_id + " > li:eq(" + list_i + ") ul.eg_list_tab li").css(this.eg_list_tab_off);
   $(this.ul_id + " > li:eq(" + list_i + ") ul.eg_list_tab li:eq(" + tab_i + ")").css(this.eg_list_tab_on);
  }

 this.ChangeListTabPage = function(list_i,tab_i){
   $(this.ul_id + " > li:eq(" + list_i + ") div.eg_list_tab_pg").css({display: "none"});
   $(this.ul_id + " > li:eq(" + list_i + ") div.eg_list_tab_pg:eq(" + tab_i + ")").fadeIn("fast");
  }

/*-----------------------------リストオープン-----------------------------*/
 this.openList = function()
  {
   var i = this.open_i;
   if(this.tab_i != "null"){this.ChangeListTabStyle(i, this.tab_i);}
   
   this.previewObj = $(this.ul_id + " > li:eq(" + i + ") .main_view img:eq(0)");
   this.fullSizeObj = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");

   this.full_size_src = this.previewObj.attr("full_size_src");
   this.KBEflag = this.previewObj.attr("KBEflag");
   
   var w = this.previewObj.width();
   var h = this.previewObj.height();
   $(this.ul_id + " > li:eq(" + i + ") .main_view").css({width: w, height: h});
   
   this.openListSeq("openList");
  }

 this.openListSeq = function(CBM)
  {
   var self = this;
   var i = this.open_i;
   switch(CBM)
    {
     case "openList":
       var CB = function(){self.openListSeq("fadeOutPreview");}
       this.fadeOutPreview(i,CB); break;

     case "fadeOutPreview":
       CB = function(){self.openListSeq("imageLoader");}
       this.imageLoader(this.fullSizeObj,this.full_size_src,CB); break;

     case "imageLoader":
       var naturalSize = getNaturalSize(this.fullSizeObj,this.full_size_src);
       this.nw = naturalSize.width;
       this.nh = naturalSize.height;
       CB = function(){self.openListSeq("ResizeMainView");}
	   this.ResizeMainView(i,this.nw,this.nh,this.KBEflag,CB); break;

     case "ResizeMainView":
       if(this.tab_i == "null"){this.tab_i = 0;}
       this.downListTab(this.tab_i);
       CB = function(){self.openListSeq("fadeInFullSize")}
	   this.fadeInFullSize(this.fullSizeObj,CB); break;

     case "fadeInFullSize":
	   $(self.ul_id + " > li:eq(" + i + ") div.contents_view").fadeIn("fast");
       CB = function(){self.openListSeq("adjustScroll");}
       this.adjustScroll(i,CB); break;
	   
     case "adjustScroll":
       this.modal0 = false;
	   if(this.close_i != "null"){this.modalOffAnd();}else{this.modalOff();}
	   if(this.KBEflag){this.setKBE(i,this.full_size_src); this.KBEflag = "null";}

     default: break;
	}

  }

/*-----------------------------フェードアウトプレビュー-----------------------------*/
 this.fadeOutPreview = function(i,CB){
   $(this.ul_id + " > li:eq(" + i + ") .main_view img:eq(0)").fadeOut(350,CB);
  }
  
/*-----------------------------イメージローダー-----------------------------*/
 this.imageLoader = function(e,full_size_src,CB){
   e.attr({src: ""}); //safari reload
   e.attr({src: full_size_src});
   e.onImagesLoad({selectorCallback: CB});
  }

/*-----------------------------リサイズメインビュー-----------------------------*/
 this.ResizeMainView = function(i,nw,nh,KBEflag,CB)
  {
   var w = nw; var h = nh;  
   if(KBEflag){w = Math.round(nw/2); h = Math.round(nh/2);}
   else{w = nw;}
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)").width(w);

   var contents_view = $(this.ul_id + " > li:eq(" + i + ") .contents_view");

   var offset = this.li_width_offset;
   if(ua.match("msie6")){offset = offset + 10;}
   var new_contents_view_width = this.li_width - w - 10 - offset;
   contents_view.css({width: new_contents_view_width});

   var main_view = $(this.ul_id + " > li:eq(" + i + ") .main_view");

   main_view.animate //メインビューリサイズ
    (
	 {width: w, height: h},
     {duration: 850, complete: CB}
	);
  }  
 
/*-----------------------------フェードインフルサイズ-----------------------------*/
 this.fadeInFullSize = function(e,CB){
   e.fadeIn(350,CB);
  }

/*-----------------------------調整スクロール-----------------------------*/
 this.adjustScroll = function(i,CB){
   $.scrollTo($(this.ul_id + " > li:eq(" + i + ")"), {speed:750,axis:'y', offset: scrollOffset, onAfter: CB, queue: false});
  }
  
/*-----------------------------リストクローズ-----------------------------*/
 this.closeList = function(){
   this.modalOn();
   this.stopKBE(this.close_i);
   this.resetCaption(this.close_i);
   this.closeListSeq("closeList");
  }

 this.quickCloseList = function()
  {
   var i = this.open_i;
   this.modalOn();
   this.open_i = "null";

   this.stopKBE(i);
   this.resetKBE(i);
   this.resetCaption(i);
   this.clearListContents(i,"null",1);
   this.fadeOutFullSize(i,"null",1);
   this.fadeInPreview(i,"null",1);
   this.modalOff();
   return true;
  }

 this.closeListSeq = function(CBM)
  {
   var i = this.close_i;
   var self = this;
   switch(CBM)
    {
     case "closeList":
       var CB = function(){self.closeListSeq("clearListContents");}
       this.clearListContents(i,CB); break;
	   
     case "clearListContents":
       CB = function(){self.closeListSeq("fadeOutFullSize");}
	   this.fadeOutFullSize(i,CB); break;
	   
     case "fadeOutFullSize":
       this.resetKBE(i);
       CB = function(){self.closeListSeq("shrinkMainView");}
	   this.shrinkMainView(i,CB); break;
	   
     case "shrinkMainView":
       CB = function(){self.closeListSeq("fadeInPreview");}
	   this.fadeInPreview(i,CB); break;
	   
     case "fadeInPreview":
       this.close_i = "null";
       this.modal1 = false;
	   if(this.open_i != "null"){this.modalOffAnd();}else{this.modalOff();}
	   
     default: break;
    }
  }

 this.clearListContents = function(i,CB,quick_mode)
  {
   $(this.ul_id + " > li:eq(" + i + ") div.eg_list_tab_pg img").css(this.gallery_off);
   $(this.ul_id + " > li:eq(" + i + ") ul.eg_list_tab li").css(this.eg_list_tab_off);
   var tab_pg = $(this.ul_id + " > li:eq(" + i + ") div.eg_list_tab_pg");
   if(quick_mode == 1){tab_pg.css({display: "none"});}
   else{this.slideUpTabPage(i,CB);}
  }
  
 this.slideUpTabPage = function(i,CB)
  {
   var tab_pg = $(this.ul_id + " > li:eq(" + i + ") div.eg_list_tab_pg");
   var main_view_h = $(this.ul_id + " > li:eq(" + i + ") .main_view_container").height();
   var contents_view_h = $(this.ul_id + " > li:eq(" + i + ") .contents_view").height();
   
   if(CB){var fn = CB;}else{fn = function(){}}
   if(main_view_h < contents_view_h){tab_pg.slideUp(750,fn);}
   else{tab_pg.css({display: "none"}); fn();}
  }

/*-----------------------------フェードアウトフルサイズ-----------------------------*/
 this.fadeOutFullSize = function(i,CB,quick_mode)
  {
   var e0 = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");
   var e1 = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(1)");

   if(e0.css("zIndex") < e1.css("zIndex")){var under_e = e0; var over_e = e1;}
   else{under_e = e1; over_e = e0;}

   under_e.css({display: "none"});
   if(quick_mode == 1){over_e.css({display: "none"});}
   else{over_e.fadeOut(350,CB);}
  }

/*-----------------------------メインビュー縮小-----------------------------*/
 this.shrinkMainView = function(i,CB,quick_mode)
  {
   var preview_img = $(this.ul_id + " > li:eq(" + i + ") .main_view img:eq(0)");
   var nw = preview_img.width();
   var nh = preview_img.height();
   
   var self = this;
   var e = $(this.ul_id + " > li:eq(" + i + ") .main_view");
   var final_style = {width: nw, height: nh}
   if(quick_mode == 1){e.css(final_style);}
   else
    {
     e.animate
      (
	   final_style,
	   {duration: 850, complete: CB}
	  );
    }
  }

/*-----------------------------プレビューフェードイン-----------------------------*/
 this.fadeInPreview = function(i,CB,quick_mode)
  {
   $(this.ul_id + " > li:eq(" + i + ") .contents_view").css({width: "auto"});
   var e = $(this.ul_id + " > li:eq(" + i + ") .main_view img:eq(0)");
   if(quick_mode == 1)
    {
	 e.css({display: "block"});
	 $(this.ul_id + " > li:eq(" + i + ") .main_view").css({width: "auto", height: "auto", overflow: "auto"});
	 return true;
	}
   else{e.fadeIn("fast",CB);}
  }

/*-----------------------------Ken Burn's Effect-----------------------------*/
 this.kbe_effect_count = 5;
 this.current_effect = 0;
 this.kbe_max_w;
 this.kbe_max_h;
 this.KBE_t;
 
 this.kbeBreaker = false;

 this.setKBE = function(i,src1,src2)
  {
   this.kbeBreaker = false;
   this.current_effect = 0;

   $(this.ul_id + " > li:eq(" + i + ") div.main_view").css({position: "relative", overflow: "hidden"});
   var e0 = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");

   if($(this.ul_id + " > li:eq(" + i + ") img.full_size").size() < 2)
    {
     e0.clone().insertAfter(e0).css({display: "none"});
	}

   if(src2){var second_src = src2;}else{second_src = src1;}
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(1)").attr({src: second_src});

   $(this.ul_id + " > li:eq(" + i + ") img.full_size").css({position: "absolute"});

   this.kbe_max_w = e0.width()*2;
   this.kbe_max_h = e0.height()*2;

   this.kbeEffectProgram = this.ShuffleKbeEffect(this.kbe_effect_count);
   this.kbeMainControl();
  }

 this.stopKBE = function(i)
  {
   this.kbeBreaker = true;
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)").stop();
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(1)").stop();
   clearTimeout(this.KBE_t);
  }

 this.resetKBE = function(i)
  {
   this.current_effect = 0;
   $(this.ul_id + " > li:eq(" + i + ") img.full_size").css({display: "none", width: "auto", top: "auto", left: "auto", right: "auto", bottom: "auto", position: "static"}).fadeTo(0,1);
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)").css({zIndex: 1, width: this.kbe_max_w/2}).attr({src: ""});
   $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(1)").css({zIndex: 2, width: this.kbe_max_w/2}).attr({src: ""});
   $(this.ul_id + " > li:eq(" + i + ") div.main_view").css({position: "relative"});
  }

 this.ShuffleKbeEffect = function(x)
  {
   var effect_count = x;
   var kbeArray = new Array(effect_count);
   for(i = 0; i < effect_count; i++){kbeArray[i] = i;}
   shuffle(kbeArray);
   return kbeArray;
  }
  
 this.kbeMainControl = function()
  {
   if(this.kbeBreaker != true)
    {
     var i = this.open_i;
     var e0 = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");
     var e1 = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(1)");

     if(e0.css("zIndex") < e1.css("zIndex")){var e_prev = e1; var e_next = e0;}
     else{e_prev = e0; e_next = e1;}

     this.kbeTransition(e_next);
     var self = this;
     e_prev.fadeOut
      (
	   1200,
	   function()
	    {
	     e_prev.css({zIndex: 1, top: "auto", bottom: "auto", left: "auto", right: "auto"});
	     e_next.css({zIndex: 2});
	    }
	  )

     if(this.current_effect == this.kbe_effect_count-1){this.current_effect = 0;}
     else{this.current_effect++;}
    }
  }
  
 this.kbeTransition = function(e)
  {
   var kbe_fn_num = this.kbeEffectProgram[this.current_effect];
   if(this.current_effect == 0){var fadeDuration = 1000;}else{fadeDuration = "null";}

   switch(kbe_fn_num)
    {
	 case 0:
	   this.kbeInTop(e,fadeDuration); break;
     case 1:
	   this.kbeBottomSlideRightOut(e,fadeDuration); break;
     case 2:
	   this.kbeTopSlideLeftOut(e,fadeDuration); break;
     case 3:
	   this.kbeLeftDownOut(e,fadeDuration); break;
     case 4:
	   this.kbeRightUpIn(e,fadeDuration); break;
     default: break;
	}
  }
  
 this.kbeInTop = function(e,fadeDuration)
  {
   var max_w = this.kbe_max_w;
   e.css({width: max_w/2, top: 0, left: 0});
   var final_left = -(Math.round(this.kbe_max_w/4));
   var final_top = -(Math.round(this.kbe_max_h/5));
   var self = this; CB = function(){self.kbeMainControl();}
   e.animate({top: final_top, left: final_left, width: this.kbe_max_w},{duration: 8000, complete: CB});
   //this.KBE_t = setTimeout(function(){self.kbeMainControl()},6700);
  }

 this.kbeBottomSlideRightOut = function(e,fadeDuration)
  {
   var max_w = this.kbe_max_w;
   e.css({width: max_w, bottom: 0, left: Math.round(-(max_w/2))});
   var final_width = Math.round(this.kbe_max_w*0.85);
   var final_bottom = -(Math.round(this.kbe_max_h/16));
   var self = this; CB = function(){self.kbeMainControl();}
   var fn = function()
    {
	 e.animate({bottom: final_bottom, left: 0, width: final_width},{duration: 8000, complete: CB});
     //this.KBE_t = setTimeout(function(){self.kbeMainControl()},6700);
	}
   if(fadeDuration != "null"){e.fadeIn(fadeDuration,fn);}else{fn();}
  }
  
 this.kbeTopSlideLeftOut = function(e,fadeDuration)
  {
   e.css({width: this.kbe_max_w, top: 0, right: -(this.kbe_max_w/2)});
   var final_width = Math.round(this.kbe_max_w*0.80);
   var final_top = -(Math.round(this.kbe_max_h/16));
   var self = this; CB = function(){self.kbeMainControl();}
   var fn = function()
    {
     e.animate({top: final_top, right: 0, width: final_width},{duration: 8000, complete: CB});
     //this.KBE_t = setTimeout(function(){self.kbeMainControl()},6700);
	}
   if(fadeDuration != "null"){e.fadeIn(fadeDuration,fn);}else{fn();}
  }

 this.kbeLeftDownOut = function(e,fadeDuration)
  {
   e.css({width: this.kbe_max_w, bottom: Math.round(-this.kbe_max_h*0.45), left: 0});
   var final_width = Math.round(this.kbe_max_w*0.9);
   var final_left = -(Math.round(this.kbe_max_w*0.05));
   var self = this; CB = function(){self.kbeMainControl();}
   var fn = function()
    {
     e.animate({bottom: 0, left: final_left, width: final_width},{duration: 8000, complete: CB});
     //this.KBE_t = setTimeout(function(){self.kbeMainControl()},6700);
    }
   if(fadeDuration != "null"){e.fadeIn(fadeDuration,fn);}else{fn();}
  }

 this.kbeRightUpIn = function(e,fadeDuration)
  {
   var start_width = Math.round(this.kbe_max_w*0.8);
   var start_right = -(Math.round(this.kbe_max_w*0.05));
   e.css({top: 0, width: start_width, right: start_right});
   var final_top = 5-this.kbe_max_h/2;
   var self = this; CB = function(){self.kbeMainControl();}
   var fn = function()
    {
     e.animate({top: final_top, right: 0, width: self.kbe_max_w},{duration: 8000, complete: CB});
     //this.KBE_t = setTimeout(function(){self.kbeMainControl()},6700);
	}
   if(fadeDuration != "null"){e.fadeIn(fadeDuration,fn);}else{fn();}
  }

/*-----------------------------ギャラリー機能-----------------------------*/
 this.changeMainView = function(i,j)
  {
   if(this.modal == false)
    {
     this.img_i = j;
     this.modalOn();
	 
	 $(this.ul_id + " > li:eq(" + i + ") div.contents_view").fadeOut(400);
     this.previewObj = $(this.ul_id + " > li:eq(" + i + ") div.eg_list_tab_pg img:eq(" + j + ")");
     this.fullSizeObj = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");

	 var p = this.previewObj;
     this.full_size_src = p.attr("full_size_src");
     this.KBEflag = p.attr("KBEflag");
	 
	 this.resetCaption(i);
	 this.cap_t = p.attr("cap_t");
	 this.cap_b = p.attr("cap_b");

     $(this.ul_id + " > li:eq(" + i + ")  div.eg_list_tab_pg img").css(this.gallery_off);
     this.previewObj.css(this.gallery_on);

     this.slideUpTabPage(i);
     this.changeMainViewSeq("changeMainView");
    }
  }

 this.changeMainViewSeq = function(CBM)
  {
   var self = this;
   var i = this.open_i;
   var j = this.img_i;
   var CB;
   switch(CBM)
    {
     case "changeMainView":
	   this.stopKBE(i);
       CB = function(){self.changeMainViewSeq("fadeOutFullSize");}
	   this.fadeOutFullSize(i,CB,0); break;
	   
     case "fadeOutFullSize":
       this.resetKBE(i);
	   var e = $(this.ul_id + " > li:eq(" + i + ") img.full_size:eq(0)");
       this.full_size_src = this.previewObj.attr("full_size_src");

       CB = function(){self.changeMainViewSeq("imageLoader");}
       this.imageLoader(this.fullSizeObj,this.full_size_src,CB); break;

     case "imageLoader":
       var naturalSize = getNaturalSize(this.fullSizeObj,this.full_size_src);
       this.nw = naturalSize.width;
       this.nh = naturalSize.height;
       CB = function(){self.changeMainViewSeq("ResizeMainView");}
	   this.ResizeMainView(i,this.nw,this.nh,this.KBEflag,CB); break;

     case "ResizeMainView":
       if(this.tab_i == "null"){this.tab_i = 0;}
       this.downListTab(this.tab_i);
   	   if(this.cap_t){this.setCaption("top",i);}
	   if(this.cap_b){this.setCaption("bottom",i);}
       CB = function(){self.changeMainViewSeq("fadeInFullSize");}
	   this.fadeInFullSize(this.fullSizeObj,CB); break;

     case "fadeInFullSize":
	   $(self.ul_id + " > li:eq(" + i + ") div.contents_view").fadeIn("fast");
       CB = function(){self.changeMainViewSeq("adjustScroll");}
       this.adjustScroll(i,CB); break;
	   
     case "adjustScroll":
       this.modal0 = false;
	   //if(this.close_i != "null"){this.modalOffAnd();}else{this.modalOff();}
       this.modalOff();
	   if(this.KBEflag){this.setKBE(i,this.full_size_src); this.KBEflag = "null";}
	   
     default: break;
    }
  }

 this.resetCaption = function(i)
  {
   $(this.ul_id + " > li:eq(" + i + ") div.main_view").css({position: "relative"});
   var cap = $(this.ul_id + " > li:eq(" + i + ") div.main_view > div.main_view_caption");
   if(cap.size() > 0){cap.html("");}
   else
    {
	 $(this.ul_id + " > li:eq(" + i + ") div.main_view").append('<div class="main_view_caption cap_png"></div>');
	 cap = $(this.ul_id + " > li:eq(" + i + ") div.main_view > div.main_view_caption");
	}
   cap.css({display: "none", top: "auto", bottom: "auto"});
   $(".cap_png").pngfix();
  }

 this.setCaption = function(v_pos,i)
  {
   $(this.ul_id + " > li:eq(" + i + ") img.full_size").css({position: "absolute", zIndex: 0}); //ie fix

   var cap = $(this.ul_id + " > li:eq(" + i + ") div.main_view > div.main_view_caption");

   if(ua_name == "msie")
    {
     var box_w = $(this.ul_id + " > li:eq(" + i + ") div.main_view").width();
     var cap_pd_l = cap.css("paddingLeft");
     var x = cap_pd_l.indexOf("px");
     var cap_hr_pd = cap_pd_l.substring(0,x)*2;

     var cap_mg_l = cap.css("marginLeft");
     x = cap_mg_l.indexOf("px");
     var cap_hr_mg = cap_mg_l.substring(0,x)*2;

     var w = (box_w - cap_hr_pd - cap_hr_mg) + "px";
	}
   else{w = "auto";}
   
   cap.css({position: "absolute", width: w, display: "block", zIndex: 100});
   if(v_pos == "top"){cap.css({top: "0px"}).html(this.cap_t);}
   if(v_pos == "bottom"){cap.css({bottom: "0px"}).html(this.cap_b);}
  }

 this.resetEgList = function()
  {
   if(this.quickCloseList() == true)
    {
     $(this.ul_id + " .main_view").unbind();
     $(this.ul_id + " ul.eg_list_tab li").unbind();
     $(this.ul_id + " div.eg_list_tab_pg img").unbind();
     return true;
	}
  }
 

}


/*-------------------------------------------------------------------------------*/
/*--                                  egAccordion                              --*/
/*-------------------------------------------------------------------------------*/

function egAccordion(ini){

 this.current_i = "null";
 this.blocker = false;

 this.setList = function()
  {
   $(ini.root + " > li > " + ini.contents).css({display: "none"});
   var self = this;
   var e = $(ini.root + " > li > " + ini.trigger);
   e.css({cursor: "pointer"});
   if(ini.autoClose){e.each(function(i){$(this).mousedown(function(){self.selectList(i);});});}
                else{e.each(function(i){$(this).toggle(
				                                           function(){self.openList(i);},
														   function(){self.closeList(i);}
														  );});}
  }

 this.selectList = function(i)
  {
   var c = this.current_i;
   if(c == i){this.closeList(i); this.current_i = "null";}
   else
    {
	 this.closeList(c);
     this.openList(i);
     this.current_i = i;
    }
   this.marking(c);
  }

 this.openList = function(i){
   $(ini.root + " > li:eq(" + i + ") > " + ini.contents).slideDown(ini.openSpeed);
  }

 this.closeList = function(i){
   $(ini.root + " > li:eq(" + i + ") > " + ini.contents).slideUp(ini.closeSpeed);
  }

 this.marking = function(i)
  {
   if(ini.marking)
    {
     if(ini.marking == "once"){$(ini.root + " > li > " + ini.trigger).css(ini.markingOff);}
     $(ini.root + " > li:eq(" + i + ") > " + ini.trigger).css(ini.markingOn);
	}
  }

}


/*----------------------------------------------------------------------------*/
/*--                              フォームチェック                          --*/
/*----------------------------------------------------------------------------*/

function formCheck(form){
 if(!checkResponce(form.sw)){return false;}
 //return true;
}

function checkResponce(obj){
 if(obj.value == "")
  {
   alert("製品名の一部、キーワードなどを入力してください。");
   obj.focus();
   return false;
  }
 if(obj.value.length < 2)
  {
   alert("2文字以上入力してください。");
   obj.focus();
   return false;
  }
 if(obj.value.length > 32)
  {
   alert("文字数オーバーです。");
   obj.focus();
   return false;
  }
 return true;
}


/*----------------------------------------------------------------------------------*/
/*--                                    フェーダー                                --*/
/*----------------------------------------------------------------------------------*/

function egFader(ini){

 this.trigger = ini.trigger;
 this.fader = ini.fader;

 this.setFader = function()
  {
   for(var i=0; i<this.trigger.length; i++)
    {
	 if(this.trigger[i] != null)
	  {
       this.bindFaderOn(i);
       this.bindFaderOff(i);
	  }
	}
  }
 
 this.bindFaderOn = function(i){
   var self = this;
   $(this.trigger[i]).mouseover(function(){self.faderIn(i);});
  }

 this.bindFaderOff = function(i){
   var self = this;
   $(this.trigger[i]).mouseout(function(){self.faderOut(i);});
  }

 this.faderIn = function(i){
   var self = this;
   $(this.trigger[i]).unbind("mouseover");

   $(this.fader[i]).fadeIn(850,function(){self.bindFaderOn(i);});
  }

 this.faderOut = function(i){
   $(this.fader[i]).fadeOut("normal");
  }

}


/*--------------------------------------------------------------------------------*/
/*--                                 サーチリスト                               --*/
/*--------------------------------------------------------------------------------*/

function egsList(ini){

 this.list_box_id = ini.list_box_id;
 
 this.setList = function()
  {
   var li_len = $(this.list_box_id + " li").size();
   for(var i=0; i<li_len; i++)
    {
	 var e = $(this.list_box_id + " li:eq(" + i + ")");
	 var id = e.attr("id");
	 if(id == "current_sp"){$(this.list_box_id + " li:eq(" + i + ") a").css({color: "#fff"});}
	                   else{this.bindListEffect(i);}
	}
  }

 this.bindListEffect = function(i)
  {
   var self = this;
   $(this.list_box_id + " li:eq(" + i + ")").hover
     (
      function(){self.listOn(i)},
	  function(){self.listOff(i)}
	 );
  }

 this.listOn = function(i){
   $(this.list_box_id + " li:eq(" + i + ")").css({backgroundColor: "#B0B6BF"});
  } 
 
 this.listOff = function(i){
   $(this.list_box_id + " li:eq(" + i + ")").css({backgroundColor: "transparent"});
  } 


}


/*----------------------------------------------------------------------------------*/
/*--                                  ナビゲーション                              --*/
/*----------------------------------------------------------------------------------*/
function egNavi(ini){

 this.menuCondition = false;

 this.setNavi = function(opt)
  {
   this.auto_scroll = opt.auto_scroll;
   this.mode = opt.mode;
   var self = this;
   
   if(!(ua.match("msie6")))
    {
	 this.fixedMenu();
	 scrollOffset = -25;
	 //$(this.menu_toggle).mousedown(function(){self.toggleMenu();});
	}
   
   $("div.jump_page_top").mousedown(function(){self.jumpPageTop();});
   if(this.mode == "search"){$(ini.map_id + " li.search_box").css({backgroundPosition: "0px -40px"});}
   if(this.mode == "nosearch"){$(ini.map_id + " li.search_box").css({display: "none"});}
   this.setStartRoute(0);
  }

 this.fixedMenu = function()
  {
   var self = this;
   $(window).scroll
        (
         function()
          {
	       var float_menu = $(ini.float_menu);
		   var fixed_navi = $(ini.fixed_navi);
	       var y = $(window).scrollTop();
	       if(y > 550)
	        {
			 if(self.menuCondition == true){self.toggleMenu();}
			 else{float_menu.css({position: "fixed", top: "-547px"});}
			 fixed_navi.fadeIn(350);
	   	    }
           else
	 	    {
	  	     float_menu.css({position: "absolute", top: "0px"});
			 fixed_navi.fadeOut(250);
	        }
          }
		);
  }


 this.jumpPageTop = function()
  {
   $.scrollTo($(ini.page_top), {speed:1000,axis:'y', queue: false});
  }

 this.setStartRoute = function(i)                            //route map開始
  {
   var self = this;
   var route_len = $(ini.map_id + " .route_box").size();
   this.column_len = new Array(route_len);
   this.column_len[i] = $(ini.map_id + " .route_box:eq(" + i + ") ul").size();
   $(ini.map_id + " .route_selector span").unbind().css({cursor: "pointer", color: "#84888b", textDecoration: "underline"});

   if(route_len > 1 && this.column_len[i] > 2)
    {
	 $(ini.map_id + " .route_selector span:eq(" + i + ")").css({cursor: "text", color: "#789", textDecoration: "none"});
	 for(a=0; a<route_len; a++)
	  {
	   if(a != i){this.bindRouteChanger(a);}
	  }
	}

   var route_box_w = (this.column_len[i] * 215) + 10;
   $(ini.map_id + " .route_box").css({display: "none"});
   $(ini.map_id + " .route_box:eq(" + i + ")").css({width: route_box_w, display: "block"});

   setTimeout(function(){self.startRoute(i);},1000);
  }

 this.bindRouteChanger = function(i)
  {
   var self = this;
   $(ini.map_id + " .route_selector span:eq(" + i + ")").click(function(){self.auto_scroll=false; self.setStartRoute(i);});
  }

  this.startRoute = function(i)
   {
    //this.addSearchBox(i); 検索窓
    var column_count = this.column_len[i];
    var comp_slide = false;
    for(var j=0; j<column_count; j++)
     {
	  var left_pos = (column_count-j-1)*ini.column_w + "px";
	  this.slideColumn(i,j,left_pos);
	 }
   }

 this.slideColumn = function(i,j,left_pos)                            //カラムスライダー
  {
   var self = this;
   $(ini.map_id + " .route_box:eq(" + i + ") ul:eq(" + j + ")").animate({
     left: left_pos
    }, "slow",function(){self.scrollColumn(i,j)});
  }

 this.scrollColumn = function(i,j)                            //スクロール
  {
   var self = this;
   var end_column = this.column_len[i] - 1;
   if(j == end_column){var comp_route = true;}else{comp_route = false;}
   if(j == end_column)
    {
     $(ini.map_id + " div:eq(" + i + ") ul:eq(" + j + ")").scrollTo( $(ini.map_id + " div:eq(" + i + ") ul:eq(" + j + ") .scrl_fg"), {speed:1000,axis:'y', queue: false, onAfter: function(){self.startMain();}} );
	}
   else
    {
	 $(ini.map_id + " div:eq(" + i + ") ul:eq(" + j + ")").scrollTo( $(ini.map_id + " div:eq(" + i + ") ul:eq(" + j + ") .scrl_fg"), {speed:1000,axis:'y', queue: false} );
	}
  }


 this.startMain = function()
  {
   //if(!(ua.match("msie6"))){$("ul.column_box").css({backgroundColor: "transparent"});}
   var self = this;
   if(this.auto_scroll == true)
    {
     $.scrollTo( $("#main_center"), {speed:1000,axis:'y', offset: scrollOffset, queue: false, onAfter: function(){if(self.cb){self.cb();}}} );
	}
   else{if(self.cb){self.cb();}}
  }  

}


var NAVI = new egNavi({
                        page_top: "body",
						float_menu: "#float_menu",
						fixed_navi: "#fixed_navi",
						map_id: "#map_box",
						column_w: 215
                      });