var mainMenuLastClicked = null;
var colMenuLastClicked = null;

function initWebnewsBlog()
{
	/*
	var link;
	jQuery( "#footer-blog-link > ul > li > a").css( "background", "url('" + blogThemeUrl + "/images/footer-blog-link-list-style-icon.gif') no-repeat bottom center" );
	jQuery( "#footer-blog-link > ul > li > a").click( toggleFooterClick );
	jQuery( "<a id='toggle-footer-content' href='#' title='Apri'>Apri</a>" ).prependTo( "#footer-blog-link" );
	link = jQuery( "#toggle-footer-content" );
	link.click( toggleFooterClick );
	link.attr( "class", "closed" );
	* */
	//jQuery( ".column-content-inner" ).hide();
	//jQuery( "#column-content" ).hide();
	//jQuery( "#column-menu > li > a" ).click( columnMenuClick );
	//jQuery( ".column-close > a" ).click( hideColumnContent );
	//jQuery( ".last-news-content" ).hide();
	//jQuery( "#last-news-title").css( "background-image", "url('layout/bg-last-news-closed.png')" );

	//jQuery( "<a id='toggle-news-content' href='#' title='apri'>apri</a>" ).prependTo( "#last-news-title" );
	//link = jQuery( "#toggle-news-content" );
	//link.click( toggleNewsClick );
	//link.attr( "class", "closed" );


	//jQuery( "#tabs-navigator > li > a" ).click( tabNavigatorClick );
	//jQuery( "#video-list" ).hide();
	//jQuery( "#download-list" ).hide();

	jQuery( 'a[rel="external"]' ).click( openExternalLink );
	jQuery( '.share-on-facebook a' ).click( shareOnFacebook );
}

/**
 * Associato ad un tag <a>, ne apre il link in una nuova finestra
**/
function openExternalLink()
{
	window.open( jQuery( this ).attr( 'href' ) );
	return false;
}

function changeNetworkSite()
{
	var _value = jQuery("select#sel-networksite").val();
	if(_value == "") {
		return false;
	} else {
		window.location.href = _value + '/';
	}
}
function tabNavigatorClick()
{
	jQuery( ".tabs-container > div" ).hide();
	jQuery( "#" + jQuery( this ).attr( "class" ).split("-link").join("") ).show();
	jQuery( "#tabs-navigator > li > span" ).each(
		function()
		{
			jQuery( this ).parent().html( spanToLink( jQuery( this ) ) );
		}
	);
	jQuery( this ).parent().html( linkToSpan( jQuery( this ) ) );
	jQuery( "#tabs-navigator > li > a" ).click( tabNavigatorClick );
	return false;
}
function linkToSpan( link )
{
	var style = link.attr( "class" );
	var value = link.html();
	return "<span class='" + style + "'>" + value + "</span>";
}
function spanToLink( span )
{
	var style = span.attr( "class" );
	var value = span.html();
	return "<a class='" + style + "' href='#' title='" + value + "'>" + value + "</a>";
}
function toggleNewsClick()
{
	var content = jQuery( this ).parent().parent().children(".last-news-content");
	var visible = content.css( "display" ) != "none";
	var link = jQuery( this );
	if( visible ){
		content.hide();
		jQuery( "#last-news-title").css( "background-image", "url('images/bg-last-news-closed.png')" );
		link.attr( "class", "closed" );
		link.attr( "title", "apri" );
		link.html( "apri" );
	} else {
		content.show();
		jQuery( "#last-news-title").css( "background-image", "url('images/bg-last-news-opened.png')" );
		link.attr( "class", "opened" );
		link.attr( "title", "chiudi" );
		link.html( "chiudi" );
	}
	return false;
}
function toggleFooterClick()
{
	var content = jQuery( "#footer-blog-content" );
	var visible = content.css( "display" ) != "none";
	var openlink = jQuery( "#toggle-footer-content" );
	if( visible ){
		content.hide();
		openlink.attr( "class", "closed" );
		openlink.attr( "title", "Apri" );
		openlink.html( "Apri" );
	} else {
		content.show();
		openlink.attr( "class", "opened" );
		openlink.attr( "title", "Chiudi" );
		openlink.html( "Chiudi" );
		window.scrollTo( 0, 5000 );
	}
	return false;
}
function mainMenuClick()
{
	var mainMenu = jQuery( "#main-menu-content" );
	if( mainMenuLastClicked == this ){
		mainMenu.slideUp();
		mainMenuLastClicked = null
	} else {
		if( mainMenuLastClicked == null ){
			mainMenu.slideDown();
		}
		mainMenuLastClicked = this;
	}
}
function columnMenuClick()
{
	var showing = jQuery( this ).parent().attr( "class" ).split( "menu" ).join( "content" );
	if( colMenuLastClicked == showing){
		hideColumnContent();
	} else {
		jQuery( "#column-menu > li > a" ).attr( "class", "" );
		jQuery( this ).attr( "class", "selected" );
		showColumnContent( showing );
	}
	return false;
}
function showColumnContent( id )
{
	jQuery( ".column-content-inner" ).hide();
	jQuery( "#column-content" ).show();
	jQuery( "#" + id ).show();
	jQuery( "#column-menu" ).css( "background-image", "url('images/bg-column-menu-opened.png')" );
	colMenuLastClicked = id;
}
function shareOnFacebook()
{
	var u = location.href;
	var t = document.title;
	window.open
	(
		'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t),
		'sharer','toolbar=0,status=0,width=626,height=436'
	);
	return false;
}
$.noConflict();
jQuery( document ).ready( initWebnewsBlog );