var hover = false;

if ($.browser != 'msie') {
    window.setInterval("checkHash()", 200);
}

var expected_hash = window.location.hash;

function checkHash() {
    if (expected_hash != window.location.hash) {
        expected_hash = window.location.hash;
        if (expected_hash == '#home' || expected_hash == '') { back(); }
        else { $('a[href='+expected_hash+']').click(); }
    }
}

function updateHash(value, title) {
    window.location.hash = expected_hash = value;
}

function back() {
    $('#nav').show();
    $('.tab:visible').hide();
    updateHash('#home');
    return false;
}

$(function(){
    $('#nav a.proxy').click(function(){
        $('#nav').hide();
        $( $(this).attr('href') + '_tab' ).show();
        updateHash( $(this).attr('href') );
        return false;
    });
    $('a.back').click(back);
   
    if (expected_hash) { $('a[href='+expected_hash+']').click(); }
    
    $('ul.nav').superfish({
		animation : { opacity:"show", height:"show" },
		onHide: function(){ if(!hover) {$('#tip').hide(); hover = false;} }
	});
    
    $('.gallery a').fancybox({ 'zoomSpeedIn': 0, 'zoomSpeedOut': 0, 'overlayShow': true });
    
    $('.nav a').hover(
        function() {
            var offset = $(this).offset(), css = {};
            
            hover = true;
            
            $('#tip p').text( $(this).data('title') );
            
            if ($(this).parents('li').length !== 1) {
                css = {
                    top: offset.top,
                    left: offset.left + 30
                };
            }
            else {
                css = {
                    top: offset.top - 25,
                    left: offset.left - ($('#tip').width() / 2) + 10
                };
            }
            $('#tip').css(css).fadeIn();
        },
        function(){
            hover = false;
            $('#tip').hide();
        }
    ).each(function(){
        $(this).data('title', $(this).attr('title'));
        $(this).attr('title', '');
    });
});
