///////////////////////////////////
//
//  画像ロールオーバー用
//
///////////////////////////////////
$(document).ready(function() {
    var postfix = '_on';
    $('#g_navi img, #column #form img, #writer #form img, .mq_navi img').not('[src*="'+ postfix +'."]').each(function() {
        var img = $(this);
        var src = img.attr('src');
        var src_on = src.replace('_off', '_on');
        $('<img>').attr('src', src_on);
        img.hover(
            function() {
                img.attr('src', src_on);
            },
            function() {
                img.attr('src', src);
            }
        );
    });
});


///////////////////////////////////
//
//  ポップアップ用
//
///////////////////////////////////
function openWin(win,w,h,iscroll,iresize){
	Nurl = window.location.href;
	wx = screen.width;
	wy = screen.height;
		if(document.all){
			if (typeof document.body.style.maxHeight != "undefined") {
			  // IE 7, mozilla, safari, opera 9
			  var h = h + 28;
			} else {
			  // IE6, older browsers
			  var h = h - 10;
			  window.location.href = Nurl;
			}
		}
		else if(document.layers || document.getElementById){
		// nn
		}
		else{
		//other
		}
	x = (wx - w) / 2;
	y = (wy - h) / 2;
	//alert("scrollbars="+intScroll+",resizable="+intResize);
    myWin = window.open(win,"newWin","width="+w+",height="+h+",scrollbars="+iscroll+",resizable="+iresize+",menubar=0");
	myWin.resizeTo(w,h);
	myWin.moveTo(x,y);
}




///////////////////////////////////
//
//  別ウィンドウ用
//
///////////////////////////////////
function winBlank(url){
	Nurl = window.location.href;
//	wName = window.name ;
//	alert(wName);
//	if(wName != ""){
		if(!window.opener.closed)	{
			//開いているときの処理
			//alert("閉じてない");
			window.opener.location.href = url;
			window.opener.focus();
			window.location.href = Nurl;
		} else {
			//alert("閉じてる");
			window.open(url,'main');
			window.location.href = Nurl;
		}
//	} else {
//		window.open(url,"main");
//		window.location.href = Nurl;
//	}
}





//////////////////////////////////////////
//
//  バックナンバー・現在地用
//
//////////////////////////////////////////
function highlight_active_links(active_url) {
  $("#sidecontents ul a").each(function(){
    var current_href = $(this).attr("href");
    current_href = active_url + current_href;
    if (document.location.href == current_href) {
      $(this).addClass("active");
    }
  });
}


//////////////////////////////////////////
//
//  新規ウインドウ
//
//////////////////////////////////////////
function openWindow(url) {
    var w = screen.width;
    var h = screen.height;
    window.open(url, document.title, 'width=' + w + ',height=' + h + ',toolbar=no,menubar=no,location=no,scrollbars=yes');
}


//////////////////////////////////////////
//
//  フォームクリア
//
//////////////////////////////////////////
$.fn.clearForm = function() {
  return this.each(function() {
    var type = this.type, tag = this.tagName.toLowerCase();
    if (tag == 'form')
      return $(':input', this).clearForm();
    if (type == 'text' || type == 'password' || tag == 'textarea') {
      this.value = '';
    } else if (type == 'checkbox' || type == 'radio') {
      this.checked = false;
      if (this.value == '') {
          this.checked = true;
      }
    } else if (tag == 'select') {
      this.selectedIndex = 0;
    }
  });
};


//////////////////////////////////////////
//
//  タブパネル
//
//////////////////////////////////////////
$(document).ready(function() {
    $(".tabpanel").each(function() {
        var tabpanelId = $(this).attr('id');
        $("#"+tabpanelId+" ul.panel li.content:not("+$("#"+tabpanelId+" ul.tab li a.selected").attr("href")+")").hide();
        $("#"+tabpanelId+" ul.tab li a").click(function() {
            $("#"+tabpanelId+" ul.tab li a").removeClass("selected");
            $(this).addClass("selected");
            $("#"+tabpanelId+" ul.panel li.content").hide();
            $($(this).attr("href")).show();
            return false;
        });
    });
});


$(document).ready(function() {
  $('#sidecontents #chiebukuro').load('/chiebukuro/side');
});