$(function() {
    var animationTime = 750;
	$('#menu a').bind('click',function(event){
		var $anchor = $(this);

	    if($anchor.attr('href').indexOf('javascript') != -1 || $anchor.attr('href').indexOf('#') != 0) {
            return;
        }

        if(window['yt-frost-player'].getPlayerState() == 1 && $anchor.attr('href').indexOf('video') == -1) {
            window['yt-frost-player'].pauseVideo();
        }

        $('html, body').stop().animate({
			scrollLeft: $($anchor.attr('href')).offset().left
		}, animationTime);
        // set the location accordingly, so we can bookmark just as normal
        event.preventDefault();
        window.setTimeout(function(){self.location.href = $anchor.attr('href');}, animationTime+10);
	});
});


var newsletterPopupStatus = 0;
var playercontrolsPopupStatus = 0;

function fadePopupIn(name) {
    if(window[name + 'PopupStatus'] == 1) {
        $('#' + name + '-popup').fadeOut('fast');
        window[name + 'PopupStatus'] = 0;
        return;
    }

    if(window[name + 'PopupStatus'] == 0) {
        $('#' + name + '-popup').fadeIn('fast');
        window[name + 'PopupStatus'] = 1;
        return;
    }
}

function fadePopupOut(name) {
    if(window[name + 'PopupStatus'] == 1) {
        $('#' + name + '-popup').fadeOut("fast");
        window[name + 'PopupStatus'] = 0;
    }
}

function positionPopup(name) {
    var x = $('#' + name).position().left;
    var y = $('#' + name).offset().top;
    var width = $('#' + name).width();
    var height = $('#' + name).height();
    var boxWidth = $('#' + name + '-popup').width();
    var left = 0;
    if(name == 'playercontrols') {
        left = 20;
    } else {
        left = x+width/2-boxWidth/2-10;
    }
        $('#' + name + '-popup').css({
        "top" : y+height+10,
        "left": left 
    });
}

