$(function(){
    //entrance
    var entranceVal = $.cookie('visited');

    if(entranceVal){
        $('#topEntrance').remove();
    }else{
        setTimeout(function(){
            $('#topEntrance').fadeOut(200, function(){
                $(this).remove();
            });
        }, 5000);
        $.cookie('visited', 'visited',{ expires: 1 });
    }


    $('#topEntrance a').click(function(){
        $('#topEntrance').fadeOut(200, function(){
            $(this).remove();
            $.cookie('visited', 'visited',{ expires: 1 });
        });
    });


    $('#cookieReset').click(function(){
        $.cookie('visited', null);
    });

    

    //preLoad
    var imgSrc = new Image();
    imgSrc.src = './img/img_main_o.png';

    //Hover
    $('#gNav li a').each(function(){
        var className = $(this).parent().attr('class');
        $(this).hover(function(){
            $('#content li.'+className+' a').addClass('Hover');
        }, function(){
            $('#content li.'+className+' a').removeClass('Hover');
        });
    });

    $('#gNav li.Map a').hover(function(){
        $('#footer dd p.Addr a').addClass('Hover');
    }, function(){
        $('#footer dd p.Addr a').removeClass('Hover');
    });

    $('#gNav li.Mail a').hover(function(){
        $('#footer dd p.Mail a').addClass('Hover');
    }, function(){
        $('#footer dd p.Mail a').removeClass('Hover');
    });

    $('#content li a').each(function(){
        var className = $(this).parent().attr('class');
        $(this).hover(function(){
            $('#gNav li.'+className+' a').addClass('Hover');
        }, function(){
            $('#gNav li.'+className+' a').removeClass('Hover');
        });
    });

    $('#footer dd p.Addr a').hover(function(){
        $('#gNav li.Map a').addClass('Hover');
    }, function(){
        $('#gNav li.Map a').removeClass('Hover');
    });

    $('#footer dd p.Mail a').hover(function(){
        $('#gNav li.Mail a').addClass('Hover');
    }, function(){
        $('#gNav li.Mail a').removeClass('Hover');
    });

    var containerHeight = $(window).height();
    if(containerHeight>620){
        var marginValue = (containerHeight-620)/2;
        $('body#home #content').css('margin-top',marginValue);
    }
    
    // external link
    $('a[href^="http"]').not('a[href^="http://localhost/"],a[href^="http://www.dokkatouyu.com/"]').click(function(){
        window.open(this.href, '');
        return false;
    });


    $.ga.load('UA-10599728-1');
});

//window background position ctrl

$(window).resize(function(){
    var containerHeight = $(window).height();
    if(containerHeight>620){
        var marginValue = (containerHeight-620)/2;
        $('body#home #content').css('margin-top',marginValue);
    }
    tb_getPageSize();
});

