/*
* Copyright (C) 2010 Anderson Costa
* Licenced under the MIT license
* http://www.mangava.com.br/
*/
(function($) {
	$.fn.expandable = function(settings) {
		settings = $.extend({
			hoverElement:'',
			expandElement:'',//tagName, class or id of element to expand, only if expandable element depends on the hover trigger of other element
			configClass: 'expandable_sys',
			expandPosition: 'bottom',//top or bottom
			totalHeight: 325,
			minHeight: 0,
			duration: 200
		}, settings);

		return $(this).each(function(){
		//Verify if expandable and hover are not the same element
		var expandable = settings.expandElement;
		var hoverEl = settings.hoverElement;
		if(hoverEl!='' && expandable != ''){
			//consider that if hover and expandable are not the same, hover is inside the main element
			
			//Add class to expand element
			$(expandable).addClass(settings.configClass);
			$(this).find(hoverEl).hover(function(){
				$(expandable).animate({
					height:settings.totalHeight
				});
			});
			$(expandable).bind('mouseleave',function(){
			$(this).animate({
				height:settings.minHeight
				});
			});
		}
		else if(hoverEl != ''){
			$(this).addClass(settings.configClass).find(hoverEl).hover(function(){
				$(this).stop().animate({
					height:settings.totalHeight},
					{queue:false,duration:settings.duration});
				}, function() {
					$(this).stop().animate({height:settings.minHeight},{queue:false,duration:settings.duration});
				});	
		}
		});
		//$(this).addClass(settings.configClass);
		if (this.complete || this.naturalWidth > 0){
				$(this).trigger('load');
		}
	}
})(jQuery);

