var GB_ANIMATION = true;
var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;
var callback;
/**
 * Lightbox plugin
 * @param url URL of the lightbox source
 * @param height Height, in px of the lightbox
 * @param width Width, in px of the lightbox
 * @param type Either 'iframe', or 'ajax'. Defaults to iframe
 * @param callback Callback is run once the lightbox has been closed
 * @param ajaxload Callback is run once the ajax src has loaded
 */

function GB_show(url, height, width, type, callback, ajaxload) {

	var method = type || "iframe";
    GB_HEIGHT = height || 400;
    GB_WIDTH = width || 400;
    callback = callback || function(){};
	ajaxload = ajaxload || function(){};

    if(!GB_DONE) {
        $(document.body).append("<div id='GB_overlay'></div><div id='GB_window'>"+"<div id='GB_close'></div><div id='GB_content'></div></div>");
        $("#GB_window #GB_close, #GB_overlay").click(function(){
          $("#GB_window,#GB_overlay").hide(); 
          $('body').removeClass('blackout'); 
		  $('body').removeClass('yell_modal');
          callback();
        });
   
        $(window).resize(GB_position);
        GB_DONE = true;
    }
    $("#GB_frame").remove();
	if(method=="ajax"){
		$("#GB_content").append('<div id="GB_frame"></div>');
		$.ajax({
			  url: url,
			  dataType: 'html',
			  success: function(data) {
				$("#GB_frame").html(data);
			    ajaxload();
			  }
			});
	}else{
		$("#GB_content").append('<iframe style="height:'+GB_HEIGHT+'px;" border="0" frameborder="0" id="GB_frame" src="'+url+'"></iframe>');
	}

    $("#GB_overlay").show();
    $('body').addClass('blackout');
    GB_position();
	
    if(GB_ANIMATION){
        $("#GB_window").fadeIn("slow");
    }else{
        $("#GB_window").show();
    }
}

function GB_position() {
	
    var windowW = $(window).width();
    var windowH = $(window).height();
    var docH = $('body').height();


    $("#GB_window").css({top: "0", left: "0", position: "fixed"});
    $("#GB_overlay").css({top: "0", left: "0"});

    $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px", left: ((windowW - GB_WIDTH)/2)+"px", top: ((windowH-GB_HEIGHT)/2)+"px"});
    $("#GB_overlay").css({height:docH+"px", width:windowW+"px"});
}

function GB_resize(height, width) {
	GB_HEIGHT = height || GB_HEIGHT;
	GB_WIDTH = width || GB_WIDTH;
	GB_position();
}

function GB_close() { 
	$("#GB_close").trigger('click');	
}

function GB_RefreshPage() {
	window.location.reload();
}

function GB_RefreshFollowButton(object, data, string) {	
	if (string == 'follow') {
		object.replaceWith('<a id="unfollow-me-btn" data-name="'+data+'" class="unfollow-link btn-link btn-link-grey" href="'+_SERVER_+'/member/unfollowmember/'+data+'?_popup">Unfollow me</a>');
		Cufon.replace('#unfollow-me-btn');
	} else {
		object.replaceWith('<a id="follow-me-btn" data-name="'+data+'" class="follow-link btn-link btn-link-grey" href="'+_SERVER_+'/member/followmember/'+data+'?_popup">Follow me</a>');
		Cufon.replace('#follow-me-btn');
	}
}

function GB_RefreshFollowLink(object, data, string) {	
	if (string == 'follow') {
		object.replaceWith('<a href="'+_SERVER_+'/member/unfollowmember/'+data+'?_popup" class="unfollow-link" data-name="'+data+'">Unfollow me</a>');		
	} else {
		object.replaceWith('<a href="'+_SERVER_+'/member/followmember/'+data+'?_popup" class="follow-link" data-name="'+data+'">Follow me</a>');
	}
}


