/*============================================================================ 
jquery.function.js
============================================================================ */

/**********************************************************
setClassBtn
--------
指定の要素のclass属性に"btn"を設定
@param / @return
**********************************************************/
function setClassBtn() {
	$("ul.unitBtn li img, p.btnMore img, .btnView img, .btnEdit img, .btn img").each(function() {
		$(this).addClass("btn");
	});
	
	$("p.btnView img[src$='/images/common/btn_view_01.gif']").each(function() {
		$(this).addClass("normal");
	});
	
	$("p.btnView img[src$='/images/common/btn_view_02.gif']").each(function() {
		$(this).addClass("half");
	});
	
}



/**********************************************************
pageScroll
--------
ページをスムーズにスクロール（ href属性値が#で始まるものが対象 ）
@param / @return
**********************************************************/
function pageScroll() {
	$("a[href*=#]").click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
}



/**********************************************************
bigTarget
--------
クリックエリアを拡大
@param / @return
**********************************************************/
function setBigTarget() {
	$("div.innerCommon p.btnView a").bigTarget({
		hoverClass: 'bigTargetOver',  // CSS class applied to the click zone onHover
		clickZone : 'div:eq(0)'       // jQuery parent selector
	});
};



/**********************************************************
changeLabelColor
--------
チェックボックスクリック時にラベルの色変更
@param / @return
**********************************************************/
function changeLabelColor(){
    $("label,:checkbox").click(function(){
        $("label").css("color","")
        $(":checked").each(function(){
            $("label[for='"+$(this).attr("id")+"']").css("color","#000000")
        })
    })
};




/**********************************************************
initRollOverImages
--------
マウスオーバーで画像を切換
@param / @return
**********************************************************/
function initRollOverImages() {
	var image_cache = new Object();
	$("a img.btn,input[type=image].btn").not("[src*='_o.'],[src*='_d.']").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_on = this.src.substr(0, dot) + '_o' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_on;
		$(this).hover(
			function() { this.src = imgsrc_on; },
			function() { this.src = imgsrc; }
		);
	});
}



/**********************************************************
initRollOverImages2
--------
マウスオーバーで画像を切換:divに直接当てる
@param / @return
**********************************************************/
function initRollOverImages2() {
    $("div.innerCommon").mouseover(function(){
        $(this).find("img.normal").attr("src","/images/common/btn_view_01_o.gif");
        $(this).find("img.half").attr("src","/images/common/btn_view_02_o.gif");
    }).mouseout(function(){
        $(this).find("img.normal").attr("src","/images/common/btn_view_01.gif");
        $(this).find("img.half").attr("src","/images/common/btn_view_02.gif");
    })
}

/**********************************************************
attachThickboxForm
--------
フォームのsubmitした結果をThickboxで表示
@param / @return
**********************************************************/
function attachThickboxForm() {
    var thickboxparams = '&KeepThis=true&TB_iframe=true&height=588&width=886';
    $("form.thickboxform").each(function(){
        $(this).bind("submit", function(){
            var title, url, rel, formParams;
            title = this.title || this.name || null;
            formParams = $(this).serialize();
            formParams = formParams.replace(/%5B%5D=/gi, "[]=");
            formParams = formParams.replace(/%5B([^&]*?)%5D=/gi, "[$1]=");
            url = this.action + '?' + formParams + thickboxparams;
            rel = this.rel || false;
            tb_show(title, url, rel);
            return false;
        });
    });
}

function attachPopUpWindow() {
    $(function(){
        $('a.popup').each(function(){
            $(this).click(function(){
                popup(this.href);
                return false;
            });
        });
    });
}

function popup(url) {
    window.open(url, "popup","width=632,height=950,menubar=no,scrollbars=yes,resizable=yes");
}


/**********************************************************
実行処理
**********************************************************/
$(document).ready(setClassBtn);
$(document).ready(setBigTarget);
$(document).ready(pageScroll);
$(document).ready(changeLabelColor);
$(document).ready(initRollOverImages);
$(document).ready(initRollOverImages2);
$(document).ready(attachThickboxForm);
$(document).ready(attachPopUpWindow);


