﻿/*-------------------------------------------------------------------------------*/
/*                        cucco user interface 2010.01.29                        */
/*-------------------------------------------------------------------------------*/
 
function referrerCheck(){
 var ref = document.referrer;
 if(!(ref.match("http://www.ccucco.com")) && !(ref.match("https://www.ccucco.com"))){clearCookie();};
}

function clearCookie(){
 $.cookie('parent_type',"",{path: "/", expires: 1});
 $.cookie('parent_name',"",{path: "/", expires: 1});
 $.cookie('parent_url',"",{path: "/", expires: 1});
}

function recordHistory(type,name,url){
 $.cookie('parent_type',type,{path: "/", expires: 7}); //write 7days
 if(type == "genre_list"){
   $.cookie('parent_name',name,{path: "/", expires: 7}); //write 7days
   $.cookie('parent_url',url,{path: "/", expires: 7}); //write 7days
  }
}

function bindHistoryRecorder(container,type){
 
 var e = $(container + " a");
 e.each(function(i){
         var name_source = $(this).html().replace("<br />","・").replace("<br>","・");
         var name = tagRemover(name_source);
         var url = $(this).attr("href");
		 if(url != "http://www.ccucco.com/"){
          $(this).click(function(){recordHistory(type,name,url);});
		 }
		}
 );
}


/*-------------------------------------------------------------------------------*/
/*                              レコメンド・ビューワー                           */
/*-------------------------------------------------------------------------------*/

function kotoViewer(ini){

 var self = this;
 this.slide_show = true;

 this.setLoadListener = function(){
  var c = 0;
  $.timer(ini.ll_interval, function (timer){
   if(!self.loadListener() && c < ini.ll_count){
    c++;
    timer.reset(ini.ll_interval);
   }else{
    timer.stop();
	if(c < ini.ll_count){self.setViewer();}
	else{$(ini.id).slideUp();}
   }
  });
 }

 this.loadListener = function(){
  if($(ini.listener_target).size()){return true;}
  else{return false;}
 }

 this.setViewer = function(){
  $(ini.listener_target).fadeOut('fast');
  this.render();
  this.bindMenuEvent();
  this.startSlideShow();
  $(ini.png_class).pngfix();
  $(ini.title_png_class).pngfix();
 }
 
 this.render = function(){
  this.items = $(ini.id + ' ' + ini.item_unit);
  var l = '';
  var d = '';

  this.items.each(function(i){
   var item = $(this).find(ini.item_title);
   var name = item.text();
   var url = item.attr('href');
  
   var image_src = $(this).find(ini.item_image).attr('src');
   l += '<a href="#' + i + '" class="koto_viewer_list_box"><img src="' + image_src + '" /></a>';
  
   var image_src_array = image_src.split('/');
   var file_name = image_src_array[(image_src_array.length - 1)];
   var p_code = file_name.split('-')[0];
   var a_attr = 'href="' + url + '" title="' + name + '" idx="' + i + '"';
   var load_handler = 'onload="' + ini.obj_name + '.imageLoadListener(this)"';
  
   d += '<a ' + a_attr + '><img src="' + ini.item_image_path + file_name + '" width="600" ' + load_handler + ' /></a>';
   d += '<a ' + a_attr + '><img src="' + ini.item_image_path + p_code + '-1.jpg" width="600" ' + load_handler + ' /></a>';
   d += '<a ' + a_attr + '><img src="' + ini.item_image_path + p_code + '-2.jpg" width="600" ' + load_handler + ' /></a>';
   d += '<a ' + a_attr + '><img src="' + ini.item_image_path + p_code + '-01.jpg" width="600" ' + load_handler + ' /></a>';
   d += '<a ' + a_attr + '><img src="' + ini.item_image_path + p_code + '-02.jpg" width="600" ' + load_handler + ' /></a>';
  });

  $(ini.id).css({height: ini.id_height});
  $(ini.viewer_list).html(l);
  $(ini.viewer_display).html(d);
  $(ini.viewer).slideDown();
 }
 
 this.imageLoadListener = function(e){
  $(e).attr('ilf','1');
 }
 
 this.bindMenuEvent = function(){
  var buttons = $(ini.viewer_list + ' a');
  buttons.each(function(i){
   var e = $(this);
   e.click(function(){self.itemSelected(i);});
  });
 }

 this.itemSelected = function(i){
  this.slide_show = false;
  this.changeImage(i);
 }
 
 this.changeImage = function(i){
  $(ini.viewer_list + '>a[sf="1"]').attr('sf','0').css(ini.sf0);
  $(ini.viewer_list + ' a:eq(' + i + ')').attr('sf','1').css(ini.sf1);

  $(ini.viewer_display + '>a[df="1"]').attr('df','0').fadeOut();
  
  var images = $(ini.viewer_display + '>a[idx="' + i + '"] img[ilf="1"]');
  var images_size = images.size();
  var r=Math.floor(Math.random()*images_size);
  var image_box = $(ini.viewer_display + '>a[idx="' + i + '"] img[ilf="1"]:eq(' + r + ')').parent('a');

  var title = image_box.attr('title');
  var url = image_box.attr('href');
  image_box.attr('df','1').fadeIn();
  $('#' + ini.viewer_title_id).html('<a href="' + url + '">' + title + '</a>');
 }

 this.startSlideShow = function(){
  var c = 0;
  $.timer(ini.ss_delay, function (timer){
   if(self.slide_show){
    self.changeImage(c);
    if(c == self.items.size()-1){c = 0;}
    else{c++;}
    timer.reset(ini.ss_interval);
    }else{
    timer.stop();
   }
  });
 }

}


