$(document).ready(setupLogin);
function setupLogin() {
    $('a.close').click(closeLightbox);
    $('a.login').attr('href', 'javascript:addLightbox()');
    changeCss();
}
function addLightbox() 
{
    var tail = '?r+' + Math.round(Math.random * 10000);
    $('#reelzProfile').attr('src', '/profile/profilesb.aspx' + tail);
    $('body').append('<div class="overlay"></div>');
    
    $('div.overlay').click(function() {
        closeLightbox();
    }).fadeIn('slow');
    
    $('#loginBox-container').slideDown('slow');
    
    $('#loginBox-container').click(function() {
        closeLightbox();
    }).fadeIn('slow');

    if (!pageTracker) var pageTracker = _gat._getTracker(_uacct);
    pageTracker._trackPageview(); // seems wrong to have this, but is necessary avoid 'y is undefined error'
    pageTracker._trackEvent('Login Shadowbox', 'Login Clicked');
}
function closeLightbox() {
    $('#loginBox-container').slideUp();
    $('div.overlay').fadeOut('slow', refreshParent).remove();
    deleteCookie("__REELZ_OPTINSTATE");
    //refreshParent();
}
function refreshParent() {
    if (typeof isLoggedIn != 'undefined' && isLoggedIn) {
        if (getCookie("__REELZ_ACCOUNT_ID") != null) {
            top.location = location.href;
        }
    }
}
function changeCss() {
    if ($('#loginBox-container')) {
        var imageHeight = $('#loginBox-container').height();
        var imageWidth = $('#loginBox-container').width();
        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        $('#loginBox-container').css({ "left": windowWidth / 2 - imageWidth / 2, "top": windowHeight / 2 - imageHeight / 2 });
    }
};
$(window).bind("resize", function() { changeCss(); });

//this.tooltip = function() {
//    /* CONFIG */
//    xOffset = 150;
//    yOffset = 25;
//    // these 2 variable determine popup's distance from the cursor
//    // you might want to adjust to get the right result		
//    /* END CONFIG */
//    $("a.tooltip").hover(function(e) {
//        this.t = this.title;
//        this.title = "";
//        $("body").append("<p id='tooltip'>" + this.t + "</p>");
//        $("#tooltip")
//			.css("top", (e.pageY - xOffset) + "px")
//			.css("left", (e.pageX + yOffset) + "px")
//			.fadeIn("fast");
//    },
//	function() {
//	    this.title = this.t;
//	    $("#tooltip").remove();
//	});
//    $("a.tooltip").mousemove(function(e) {
//        $("#tooltip")
//			.css("top", (e.pageY - xOffset) + "px")
//			.css("left", (e.pageX + yOffset) + "px");
//    });
//};
//// starting the script on page load
//$(document).ready(function() {
//    tooltip();
//});