jQuery(document).ready(function(){
	$('ul#scrollticker').show(); 
	$('ul#scrollticker').liScroll(); 

  $('.newstxt.expandable').expander({
    slicePoint:       190,  // the number of characters at which the contents will be sliced into two parts. 
                            // Note: any tag names in the HTML that appear inside the sliced element before 
                            // the slicePoint will be counted along with the text characters.
    widow:            4,  // a threshold of sorts for whether to initially hide/collapse part of the element's contents. 
                          // If after slicing the contents in two there are fewer words in the second part than 
                          // the value set by widow, we won't bother hiding/collapsing anything.

    expandText:         '[mostra&nbsp;tutto&nbsp;&raquo;]', // default is 'read more...'
    //expandText:       'read more', // text displayed in a link instead of the hidden part of the element. 
                                      // clicking this will expand/show the hidden/collapsed text

    expandPrefix:     '&hellip; ',
    collapseTimer:    0, // number of milliseconds after text has been expanded at which to collapse the text again
    expandEffect:     'show',
    expandSpeed:      '',   // speed in milliseconds of the animation effect for expanding the text
    userCollapse:     true, // allow the user to re-collapse the expanded text.

    userCollapseText: '[&laquo;&nbsp;contrai]',  // default is '[collapse expanded text]'
    //userCollapseText: '[collapse expanded text]',  // text to use for the link to re-collapse the text

    userCollapsePrefix: ' ',
    onInit: function (element) {
      $(element).parent('.newsbox').children('.expandable').find('span.read-more a').attr('class', 'read-more-href');

      $(element).parent('.newsbox').children('.newstitle').unbind('click');
      $(element).parent('.newsbox').children('.newstitle').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.read-more a.read-more-href').click();});
      $(element).parent('.newsbox').children('.newstxt').unbind('click');
      $(element).parent('.newsbox').children('.newstxt').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.read-more a.read-more-href').click();});

      if ($(element).parent('.newsbox').children('.attachbox-inside') && $(element).parent('.newsbox').children('.attachbox-inside').html()) $(element).parent('.newsbox').children('.expandable').find('span.read-more a').before('<span>' + $(element).parent('.newsbox').children('.attachbox-inside').html() + '</span>');
      $(element).parent('.newsbox').children('.attachbox-outside').hide();
    },
    afterExpand: function (element) {
      $(element).parent('.newsbox').children('.newstitle').unbind('click');
      $(element).parent('.newsbox').children('.newstitle').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.re-collapse a').click();});
      $(element).parent('.newsbox').children('.newstxt').unbind('click');
      $(element).parent('.newsbox').children('.newstxt').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.re-collapse a').click();});

      $(element).parent('.newsbox').children('.attachbox-outside').show();
    },
    onCollapse: function (element) {
      $(element).parent('.newsbox').children('.newstitle').unbind('click');
      $(element).parent('.newsbox').children('.newstitle').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.read-more a.read-more-href').click();});
      $(element).parent('.newsbox').children('.newstxt').unbind('click');
      $(element).parent('.newsbox').children('.newstxt').click(function(){$(this).parent('.newsbox').children('.expandable').find('span.read-more a.read-more-href').click();});

      $(element).parent('.newsbox').children('.attachbox-outside').hide();
    }
  });

  $('.curriculum.expandable').expander({
    slicePoint:       80,  // the number of characters at which the contents will be sliced into two parts. 
                            // Note: any tag names in the HTML that appear inside the sliced element before 
                            // the slicePoint will be counted along with the text characters.
    widow:            4,  // a threshold of sorts for whether to initially hide/collapse part of the element's contents. 
                          // If after slicing the contents in two there are fewer words in the second part than 
                          // the value set by widow, we won't bother hiding/collapsing anything.

    expandText:         '[mostra&nbsp;tutto&nbsp;&raquo;]', // default is 'read more...'
    //expandText:       'read more', // text displayed in a link instead of the hidden part of the element. 
                                      // clicking this will expand/show the hidden/collapsed text

    expandPrefix:     '&hellip; ',
    collapseTimer:    0, // number of milliseconds after text has been expanded at which to collapse the text again
    expandEffect:     'show',
    expandSpeed:      '',   // speed in milliseconds of the animation effect for expanding the text
    userCollapse:     true, // allow the user to re-collapse the expanded text.

    userCollapseText: '[&laquo;&nbsp;contrai]',  // default is '[collapse expanded text]'
    //userCollapseText: '[collapse expanded text]',  // text to use for the link to re-collapse the text

    userCollapsePrefix: ' ',
    onInit: function (element) {
      $(element).parent().parent('.newsbox').unblind('click');
      $(element).parent().parent('.newsbox').click(function(){$(this).children().children('.expandable').find('span.read-more a').click();});
      $(element).parent().parent('.newsbox').css('cursor', 'pointer');
    },
    afterExpand: function (element) {
      $(element).parent().parent('.newsbox').unblind('click');
      $(element).parent().parent('.newsbox').click(function(){$(this).children().children('.expandable').find('span.re-collapse a').click();});
      $(element).parent().parent('.newsbox').css('cursor', 'pointer');
    },
    onCollapse: function (element) {
      $(element).parent().parent('.newsbox').unblind('click');
      $(element).parent().parent('.newsbox').click(function(){$(this).children().children('.expandable').find('span.read-more a').click();});
      $(element).parent().parent('.newsbox').css('cursor', 'pointer');
    }
  });

  $('a.fancy-selector').fancybox();

  $('#personaggi_regione_select, #personaggi_istituzione_select, #personaggi_posizione_select').change(function() {
    $('#personaggi_filter_form').submit();
  });

  $('#personaggi_filter_reset').click(function(){ document.location.href = '/personaggi'; });

  var url_anchor = $.url().attr('anchor');
  if (url_anchor)
  {
    var news_div = $('a[name=' + url_anchor + ']').parent().next().next();
    news_div.find('span.read-more a.read-more-href').click();
  }

  if ($('#header_username')) {
    $('#header_username').focus();
  }

  if ($('#login-auth-error-launch') && $('#login-auth-error')) {
    $('#login-auth-error-launch').fancybox({
      'transitionIn'		:	'elastic',
      'transitionOut'		:	'elastic',
      'speedIn'			:	600,
      'speedOut'			:	200,
      'width'			:	400,
      'height'			:	75,
      'autoDimensions'  : false
    });

    $('#login-auth-error-launch').click();
  }
});