/*-------------------------------------------------------------------------------*/
/*                            トピックパス　デコレーション                       */
/*-------------------------------------------------------------------------------*/

function topicPath(){
  
 var t = $('table[background="../html/images/item/dot_6.gif"]');
 if(!t.size()){t = $('table[background="../html/images/category/dot_6.gif"]');}
 var es = $('a.crumbsList');
 var es_size = es.size();
 
 if(t.size()){
  var s = '<div id="topic_path"><a class="topic_path_top" href="http://www.ccucco.com/"></a>';

  var e = es.eq(1);
  str = e.html();
    if(str.match('<br') || str.match('<BR')){var c = 'topic_path_double';}
    else{c = 'topic_path_single';}
    s += '<a class="' + c + '" href="' + e.attr('href') + '">' + e.html() + '</a>';
 
  s += '</div>';
  t.replaceWith(s);
 }

}


/*-------------------------------------------------------------------------------*/
/*                                  ブランドサーチ                               */
/*-------------------------------------------------------------------------------*/

 function brandSearch(ini){
  
  var self = this;
  var keys = $(ini.keys_id + ' li');
  var letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
  
  this.setSearch = function(){
   this.brandIndexer();
   this.setKeys();
   this.setCurrentBrand();
   $(ini.next_id).mousedown(function(){self.downNextKey();});
   $(ini.prev_id).mousedown(function(){self.downPrevKey();});
   $(ini.all_id).mousedown(function(){self.clearIni();});
  }
  
  this.setKeys = function(){
   keys.each(function(i){
    var e = $(this);
   
    var xPos = self.getXPos(i);
	var yPos = self.getYPos(i);

    e.css({backgroundPosition: xPos + 'px ' + yPos + 'px'})
     .mouseover(function(){self.onKey(e, xPos, yPos)})
     .mouseout(function(){self.outKey(e, xPos, yPos)});

	 if(i < (keys.size()-1)){
	  e.mousedown(function(){self.downKey(e, xPos, yPos, i)});
	 }
	 else{e.mousedown(function(){self.clearIni();});}
   });
  }
  
  this.getXPos = function(i){
   if(!(i%7)){var xPos = 0;}
   else if(!((i-1)%7)){xPos = -25;}
   else if(!((i-2)%7)){xPos = -50;}
   else if(!((i-3)%7)){xPos = -75;}
   else if(!((i-4)%7)){xPos = -100;}
   else if(!((i-5)%7)){xPos = -125;}
   else{xPos = -150;}
   return xPos;
  }

  this.getYPos = function(i){
   if(i<=6){var yPos = 0;}
   else if(i<=13){yPos = -30;}
   else if(i<=20){yPos = -60;}
   else if(i<=27){yPos = -90;}
   else{}
   return yPos;
  }

  this.onKey = function(e, xPos, yPos){
   if(e.attr('cur_key') != 1){
    e.css({backgroundPosition: (xPos -180) + 'px ' + (yPos - 2) + 'px'});
   }
  }

  this.outKey = function(e, xPos, yPos){
   if(e.attr('cur_key') != 1){
    e.css({backgroundPosition: xPos + 'px ' + yPos + 'px'});
   }
  }

  this.downKey = function(e, xPos, yPos ,i){
  
   $(ini.status_id).slideDown();
   this.resetCurKey(this.curXPos, this.curYPos);
   this.curXPos = xPos;
   this.curYPos = yPos;
   this.curI = i;
   e.attr('cur_key',1).css({backgroundPosition: (xPos -180) + 'px ' + (yPos - 2) + 'px'});
   var letter = letters[i];
   $(ini.ini_id).html(letter);
   $(ini.root + ' > li[bi="' + letter + '"]').show();
   $(ini.root + ' > li[bi!="' + letter + '"]').hide();
  }
  
  this.remoteDownKey = function(L){
   var i = letters.indexOf(L);
   var e = $(ini.keys_id + ' li:eq(' + i + ')');
   var xPos = this.getXPos(i);
   var yPos = this.getYPos(i);
   this.downKey(e,xPos,yPos,i);
  }
  
  this.downPrevKey = function(){
   var i = this.curI;
   if(i || i==0){
    if(0 < i){var prevI = i - 1;}
	                    else{prevI = keys.size()-2;}
						
    var e = $(ini.keys_id + ' li:eq(' + prevI + ')');
    var xPos = this.getXPos(prevI);
    var yPos = this.getYPos(prevI);
    this.downKey(e,xPos,yPos,prevI);
   }
  }
  
  this.downNextKey = function(){
   var i = this.curI;
   if(i || i==0){
    if(i < (keys.size()-2)){var nextI = i + 1;}
	                    else{nextI = 0;}
						
    var e = $(ini.keys_id + ' li:eq(' + nextI + ')');
    var xPos = this.getXPos(nextI);
    var yPos = this.getYPos(nextI);
    this.downKey(e,xPos,yPos,nextI);
   }
  }

  this.resetCurKey = function(xPos, yPos){
   $(ini.keys_id + ' li[cur_key="1"]').attr('cur_key',0).css({backgroundPosition: xPos + 'px ' + yPos + 'px'});
  }
  
  this.clearIni = function(xPos, yPos){
   $(ini.status_id).slideUp();
   this.resetCurKey(this.curXPos, this.curYPos);
   $(ini.root + " li").show();
  }
  
  this.setCurrentBrand = function(){
   var par_a = $('a.crumbsList:eq(1)');
   if(par_a){
    var cat_url = par_a.attr("href");
    if(cat_url){cat_url = cat_url.replace('..','http://www.ccucco.com');}
	var curr_a = $(ini.root + ' li a[href*="' + cat_url + '"]');
    if(curr_a.size()){curr_a.parent(ini.list_unit).addClass("current_brand");}
   }
  }
  
  this.brandIndexer = function(){
   var e = $(ini.root + " > li");
   e.each(function(){
    var bi = $(this).text().substr(0,1).toUpperCase();
	$(this).attr('bi',bi);
   });
  }
  
 }



