$(function(){
	
	//$("div.scroll").smoothDivScroll();
	
	$('ul.nav a').bind('click',function(event){
		var $anchor = $(this);
		//alert($('.section').index($($anchor.attr('href')))*$('.scrollWindow').height());
		$('.scrollWindow').stop().animate({
			scrollTop: $('.section').index($($anchor.attr('href')))*$($anchor.attr('href')).height()
		}, 1500,'easeInOutExpo');
		/*
		if you don't want to use the easing effects:
		$('html, body').stop().animate({
			scrollTop: $($anchor.attr('href')).offset().top
		}, 1000);
		*/
		event.preventDefault();
	});

});


function initTimeline(options){
	var hasPermission=1;

	var settings = {

	  'permissions'		:	'publish_actions',
	  'callback'		:	null,
	  'onCancel'		:	null

	};
	
	if ( options ) { 
	$.extend( settings, options );
	}
	
	FB.getLoginStatus(function(response) {
		   console.log('Facebook Status');
		   console.log(response);
		  if (response.status === 'connected') {

			  var FQL = 'SELECT '+settings.permissions+' FROM permissions WHERE uid='+response.authResponse.userID;

					FB.api(
						  {
							method: 'fql.query',
							query: FQL
						  },
						  function(response) {

							  var perms=settings.permissions.split(',');

							  $.each(perms, function(index, value) {

								  value=$.trim(value);

								  if(response[0][value]!="1" || response[0][value]=='undefined'){ hasPermission=0; }

							   });
					});
		  }



		if (response.status == 'connected' && hasPermission==0 ) {

			FB.login(function(response) {

			  

				  if(typeof settings.callback == 'function'){ settings.callback.call(this,settings); }

			 

			}, {scope:settings.permissions}); 

		} else {

			if(typeof settings.callback == 'function'){ settings.callback.call(this,settings); }
		}

   });	
	
}
function postRead(settings)
{
	
	//console.log(settings);
	
	FB.api('/me/thecorridorli:read' + 
				'?'+settings.obj+'='+settings.url+'','post',
				function(response) {
		if (!response || response.error) {
				console.log('Error occured');
		} else {
			console.log('Post was successful! Action ID: ' + response.id);
			}
	});
}

function postWatch(settings)
{
	
	//console.log(settings);
	
	FB.api('/me/thecorridorli:watch' + 
				'?'+settings.obj+'='+settings.url+'','post',
				function(response) {
		if (!response || response.error) {
				console.log('Error occured');
		} else {
			console.log('Post was successful! Action ID: ' + response.id);
			}
	});
}    

