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

function main(context) {
	//alert('Ready!');
	
	//TARGET _BLANK
	$("a._blank",context).click(function(){this.target="_blank";});
	
	//NASCONDI ADVICE
	$("span.close").click(function(){$(this).parent().parent().hide("slow");});
	$("div.info").click(function(){$("div.info").hide("slow");});
	if ($("div.info").html()){setTimeout('$("div.info").fadeOut("slow");',5000);}
	
	//DISABILITO IL TASTO DESTRO PER LE IMMAGINI DELLA PAGINA
	$("img",context).bind("contextmenu",function(e){return false;});
	
	//SLIDESHOWS
	$("#slideshows img",context).imgpreload(function(){
		//ATTIVO LO SLIDESHOW
		$("#slideshows",context).cycle({ 
			fx:     	'fade', 
			speed:  	2000, 
			timeout: 	2000,
			cssAfter:   "currentSlide",
			//cleartype:     !$.support.opacity,
			cleartypeNoBg: false
		});
	});
	
	//FANCYBOX
	/*$("a.fancyimage").click(function(event){
		event.preventDefault;
		
		$.fancybox({
			'transitionIn'	: 	'elastic',
			'transitionOut'	: 	'elastic',
			'easingIn'      : 	'easeOutBack',
			'easingOut'     : 	'easeInBack',
			'title'			: 	$(this).find(".particular_text").html(),
			'href'			:	this.href,
			'overlayShow'	: 	true,
			'overlayOpacity': 	0.7,
			'overlayColor'	: 	'#000',
			'cyclic'		:	true,
			'titlePosition'	: 	'over',
			'onStart'		:	function(index) {
				//console.log(this.index);
				//this.title = $(event).find(".particular_text").html();
			},
			'onComplete'	:	function() {
				/*$("#fancybox-wrap").hover(function() {
					$("#fancybox-title").fadeIn("fast");
				}, function() {
					$("#fancybox-title").fadeOut("fast");
				});*
			}
		});
		
		return false;
	});*/
	
	$("a.fancyimage",context).fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#CCCB35',
		'speedIn'		:	500,
		'speedOut'		:	500,
		'cyclic'		:	true,
	});
	$("a.fancycontent",context).fancybox();
	$("a.fancyplayer",context).fancybox();
	
	$("a.fancyyoutube",context).each(function(event){
		$(this).fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'overlayOpacity':	0.7,
			'overlayColor'	:	'#CCCB35',
			'speedIn'		: 500,
			'speedOut'		: 500,
			'title'			: $(this).title,
			'width'			: 680,
			'height'		: 495,
			'href'			: $(this).attr("href").replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
				'wmode'				: 'transparent',
				'allowfullscreen'	: 'true',
				'autoplay		'	: 'true',
				'loop'				: 'true'
			}
		});
	});
	
	$("#company",context).fancybox({
		'autoDimensions':	false,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#CCCB35',
		'speedIn'		:	500,
		'speedOut'		:	500,
		'width'			:	300,
		'height'		:	400
	});
	$("#privacy",context).fancybox({
		'autoDimensions':	false,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#CCCB35',
		'speedIn'		:	500,
		'speedOut'		:	500,
		'width'			:	300,
		'height'		:	400
	});

	var gmap = '<iframe id="gmap" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.it/maps/ms?hl=it&amp;ie=UTF8&amp;msa=0&amp;msid=116483863102582381700.0004891302deca71d31a9&amp;ll=45.125158,10.8654&amp;spn=0.222856,0.356369&amp;iwloc=0004891302e1f3265b941&amp;output=embed"></iframe>';
	$("#gmap_link",context).fancybox({
		'padding'		: 0,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'overlayOpacity':	0.7,
		'overlayColor'	:	'#CCCB35',
		'speedIn'		:	500,
		'speedOut'		:	500,
		'content'		:	gmap,
		'onStart'		: 	function(element){
				//do something...
			}
	});
		
		
		
	//PAGINAZIONE
	//$("#gallery").paginate();
	/*$('#gallery, #category').pager('div.pager', {
		navId: 'pagination',
		highlightClass: 'current'
	});*/

	//EFFETTI DELLA GALLERY
	$("a.image_frame",context).hoverIntent(
	  function () {
		$(this).animate({
    		opacity: 1
  		}, 'fast', function() {
    		// Animation complete.
  		});
		
		//$(this).find(".caption").slideDown('fast');
		
		$(this).find("img").animate({
    		width: '78px',
			height: '78px',
			top: '0px',
			left: '0px'
  		}, 'fast', function() {
    		// Animation complete.
  		});
		
		$(this).find(".greyscale").fadeOut();
	  }, 
	  function () {
		$(this).animate({
    		opacity: 0.7
  		}, 'fast', function() {
    		// Animation complete.
  		});
		
		//$(this).find(".caption").slideUp('fast');
		
		$(this).find("img").animate({
    		width: '180px',
			height: '180px',
			top: '-73px',
			left: '-73px'
  		}, 'fast', function() {
    		// Animation complete.
  		});
		
		$(this).find(".greyscale").fadeIn();
	  }
	);
	
	//SCROLLBAR
	/*$('.scrollpanel').jScrollPane({
		scrollbarWidth: 5,
		scrollbarMargin: 10
	});*/
	
	//VALIDAZIONE DELLE FORM
	$("form",context).each(function(){
			$(this).validate({
				submitHandler: function(form) {
				//form.submit();		//submit in postback
				formSubmit(form);		//submit in ajax
				return false;
			}
		});
	});
	
	//RESET DEI CAMPI DELLA FORM DEI CONTATTI
	$("#reset",context).click(
		function () {
			$(this).parent("form").clearForm();
    	}
	);
}


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