
var boolCallFlashCalled = false;

$(document).ready(function () {

    // CODA SLIDER
    if (document.getElementById('coda-slider-1')) {
        $('#coda-slider-1').codaSlider();
    }



    // START LAVALAMP AFTER CUFON IS READY
    Cufon.CSS.ready(function () {
        $('.sub_distillery, .sub_wheretobuy').lavaLamp({
            autoReturn: true,
            speed: 200,
            homeTop: 200,
            homeLeft: 25
        });

        var lockClass = $(".sub_custodians li:last-child a").attr('class');

        if (lockClass == "notLocked") {
            $('.sub_custodians').lavaLamp({
                autoReturn: true,
                speed: 200,
                homeTop: 200,
                homeLeft: 25
            });
        }

    });


    // BACKGROUND EFFECT ON TOP-MENU FIRST-LEVEL ITEMS
    $('#menubar ul li span a').animate({ 'opacity': '0' }, 10);

    $('#menubar ul li span').hover(
		function () {
		    $(this).find('a').animate({ 'opacity': '1' }, 500);
		},
		function () {
		    $(this).find('a').animate({ 'opacity': '0' }, 'slow');
		});


    // SLIDE DOWN AND UP TOP MENU PANEL 
    $('.mm_distillery, .mm_custodians, .mm_wheretobuy').mouseenter(function () {
        $('#supershadow').addClass('ss_activate').css('opacity', '0.6');
        $('#topBar').stop().animate({ height: 200 }, 500);


        if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {

            var elements = document.documentElement.getElementsByTagName('select');

            for (var i = 0; i < elements.length; i++) {
                elements[i].style.visibility = "hidden";
            }
        };

    });

    // small fix. wait till animation is complete
    // then remove/unwrap elements. prevents cufon from
    // getting messed up in IE
    $('.mm_distillery, .mm_custodians, .mm_wheretobuy').mouseleave(function () {

        $('#topBar').stop().animate({ height: 40 }, 500,
             function () {
                 $('#supershadow').removeClass('ss_activate');
                 if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {

                     var elements = document.documentElement.getElementsByTagName('select');

                     for (var i = 0; i < elements.length; i++) {
                         elements[i].style.visibility = "visible";
                     }
                 };
             });
    });


    // LINK OVER FX
    $('#footer ul li a, .d_post h2 a').hover(function () {
        $(this).stop().animate({ color: '#6B6B6C' }, 400);
    }, function () {
        $(this).stop().animate({ color: '#E4E5E6' }, 400);
    });

    $('a.fxLink, #left_wrapper ul li a, .buynow a, #fancybox-close, .backbtn a, .dwnld_wrapper a, .ico_rss a, .d_comments a, p.red_arrow a, .notLoggedIn a, p.becomecustodian a, .d_submit_comment a').hover(function () {
        $(this).stop().animate({ color: '#E4E5E6' }, 400);
    }, function () {
        $(this).stop().animate({ color: '#6B6B6C' }, 400);
    });

    $('#login_form a').hover(function () {
        $(this).stop().animate({ color: '#B90101' }, 400);
    }, function () {
        $(this).stop().animate({ color: '#000' }, 400);
    });


    // AUTO SET THE #content SIZE
    makeContentBlock();
    $(window).bind('resize', function () {
        makeContentBlock();
    });

    $('#main').css('visibility', 'visible');

});

/*---------------------------------------------->
cufon replace
<----------------------------------------------*/
function cufonGo() {

    Cufon.now()

    // CUFON
    Cufon.replace('#menubar ul li ul li', {
        color: '#6B6B6C',
        hover: {
            color: '#E4E5E6'
        },
        hoverables: { li: true }
    });

    /*Cufon.replace('#footer ul li', {
    color: '#E4E5E6',
    hover: {
    color: '#6B6B6C'
    }
    });*/

    Cufon.replace('#d_posts .panel .d_post h2', {
        color: '#E4E5E6',
        hover: {
            color: '#6B6B6C'
        }
    });

}


function makeContentBlock() {

    var browserWidth = $(window).width();
    var browserHeight = $(window).height();

    
    // GET THE HEIGHT 

    var contentHeight = 0;
        
    // If it has a Liquid Content inside define its height based on the browser window
    if ($('.hasLiquidContent').length != 0) {
        contentHeight = browserHeight - 70;
    }
    // If not, get the height based on the size of the within content
    else {
        contentHeight = $('#content').height();
    }
 
    // SET THE HEIGHT
    $('#content').height(contentHeight);



    // GET THE WIDTH

    var contentWidth = 0;

    if (document.getElementById('left_wrapper')) {

        if (document.getElementById('RightMenu')) {

            contentWidth = browserWidth - 470;
            // 450px == LeftCol + RightMenu
            // 20px == Safe area in case of vertical scrollbar 
        }

        else {

            contentWidth = browserWidth - 270;
            //  250px == LeftCol
            // 20px == Safe area in case of vertical scrollbar 
        }
    }

    else {

        if (document.getElementById('RightMenu')) {

            contentWidth = browserWidth - 210;
            // 190px == RightMenu
            // 20px == Safe area in case of vertical scrollbar 
        }

        else {
            var contentWidth = "100%";
        }
    }

    // SET THE WIDTH
    $('#content').width(contentWidth);


    // ALIGN VERTICALLY
    // If there's .AlignVertical div, align it vertically based on its height. The div is also aligned 
    
    if ($(".AlignVertical").length) {
        
        var avWidth = $('.AlignVertical').width();
        var avHeight = $('.AlignVertical').height();
        

        var avMarginLeft = -(avWidth / 2);
        var avMarginTop = -(avHeight / 2);
        
        
        $('.AlignVertical').width(avWidth).height(avHeight);
        $('.AlignVertical').css({marginTop: avMarginTop, marginLeft: avMarginLeft});

    }

    if (typeof window.callFlash == 'function') {
        if (!boolCallFlashCalled) {
            callFlash();
            //boolCallFlashCalled = true;
        }
    }

}
