// Beat Fly JS Core Document
$(document).ready(function() {
	//inizialize equalHeight Function
	equalHeight($(".box"));
	
	//Tabs
	var tabs = $('ul.tabs');

	tabs.each(function(i) {

		//Get all tabs
		var tab = $(this).find('> li > a');
		tab.click(function(e) {

			//Get Location of tab's content
			var contentLocation = $(this).attr('href');

			//Let go if not a hashed one
			if(contentLocation.charAt(0)=="#") {

				e.preventDefault();

				//Make Tab Active
				tab.removeClass('active');
				$(this).addClass('active');

				//Show Tab Content & add active class
				$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');

			}
		});
	});
		
	//share it
	$("#share").jsocial({highlight: true,
		buttons: "delicious,facebook,stumbleupon,twitter,digg,", 
		imagedir: "images/", 
		imageextension: "png", 
		blanktarget: true});
			
	//rss1
	$('#rss1').rssfeed('http://www.ansa.it/web/notizie/regioni/lazio/lazio_rss.xml', {
		header: false,
		titletag: 'h6',
		content: false,
		linktarget: '_blank',
		showerror: true,
		errormsg: 'Feed momentaneamente non disponibile!',
		limit: 4
	});
	
	//rss2
	$('#rss2').rssfeed('http://www.ansa.it/web/notizie/rubriche/economia/economia_rss.xml', {
		header: false,
		titletag: 'h6',
		content: false,
		linktarget: '_blank',
		showerror: true,
		errormsg: 'Feed momentaneamente non disponibile!',
		limit: 4
	});
	
	//rss3
	$('#rss3').rssfeed('http://www.ansa.it/web/notizie/rubriche/topnews/topnews_rss.xml', {
		header: false,
		titletag: 'h6',
		content: false,
		linktarget: '_blank',
		showerror: true,
		errormsg: 'Feed momentaneamente non disponibile!',
		limit: 4
	});
	
	// Create the dropdown base - responsive nav
	$("#menu select.mobile-navigation").change(function() {
  		window.location = $(this).find("option:selected").val();
	});
						
});//end

//equalHeight Function
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
			if(thisHeight > tallest) {
				tallest = thisHeight;
			}
	});
	group.height(tallest);
}

//go up
$(function () {
	var scroll_timer;
	var displayed = false;
	var $message = $('#message a');
	var $window = $(window);
	var top = $(document.body).children(0).position().top;
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () {
			if($window.scrollTop() <= top)
			{
				displayed = false;
				$message.fadeOut(500);
			}
			else if(displayed == false)
			{
				displayed = true;
				$message.stop(true, true).show().click(function () { $message.fadeOut(500); });
			}
		}, 100);
	});
});
