var is_share_fixed = false;

$(document).ready(function()
{
//jquery start
	$('#slides').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: true,                 // determines if default 'next'/'prev' controls are displayed
		speed: 400,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: 'next',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: 'prev',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: false,                    // determines if slides will move automatically
		pause: 3500,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'wpr_controls'  // class name to be used for the outer wrapper of the slideshow
	});
	$('#slides2').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: false,                 // determines if default 'next'/'prev' controls are displayed
		speed: 400,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: 'next',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: 'prev',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: false,                    // determines if slides will move automatically
		pause: 3500,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'wpr_controls'  // class name to be used for the outer wrapper of the slideshow
	});

	$('.slider').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: true,                 // determines if default 'next'/'prev' controls are displayed
		speed: 400,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: 'next',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: 'prev',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: false,                    // determines if slides will move automatically
		pause: 3500,                    // time between each slide transition (auto mode only)
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'wpr_controls'  // class name to be used for the outer wrapper of the slideshow
	});
	$('.sliderVisore').bxSlider({
		alignment: 'horizontal',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: true,                 // determines if default 'next'/'prev' controls are displayed
		speed: 600,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: '',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: '',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: true,                    // determines if slides will move automatically
		pause: 10000,                    // time between each slide transition (auto mode only)
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'wpr_controls'  // class name to be used for the outer wrapper of the slideshow
	});
	$('.sliderHome').bxSlider({
		pager: false,
		next_text: '',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: '',              // text to be displayed for the 'prev' control
		prev_image: ''                 // image to be used for the 'prev' control
	});
	$("a.print").click(function(){
		window.print();
	});
	
	$("a[rel=external]").attr("target","_blank");
	
	/* social sidebar */
	if ( $("#share-cnt .shareholder").length ) {
		var orig_sidebar_top = $('#share-cnt .shareholder').position().top;
		if ($.browser.webkit) {
			$('#share-cnt .shareholder').css({left: '-389px'});
		}
		else {
			$('#share-cnt .shareholder').css({left: '-390px'});
		}
	}

	$(window).scroll( function() {
		
		var viewportHeight = parseInt( $( window ).height() );	
		var pageScroll =  parseInt( $(document).scrollTop() );
		var global_wrapper_top = $('.scheda').position().top;

		if ( pageScroll > ($('.footer').position().top - 350) ) {
			
			if (is_share_fixed) {

				$('#share-cnt').css({position: 'absolute',top: '0'});
				if ($.browser.webkit) {
					$('#share-cnt .shareholder').css({top: ($('.footer').position().top - 650) + 'px',left: '-389px'});
				}
				else {
					$('#share-cnt .shareholder').css({top: ($('.footer').position().top - 650) + 'px',left: '-390px'});
				}
				is_share_fixed = false;
			}

		} else if (pageScroll > ($('.scheda').position().top + orig_sidebar_top - 20)  ) {

			$('#share-cnt').css({position: 'fixed',top: '0'});
			if ($.browser.webkit) {
				$('#share-cnt .shareholder').css({top: '20px',left: '-589px'});
			}
			else {
				$('#share-cnt .shareholder').css({top: '20px',left: '-590px'});
			}
			is_share_fixed = true;

		} else {

			if (is_share_fixed) {

				$('#share-cnt').css({position: 'absolute',top: '7px'});
				if ($.browser.webkit) {
					$('#share-cnt .shareholder').css({top: orig_sidebar_top + 'px',left: '-389px'});
				}
				else {
					$('#share-cnt .shareholder').css({top: orig_sidebar_top + 'px',left: '-390px'});
				}
				is_share_fixed = false;
			}

		}
	});

	treccani_resize();

	// window resizing
	$(window).resize(function() {
		treccani_resize();
	});
//jquery stop
});
function equalHeight(group) {
	tallest = 0;

	group.each(function() {
        if ($.browser.webkit) {
			//thisHeight = $(this).innerHeight()-55;
			thisHeight = $(this).height();
		}
		else {
			thisHeight = $(this).height();
		}
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
function equalHeight2() {
	thisHeightSx = $('#videoColsx');
	thisHeightDx = $('#actionColdx');
	/* applico a tutte le colonne la stessa altezza */
	tallest = 0;
	$(".box3Cols .boxElem164").each(function() {
		thisHeight = $(this).height();
		if ($.browser.webkit) {
			thisHeight = $(this).innerHeight();
			thisHeight = thisHeight-50;
		}
		if(thisHeight > tallest) {
			tallest = (thisHeight);
		}
	});
	$(".box3Cols .boxElem164").height(tallest);
	
	var highestCol = Math.max($('#videoColsx').height(),$('#actionColdx').height());
	diffToAdd = highestCol-tallest-50-54;
	tallest2 = tallest+diffToAdd;
	$(".box3Cols .boxElem164").height(tallest2);
	thisHeightSx.height(highestCol);
	thisHeightDx.height(highestCol);
}
function equalHeight3() {
	thisHeightSx = $('#videoColsx');
	thisHeightDx = $('#actionColdx');
	tallest = 0;
	var highestCol = Math.max($('#videoColsx').height(),$('#actionColdx').height());
	diffToAdd = highestCol-tallest-50-54;
	tallest2 = tallest+diffToAdd;
	thisHeightSx.height(highestCol);
	thisHeightDx.height(highestCol);
}
function tabs() {
	$('.tabStd > li').click(function(event) {
		$(this).parent('ul').children('li').removeClass('tabs-selected');
		event.preventDefault();
		var initlink = $(this).children('a').attr("href");
		var initlink = initlink.replace('#', '');
		$(this).addClass('tabs-selected');
		if ( $(this).parent('.tabStd').parent('.tabsCnt').length > 0 ){
			$(this).parent('.tabStd').parent('.tabsCnt').children('.tabBlock').css('display','none');
			$(this).parent('.tabStd').parent('.tabsCnt').children('#'+initlink).css('display','block');
		}
	}) 
}
function MenuDx() {
	if ($('#menuDx li').hasClass('sel')) {
		$('#menuDx li.sel > ul').show();
		if ($('#menuDx li.subsel').children('ul')) {
			$('#menuDx li.subsel > ul').show();
		}
	}
	$('#menuDx li a').click(function() {
		var checkElement = $(this).next();
		if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
			return false;
		}
		if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
			$('#menuDx ul:visible').hide();
			$('#menuDx li').removeClass('sel');
			checkElement.show();
			checkElement.parent('li').addClass("sel");
			return false;
		}
		else {
			$('#menuDx ul:visible').hide();
			$('#menuDx li').removeClass('sel');
			$(this).parent('li').addClass("sel");
		}
	});
}
function treccani_resize() {

	if ( $( window ).width() < 1160 ) {
		$('#share-cnt').hide();
	} else {
		$('#share-cnt').show();
	}
}
