$(document).ready(function() {

  // Script per Spotlight

	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	$(".image_reel").css({'width' : imageReelWidth});
	
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; 
		var image_reelPosition = triggerID * imageWidth; 

		$(".paging a").removeClass('active'); 
		$active.addClass('active'); 
		
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	rotateSwitch = function(){		
		play = setInterval(function(){ 
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { 
				$active = $('.paging a:first'); 
			}
			rotate(); 
		}, 8000); //Timer
	};
	
	rotateSwitch();
	
	$(".image_reel a").hover(function() {
		clearInterval(play);
	}, function() {
		rotateSwitch();
	});	
	
	$(".paging a").click(function() {	
		$active = $(this);
		clearInterval(play); 
		rotate(); 
		rotateSwitch(); 
		return false; 
	});
	
	
	
	// Script per campo ricerca
	var defaultValueSearch = $("#form_search_text").val();
	$("#form_search_text").focus(function() {
  	if ($(this).val() == defaultValueSearch) {
      $(this).val("");
    }
  });
  $("#form_search_text").blur(function() {
    if ($(this).val() == "") {
      $(this).val(defaultValueSearch);
    }
  });
  


	// Script per campo newsletter
	var defaultValueSubscribe = $('#form_subscribe_text').val();
	$("#form_subscribe_text").focus(function() {
  	if ($(this).val() == defaultValueSubscribe) {
      $(this).val("");
    }
  });
  $("#form_subscribe_text").blur(function() {
    if ($(this).val() == "") {
      $(this).val(defaultValueSubscribe);
    }
  });
  

	// Script per link sui bottoni
  $('a.option_add').click(function (event) { 
     event.preventDefault();
	});
  
});
