// Used plugin: http://jscrollpane.kelvinluck.com/
// TODO add moving up to stack when opening
// TODO on resize constrain all windows to the visible viewport

// Use background as loader screen
function pullBackground () // TODO rewrite to pull any element to the top of the screen (also use on windows)
{
	document.getElementById('background').style.zIndex = '100000';
}
// Use background as background
function pushBackground ()
{
	document.getElementById('background').style.zIndex = '0';
}

// Twitter
function loadTwitter ()
{
	$('.tweet').empty().tweet({
		'username' : 'lenny_leleu',
		'avatar_size' : 48,
		'count' : 10,
		/*'query' : 'lenny_leleu',*/
		'loading_text' : 'Loading tweets...'
	});
}

// Tumblr
function loadTumblr ()
{
    $('.tumblr').empty().tumblr({
        'username' : 'lenny_leleu'
    });
}

// Ready
$(document).ready(function () {
	// Load screen
	pullBackground();
	
	// Enhance page elements
	var obj_logomenu = new ns.userElements.jLogoMenu({
		'menu_id': 'navigation_menu'
	});
	var obj_activator = new ns.userElements.jActivatorElement({
		'activator_id': obj_logomenu.getLogoId(),
		'target_id': obj_logomenu.getMenuId(),
		'activate': obj_logomenu.showMenu,
		'deactivate': obj_logomenu.hideMenu
	});
	$('.navigation').css({
		'position': 'absolute'/*,
		'top': function() {
			return ($(window).height()/2.30 - $('#navigation').height()/2) + 'px';
		},
		'left': function() {
			return ($(window).width()/2.15 - $('#navigation').width()/2) + 'px';
		}*/
	});
	
	var obj_desktop = new ns.userElements.jDesktop();
	obj_desktop.setNavigation($('.navigation').find('li'));
	
	var obj_gallery = new ns.userElements.jGallery();
	obj_gallery.setNavigation($('.gallery_anchor'));
	obj_gallery.setCallback('./page/collections.callback.php');
	
	// Load twitter
	$('.tweet').bind('loaded', function ()
	{
		$('a.tweet_avatar').each(function ()
		{
			if (-1 !== $(this).attr('href').indexOf('lenny_leleu'))
			{
				$(this).closest('li').addClass('tweet_own');
			}
		});
	});
	loadTwitter();
    loadTumblr();
	
	// Release screen
	pushBackground();
});
