jQuery.fn.center = function (absolute, top) {
    return this.each(function () {
        var t = jQuery(this);

        t.css({
            position:    absolute ? 'absolute' : 'fixed', 
            left:        '50%', 
            top:        top, 
            zIndex:        '999'
        }).css({
            marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
            marginTop:    '-' + (t.outerHeight() / 2) + 'px'
        });

        if (absolute) {
            t.css({
                marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
                marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
            });
        }
    });
};

// put divs to be be displayed here. refer to prototpe for various actions on a div that is possible.
function show_loading_image()
{
		jQuery("#loading_image").center(true,'20%');
		jQuery("#loading_image").fadeIn(1000);
		return false;
}

function hide_loading_image()
{
		jQuery("#loading_image").fadeOut(1000);
		return false;
}

// account details
function show_cancel_account()
{
		jQuery("#close_this_account").center(true,'20%');
		jQuery("#close_this_account").fadeIn(1000);
		return false;
}

function hide_cancel_account()
{
		jQuery("#close_this_account").fadeOut(1000);
		return false;
}

// what_is_cvv
function show_cvv()
{
		jQuery("#cvv_info").center(true,'20%');
		jQuery("#cvv_info").fadeIn(300);
		return false;
}
function hide_cvv(){Element.hide('cvv_info');return false;}

// util explaination
function show_util_info()
{
	jQuery("#util_info").center(true,'20%');
	jQuery("#util_info").fadeIn(300);
	return false;
}
function hide_util_info(){
	jQuery("#util_info").fadeOut(300);
	return false;
}

// employee sparkline explaination
function show_spark_info()
{
	jQuery("#spark_info").center(true,'10%');
	jQuery("#spark_info").fadeIn(300);
	return false;
}
function hide_spark_info(){
	jQuery("#spark_info").fadeOut(300);
	return false;
}


// activity explaination
function show_activity_info(){
			jQuery("#activity_info").center(true,'20%');
			jQuery("#activity_info").fadeIn(1000);
			return false;
}

function hide_activity_info(){
			jQuery("#activity_info").fadeOut(1000);
			return false;
}

function show_feedback()
{
	Element.show('feedback');center('feedback');return false;
/*	jQuery("#feedback").center(true,'20%');
	jQuery("#feedback").fadeIn(1000);
	return false;
	*/
}

function hide_feedback()
{
	jQuery("#feedback").fadeOut(1000);
	return false;	
}

function show_custom_report()
{
	Element.show('custom_report');center('custom_report');return false;
/*	jQuery("#custom_report").center(true,'20%');
	jQuery("#custom_report").fadeIn(1000);
	return false;
	*/
}

function hide_custom_report()
{
	jQuery("#custom_report").fadeOut(1000);
	return false;	
}

function toggle_display(a, b)
{
	jQuery("#" + a).toggle();	
	jQuery("#" + b).toggle();	
}

// upgrade/downgrade confirm
function show_upgrade_confirm()
{
	jQuery("#verify_upgrade").center(true,'20%');
	jQuery("#verify_upgrade").fadeIn(1000);
	return false;
}
function hide_upgrade_confirm()
{
	jQuery("#verify_upgrade").fadeOut(1000);
	return false;
}
function show_downgrade_confirm()
{
	jQuery("#verify_downgrade").center(true,'20%');
	jQuery("#verify_downgrade").fadeIn(1000);
	return false;
}
function hide_downgrade_confirm()
{
	jQuery("#verify_downgrade").fadeOut(1000);
	return false;	
}


function showLoginLogout(){if((user_login!=null)&&(user_login!='')){new Insertion.Top('user_status','<div id=\"loginlogout\">User: <a href="/users/show/'+user_id+'">'+user_login+'</a>&nbsp;&nbsp;|&nbsp<a href="/account/logout">Sign Out</a>&nbsp;&nbsp;|&nbsp<a href="/account/edit">Settings</a></div>');}else{new Insertion.Top('user_status',"<div id=\"loginlogout\"><a href=\"\" onclick=\"showEmailBox(); return false;\">Log In</a></div>");}}
function center(element){try{element=document.getElementById(element);}catch(e){return;}
var my_width=0;var my_height=0;if(typeof(window.innerWidth)=='number'){my_width=window.innerWidth;my_height=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){my_width=document.documentElement.clientWidth;my_height=document.documentElement.clientHeight;}
else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){my_width=document.body.clientWidth;my_height=document.body.clientHeight;}
element.style.position='absolute';element.style.zIndex=99;var scrollY=0;if(document.documentElement&&document.documentElement.scrollTop){scrollY=document.documentElement.scrollTop;}else if(document.body&&document.body.scrollTop){scrollY=document.body.scrollTop;}else if(window.pageYOffset){scrollY=window.pageYOffset;}else if(window.scrollY){scrollY=window.scrollY;}
var elementDimensions=Element.getDimensions(element);var setX=(my_width-elementDimensions.width)/2;var setY=(my_height-elementDimensions.height)/2+scrollY;setX=(setX<0)?0:setX;setY=(setY<0)?0:setY;element.style.left=setX+"px";element.style.top=setY+"px";element.style.display='block';}
