var Page = {}; //Global page var for holding page attributes

function newWindow(newLocation, width, height) {
	popUp=window.open(newLocation, '', 'width='+width+',height='+height+',screenX=20,screenY=20,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no');
	popUp.focus();
}

function setContentDimensions (c,minW,minH)
{
    var newSize = calcContstraints(minW,minH);
    c.height(newSize.height);
    c.width(newSize.width);
}

/*
 * Calculate the content dimensions with constraints on size
 */
function calcContstraints(minW,minH) {
    var size = {}; 
    var w = $(window).width(); 
    var h = $(window).height();
    
   	if (w < minW)
   	    size.width = minW;
	else
	    size.width = w;

   	if (h < minH)
   	    size.height = minH;
	else
	    size.height = h;    
	    
	return size;
}

//Centers an element in its container
//@param e the element
//@param c the container
function centerElementHorizontal(e,c)
{
    e.css("left", Math.round((c.width()/2) - (e.width()/2))); 
}

function centerElementVertical(e,c) 
{
    e.css("bottom", Math.round((c.height()/2) - (e.height()/2)));
}

function centerElementVerticalMargin(e,c)
{
    e.css("padding-top", Math.round((c.height() / 2) - (e.height() / 2)) + "px");
}

// [jQuery plugin] 
// Init share link drop down menus
(function($) {
    $.fn.initMenu = function(buttonSelector, menuSelector) {

        return this.each(function() {

            var onLinks = false;
            var onButton = false;

            var button = $(this).find(buttonSelector);
            var menu = $(this).find(menuSelector);

            function showShareLinks() {
                button.addClass("active");
                menu.slideDown();
            }

            function hideShareLinks() {
                if (!onButton && !onLinks) {
                    button.removeClass("active");
                    menu.slideUp();
                }
            }

            function timeOutHide() {
                if (!onButton && !onLinks) {
                    setTimeout(hideShareLinks, 500);
                }
            }

            $(this).hoverIntent(
                function() { onButton = true; showShareLinks(); },
                function() { onButton = false; timeOutHide(); }
            );

            menu.hover(
                function() { onLinks = true; },
                function() { onLinks = false; timeOutHide(); }
            );

        });
    }

})(jQuery);