j$(function(){

    //職種
    j$('#SearchCategory > ul > li')
        .find('input[type="checkbox"]')
        .each(function(){
            j$(this).data('sendValue', j$(this).nextAll('input[type="hidden"]') );
            j$(this).nextAll('input[type="hidden"]').remove();
        });

    j$('#SearchCategory > ul > li')
        .find('input:enabled,input:enabled + label')
        .click(function(){

            if( j$(this).parent().find('input').attr('checked') ){
                j$(this)
                    .parent()
                    .find('label')
                    .css({ backgroundPosition : '-126px 0px' })
                    .parent()
                    .find('input[type]')
                    .each( function(){
                        j$(this).after( j$(this).data('sendValue') );
                    } );
            } else {
                j$(this)
                    .parent()
                    .find('label')
                    .css({ backgroundPosition : '0px 0px' })
                    .parent()
                    .find('input[type="hidden"]')
                    .remove();
            }

        });

    j$('#SearchCategory > ul > li:has(input:disabled)')
        .fadeTo(1,0.3);

    j$('#SearchCategory > ul > li > label[for="CategoryWeb"]').css({ backgroundImage : 'url(/images/SearchCategoryIconWeb.png)' });
    j$('#SearchCategory > ul > li > label[for="CategoryMultimedia"]').css({ backgroundImage : 'url(/images/SearchCategoryIconMultimedia.png)' });
    j$('#SearchCategory > ul > li > label[for="CategoryEnvironment"]').css({ backgroundImage : 'url(/images/SearchCategoryIconEnvironment.png)' });
    j$('#SearchCategory > ul > li > label[for="CategoryPublication"]').css({ backgroundImage : 'url(/images/SearchCategoryIconPublication.png)' });
    j$('#SearchCategory > ul > li > label[for="CategoryProduct"]').css({ backgroundImage : 'url(/images/SearchCategoryIconProduct.png)' });
    j$('#SearchCategory > ul > li > label[for="CategoryFashion"]').css({ backgroundImage : 'url(/images/SearchCategoryIconFashion.png)' });


    //地域
    //inputクリック
    j$('#SearchPlaceInput > li > ul > li > input')
        .click( function(event){

            var $input = j$(this),
                tmpId = $input.attr('id'),
                targetId = '#' + tmpId.replace('Place','Layer');

            if( $input.attr('checked') == false )
            {
                j$(targetId)
                    .stop(true,true)
                    .fadeTo(150,0,function(){
                        j$(targetId).css({ visibility : 'hidden' });
                    });
            }
            else
            {
                j$(targetId)
                    .stop(true,true)
                    .fadeTo(1,0.5)
                    .css({ visibility : 'visible' })
                    .fadeTo(50,1);
            }
        } );

    //ラベルクリック
    j$('#SearchPlaceInput > li > ul > li > label')
        .click( function(event){

            event.preventDefault();
            var $input = j$(this).prev('input');

            if( $input.attr('checked') )
            {
                $input.removeAttr('checked').trigger('click').removeAttr('checked');
            }
            else
            {
                $input.attr({checked : 'checked'}).trigger('click').attr({checked : 'checked'});
            }
        });

    //ホバー
    j$('#SearchPlaceInput > li > ul > li > *')
        .hover(
            function(event){

                var $input = j$(this).parent().find('input'),
                    tmpId = $input.attr('id'),
                    targetId = '#' + tmpId.replace('Place','Layer');

                j$(targetId)
                    .stop(true,true)
                    .css({ visibility : 'visible' })
                    .fadeTo(70,0.6);

            },
            function(event){

                var $input = j$(this).parent().find('input'),
                    tmpId = $input.attr('id'),
                    targetId = '#' + tmpId.replace('Place','Layer'),
                    targetAlpha = 0,
                    targetState = 'hidden';

                if($input.attr('checked')){
                    targetAlpha = 1.0;
                    targetState = 'visible';
                }

                j$(targetId)
                    .stop(true,true)
                    .fadeTo(200,targetAlpha,function(){
                        j$(this).css({ 'visibilty' : targetState });
                    });

            });


    //全国
    j$('#SearchPlaceWholeJapan').click(function(){
        j$('#SearchPlaceInput > li > ul > li > input[id!=PlaceForeign]')
            .attr({checked:'checked'})
            .trigger('click')
            .attr({checked:'checked'});

    });

    //クリア
    j$('#SearchPlaceClear').click(function(){
        j$('#SearchPlaceInput > li > ul > li > input')
            .removeAttr('checked')
            .trigger('click')
            .removeAttr('checked');
    });

    j$('#SearchEmployment > ul > li > input:enabled + label')
        .click(function(event){
            j$( '#' + j$(this).attr('for') ).click();
            return false;
        });
});
