$(document).ready(function () {
    setInterval('blink()', 5000);

    $('a[href=#top]').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    $("#footer-pops a").hover(
        function () {
            $(this).find('img.inactive').css('display', 'none');
            $(this).find('img.active').css('display', 'block');
        },
        function () {
            $(this).find('img.active').css('display', 'none');
            $(this).find('img.inactive').css('display', 'block');
        }
    );

    $("#nav li").hover(
        function () { $(this).addClass('hover'); },
        function () { $(this).removeClass('hover'); }
    );

    $('.toggle').click(function () {
        $(this).next().slideToggle("slow");
        $(this).text($(this).text() == 'click to expand >' ? '< click to hide' : 'click to expand >');
    });

    $('ul.hasToggle li').each(function () {
        $(this).find('a:eq(0)').siblings().not('h3').addClass('toggle-content');
        $(this).find('a:eq(0)').click(function () {
            $(this).siblings().not('h3').slideToggle("slow");
            $(this).text($(this).text() == 'click to expand >' ? '< click to hide' : 'click to expand >');
        });
    });

    $('#top-nav a, #footer-nav a').each(function () {
        if ($('body').hasClass($(this).attr('href').substring(1)))
            $(this).addClass('current');
    });

    $('#main-nav li a').each(function () {
        if ($('body').hasClass($(this).attr('href').substring($(this).attr('href').lastIndexOf('/') + 1)))
            $(this).addClass('current');
    });

    $('#header-bottom .change-location').click(function () {
        $('#header-bottom .enter-zip').css('display', 'block');
        $('#header-bottom .current-location').css('display', 'none');
    });
    
    jQuery.fn.center = function (width, height) {
        if (width == undefined) width = this.width();
        if (height == undefined) height = this.height();
        this.css("left", (($(window).width() - width) / 2) + $(window).scrollLeft() + "px");
        this.css("top", (($(window).height() - height) / 2) + $(window).scrollTop() + "px");
        return this;
    }
});
function blink() {
    setTimeout("$('#header-left a').addClass('flicker')", 100);
    setTimeout("$('#header-left a').removeClass('flicker')", 200);
    setTimeout("$('#header-left a').addClass('flicker')", 300);
    setTimeout("$('#header-left a').removeClass('flicker')", 400);
}

//$(document).ready(function () {
//    $('#item-video').each(function () {                
//        FlowPlayer($(this).attr('rel'));
//    });
//});

var videoPreview = '<div class="preview">';
videoPreview += '<div class="video-container"><div id="item-video"></div><div class="close"></div></div>';
videoPreview += '</div>';
videoPreview += '<div class="overlay"></div>';

$(document).ready(function () {
    $('.play-video').live('click', function () {
        $('body').append(videoPreview);
        $('.overlay').css('height', $('body').height());
        FlowPlayer($(this).attr('rel'));
        $('.preview').center();
    });
    $('.preview .close, .overlay').live('click', function () {
        $('.preview').remove();
        $('.overlay').remove();
    });
});

function FlowPlayer(file) {
    flowplayer("item-video", {
        // our Flash component 
        src: "/common/flash/flowplayer.leapfrog-3.1.5.swf",
        width: 640,
        height: 480,
        wmode: 'transparent',
        quality: 'high',
        menu: 'true',
        // we need at least this Flash version 
        version: [10, 0],
        expressInstall: '/common/flash/flebExpressInstall.swf'
        // here is our third argument which is the Flowplayer configuration 
    }, {
        key: '9ccac5b5f58b5f232a1',
        clip: {
            url: "/common/flash/" + file,
            autoPlay: true,
            autoBuffering: true
        }
    });
}