/*-------------------------------------------------------------------------------*/
/*                                 サブカテゴリーUI                              */
/*-------------------------------------------------------------------------------*/

function subCategoryUI(ini){

 this.target_parrent = '#common_src';
 this.container = 'div#SCUI';
 this.header = 'div#sc_header';
 this.navi = 'ul#sc_navi';
 this.contents = 'ul#sc_contents';
 this.sc_title_box = 'div#sc_title_box';
 this.scTtitleId = 'scTtitle';
 this.scTsizeXid = 'scTsizeX';
 this.scTsizeYid = 'scTsizeY';
 this.scTsizeBoxId = 'scTsizeBox';
 
 this.item_box_class = 'i_box';
 this.discount_rate_class = 'd_r';
 this.item_name_class = 'i_n';
 this.price_class = 'pr';
 this.discount_price_class = 'd_p';

 this.sc_float_preview = 'div#sc_float_preview';
 this.scFPtitleId = 'scFPtitle';
 this.scFPsizeBox = 'scFPsizeBox';
 this.scFPimgBoxId = 'scFPimgBox';
 this.scFPsizeYid = 'scFPsizeY';
 this.scFPsizeXid = 'scFPsizeX';
 this.scFPsizeZid = 'scFPsizeZ';
 this.scFPmsgId = 'scFPmsg';
 this.scFPcurrId = 'scFPcurr';
 this.scFPitemCount = 'scFPitemCount';
 this.scFPss_interval = 750;
 
 this.item_span = 116;
 this.line_item_size = 4;
 this.navi_select = '#333';
 this.navi_select_sub2 = '#58f';
 this.navi_select_bg = '#dfdfdf';
 
 this.gallery_class = 'sc_gallery';
 
 this.image_path = 'http://www.ccucco.com/site_data/cabinet/item/';
 this.gallery_size = 6;
 this.option_gallery_size = 7;
 this.max_gallery_size = 7;
 
 this.scFPimgsArray = [];
 
 var self = this;

 this.build = function(){
  var scFPtag = this.sc_float_preview.split('#')[0];
  var scFPid = this.sc_float_preview.split('#')[1];
  var scFP = '<' + scFPtag + ' id="' + scFPid + '"><div id="' + this.scFPtitleId + '"></div><div id="' + this.scFPsizeBox + '"><div id="' + this.scFPsizeXid + '"></div><div id="' + this.scFPsizeYid + '"></div><div id="' + this.scFPimgBoxId + '"></div><div id="' + this.scFPsizeZid + '"></div></div><div id="' + this.scFPmsgId + '"></div></' + scFPtag + '>';

  var cBooks = '<div id="modalOverlay"></div><div id="zoomTransition"></div><div id="cBooks"><ul id="cBooks_pages"></ul><img id="cBooks_page_turn" src="http://www.ccucco.com/site/library/css_bg/cbooks_page_turn.png" /><div id="cBooks_close"></div><div id="cBooks_prev_page"></div><div id="cBooks_next_page"></div></div>';
  $("body").append(scFP + cBooks);
  this.set_cBooks();

  this.renderer();
  this.scFP = $('#' + this.sc_float_preview.split('#')[1]);
  this.tableIndexer();
  $(this.target_parrent).hide();
  
  this.navi_offset = $(this.navi).offset();
  var scFPleft = this.navi_offset.left + 210;
  this.scFP.css({left: scFPleft});
  
  $(this.navi + ' li').click(function(){self.changeSc($(this));})
                       .mouseover(function(){self.showFloatPreview($(this));})
                       .mousemove(function(e){self.moveFloatPreview(e);});
  $(this.navi).hover(
                      function(){self.scFP.show(); $(self.sc_float_preview).pngfix();},
                      function(){self.scFP.hide();}
					 );
  this.setStartCondition();
 }


 this.showFloatPreview = function(li_obj){
  this.scFPss = false;
  var sc_idx = li_obj.attr('idx');
  var title = li_obj.find('h4').html();
  //var img_src = li_obj.attr('img_src');
  
  if(!this.scFPimgsArray[sc_idx]){
   var title_table = ini.target.find('table.tt:eq(' + sc_idx + ')');
   var first_table_idx = title_table.attr('id').substr(1) - 0 + 1;
   var imgs = ini.target.find('table:eq(' + first_table_idx + ') img');
   //img_src = imgs.eq(0).attr('src');
   //li_obj.attr('img_src',img_src);
   this.scFPimgsArray[sc_idx] = imgs;
  }
  
  var min_item_size = li_obj.attr('min_item_size');
  var item_size = li_obj.attr('item_size');
  
  if(!min_item_size){
   min_item_size = ini.target.find('table:eq(' + first_table_idx + ') img').size();
   li_obj.attr('min_item_size',min_item_size);
  }

  var first_img = '<img src="' + this.scFPimgsArray[sc_idx].eq(0).attr('src') + '" />';
  var size_y = li_obj.attr('size_y'); if(size_y){size_y = '高さ<br />' + size_y;}else{size_y = ' ';}
  var size_x = li_obj.attr('size_x'); if(size_x){size_x = '幅' + size_x;}else{size_x = ' ';}
  var size_z = li_obj.attr('size_z'); if(size_z){size_z = 'マチ<br />' + size_z;}else{size_z = ' ';}

  var msg = '<span id="' + this.scFPcurrId + '">1</span> / <span id="' + this.scFPitemCount + '">';
  this.scFPcurrId
  if(item_size){msg += item_size + '</span>アイテム';}
  else{
   if(min_item_size<5){msg += min_item_size + '</span>アイテム';}
   else{msg += min_item_size + '</span>アイテム以上...';}
  }
  
  $('#' + this.scFPtitleId).html(title);
  $('#' + this.scFPsizeXid).html(size_x);
  $('#' + this.scFPsizeYid).html(size_y);
  $('#' + this.scFPimgBoxId).html(first_img);
  $('#' + this.scFPsizeZid).html(size_z);
  $('#' + this.scFPmsgId).html(msg);
  this.scFP.show();
  if(this.scFPssTimer){this.scFPssTimer.stop();}
  this.scFPslideShow(sc_idx);
 }
 
 
 this.scFPslideShow = function(sc_idx){
  this.scFPss = true;
  var imgs = this.scFPimgsArray[sc_idx];
  var imgs_size = imgs.length;
  var target = $('#' + self.scFPimgBoxId + ' img');
  var counter = $('#' + self.scFPcurrId);
  var c = 1;
  this.scFPssTimer = $.timer(this.scFPss_interval, function (timer){
   if(self.scFPss && c < imgs_size){
	var img_src = imgs.eq(c).attr('src');
	target.attr('src',img_src);
	counter.html(c+1);
    c++;
    //timer.reset(self.scFPss_interval);
   }else{
    c = 0;
	//timer.reset(self.scFPss_interval);
   }
  });
 }
 

 this.moveFloatPreview = function(e){
  var posX = this.navi_offset.left + 210;
  var posY = e.pageY;
  this.scFP.css({top: posY-110});
 }

 
 this.hideFloatPreview = function(){
  this.scFPss = false;
  this.scFP.hide();
 }


 this.renderer = function(){
  var scNtag = this.navi.split('#')[0];              var scNid = this.navi.split('#')[1];
  var scCtag = this.contents.split('#')[0];          var scCid = this.contents.split('#')[1];
  var scN = '<' + scNtag + ' id="' + scNid + '">'; //sub category Navigation
  var scC = '<' + scCtag + ' id="' + scCid + '">'; //sub category Contents

  scC += '<' + this.sc_title_box.split('#')[0] + ' id="' + this.sc_title_box.split('#')[1] + '"><div id="' + this.scTsizeXid + '"></div><div id="' + this.scTsizeYid + '"></div><div id="' + this.scTsizeBoxId + '"></div><div id="' + this.scTtitleId + '"></div></div>';

  var cat_anchors = ini.target.find('a[name]'); //category anchors
  this.scFPimgsArray = new Array(cat_anchors.size());

  cat_anchors.each(function(i){
   $(this).next('table').attr('class','tt'); //marking title tables
   var scNames = $(this).attr('name').replace(/　/,' ').split(' ');
   var scName = scNames[0];
   var scNameDecorated = [];
   var scSizeStr;
   var sizeYXZ = ['','','']; //need for no size item! if without this, an error

   for(j=1; j<scNames.length; j++){
    scNameDecorated = self.listDecoration(j,scNames[j]);
	if(!scNameDecorated[1]){
     scName += scNameDecorated[0];
	}
	if(scNameDecorated[1]){scSizeStr = scNameDecorated[0]};
   }

   if(scSizeStr){
    sizeYXZ = self.getItemSize(scSizeStr);
   }

   scN += '<li idx="' + i + '" size_y="' + sizeYXZ[0] + '" size_x="' + sizeYXZ[1] + '" size_z="' + sizeYXZ[2] + '"><a href="#sc' + i+'' + '"><h4>' + scName + '</h4></a></li>';
   scC += '<li></li>';
  });
  scN += '</' + scNtag + '>';
  scC += '</' + scCtag + '>';

  var header = $(this.container).children(this.header);//.hide();
  header.after(scN+scC).hide();
  $(this.contents + ' li').hide();
 }
 

 this.listDecoration = function(i,str){
  var size_flag = 0;
  if(i == 2){new_str = '<br />';}
  if(str.search(/[0-9\.]+(cm|ｃｍ)/) >= 0){
   size_flag = 1;
   new_str = '<br /><span class="size">' + str.replace(/ｃｍ/,'cm').replace(/[Xx]/,'×') + '</span>';
  }
  else{new_str = ' <span class="sub2cat">' + str + '</span>';}
  return [new_str,size_flag];
 }


 this.getItemSize = function(str){
  var sizeY = str.match(/高さ([0-9\.]+(cm|mm))/) + '';
  var sizeYval = sizeY.split(',')[1];
  if(!sizeYval){sizeYval = '';}
  var sizeX = str.match(/幅([0-9\.]+(cm|mm))/) + '';
  var sizeXval = sizeX.split(',')[1];
  if(!sizeXval){sizeXval = '';}
  var sizeZ = str.match(/マチ([0-9\.]+(cm|mm))/) + '';
  var sizeZval = sizeZ.split(',')[1];
  if(!sizeZval){sizeZval = '';}
  return [sizeYval,sizeXval,sizeZval];
 }
 
 
 this.tableIndexer = function(){
  this.tables = ini.target.find('table');
  this.tables.each(function(j){$(this).attr('id','t' + j);});
 }
 
 
 this.setStartCondition = function(){
  
  this.curr_id = location.hash.substr(3);
  //if(location.hash == '#cat'){this.curr_id == ini.start_index;}
  if(!this.curr_id || isNaN(this.curr_id - 0)){
   this.curr_id = ini.start_index;
   var url = document.location.href.split('#')[0];
   document.location.href = url + '#sc' + this.curr_id;
  }
  var e = $(this.navi + ' li:eq(' + this.curr_id + ')');
  this.changeSc(e);
 }

 /*---------------------------------
  change SC
 ---------------------------------*/
 this.changeSc = function(e){

  var old = $(this.contents + ' li[dFg = "1"]');
  if(old.size()>0){
   old.attr('dFg','0').hide();
  }

  this.changeScStyle(e);
  
  //var sc_idx = $(this.navi + ' li').index(e);
  var sc_idx = e.attr('idx') - 0;
  this.sc_idx = sc_idx;
  var sc_title = e.find('h4').text();
  $('#' + this.scTtitleId).html(sc_title);

  var title_table = ini.target.find('table.tt:eq(' + sc_idx + ')');
  var first_table_idx = title_table.attr('id').substr(1) - 0 + 1;

  var sc_size = $(this.navi + ' li').size();
  if(sc_idx == sc_size - 1){
   var last_table_idx = this.tables.size() - 1;
  }
  else{
   var next_title_table = ini.target.find('table.tt:eq(' + (sc_idx+1) + ')');
   last_table_idx = next_title_table.attr('id').substr(1) - 0 - 1;
  }
  
  var curr = $(this.contents + ' li:eq(' + sc_idx + ')');

  if(!curr.attr('rFg')){
   this.i_counter = 0;
   curr.attr({rFg:1, dFg: 1}).html(this.scStr(first_table_idx,last_table_idx));
   var items = $(this.contents + ' li:eq(' + sc_idx + ') div.' + this.item_box_class);
   var items_count = items.size();
   items.click(function(){self.cBooksLounch($(this));});
   e.attr('item_size',items_count);
   this.scFPimgsArray[sc_idx] = items.find('img');
  }
  else{
   curr.attr({dFg: 1});
   items_count = e.attr('item_size');
  }

  if(this.cBooksChangeItems(items_count)){this.scFadeIn(curr,sc_idx);}
  
  var w = e.attr('size_x');
  var h = e.attr('size_y');
  this.setTitleBox(w,h);
 }
 
 
 this.setTitleBox = function(w,h){
  var size_x = w.replace('cm','').replace('mm','') - 0;
  var size_y = h.replace('cm','').replace('mm','') - 0;
  
  if(size_x && size_y){
   var x_rate = size_x/200;
   if(x_rate>1){size_x = size_x/x_rate; size_y = size_y/x_rate;}
   else{
    if(size_x < 75){size_x = size_x*2.6; size_y = size_y*2.6}
    else if(size_x < 100){size_x = size_x*2; size_y = size_y*2}
    else{}
   }

   $('#' + this.scTsizeYid).css({paddingTop: size_y/2.5}).html(h).show();
   var pL = $('#' + this.scTsizeYid).width() + (size_x/2.5);
   $('#' + this.scTsizeXid).css({paddingLeft: pL}).html(w).show();
   $('#' + this.scTsizeBoxId).css({width: size_x, height: size_y}).show();
  }
  else{
   $('#' + this.scTsizeXid).hide();
   $('#' + this.scTsizeYid).hide();
   $('#' + this.scTsizeBoxId).hide();
  }
 }
 

 this.scFadeIn = function(e,sc_idx){
  e.fadeIn('750',function(){
 
     /*var imgs = $(self.contents + ' li:eq(' + sc_idx + ') div.' + self.item_box_class + ' img');
     imgs.each(function(i){
       var img = imgs.get()[i];
       Reflection.add(img, { height: 2/5, opacity: 0 });
	 });*/

  });
 }
 

 this.scStr = function(f,l){

  var scStr = '';
  for(var i = f; i <= l; i++){
   var items = ini.target.find('table:eq(' + i + ') a');
   items.each(function(j){
	self.i_counter++;
    scStr += self.itemStr($(this));
   });
  }
  return scStr;
 }
 
 
 this.itemStr = function(item){
  
  var item_url = item.attr('href');
  var img_url = item.children('img').attr('src');
  
  if(item.children('font').size() == 4){
   var discount_rate = item.children('font:eq(0)').html() + ' ▼';
   var item_name = item.children('font:eq(1)').html();
   var price = item.children('font:eq(2)').html();
   var discount_price = item.children('font:eq(3)').html();
  }
  else{
   discount_rate = null;
   item_name = item.children('font:eq(0)').html();
   discount_price = item.children('font:eq(1)').html();
  }

  var s = '<div item_url="' + item_url + '" class="' + this.item_box_class + '" idx="' + (this.i_counter-1) + '">';
  s += '<img src="' + img_url + '" />';
  if(discount_rate){s += '<span class="' + this.discount_rate_class + '">' + discount_rate + '</span>';}
  s += '<p><span class="' + this.item_name_class + '">' + item_name + '</span>';
  //if(price){s += '<span class="' + this.price_class + '">' + price + '</span>';}
  s += '<span class="' + this.discount_price_class + '">' + discount_price + '</span>';
  s += '</p></div>';

  return s;
 }


 this.changeScStyle = function(e){
  $(this.navi + ' li').attr('style','');
  $(this.navi + ' li a').attr('style','');
  $(this.navi + ' li a span').attr('style','');
  e.children('a').css({
                        color: this.navi_select,
						backgroundColor: this.navi_select_bg
                       });
  e.children('a').children('h4').children('span').css({color: this.navi_select_sub2});
 }

 /*---------------------------
   cBooks initialize
 ---------------------------*/ 
 this.set_cBooks = function(){

  this.zt = $('#zoomTransition');
  this.modalOverlay = $('#modalOverlay');
  this.cBooks = $('#cBooks');
  this.cBooks_close = $('#cBooks_close');
  
  this.cBooks_prev_page = $('#cBooks_prev_page');
  this.cBooks_prev_page_able = {backgroundPosition: '0 0', cursor: 'pointer'}
  this.cBooks_prev_page_disable = {backgroundPosition: '-90px 0px', cursor: 'default'}

  this.cBooks_next_page = $('#cBooks_next_page');
  this.cBooks_next_page_able = {backgroundPosition: '-115px 0px', cursor: 'pointer'}
  this.cBooks_next_page_disable = {backgroundPosition: '0 0', cursor: 'default'}
  
  this.cBooksWidth = 900;
  this.cBooksHeight = 704;
  this.cBooksShadow_size = 25;
  this.ztF_w = this.cBooksWidth - this.cBooksShadow_size*2;
  this.ztF_h = this.cBooksHeight - this.cBooksShadow_size*2;
  
  this.cBooks_imgs_size = 6;
  this.cBooks_option_imgs_size = 7;
  this.cBooks_image_path = 'http://www.ccucco.com/site_data/cabinet/item/';
  
  this.cBooksPageWidth = 758;
  
  this.page_turn_blocker = false;
  this.page_turn_nextStart = {width: 0, left: 848, opacity: 0}
  this.page_turn_nextFinish = {width: 104, left: -10, opacity: 0.5}
  this.page_turn_prevStart = {width: 124, left: -34, opacity: 1.0}
  this.page_turn_prevFinish = {width: 0, left: 800, opacity: 0.8}
  
  this.cBooks_prev_page.click(function(){self.cBooks_prevPage();});
  this.cBooks_next_page.click(function(){self.cBooks_nextPage();});
  
  this.cBooks_sliderOn = {backgroundColor: '#eee', border: '1px solid #36f'}
  this.cBooks_sliderOff = {backgroundColor: 'transparent', border: 'none'}
 }
 
 /*---------------------------
   cBooks items change
  ---------------------------*/
 this.cBooksChangeItems = function(items_count){
  this.items_count = items_count;
  this.cBooksImagesLoadCounters = new Array(items_count);
  
  var s = '';
  for(i=0; i<this.items_count; i++){
   s += '<li class="cBooks_page" idx="' + (this.items_count-i-1) + '"></li>';
  }
  
  $('#cBooks_pages').html(s);
  return true;
 }
 
 /*---------------------------
   cBooks Lounch & Close
  ---------------------------*/
 this.cBooksLounch = function(e){
 
  this.curr_item_idx = e.attr('idx');
  this.cBooksPageRender(e,this.curr_item_idx,1);

  var offset = e.offset();
  this.ztS_left = offset.left;
  this.ztS_top = offset.top;
  this.ztS_w = e.width();
  this.ztS_h = e.height();

  this.cBooksPopup();
  this.modalOverlay.click(function(){self.cBooksHide();});
  this.cBooks_close.click(function(){self.cBooksHide();});
  
  if(0 < this.curr_item_idx && this.curr_item_idx < this.items_count-1){
   this.cBooks_prev_page.css(this.cBooks_prev_page_able); //html(this.curr_item_idx);
   this.cBooks_next_page.css(this.cBooks_next_page_able); //html(this.curr_item_idx - 0 + 2);
  }
  else if(this.curr_item_idx == 0){
   this.cBooks_prev_page.css(this.cBooks_prev_page_disable); //.html('');
   if(this.items_count == 1){this.cBooks_next_page.css(this.cBooks_next_page_disable);}
   else{this.cBooks_next_page.css(this.cBooks_next_page_able);} //.html(this.curr_item_idx - 0 + 2);}
  }
  else{
   this.cBooks_prev_page.css(this.cBooks_prev_page_able); //.html(this.curr_item_idx);
   this.cBooks_next_page.css(this.cBooks_next_page_disable); //.html(this.curr_item_idx - 0 + 1);
  }

 }

 this.cBooksPopup = function(){

  var arrPageSizes = getPageSize();
  var arrPageScroll = getPageScroll();

  this.modalOverlay.css({
   backgroundColor:	'#fff',
   opacity:	0,
   width: arrPageSizes[0],
   height: arrPageSizes[1]
  }).show();

  if(arrPageSizes[0] >= this.cBooksWidth){
   var cBooksLeftPos = (arrPageSizes[0]/2) - (this.cBooksWidth/2);
  }else{cBooksLeftPos = 0;}
  
  var finalTop = arrPageScroll[1] + (arrPageSizes[3] / 10);
  var finalLeft = cBooksLeftPos;
  
  this.ztF_left = finalLeft + this.cBooksShadow_size;
  this.ztF_top = finalTop + this.cBooksShadow_size;
  
  this.zt.css({left: this.ztS_left, top: this.ztS_top, width: this.ztS_w, height: this.ztS_h, opacity: 0.4, display: 'block'})
          .animate(
                   {left: this.ztF_left, top: this.ztF_top, width: this.ztF_w, height: this.ztF_h, opacity: 0.8},
                   {duration: 200, queue: false , complete: function(){$(this).hide(); self.cBooksShow(finalLeft,finalTop);}}
			      );
 }
 
 this.cBooksShow = function(finalLeft, finalTop){
  this.modalOverlay.css({opacity: 0.5});
  this.cBooks.css({left: finalLeft, top: finalTop}).show();
  this.cBooksLeft = this.cBooks.offset().left;
 }
 
 this.cBooksHide = function(){

  var e = $(this.contents + ' li:eq(' + this.sc_idx + ') div.' + this.item_box_class + ':eq(' + this.curr_item_idx + ')');
  var offset = e.offset();
  this.ztS_left = offset.left;
  this.ztS_top = offset.top;
  this.ztS_w = e.width();
  this.ztS_h = e.height();
   
  this.modalOverlay.css({opacity: 0});
  $('li.cBooks_page').css({width: 0});
  this.cBooks.hide();
  this.zt.show()
          .animate(
                   {left: this.ztS_left, top: this.ztS_top, width: this.ztS_w, height: this.ztS_h, opacity: 0.4},
                   {duration: 200, queue: false, complete: function(){self.zt.fadeOut(350,function(){self.modalOverlay.hide();});}}
		          );
 }
 
 /*---------------------------
   cBooks PageRender
  ---------------------------*/
 this.cBooksPageRender = function(e,idx,show_option){
  var page_container = $('li.cBooks_page[idx="' + idx + '"]');
  if(!show_option){page_container.hide().css({width: 0});}
  if(!page_container.attr('rFg') || !this.cBooksImagesLoadCounters[idx]){
   page_container.html(this.cBooksPageSrc(e,idx))
                 .attr('rFg','1');
  }
  if(show_option){page_container.show().css({width: this.cBooksPageWidth});}
  return false;
 }
 
 this.cBooksPageSrc = function(e,idx){
  this.item_url = e.attr('item_url');
  var img_url = e.find('img').attr('src');
  this.p_code = getPcodeFromImgUrl(img_url);
  this.discount_rate = e.find('.d_r').text();
  this.item_name = e.find('.i_n').text();
  this.price = e.find('.pr').text();
  this.discount_price = e.find('.d_p').text();

  this.cBooksImagesLoadCounters[idx] = [0,0,0];
  var s = this.cBooksImageStackRender(this.p_code,idx);
  s += '<div class="cBooks_imgs_slider"></div>';
  s += '<div class="cBooks_infoBox"><p class="i_n">' + this.item_name + '</p><p class="d_p">' + this.discount_price + '</p>';
  s += '<a href="' + this.item_url + '"></a></div>';

  return s;
 }
 

 this.cBooks_prevPage = function(){
  if((this.curr_item_idx-0) > 0 && !this.page_turn_blocker){
  
   this.page_turn_blocker = true;
   var prev_idx = this.curr_item_idx-1;
   var e = $(this.contents + ' li:eq(' + this.sc_idx + ') div.' + this.item_box_class + ':eq(' + prev_idx + ')');
   
  
   var page_container = $('li.cBooks_page[idx="' + this.curr_item_idx + '"]');
   var prev_page_container = $('li.cBooks_page[idx="' + prev_idx + '"]');
   var page_turn = $('#cBooks_page_turn');
   page_container.hide().css({width: 0});

   this.cBooks_next_page.css(this.cBooks_next_page_disable); //.html('');
   page_turn.css(self.page_turn_prevStart)
            .show()
            .animate(
                     self.page_turn_prevFinish,
                     500,
                     function(){
                                  self.cBooksPageRender(e,prev_idx);
                                  prev_page_container.css({width: self.cBooksPageWidth}).show();
								  $(this).fadeOut('fast');
								  self.cBooks_next_page.css(self.cBooks_next_page_able); //.html(prev_idx + 2);
								  self.page_turn_blocker = false;
								  self.scUIchecker(prev_idx);
                                 }
                    );
   this.curr_item_idx = prev_idx;
   this.cBooks_prev_page.css(this.cBooks_prev_page_able); //.html(prev_idx);
   if(prev_idx == 0){this.cBooks_prev_page.css(this.cBooks_prev_page_disable).html('');}
  }
 }

 this.cBooks_nextPage = function(){
  if(this.curr_item_idx < this.items_count-1 && !this.page_turn_blocker){
   
   this.page_turn_blocker = true;
   var next_idx = (this.curr_item_idx-0)+1;
   var e = $(this.contents + ' li:eq(' + this.sc_idx + ') div.' + this.item_box_class + ':eq(' + next_idx + ')');

   var page_container = $('li.cBooks_page[idx="' + this.curr_item_idx + '"]');
   var next_page_container = $('li.cBooks_page[idx="' + next_idx + '"]');
   var page_turn = $('#cBooks_page_turn');
   page_container.animate({width: 0},500);
   
   this.curr_item_idx = next_idx;
   this.cBooks_next_page.css(this.cBooks_next_page_disable); //.html('');

   page_turn.css(self.page_turn_nextStart)
            .show()
            .animate(
                     self.page_turn_nextFinish,
                     650,
                     function(){
                                  self.cBooksPageRender(e,next_idx);
                                  self.cBooks_prev_page.css(self.cBooks_prev_page_able); //.html(next_idx);
                                  next_page_container.css({width: self.cBooksPageWidth}).show();
                                  $(this).fadeOut('fast');
                                  if(next_idx == self.items_count-1){self.cBooks_next_page.css(self.cBooks_next_page_disable);} //.html(next_idx+1);}
                                  else{self.cBooks_next_page.css(self.cBooks_next_page_able);} //.html(next_idx+2);}
								  self.page_turn_blocker = false;
								  self.scUIchecker(next_idx);
                                 }
                    );		 
  }
 }


 this.cBooksImageStackRender = function(p_code,idx){
  var s = '<div class="cBooks_imgs">';

  var src0 = this.cBooks_image_path + p_code + '-0.gif';
  s += '<img src="' + src0 + '" onerror="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,0)" onload="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,1)" />';
  
  var src1 = this.cBooks_image_path + p_code + '-0.jpg';
  s += '<img src="' + src1 + '" onerror="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,0)" onload="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,1)" />';
  
  for(var i = this.cBooks_imgs_size; i >=1 ; i--){
   var src = this.cBooks_image_path + p_code + '-' + i + '.jpg';
   s += '<img src="' + src + '" onerror="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,0)" onload="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,1)" />';
  }
    
  for(var j = 5; j >= 1; j--){
   var s2 = this.cBooks_image_path + p_code + '-0' + j + '.jpg';
   s += '<img src="' + s2 + '" onerror="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,0)" onload="' + ini.obj_name + '.imageLoadListener(' + idx + ',this,1)" />';
  }
  s += '</div>';

  return s;
 }


 this.imageLoadListener = function(idx,e,lFg){
  this.cBooksImagesLoadCounters[idx][0]++;
  if(!lFg){
   $(e).remove();
   this.cBooksImagesLoadCounters[idx][1]++;
  }
  var max_img_size = this.cBooks_imgs_size + this.cBooks_option_imgs_size;
  if(this.cBooksImagesLoadCounters[idx][0] == max_img_size){
   if(this.cBooksImagesLoadCounters[idx][1] == max_img_size){
    $('#cbooks_imgs').html('<span>No images...</span>'); 
   }
   else{
    this.cBooksImagesLoadCounters[idx][2] = 1;
	if(idx == this.curr_item_idx){
     setTimeout(function(){self.cBooks_imageChangeUI(idx);},500);
	 //this.cBooksSS(idx);
	}
   }

  }
 } 

 
 this.scUIchecker = function(idx){
  var page = $('li.cBooks_page[idx="' + idx + '"]');
  if(this.cBooksImagesLoadCounters[idx][2] && !page.attr('acui')){
   //$('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs').unbind('mousemove');
   this.cBooks_imageChangeUI(idx);
  }
 }
 

 this.cBooks_imageChangeUI = function(idx){
  var imgs_container = $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs');
  var imgs_slider = $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs_slider');
  var imgs_size = this.cBooksImagesLoadCounters[idx][0] - this.cBooksImagesLoadCounters[idx][1];

  var slider_width = Math.floor(598/imgs_size);
  var s = '';
  for(i = 0; i<imgs_size; i++){
   s += '<div></div>';
  }
  imgs_slider.html(s);
  $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs_slider div').css({width: slider_width});

  imgs_slider.mousemove(function(e){self.cBooks_imageChanger(e,idx,slider_width,imgs_size);})
             .mouseout(function(){$('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs_slider div').css(self.cBooks_sliderOff);});
  $('li.cBooks_page[idx="' + idx + '"]').attr('acui',1);
 }
 
 
 this.cBooks_imageChanger = function(e,idx,slider_width,imgs_size){
  var posX = e.pageX - this.cBooksLeft - 90;
  var img_idx = Math.floor(posX/slider_width);
  if(img_idx >= imgs_size){img_idx = imgs_size-1;}
  //$('#test').html(posX);
  
  $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs img').hide();
  $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs img:eq(' + img_idx + ')').show();
  $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs_slider div').css(this.cBooks_sliderOff);
  $('li.cBooks_page[idx="' + idx + '"] .cBooks_imgs_slider div:eq(' + img_idx + ')').css(this.cBooks_sliderOn);
 }




}

