$(document).ready(function() {
	
	//$(".thickbox").colorbox({maxHeight:'95%',maxWidth:'95%'});
	//$(".forms").colorbox({width:550});
	
	$.ajaxSetup ({
		cache: false
	});
	
	$(window).bind("scroll", function(){
		$offset = $(this).scrollTop (); //$('html').offset().top;
		$('div#alert').css ('top', $offset);
		
		$offset = $(this).scrollTop() + $('document').innerHeight()/2;
		$('div#loader').css ('top', $offset);
	});

	$('div#loader').ajaxStart(function() {
		$offset = $(window).scrollTop() + $('document').innerHeight()/2;
		$('div#loader').css ('top', $offset);
		$('div#loader').fadeIn (100);
	});

	$('div#loader').ajaxComplete(function() {
		$offset = $(window).scrollTop() + $('document').innerHeight()/2;
		$('div#loader').css ('top', $offset);
   		$('div#loader').fadeOut (250);
 	});
 

	$("ul#sharelead").find ("a[class='sharing']").each (function() {
		$(this).click (function(){
			$.get ("/tracker", {type : this.id});
		});
	});
});

function showAlert (msg) {
	$alert = $('div#alert');
	$alert.html (msg);
	alerttimer = window.setTimeout(function () {
		$alert.trigger('click');
	}, 3000);
	$offset = $(window).scrollTop (); //$('html', document.body).offset().top;
	$alert.css ('top', $offset);
	$alert.animate({height: $alert.css('line-height') || '50px'}, 200)
	.click(function () {
		window.clearTimeout(alerttimer);
		$alert.animate({height: '0'}, 200);
	});
}

function ajaxReload (container, url, anchor) {
	$("div#"+container).load (url, function (){
		$('div#loader').gotoanchor ({"anchor" : anchor});
	});	
}

function facebook_login_button () {
   FB_RequireFeatures(["Connect"], function() {
     FB.init("30828403961e1c82edbd753f22063d5b", "/facebook-platform/xd_receiver.htm", {
		"reloadIfSessionStateChanged" : true,
		permsToRequestOnConnect : "email"
		}
	 );
     FB.Connect.requireSession();
   });
   return false;
}

function facebook_logout_button () {
	FB.Connect.logout(function(){
		window.location.reload ();
	});
	return false;
}
