/******************************************************************************************
* MAIN MOBBEEL INITIALIZATION FUNCTION
*******************************************************************************************/
$(document).ready(function () {

	// Initialize technology links
	initializeItemLinks ();

	// Initialize admin links
	initializeAdminLinks ();

	// Initialize navitation children links
	initializeNavChildrenLinks ();
});


/******************************************************************************************
* This function initalizes the children menus of main navigation, hiding it firs, and 
* adding a floor (a graphic) for the menu.
*******************************************************************************************/
function initializeNavChildrenLinks () {
	// TODO - Use a native mecanism to solve this problem, NOT javascript
	// Hide Home Slider Posts from archive (temporalll!!!!) while wp solves the issue
	$('#news_archive > li:last').hide();
	
	// Add a new children at the bottom of the menu, with the floor menu image
	$('#nav_main ul.children').append('<span id="end_menu">&nbsp;</span>');
}

/******************************************************************************************
* This function initalizes the background effect for mobbeel items, like biowallet
*******************************************************************************************/
function initializeItemLinks () {
	
	$('.itemList .item').hover (
		function () {
			$(this).css({background:'#eee'});
		},
		function () {
			$(this).css({background:'transparent'});
		}
	)
	var lastItem = $('.itemList .item:last');
	$(lastItem).css({borderBottom:'1px solid gray'});

}

/******************************************************************************************
* This function initalizes the slider effect for company bottom boxes
*******************************************************************************************/
function initalizeCompanyLinks () {
$(document).ready(function(){
	//Caption Sliding (Partially Hidden to Visible)
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'40px'},{queue:false,duration:160});
	}, function() {
		$(".cover", this).stop().animate({top:'85px'},{queue:false,duration:160});
	});
});
}


/******************************************************************************************
* This function initalizes the opacity effect for admin menu
*******************************************************************************************/
function initializeAdminLinks () {

	// TODO - Use a native mecanism to solve this problem, NOT javascript
	// Hide titles for 'enhaced meta' widget in all site (we don't want it)
	$('.enhaced_meta').prev().hide();
	
	// Showing only when mouse is over the list of options (AT THE TOP OF THE PAGE)
	$('#admin_bar .enhaced_meta').hover (
		function () {
			$(this).animate({opacity: 1},300);
		},
		function () {
			$(this).animate({opacity: 0},300);
		}
	)
}

/******************************************************************************************
* This function preload all images that comes as parameter
*******************************************************************************************/
function preloadImages (selector) {
	$(document).ready(function () {

		var i = 0;//initialize
		var int=0;//Internet Explorer Fix
		$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
			int = setInterval(f,500);
		});

		var f = function () {
			var images = $(selector).length;//count the number of images on the page
			if (i >= images) {// Loop the images
				clearInterval(int);//When it reaches the last image the loop ends
				delete int;
			}
			var hiddenSelector =selector +':hidden';
			$(hiddenSelector).eq(0).fadeIn(500);//fades in the hidden images one by one
			i++;//add 1 to the count
		}; 
		$(selector).hide();//hide all the images on the page
	});
}

/******************************************************************************************
* This function preload all images that comes as parameter
*******************************************************************************************/
function initializeTwitterWidget () {
	$(document).ready (function () {
		// Load needed code from twitter
		$.getScript('http://widgets.twimg.com/j/2/widget.js', function() {

			new TWTR.Widget({
				version: 2,
				type: 'profile',
				rpp: 4,
				interval: 20000,
				width: 'auto',
				height: 300,
				theme: {
						shell: {
								background: '#2629cc',
								color: '#ffffff'
						},
						tweets: {
								background: '#ffffff',
								color: '#3f5ca3',
								links: '#eb0707'
						}
				},
				features: {
						scrollbar: true,
						loop: true,
						live: true,
						hashtags: true,
						timestamp: true,
						avatars: true,
						behavior: 'default'
				}
			}).render().setUser('biowallet').start();

		});
	});
}
