$(function(){
  
  if ($("#slider").length > 0) {
    $('#slider').nivoSlider({
      effect:'random', // Specify sets like: 'fold,fade,sliceDown'
      animSpeed: 500, // Slide transition speed
      pauseTime: 5000,
      directionNav:false
    });
  }
  
  /* Slider Natale 2011 */
/*  if ($("#c2909").length > 0) {
    $('#c2909').nivoSlider({
      effect:'random', // Specify sets like: 'fold,fade,sliceDown'
      animSpeed: 500, // Slide transition speed
      pauseTime: 5000,
      directionNav:false
    });
  }
*/
  /****/
  
  if ($("#user_autookay_pi1-type").length > 0) { 
    // bind change event to select
    $('#user_autookay_pi1-type').bind('change', function () {
        var url = $(this).val(); // get selected value
        if (url) { // require a URL
            window.location = url; // redirect
        }
        return false;
    });
  }
  

  if ($("#carousel-cars-container").length > 0) { 
	  jQuery('#carousel-cars').jcarousel({
	    scroll: 8,
	    animation: 'slow'
	  });
  }

  
  // Nella pagina del dettaglio veicolo
  // Attiviamo il fancybox sulle immagini del veicolo
  if ($(".tx-dddamgallery-pi1").length > 0) {  
  	// Apply fancybox to multiple items
  	$("a.fancybox").fancybox({
  		'transitionIn'	:	'elastic',
  		'transitionOut'	:	'elastic',
  		'speedIn'		:	600, 
  		'speedOut'		:	300, 
  		'overlayShow'	:	true,
  		'titlePosition' : 'over',
      'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
        return '<div id="fancybox-title-' + currentOpts.titlePosition + '"><strong>'+title+'</strong><br />Immagine '+(currentIndex + 1)+' di '+currentArray.length+'</div>';
      }
  	});
  }
  
  if ($("#link-info-popup").length > 0) {  
    $('#link-info-popup').click(function() {
      newwindow=window.open($(this).attr('href'),'','height=380,width=380');
      if (window.focus) {newwindow.focus()}
      return false;
    });
    
    /*$('#link-info-popup').live('click', function(){
      newwindow=window.open($(this).attr('href'),'','height=350,width=350');
      if (window.focus) {newwindow.focus()}
      return false;
    });*/
  }
  
});