/*-------------------------------------------------------------------------------*/
/*                                   　commons                                   */
/*-------------------------------------------------------------------------------*/

function tagRemover(str){
 var name = str.replace(/<\/?[^>]+>/gi, '');
 return name;
 //return str;
}

function getPcodeFromImgUrl(url){
 var url_es = url.split("/");
 var last_idx = url_es.length - 1;
 var f_name = url_es[last_idx];
 
 var p_code = f_name.split("-")[0];
 
 return p_code;
}

/**
 * From --- jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */
 
function getPageSize(){
 var xScroll, yScroll;
 if (window.innerHeight && window.scrollMaxY) {
  xScroll = window.innerWidth + window.scrollMaxX;
  yScroll = window.innerHeight + window.scrollMaxY;
 }
 else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
  xScroll = document.body.scrollWidth;
  yScroll = document.body.scrollHeight;
 }
 else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
  xScroll = document.body.offsetWidth;
  yScroll = document.body.offsetHeight;
 }
 var windowWidth, windowHeight;
 if (self.innerHeight) {	// all except Explorer
  if(document.documentElement.clientWidth){
   windowWidth = document.documentElement.clientWidth; 
  }
  else {
   windowWidth = self.innerWidth;
  }
  windowHeight = self.innerHeight;
 }
 else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
  windowWidth = document.documentElement.clientWidth;
  windowHeight = document.documentElement.clientHeight;
 }
 else if (document.body) { // other Explorers
  windowWidth = document.body.clientWidth;
  windowHeight = document.body.clientHeight;
 }	
 // for small pages with total height less then height of the viewport

 if(yScroll < windowHeight){
  pageHeight = windowHeight;
 }
 else{ 
  pageHeight = yScroll;
 }
 // for small pages with total width less then width of the viewport
 if(xScroll < windowWidth){	
  pageWidth = xScroll;		
 }
 else{
  pageWidth = windowWidth;
 }
 arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
 return arrayPageSize;
};

function getPageScroll() {
 var xScroll, yScroll;
 if (self.pageYOffset) {
  yScroll = self.pageYOffset;
  xScroll = self.pageXOffset;
 }
 else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
  yScroll = document.documentElement.scrollTop;
  xScroll = document.documentElement.scrollLeft;
 }
 else if (document.body) {// all other Explorers
  yScroll = document.body.scrollTop;
  xScroll = document.body.scrollLeft;	
 }
 arrayPageScroll = new Array(xScroll,yScroll);
 return arrayPageScroll;
};


