$(document).ready(function(){


$('.window').draggable().hide();

$("#fancy_outer").draggable();
$("#fancy_outer").css('z-index', '1000');

$('.close').text('X');

$('.close').click(
	function(){
		$(this).parent('.window').hide('normal');
	}
);

/* portfolio popups launch */
$('.btn').click(function(){

	var active = '#' + $(this).attr("id") + 'stuff';
	
	if($(active).is(':visible')){
		$(active).hide('normal');
	} else {
		switch(active){
			case '#infostuff':
			$(active).css({
				'top' : '60px',
				'left' : '20px'
			});
			break;
					
			case '#webstuff':
			$(active).css({
				'top' : '120px',
				'left' : '40px'
			});
			$('.t4').remove();
			break;
			
			case '#grastuff':
			$(active).css({
				'top' : '80px',
				'left' : '80px'
			});
			break;
			
			case '#fotstuff':
			$(active).css({
				'top' : '40px',
				'left' : '120px'
			});
			break;
		}

		$('.window').not(active).css('z-index', '10');
		$(active).css('z-index', '100').show('normal');
	
	}
	
	/*$('body').append('<span id="findout"></span>');
	$('#findout').html(active);*/
	
});


/* contatti footer */
$('#contfoot').click(function(){
	if($('#infostuff').is(':visible')){
		$('#infostuff').hide('normal');
	} else {
		$('.window').not('#infostuff').css('z-index', '10');
		$('#infostuff').css({
			'top' : '60px',
			'left' : '20px',
			'z-index' : '100'
		}).show('normal');
	}
		
});


/* on top windows */
$('.window').mousedown(
	function() {
		$(this).css('z-index', '100');
		$('.window').not(this).css('z-index', '10');
	}	
);

$('#webstuff a').not('.nav').prepend("\\\\");
$('#webstuff a').not('.nav').hover(
	function() {
		$(this).after('<span class="t4">&emsp;&there4;</span>');
	},
	function() {
		$(this).nextAll('.t4:eq(8)').remove();
	}
);

$('#info').tooltip({
	track: true,
	delay: 0,
	fade: 200,
	showURL: false,
	fixPNG: true,
	extraClass: "infotip",
	top: 20,
	left: 0
});

$('#webstuff a').tooltip({
	track: true,
	delay: 0,
	fade: 200,
	showURL: false,
	fixPNG: true,
	top: -100,
	left: 10
});

$('#infostuff a').tooltip({
	track: true,
	delay: 0,
	fade: 200,
	showURL: false,
	fixPNG: true,
	extraClass: "linktip",
	top: -57,
	left: -16
});



$('#grastuff a').fancybox();


/*flickr*/
$("#flickr").flickr({
	api_key: "d0b0d5515f99cb8fa485d75ce7a6780b",
	type: "search",
	user_id: "36203317@N04",
	per_page: 18,
	page: 1,
	sort: 'date-posted-desc',
	randomise: true,
	cutoff: 40,
	attr: 'rel="gruppo-flickr"',
	callback: fancyboxCallback
});
function fancyboxCallback(){
	$('#flickr li a').fancybox();
};



// Form validation & Send email!

$('#contact_form form').validate({

	messages:
	    {
			nome: "Obbligatorio! Inserisci un nome!",
			contatto: "Inserisci un indirizzo email valido!",
			messaggio: "Scrivi qualcosa!"
	    },
	

	submitHandler: function(form) {

		var dataString = $('#contact_form form').formSerialize(); 
		
		$.ajax({  
			type: "POST",  
			url: "email.php",  
			data: dataString,  
			success: function() {
				$('#contact_form').html("<div id='message'></div>");  
				$('#message').html("<h4 style='margin-bottom: 0;'>messaggio inoltrato</h4>").append("<p>una risposta sar&agrave; inviata appena possibile.</p>").hide().fadeIn('slow');
			}  
		});  
		return false;
	
	}
});

/*
$('.error').hide();

$("#submit").click(function() {

$('.error').hide();

var errorclass = {
	'border' : '1px solid red',
	'background' : '#ffcbcb',
	'color' : '#000',
	'margin-bottom' : '.5em'
}

	var nome = $("input#nome").val();
if (nome == "") {
    $("label#nome_err").show();
    $("input#nome").css(errorclass).focus();
    return false;
}
	
var contatto = $("input#contatto").val();
if (contatto == "") {
    $("label#contatto_err").show();
    $("input#contatto").css(errorclass).focus();
    return false;
}

var messaggio = $("textarea#messaggio").val();
if (messaggio == "") {
    $("label#messaggio_err").show();
    $("textarea#messaggio").css(errorclass).focus();
    return false;
}

var dataString = 'nome=' + nome + '&contatto=' + contatto + '&messaggio=' + messaggio;  
	//alert (dataString);return false;
	$.ajax({  
	type: "POST",  
	url: "email.php",  
	data: dataString,  
	success: function() {
		$('#contact_form').html("<div id='message'></div>");  
		$('#message').html("<h4 style='margin-bottom: 0;'>messaggio inoltrato</h4>").append("<p>una risposta sar&agrave; inviata appena possibile.</p>").hide().fadeIn('slow');
	}  
});  
return false;  

});
*/


// webscrolling
$('#webscroll').serialScroll({
	items: '.item',
	next: '.nav',
	duration: 600,
	easing: 'easeInOutQuint',
	constant: false
});

});