
(function($){
var ver="relative animation under position relative";
$.fn.slideToggleEx = function( type, duration, easing, fn ){
  if (type > 8) // エラー対処
    (function(){
      alert("第 1 引数は 0～8 だけが指定できます。\nやり直してください。\n"+"slideToggleEx( 0～8, 継続時間, easing関数, アニメ後実行関数 )"); return;
    })();
  var $target = this, o = $.extend({},$.fn.slideToggleEx.opts);
  if(!o.target || o.target[0]!==$target[0]) {
    $.extend(o,{
      orig : o,
      target : $target,
      el : $target[0],
      type : type,
      initstate : !$target.is(":hidden"),
      cnt : 1
    });
    $.extend(o, $.data(o.el,"initdone") || $.data(o.el, "initdone", getSize()));
    for (var p in o.cssdefault.H) o.cssOrig.H[p] = $.css(o.el,p,true);
    for (var p in o.cssdefault.W) o.cssOrig.W[p] = $.css(o.el,p,true);
    o.cssOrig.H.height +="px"; o.cssOrig.W.width +="px";
    $.extend($.fn.slideToggleEx.opts,o);
  }
  window.onresize = getParentWH;
  o.cnt = $.fn.slideToggleEx.opts.cnt++;
  o.odd = o.cnt % 2;
  o.type = o.type!==type ? type : o.type;
  o.duration = duration || o.duration;
  o.easing = typeof duration !=="object" ? (easing || o.easing) : "";
  o.complete = typeof duration !=="object" ? ($.isFunction(fn) && fn || o.complete) :"";

  o.cssAdjust = $.data(o.el,"Adjust"+o.type) || 
    $.data(o.el,"Adjust" + o.type, {show:adjustcssAnim(true), hide:adjustcssAnim(false)});
  o.cssAnim = $.data(o.el,"Anim" + o.type) || $.data(o.el,"Anim" + o.type, setcssAnim());
  o.cssBefore = $.data(o.el,"Before" + o.type) || $.data(o.el,"Before" + o.type, makecssBefore());
  if (o.cnt==1) $target.css(o.initstate ? o.cssBefore.show : o.cssBefore.hide);

  if (typeof o.duration !=="object")
    return this.animate( (o.initstate && !o.odd || !o.initstate && o.odd)
      ? o.cssAnim.show : o.cssAnim.hide, o.duration, o.easing, o.complete ); // アニメ起動
  else
    return this.animate( (o.initstate && !o.odd || !o.initstate && o.odd)
      ? o.cssAnim.show : o.cssAnim.hide, o.duration ); // アニメ起動

  function getSize(){
    if ($target.css("position") ==="static") $target.css({position:"relative"});
    var obj={},parent={};
    return obj= {
      parent : {W:getParentWH().W, H:getParentWH().H},
      oH : parseInt($.css(o.el,"height",true,"margin")),
      oW : parseInt($.css(o.el,"width",true,"margin")),
      oHb : parseInt($.css(o.el,"height",true,"border")),
      oWb : parseInt($.css(o.el,"width",true,"border"))
    };
  }
  function getParentWH(){
    var parent = $target.parent();
    return o.parent={W:parent.width(), H:parent.height()};
  }
  function adjustcssAnim(showhide){
    var plmn = showhide ? "-=" : "+=";
    return o.type==0 ? {top:plmn + o.oH/2 +"px", left:plmn + o.oW/2 +"px"} : // center
      o.type==1 ? {} : // 左上端
      o.type==2 ? {left:plmn + o.oW +"px"} : // 右上端
      o.type==3 ? {top:plmn + o.oH +"px", left:plmn + o.oW +"px"} : // 右下端
      o.type==4 ? {top:plmn + o.oH +"px"} : // 左下端
      o.type==5 ? {} : // 上辺
      o.type==6 ? {left:plmn + o.oW +"px"} :// 右辺
      o.type==7 ? {top:plmn + o.oH +"px"} :// 下辺
      {} ;// 左辺
  }
  function setcssAnim(){
    var obj = {};
    obj.W = (o.type!=5 && o.type!=7) ? $.extend({}, o.cssdefault.W,
        (o.oW!==o.oWb) ? {marginLeft:"toggle",marginRight:"toggle"} : {}) : {};
    obj.H = (o.type!=6 && o.type!=8) ? $.extend({}, o.cssdefault.H,
        (o.oH!==o.oHb) ? {marginTop:"toggle",marginBottom:"toggle"} : {}) : {};
     obj = $.extend({}, obj.W, obj.H, {opacity :"toggle"});
    return o.cssAnim =  {
      show:$.extend({},obj,o.cssAdjust.show),hide:$.extend({},obj,o.cssAdjust.hide)
    };
  }
  function makecssBefore(){
    var obj = {}, ret = {};
    // if marginLeft/Top == "auto", fix marginLeft/Top.
    obj.W = (o.el.style && $.attr(o.el.style,"margin-left")==="auto") ?
      {left : (o.parent.W - o.oWb)/2 +"px", marginLeft : "0px", marginRight : "0px"} :
      {left : "0px",
        marginLeft:$.css(o.el,"margin-left",true), marginRight:$.css(o.el,"margin-right",true)};
    obj.H = (o.el.style && $.attr(o.el.style,"margin-top")==="auto") ?
      {top : (o.parent.H - o.oHb)/2 +"px",marginTop : "0px", marginBottom : "0px"}:
      {top : "0px",
        marginTop:$.css(o.el,"margin-top",true), marginBottom:$.css(o.el,"margin-bottom",true)};
    ret.show = $.extend({}, o.cssOrig.H, o.cssOrig.W, obj.W, obj.H);
    if (o.cssAdjust.hide.top)
      obj.top = new Number(parseInt(obj.H.top))
        + new Number(parseInt(o.cssAdjust.hide.top.slice(2)))+"px";
    if (o.cssAdjust.hide.left)
      obj.left = new Number(parseInt(obj.W.left))
        + new Number(parseInt(o.cssAdjust.hide.left.slice(2)))+"px";
    ret.hide = $.extend({}, ret.show, obj);
    return ret;
  }
} // End of $.fn.slideToggleEx

// default 値設定と記憶用プロパティとしての機能のために
$.fn.slideToggleEx.opts = {
  duration:1000, easing:null, complete:function(){},
  cssdefault : {
    H : {
      height:"toggle",paddingTop:"toggle",paddingBottom:"toggle",
      borderTopWidth:"toggle",borderBottomWidth:"toggle"
    },
    W : {
      width:"toggle",  paddingLeft:"toggle",paddingRight:"toggle",
      borderLeftWidth:"toggle",borderRightWidth:"toggle"
    }
  },
  cssAdjust : {},
  cssOrig : {H:{},W:{}},
  cssBefore : {}
};
})(jQuery);

