// JavaScript Document
$(document).ready(function(){
	main("body");
});

function main(context){
	
	/* Intercettazione dei link */
	$("a.ajax",context).catchLink();
	
	/* Intercettazione delle form */
	$('#newsletter_form',context).ajaxForm({
		dataType 		: 'xml',
		beforeSubmit 	: 	function(data, form, options){
						        if($(form).validate()) {
									$('#result').html('<img src="Site/Theme/Images/loader.gif" alt="" /img>&nbsp;<span>Attendere prego...</span>');
									return true;
								} return false;
						    },
		success			: 	function(data){
				                $.handleResponseData(data);
				            }
	});
	
	/* Intercettazione delle form */
	/*$('#contacts_form',context).ajaxForm({
		dataType 		: 'xml',
		beforeSubmit 	: 	function(data, form, options){
								console.log($(form).validate());
								if($(form).validate()) {
									$('#result').html('<img src="Site/Theme/Images/loader.gif" alt="" /img>&nbsp;<span>Attendere prego...</span>');
									return true;
								} return false;
						    },
		success			: 	function(data){
				                $.handleResponseData(data);
				            }
	});*/
	
	$('#contacts_form',context).validate({
		submitHandler: function(form) {
		   $(form).ajaxForm({
				dataType 		: 'xml',
				beforeSubmit 	: 	function(data, form, options){
			   							$('#result').html('<img src="Site/Theme/Images/loader.gif" alt="" /img>&nbsp;<span>Attendere prego...</span>');
								    },
				success			: 	function(data){
						                $.handleResponseData(data);
						            }
			});
		}
	});
	
	$('a.image_link',context).fancybox({
		zoomSpeedIn 		: 300,
		zoomSpeedOut		: 300,
		hideOnContentClick	: false,
		overlayShow			: true,
		overlayOpacity		: 0.7
	});
	
	$('a.fancycontent',context).fancybox({
		zoomSpeedIn 		: 300,
		zoomSpeedOut		: 300,
		hideOnContentClick	: true,
		overlayShow			: true,
		overlayOpacity		: 0.7,
		frameWidth			: 400,
		frameHeight			: 330,
		cyclic				: true
	});
}


function ltIE7() {
	var semaphore;
	semaphore = !$.browser.msie || ($.browser.msie && ($.browser.version > 6));
	
	return semaphore;
}
