//var path_root = "http://localhost:8888/www/";
//var path_root = "http://localhost/www/";
var path_root = "http://www.everg.co.jp/";

function escapeLF(str)
{
 str = str + "";
 str = str.replace(/\n/g,"NeWLiN")
 return str;
}


 var ua_name = null;
 var re_version = null;
 var ua;
 var scrollOffset = 0;
 $.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 egNavi(ini){
 this.page_top = ini.page_top;
 this.float_menu = ini.float_menu;
 this.fixed_navi = ini.fixed_navi;
 this.head_map_id = ini.head_map_id;
 this.foot_map_id = ini.foot_map_id;
 this.column_w = ini.column_w;
 this.main_contents = ini.main_contents;
 this.menuCondition = false;

 this.setNavi = function(ini)
  {
   this.auto_scroll = ini.auto_scroll;
   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();});
   this.mode = ini.mode;
   if(this.mode == "search"){$(this.head_map_id + " li.search_box").css({backgroundPosition: "0px -40px"});}
   if(this.mode == "nosearch"){$(this.head_map_id + " li.search_box").css({display: "none"});}
   this.cb = ini.cb;
   this.setStartRoute(0);
  }

 this.fixedMenu = function()
  {
   var self = this;
   $(window).scroll
        (
         function()
          {
	       var float_menu = $(self.float_menu);
		   var fixed_navi = $(self.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($(this.page_top), {speed:1000,axis:'y', queue: false});
  }

 this.setStartRoute = function(i)                            //route map開始
  {
   var self = this;
   var route_len = $(this.head_map_id + " .route_box").size();
   this.column_len = new Array(route_len);
   this.column_len[i] = $(this.head_map_id + " .route_box:eq(" + i + ") ul").size();
   $(this.head_map_id + " .route_selector span").unbind().css({cursor: "pointer", color: "#84888b", textDecoration: "underline"});
   if(this.mode != "search"){$(this.foot_map_id + " .route_selector span").unbind().css({cursor: "pointer", color: "#84888b", textDecoration: "underline"});}
   if(route_len > 1 && this.column_len[i] > 2)
    {
	 $(this.head_map_id + " .route_selector span:eq(" + i + ")").css({cursor: "text", color: "#789", textDecoration: "none"});
	 if(this.mode != "search"){$(this.foot_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;
   $(this.head_map_id + " .route_box").css({display: "none"});
   $(this.head_map_id + " .route_box:eq(" + i + ")").css({width: route_box_w, display: "block"});
   if(this.mode != "search")
    {
	 $(this.foot_map_id + " .route_box").css({display: "none"});
	 $(this.foot_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;
   $(this.head_map_id + " .route_selector span:eq(" + i + ")").click(function(){self.auto_scroll=false; self.setStartRoute(i);});
   if(this.mode != "search"){$(this.foot_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)*this.column_w + "px";
	  this.slideColumn(i,j,left_pos);
	 }
   }

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

   if(this.mode != "search"){$(this.foot_map_id + " .route_box:eq(" + i + ") ul:eq(" + j + ")").css({left: left_pos});}
  }

 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)
    {
     $(this.head_map_id + " div:eq(" + i + ") ul:eq(" + j + ")").scrollTo( $(this.head_map_id + " div:eq(" + i + ") ul:eq(" + j + ") .scrl_fg"), {speed:1000,axis:'y', queue: false, onAfter: function(){self.syncColumnScroll(i,j); self.startMain();}} );
	}
   else
    {
	 $(this.head_map_id + " div:eq(" + i + ") ul:eq(" + j + ")").scrollTo( $(this.head_map_id + " div:eq(" + i + ") ul:eq(" + j + ") .scrl_fg"), {speed:1000,axis:'y', queue: false, onAfter: function(){self.syncColumnScroll(i,j);}} );
	}
  }

 this.syncColumnScroll = function(i,j)
  {
   if(this.mode != "search")
    {
     var scrlTop = $(this.head_map_id + " div:eq(" + i + ") ul:eq(" + j + ")").get()[0].scrollTop;
     var e = $(this.foot_map_id + " div:eq(" + i + ") ul:eq(" + j + ")").get()[0];
     e.scrollTop = scrlTop;
	}
  }


 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",
						head_map_id: "#map_box_head",
						foot_map_id: "#map_box_foot",
						column_w: 215,
						main_contents: "#main_center"
                      });
 

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

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 egCycle(){

this.setCycle = function(id,h)
 {
  $(id).css({height: h});
  var list_len = $(id + " li").size();
  for(var i=1; i<list_len; i++){$(id + " li:eq(" + i + ")").css({display: "none"});}
 }

}

/*----------------------------------------------------------------------------------*/
/*--                                  タブページャー                              --*/
/*----------------------------------------------------------------------------------*/

function egTab(ini){

 this.id = ini.id;
 this.page = $(this.id + " .tab_pg_items");
 this.current_pg = ini.current_pg;
 this.pg_items = ini.pg_items;

 this.setPager = function()
  {
   $(this.id + " ul.tab_pg_items li.tab_pg_item").css({display: "none"}); //事前にCSSで"none"にするとブロック要素否定となり、mojomagnify on IE7でバグ
   var tab_len = $(this.id + " ul.head_tab li").size();
   var FPS = "";
   for(var i=0; i<tab_len; i++)
     {
	  if(i == this.current_pg){this.showNewPage(i);}
      FPS += "<span>" + $(this.id + " ul.head_tab li:eq(" + i + ") span.hd_tbC").html() + "</span>";
	  if(i < (tab_len - 1)){FPS += "&nbsp;&nbsp;|&nbsp;&nbsp;"}
	 }

   $(this.id + " .foot_tab_pager").html(FPS);
   for(var i=0; i<tab_len; i++)
     {
	  if(i == this.current_pg){$(this.id + " .foot_tab_pager span:eq(" + i + ")").css({color: "#89a", fontWeight: "normal", cursor: "text"});}
	                       else{this.bindPager(i);}
	 }
  }

 this.bindPager = function(i)
  {
   var self = this;
   $(this.id + " ul.head_tab li:eq(" + i + ")").click(function(){self.changePage(i)});
   $(this.id + " .foot_tab_pager span:eq(" + i + ")").click(function(){self.changePage(i);});
  }
  
 this.changePage = function(i)
  {
   this.hideOldPage(i);
   this.showNewPage(i,true);
   this.current_pg = i;
  }

 this.hideOldPage = function(i)
 {
  this.page.css({display: "none"});
  var c = this.current_pg;
   for(var a = 0; a < this.pg_items[c].length; a++)
    {
	 $(this.id + " ul.tab_pg_items li.tab_pg_item:eq(" + this.pg_items[c][a].li + ")").css({display: "none"});
	}
   $(this.id + " ul.head_tab li:eq(" + c+ ")").css({backgroundPosition: "0 -40px"});
   $(this.id + " ul.head_tab li:eq(" + c+ ") span.hd_tbL").css({backgroundPosition: "0 -40px"});
   $(this.id + " ul.head_tab li:eq(" + c + ") span.hd_tbR").css({backgroundPosition: "0 -40px"});
   $(this.id + " .foot_tab_pager span:eq(" + c + ")").css({color: "#678", fontWeight: "bold", cursor: "pointer"});
   this.bindPager(c);
 }

 this.showNewPage = function(i,scroll)
 {
   var self = this;
   for(var a = 0; a < this.pg_items[i].length; a++)
    {
	 var e = $(this.id + " ul.tab_pg_items li.tab_pg_item:eq(" + this.pg_items[i][a].li + ")");
	 e.css({display: "block"});
	 if(this.pg_items[i][a].cb != null)
	  {
	   this.pg_items[i][a].cb(function(){self.comp_cb(i);});
	  }
	}
   $(this.id + " ul.head_tab li:eq(" + i + ")").css({backgroundPosition: "0 0"});
   $(this.id + " ul.head_tab li:eq(" + i + ") span.hd_tbL").css({backgroundPosition: "0 0"});
   $(this.id + " ul.head_tab li:eq(" + i + ") span.hd_tbR").css({backgroundPosition: "0 0"});
   $(this.id + " ul.head_tab li:eq(" + i + ")").unbind("click");
   $(this.id + " .foot_tab_pager span:eq(" + i + ")").unbind("click");
   $(this.id + " .foot_tab_pager span:eq(" + i + ")").css({color: "#89a", fontWeight: "normal", cursor: "text"});

   if(scroll == true)
    {
	 this.page.fadeIn(
	  "fast",
	  function(){$.scrollTo($(self.id), {speed:1000, offset: scrollOffset-10, axis:'y', queue: true});}
	 );
	}
   else{this.page.fadeIn("fast");}
 }
 
 this.resetPager = function(i){this.changePage(i)}

}



/*----------------------------------------------------------------------------------*/
/*--                                     回転台                                   --*/
/*----------------------------------------------------------------------------------*/

function turnTable(ini){

 this.box_id = ini.box_id;
 this.box_width = ini.box_width;
 this.box_height = ini.box_height;
 this.preview_common = ini.preview_common;
 this.original_common = ini.original_common;
 this.img_len = ini.img_len;
 this.ext = ini.ext;
 this.current_img = ini.start_img;

 this.setTable = function()                         //
  {
   var self = this;
   $(this.box_id).html("<div class='loader_box'><div class='loader_wh'></div></div>");
   $(this.box_id).css({width: this.box_width, height: this.box_height}).html(this.tableRender());
   $(this.box_id + " img:eq(" + this.current_img + ")").css({display: "block"});
   this.setTrigger();
  }

 this.setTrigger = function()
  {
   var trigger_width = Math.floor(this.box_width/this.img_len);
   $(this.box_id + " .trigger").css({width: trigger_width, height: this.box_height});
   var last_trigger_width = this.box_width - trigger_width*(this.img_len - 1) -3;
   $(this.box_id + " .trigger:eq(" + (this.img_len - 1) + ")").css({width: last_trigger_width});
   for(var i=0; i<this.img_len; i++){this.bindTurner(i);}
   $(this.box_id + ' .trigger').lightBox({fixedNavigation:true});
  }

  
 this.tableRender = function()
  {
   var V = ""; var T = "<div class='trigger_box'>";
   for(var i=0; i<this.img_len; i++)
    {
	 V += "<img src='" + this.preview_common + (i+1) + "." + this.ext + "' />";
	 T += "<div class='trigger' href='" + this.original_common + (i+1) + "." + this.ext + "'></div>";
	}
   T += "</div>";
   return V + T;
  }

 this.bindTurner = function(i)
  {
   var self = this;
   $(this.box_id + " .trigger:eq(" + i + ")").mouseover(function(){self.turnImage(i)});
  }

 this.turnImage = function(i)
  {
   $(this.box_id + " img:eq(" + this.current_img + ")").css({display: "none"});
   $(this.box_id + " img:eq(" + i + ")").css({display: "block"});
   this.current_img = i;
  }


}