jQuery(document).ready(function(){ 



  jQuery(".title").each(function (i){//※1
    if (jQuery.cookie("jizakeSearch")) {
      if ((jQuery.cookie("jizakeSearch").indexOf(i)) != -1) {
        jQuery(".title").eq(i).addClass('collapseIcon');
        //jQuery(".filterBox:not(:eq(" + i + "))").hide();
        //jQuery(".filterBox").eq(i).hide();
      } else {
        jQuery(".title").eq(i).addClass('expandIcon');
      }
    }else{
      jQuery(".title").eq(i).addClass('expandIcon'); 
    }
    i = i+1;
  });
    
  jQuery(".filterBox").each(function (i){//※1
    if (jQuery.cookie("jizakeSearch")) {
      if ((jQuery.cookie("jizakeSearch").indexOf(i)) != -1) {
        jQuery(".filterBox").eq(i).show();
      } else {
        jQuery(".filterBox").eq(i).hide();
      }
    }else{
      jQuery(".filterBox").show();//cookieが無い場合は全て隠す
    }
    i = i+1;
  });
  
  
  //クリック時のfunction設定
  jQuery(".title").click(function(){
    
    //何番目のdtなのかを変数に代入
    var index = jQuery(".title").index(this);
    var name = "jizakeSearch" ;//cookieの名前
    var cookVal = jQuery.cookie(name);//cookieの値を変数に代入
    
    jQuery(".filterBox").each(function (i){
      if(i == index){
        setTimeout(function() { jQuery(".filterBox").eq(i).show() }, 600);
        //jQuery(".filterBox").eq(i).delay(600).show();
      }else{
        setTimeout(function() { jQuery(".filterBox").eq(i).hide() }, 0);
      }
    });
    
    //クリックされたら対応するddにイベントを割り当てる
    //jQuery(".filterIn").eq(index).slideToggleEx(5,600,"easeOutQuart");
    jQuery(".filterIn").eq(index).slideToggle(400);
    
    //cookieに追加
    if (jQuery.cookie(name)) {//既に対応するcookieを持っていたら
      
      if ((cookVal.indexOf(index)) != -1) {//valueに対応する値をもっている場合
        if ((jQuery.cookie(name).length) == 1) {
        //この場合は対応するindex番号では無く、cookie自体を削除
          jQuery.cookie(name,null);
          
          setTimeout(function() {jQuery(".filterBox").show() }, 600);

          
        }else{
          var cookVal = jQuery.cookie(name).replace(index,"");//※3
          jQuery.cookie(name,cookVal,{expires:30});//↑で定義しなおした値でcookieを再セット
    
          setTimeout(function() {jQuery(".filterBox").show() }, 600);
        }
      }else{
        jQuery.cookie(name,cookVal+index,{expires:30});//cookieをセットする
        
      }
    }else{
       jQuery.cookie(name,index,{expires:30});//cookieを新たにセットする
    }
    
    jQuery(this).toggleClass('expandIcon');
    jQuery(this).toggleClass('collapseIcon');
    
    //var txt = ".filterBox:not(:eq(" + index + "))";
    //jQuery(".filterBox:not(:eq(" + index + "))").hide();
    //jQuery(".collapseIcon:not(:eq(2))").show();

  });

  jQuery(".check").toggle(
    function(){
      var index = parseInt (jQuery(".checkPref").index(this));
      //var id = '#prefecture_' + index;
      jQuery(this).prev().attr('checked', true);
      
    },
    function(){
      var index = parseInt (jQuery(".checkPref").index(this));
      jQuery(this).prev().attr('checked', false);
    }
  ); 
  
  jQuery('input[title]').each(function() {  

    jQuery(this).focus(function() {  
        jQuery(this).addClass('focused');
    });  
    jQuery(this).blur(function() {  
        jQuery(this).removeClass('focused');    
    });
  });
  
  jQuery("#filterKeywordTitle").click(function(){
    jQuery('#keyword').focus();
    
  });
  
  //jQuery('.searchResultBox > table ').opOver(1.0,0.8,400,400);
  
  jQuery('.searchResultBox > table').hover(function(){
    jQuery(this).css({"border-color":"#9CB057","border-width":"1px","background-color":"#F9FBEC"});
    jQuery(this).find("td").css({"background-color":"#F9FBEC"});
    //jquery_dump(jQuery(this));
  },function(){
    jQuery(this).css({"border-color":"#D1DCA9","border-width":"1px","background-color":"#FFFFFF"});
    jQuery(this).find("td").css({"background-color":"#FFFFFF"});
  });

  jQuery('#jizakeSearchButtonS').hover(function(){
    jQuery(this).css({"background":"url(../images/jizake/searchSubmitS.jpg) 0 -25px no-repeat"});
  },function(){
    jQuery(this).css({"background":"url(../images/jizake/searchSubmitS.jpg) 0 0 no-repeat "});
  });
  
  jQuery('.jizakeSearchSubmit').hover(function(){
    jQuery(this).css({"background":"url(../images/jizake/searchSubmit.jpg) 0 -35px no-repeat"});
  },function(){
    jQuery(this).css({"background":"url(../images/jizake/searchSubmit.jpg) 0 0 no-repeat "});
  });
  
  jQuery(".searchResultBox").click(function(){
    window.location=jQuery(this).find("a").attr("href");
    return false;
  });
  

/*
  jQuery(".checkPref").toggle(
    function(){
      var index = parseInt (jQuery(".checkPref").index(this));
      //var id = '#prefecture_' + index;
      jQuery(".checkBoxPref").eq(index).attr('checked', true);
    },
    function(){
      var index = parseInt (jQuery(".checkPref").index(this));
      jQuery(".checkBoxPref").eq(index).attr('checked', false);
    }
  );
*/
  /*
  if( !jQuery.session("keyword")  || jQuery.session("keyword") == "close"){
    jQuery('#filterKeyword').hide();
    jQuery('#filterKeywordTitle').addClass('expandIcon'); 
  }


  jQuery('#filterKeywordTitle').click(function() { 
      jQuery('#filterKeyword').slideToggle(200); 
      jQuery('#filterKeywordTitle').toggleClass('expandIcon'); 
      jQuery('#filterKeywordTitle').toggleClass('collapseIcon');
      if( !jQuery.session("keyword")  || jQuery.session("keyword") == "close"){
        jQuery.session("keyword", "open");
      }else{
        jQuery.session("keyword", "close");
      }
      jQuery.session("keyword", "close");
  });
  */
  
/*
  jQuery('#filterKeyword').hide();

  jQuery('#filterKeywordTitle').click(function() { 
      jQuery('#filterKeyword').slideToggle(200); 
      jQuery('#filterKeywordTitle').toggleClass('expandIcon'); 
      jQuery('#filterKeywordTitle').toggleClass('collapseIcon');
  });
  
  jQuery('#filterPref').hide();

  jQuery('#filterPrefTitle').click(function() { 
    jQuery('#filterPref').slideToggle(300); 
    jQuery('#filterPrefTitle').toggleClass('expandIcon'); 
    jQuery('#filterPrefTitle').toggleClass('collapseIcon'); 
  });

  jQuery('#filterKuramoto').hide();

  jQuery('#filterKuramotoTitle').click(function() { 
    jQuery('#filterKuramoto').slideToggle(400); 
    jQuery('#filterKuramotoTitle').toggleClass('expandIcon'); 
    jQuery('#filterKuramotoTitle').toggleClass('collapseIcon'); 
  });
  
  jQuery('#filterMeigara').hide();

  jQuery('#filterMeigaraTitle').click(function() { 
    jQuery('#filterMeigara').slideToggle(400); 
    jQuery('#filterMeigaraTitle').toggleClass('expandIcon'); 
    jQuery('#filterMeigaraTitle').toggleClass('collapseIcon'); 
  });

  jQuery('#filterTkri1').hide();

  jQuery('#filterTkri1Title').click(function() { 
    jQuery('#filterTkri1').slideToggle(200); 
    jQuery('#filterTkri1Title').toggleClass('expandIcon'); 
    jQuery('#filterTkri1Title').toggleClass('collapseIcon'); 
  });

  jQuery('#filterPrice').hide();

  jQuery('#filterPriceTitle').click(function() { 
    jQuery('#filterPrice').slideToggle(200); 
    jQuery('#filterPriceTitle').toggleClass('expandIcon'); 
    jQuery('#filterPriceTitle').toggleClass('collapseIcon'); 
  });
  
*/
   //jQuery.session("keyword", "close");
   //alert( jQuery.session("keyword") );
  
});

