$(document).ready(function(){

    //(キーワードでさがす)が設定されているフォームにはkeywordInputFormクラスを設定し、submit時に削除する。
    $("form").each(function(){
        $(this).bind('submit', function(event){
            return false;
        });
    });
    
    $(".keywordInput").each(function(){
        //ヘッダ部やTIARAフォトのキーワード入力フォームにデフォルト文字を挿入
        //　フォーカス時、消去し、ブラー時にvalueが入力されなかった場合また戻す
        if (!$(this).val()) {
            $(this).val('(キーワードでさがす)');
            $(this).css('color', '#777');
        }
        $(this).bind('focus', function(event){
            if ($(this).val() == '(キーワードでさがす)') {
                $(this).val('');
                $(this).css('color', '#000');
            }
        });
        $(this).bind('blur', function(event){
            if ($(this).val() == '') {
                $(this).val('(キーワードでさがす)');
                $(this).css('color', '#777');
            }
        });
    });

    //グローバルナビ ショップをさがすでロールオーバー時にサブメニュー表示
    $('#globalNaviShop').bind('mouseover', function(event){
        $('#shopMenu').css('display', 'block');
    });
    $('#globalNaviShop').bind('mouseout', function(event){
        $('#shopMenu').css('display', 'none');
    });
    $('#shopMenu').bind('mouseover', function(event){
        $('#shopMenu').css('display', 'block');
    });
    $('#shopMenu').bind('mouseout', function(event){
        $('#shopMenu').css('display', 'none');
    });

    //写真一覧系の拡大ボタン表示
    $("a.photoThumbnail").each(function(){
        $(this).bind('mouseover', function(){
            $(this).next().children().css('display', 'block');
        });
        $(this).bind('mouseout', function(){
            $(this).next().children().css('display', 'none');
        });
    });
    //拡大ボタン自信にも自分のロールオーバーなどやらないと点滅する
    $("img.zoomIcon").each(function(){
        $(this).bind('mouseover', function(){
            $(this).css('display', 'block');
        });
    });
    $("img.zoomIcon").each(function(){
        $(this).bind('mouseout', function(){
            $(this).css('display', 'none');
        });
    });

    $("img").each(function(){
        if (!$(this).hasClass('calendarButton')){
            IEPNGFIX.fix(this);
        }
    });

});

// さがす系で検索結果を閉じ再検索を表示
function openSearchBlock() {
    $('#resultBlock').css('display', 'none');
    $('#researchBlock').css('display', 'block');
}

// さがす系で再検索を閉じ検索結果を表示
function closeSearchBlock() {
    $('#resultBlock').css('display', 'block');
    $('#researchBlock').css('display', 'none');
}

function checkAll(allCheckObj, id) {
    var switchBool = allCheckObj.checked ? true : false;
    $("ul#"+id+" input").each(function(){
        $(this).attr('checked', switchBool);
    });
}

function uncheckAll(id) {
    $("ul#"+id+" input").each(function(){
        $(this).attr('checked', false);
    });
}

function resetResearhCheck() {
    $("form#researchForm input").each(function(){
        $(this).attr('checked', false);
    });
}

function addStar(id) {
    $.get("/api/star/add", { pid: parseInt(id) }, function(html, status){
        if (html == 1) {
            var inlineId = 'registDialog';
        } else {
            var inlineId = 'failedDialog';
        }
        tb_show('', '#TB_inline?height=147&width=341&inlineId=' + inlineId + '&modal=true')
    });
}

function removeStar(id) {
    $.get("/api/star/del", { pid: parseInt(id) }, function(html, status){
        if (html) {
            var inlineId = 'removeDialog';
        } else {
            var inlineId = 'failedDialog';
        }
        tb_show('', '#TB_inline?height=147&width=341&inlineId=' + inlineId + '&modal=true');
    });
}

function reloadStar(id) {
    var returnCatch = tb_remove();
    location.href = location.href;
}

function createHiddenSubmit(obj) {
    var currentButton = jQuery(obj);
    currentButton.before('<input type="hidden" name="'+currentButton.attr('name')+'" value="'+currentButton.attr('value')+'" />');
    if ($("form:has(input[name='"+currentButton.attr('name')+"'])").length) {
        $("form:has(input[name='"+currentButton.attr('name')+"'])").unbind('submit').submit();
    } else {
        $("form:has(input[id='"+currentButton.attr('id')+"'])").unbind('submit').submit();
    }
}

//(キーワードでさがす)が設定されているフォームにはsubmitButtonのonclickで、デフォルト文字を削除する。
function deleteKeywordDefault() {
    $(".keywordInput").each(function(){
        if($(this).val() == '(キーワードでさがす)') {
            $(this).val('');
        }
        return true;
    });
}

