/**
 * @author	rortelli
 * @fileOverview	Global functions and jQuery plugins used on minestrone.aptanacloud.com
 */

/**
 * See (http://jquery.com/).
 * @name jQuery
 * @class
 * See the jQuery Library  (http://jquery.com/) for full details. This just documents the function and classes that are added to jQuery by this plug-in.
*/

/**
 * See (http://jquery.com/)
 * @name jQuery.fn
 * @class
 * See the jQuery Library  (http://jquery.com/) for full details. This just
 * documents the function and classes that are added to jQuery by this plug-in.
 * @memberOf jQuery
 */

/**
 * @class
 * @description	Creates a new slideshow
 * @author		Roberto Ortelli rortelli@gmail.com
 * @return		{jQuery} chainable jQuery class
 * @param		o	Options of the slideshow
 * @param		o.elClass	The name of the container where the images are displayed
 * @param		o.path		The path to reach the folder on the server containing the images
 * @param		o.num		The number of images that can be d
 * @memberOf 	jQuery.fn
 */
jQuery.fn.slideShow = function(o){
	
	var defaults = {
		elClass: null,
		path: null,
		num: null
	};
	
	var settings = $.extend(defaults, o),
		el = $("." + settings.elClass),
		i = 1;
	
	for (var n = 0; n<5; n++) {
		var im = new Image(10,10),
			num = n + 1;
		im.src= settings.path + num +".jpg";	
	}
	
	setInterval(function() {
		
		el.append("<div id='empty-element'></div>").ready(function() {
			
			$("#empty-element").show().animate({
				opacity: 1
			}, 1000, function() {
				
				i = (i < settings.num) ? i + 1 : 1;
				
				el.css({
					backgroundImage: "url("+ settings.path + i +".jpg)"
				});
				$("#empty-element").animate({
					opacity: 0
				}, 1000, function() {
					$(this).remove();
				})
			});
		});
	}, 10000);
}

/**
 * @author	rortelli
 * @class	Preload of a set of images
 * @param	{Array|String} arguments contains a list of images
 * @return {jQuery} chainable jQuery class
 * @memberOf jQuery
 */
jQuery.preloadImages = function() {
	for (var i = 0; i<arguments.length; i++) {
    	jQuery("<img>").attr("src", arguments[i]);
	}
}

/**
 * @description	Simplify the console.log command
 * @author	rortelli
 * @param	arguments contains a list of images
 * @function
 */
function log() {
  try {
    console.log.apply( console, arguments );
  } catch(e) {}
}



$(document).ready(function() {
	$("#menu li a").hover(function(){
		
		$(this).animate({
			width: 200
		}, 500)	
	}, function(){
		
		$(this).animate({
			width: 79
		}, 500);
	});
	
	$("#menu .menu-login").bind("click", function() {
		
		this.blur();
		
		var $login = $("#login");
		if ( $login.is(":hidden") ) {
			$login.show();
			$(this).parent().addClass("selected");
		}
		else {
			$login.parent("li").removeClass("selected");
		}
		
		return false;
	});
	
});
