$(document).ready(function(){

	

	/* Zoom Icon */

	$(function(){

		$(".zoom a").append("<span></span>");

		$(".zoom a").hover(function(){

			$(this).children("img").stop(true, true).animate({opacity:0.7},300);

			$(this).children("span").stop(true, true).fadeIn(300);

		},function(){

			$(this).children("img").stop(true, true).animate({opacity:1},250);

			$(this).children("span").stop(true, true).fadeOut(250);

		});

	});

	/* End Zoom Icon */

	

	/* News Toggler */

	$(function(){

		$(".collapsible-content").hide();

		$('.news-trigger').toggle(

			function() {

				$(this).toggleClass("opened").parent().next().slideDown();

				$(this).html('Riduci <img src="img/button-arrow-up.png" alt="" class="collapse-arrow-up">');

			},

			function() {

				$(this).toggleClass("opened").parent().next().slideUp();

				$(this).html('Espandi e Leggi');

			}

		);

	});

	/* End News Toggler */

	

	/* Archive Toggler */

	jQuery(function(){

		$('.archive-trigger').toggle(

			function() {

				$(this).next().next().slideUp().parent().toggleClass("closed");

				$(this).html('<img src="img/collapse-button-down.png" alt="" />');

			},

			function() {

				$(this).next().next().slideDown().parent().toggleClass("closed");

				$(this).html('<img src="img/collapse-button-up.png" alt="" />');

			}

		);

	});

	/* End Archive Toggler */



});





$(document).ready(function(){

/* Input Placeholder for All Browsers */

	$('[placeholder]').focus(function() {

		var input = $(this);

		if (input.val() == input.attr('placeholder')) {

			input.val('');

			input.removeClass('placeholder');

		}

		}).blur(function() {

			var input = $(this);

			if (input.val() == '' || input.val() == input.attr('placeholder')) {

				input.addClass('placeholder');

				input.val(input.attr('placeholder'));

			}

		}).blur().parents('form').submit(function() {

		$(this).find('[placeholder]').each(function() {

			var input = $(this);

				if (input.val() == input.attr('placeholder')) {

				input.val('');

			}

		})

	});

	/* End Input Placeholder for All Browsers */

});	



/***************************************************

		  DROPDOWN MENU

***************************************************/

/* Navigation Dropdowns */

$(document).ready(function(){

	$("#nav li li").hover(

		function () {

			$(this).parents("li").addClass("hover");

		},

		function () {

			$(this).parents("li").removeClass("hover");

		}

	);

});	

	/* End Navigation Dropdowns */







(function($){ 		  

	$.fn.popupWindow = function(instanceSettings){

		

		return this.each(function(){

		

		$(this).click(function(){

		

		$.fn.popupWindow.defaultSettings = {

			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left

			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left

			height:500, // sets the height in pixels of the window.

			left:0, // left position when the window appears.

			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.

			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.

			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.

			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.

			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.

			width:500, // sets the width in pixels of the window.

			windowName:null, // name of window set from the name attribute of the element that invokes the click

			windowURL:null, // url used for the popup

			top:0, // top position when the window appears.

			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.

		};

		

		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});

		

		var windowFeatures =    'height=' + settings.height +

								',width=' + settings.width +

								',toolbar=' + settings.toolbar +

								',scrollbars=' + settings.scrollbars +

								',status=' + settings.status + 

								',resizable=' + settings.resizable +

								',location=' + settings.location +

								',menuBar=' + settings.menubar;



				settings.windowName = this.name || settings.windowName;

				settings.windowURL = this.href || settings.windowURL;

				var centeredY,centeredX;

			

				if(settings.centerBrowser){

						

					if ($.browser.msie) {//hacked together for IE browsers

						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));

						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));

					}else{

						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));

						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));

					}

					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();

				}else if(settings.centerScreen){

					centeredY = (screen.height - settings.height)/2;

					centeredX = (screen.width - settings.width)/2;

					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();

				}else{

					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	

				}

				return false;

			});

			

		});	

	};

	

	// News Ticker che si interrompe all'hover dell'utente



$(function() {

	  

		//cache the ticker

		var ticker = $("#ticker");

		  

		//wrap dt:dd pairs in divs

		ticker.children().filter("dt").each(function() {

		  

		  var dt = $(this),

		    container = $("<div>");

		  

		  dt.next().appendTo(container);

		  dt.prependTo(container);

		  

		  container.appendTo(ticker);

		});

				

		//hide the scrollbar

		ticker.css("overflow", "hidden");

		

		//animator function

		function animator(currentItem) {

		    

		  //work out new anim duration

		  var distance = currentItem.height();

			duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;



		  //animate the first child of the ticker

		  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {

		    

			//move current item to the bottom

			currentItem.appendTo(currentItem.parent()).css("marginTop", 0);



			//recurse

			animator(currentItem.parent().children(":first"));

		  }); 

		};

		

		//start the ticker

		animator(ticker.children(":first"));

				

		//set mouseenter

		ticker.mouseenter(function() {

		  

		  //stop current animation

		  ticker.children().stop();

		  

		});

		

		//set mouseleave

		ticker.mouseleave(function() {

		          

          //resume animation

		  animator(ticker.children(":first"));

		  

		});

	  });









/* Trips Viewer Tabs */

	$(function() {

		$(".tab-content").hide();

		$("ul.tabs-nav li:first").addClass("active").show();

		$(".tab-content:first").show();

	

		$("ul.tabs-nav li").click(function() {

	

			$("ul.tabs-nav li").removeClass("active");

			$(this).addClass("active");

			$(".tab-content").hide();

	

			var activeTab = $(this).find("a").attr("href");

			$(activeTab).fadeIn();

			return false;

		});

	});

	/* End Trips Viewer Tabs */







/***************************************************

		FORM VALIDATION JAVASCRIPT

***************************************************/

/*	$(document).ready(function() {

$('form#contact_form').submit(function() {

		$('form#contact_form .error').remove();

		var hasError = false;

		$('.requiredField').each(function() {

			if(jQuery.trim($(this).val()) == '') {

            	var labelText = $(this).prev('label').text();

            	$(this).parent().append('<span class="error">Inserisci il campo '+labelText+'</span>');

            	$(this).addClass('inputError');

            	hasError = true;

            } else if($(this).hasClass('email')) {

            	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

            	if(!emailReg.test(jQuery.trim($(this).val()))) {

            		var labelText = $(this).prev('label').text();

            		$(this).parent().append('<span class="error">Campo '+labelText+' errato</span>');

            		$(this).addClass('inputError');

            		hasError = true;

            	}

            }

		});

		if(!hasError) {

			$('form#contact_form input.submit').fadeOut('normal', function() {

				$(this).parent().append('');

			});

			var formInput = $(this).serialize();

			$.post($(this).attr('action'),formInput, function(data){

				$('form#contact_form').slideUp("fast", function() {

					$(this).before('<p class="success">Grazie! Email inviata. Ti risponderemo il prima possibile.</p>');

				});

			});

		}



		return false;



	});

});*/







})(jQuery);
