/**	
 * moFade 0.1a
 * http://hauptbenutzer.de
 *
 * Copyright 2011, Moritz Flucht
 *
 * Fades any element properly to its destination opacity whilst stopping ongoing animations
 * + auto hides elements faded to 0.0 opacity
 * + auto shows elements fading from display=none
*/

$.fn.moFade = function(opa, time) {
	time = time || 500;
	opa = opa || 0.0;
	$(this).each(function(){
		if($(this).css('display') == 'none')
			$(this).css('opacity', 0.0);

		if(opa == 0.0)
			$(this).stop().animate({'opacity': 0.0}, time, function() { $(this).css("display", "none"); });
		else
			$(this).stop().css("display", "block").animate({'opacity': opa}, time);
	});
	
	return $(this);
}

$.fn.moTip = function(time, position) {
	position = position || 'center';

	$(this).each(function(){
		var rel = $(this).attr("rel");
		$(this).appendTo("body");
		$(this).mouseover(function(){
			$(this).moFade(1.0, time);
		});
		$(this).mouseleave(function(){
			$(this).moFade(0.0, time);
		});
		var tip = $(this);
		$(rel).mouseover(function(){
			if(position == 'center')
			{
				tip.moFade(1.0, time).css({
					'left': $(rel).offset().left + ($(rel).width()/2) - tip.width()/2,
					'top': $(rel).offset().top + ($(rel).height()/2) - tip.height()/2
					});
			}
			
		});
		$(rel).mouseleave(function(){
			tip.moFade(0.0, 700);
		});
	});
}
$.fn.moSlide = function(width) {
	$(this).each(function(){
		$(this).css({'position': 'relative', 'overflow': 'hidden', 'height': $(this).children(".moslide-slider:first-child").height()+10, 'width': $(this).width() });
		$(this).wrapInner("<div class='moslide-container' />");
	});
	$(".moslide-container").css({'position': 'absolute', 'left': 0, 'top': 0, 'width': $(this).width()*3 });
	$(".moslide-slider").css({'float': 'left', 'width': $(this).width() });
	$(".moslide-slider:first-child").addClass("active");
	$(".moslide-link").live("click", function(){
		var slide = $($(this).attr("href"));
		if(slide.is(":first-child")) {
			$(".moslide-container").animate({left: 0}, 300);
		}
		else {
			$(".moslide-container").animate({left: slide.width()*-1}, 300);
		}
		return false;
	});
};

