// LS-RP Javascript

jQuery(document).ready(function(){
	
	// ###########
	// Carrusel
	jQuery('#featured ul').roundabout({
		easing: 'easeOutInCirc',
		duration: 300
	});

	
	// ###########
	// mcmavaGusta
	jQuery(function() {
		jQuery(".button").click(function() {
		var manualid = jQuery("input#manualid").val();

		if (manualid == "") {
			jQuery("label#manualid_error").show();
			jQuery("input#manualid").focus();
			return false;
		}
		var dataString = 'manualid='+ manualid;
		//alert (dataString);return false;

		jQuery.ajax({
			type: "POST",
			url: "ajax/esUtil.php",
			data: dataString,
			success: function() {
				jQuery('#mcmavaGusta').html("<img class='ajax' src='images/cargando.gif' border='0' />")
				jQuery('#mcmavaGusta').hide()
				.fadeIn(777, function() {
					jQuery('#mcmavaGusta').html("<p class='ajax'>Gracias por sus comentarios &nbsp; <p class='ajaxcorrecto'></p></p>");
				});
				}
			});
			return false;
		});
	});
	
	
	
	// ###########
	// SubMenu
	jQuery("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	jQuery("ul.topnav li span").mouseover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		jQuery(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
 
		jQuery(this).parent().hover(function() {
		}, function(){	
			jQuery(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});
 
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			jQuery(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			jQuery(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	// ###########
	// Menu top
	(function() {
		var fadeSpeed = 200, fadeTo = 0.5, topDistance = 30;
		var topbarME = function() { $('#uberbar').fadeTo(fadeSpeed,1); }, topbarML = function() { $('#uberbar').fadeTo(fadeSpeed,fadeTo); };
		var inside = false;
		//do
		$(window).scroll(function() {
			position = $(window).scrollTop();
			if(position > topDistance && !inside) {
				//add events
				topbarML();
				$('#uberbar').bind('mouseenter',topbarME);
				$('#uberbar').bind('mouseleave',topbarML);
				inside = true;
			}
			else if (position < topDistance){
				topbarME();
				$('#uberbar').unbind('mouseenter',topbarME);
				$('#uberbar').unbind('mouseleave',topbarML);
				inside = false;
			}
		});
	})();
	

	// ###########
	// Hover Posts
	var opacity = 0.7, toOpacity = 0.9, duration = 250;
	jQuery('.opacity').css('opacity',opacity).hover(function() {
			jQuery(this).fadeTo(duration,toOpacity);
		}, function() {
			jQuery(this).fadeTo(duration,opacity);
		}
	);


	// ###########
	// Pestaņas
	jQuery(".tab_content").hide(); //Hide all content
	jQuery("ul.tabs li:first").addClass("active").show(); //Activate first tab
	jQuery(".tab_content:first").show(); //Show first tab content
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		jQuery(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	
	// ###########
	// Tooltips
	jQuery(function() {
		jQuery('#tooltip_donar').tipsy({fade: true, gravity: 'n'});
		jQuery('#tooltip_facebook').tipsy({fade: true, gravity: 'n'});
		jQuery('#tooltip_facebook_share').tipsy({fade: true, html: true});
		jQuery('#tooltip_buzz_share').tipsy({fade: true, html: true});
		jQuery('#tooltip_ip').tipsy({fade: true, html: true});
		/*jQuery('#north').tipsy({fade: true, gravity: 'n'});
		jQuery('#south').tipsy({fade: true, gravity: 's'});
		jQuery('#east').tipsy({fade: true, gravity: 'e'});
		jQuery('#west').tipsy({fade: true, gravity: 'w'});*/
	});
	
});