// Fancybox+BlockUI

$(document).ready(function(){

	var preventClick=false;
	
	$(".pic a").bind("click",function(e){
		/* This function stops the drag from firing a click event and showing the lightbox */
		if(preventClick)
		{
			e.stopImmediatePropagation();
			e.preventDefault();
		}
	});

	$(".pic").draggable({
		/* Converting the images into draggable objects */
		containment: 'parent',
		start: function(e,ui){
			/* This will stop clicks from occuring while dragging */
			preventClick=true;
		},
		
		stop: function(e, ui) {
			/* Wait for 250 milliseconds before re-enabling the clicks */
			setTimeout(function(){ preventClick=false; }, 250);
		}
	});


	$('.pic').mousedown(function(e){
								 
		/* Executed on image click */
		
		var maxZ = 0;
		
		/* Find the max z-index property: */
		
		$('.pic').each(function(){
			var thisZ = parseInt($(this).css('zIndex'))
			if(thisZ>maxZ) maxZ=thisZ;
		});
		
		/* Clicks can occur in the picture container (with class pic) and in the link inside it */
		if($(e.target).hasClass("pic"))
		{
			/* Show the clicked image on top of all the others: */
			$(e.target).css({zIndex:maxZ+1});
		}
		else $(e.target).closest('.pic').css({zIndex:maxZ+1});
	});
	
	/* Converting all the links to a fancybox gallery */
	$("a.fancybox").fancybox({
		zoomSpeedIn: 300,
		zoomSpeedOut: 300,
	//'overlayShow'			: false,
	});
	
	/* Converting the share box into a droppable: */
	$('.drop-box').droppable({
		hoverClass: 'active',
		drop:function(event,ui){
			/* Fill the URL text field with the URL of the image. */
			/* The id of the image is appended as a hash #pic-123 */
			$('#url').val(location.href.replace(location.hash,'')+'#'+ui.draggable.attr('id'));
			$('#modal').dialog('open');
		}
	});

	/* Converts the div with id="modal" into a modal window  */
	$("#modal").dialog({
		bgiframe: true,
		modal: true,
		autoOpen:false,
		buttons: {
				Ok: function() {
					$(this).dialog('close');
				}
			}
	});
	
	if(location.hash.indexOf('#pic-')!=-1)
	{
		/* Checks whether a hash is present in the URL */
		/* and shows the respective image */
		$(location.hash+' a.fancybox').click();
	}
	
});


$(document).ready(function() {
	$("a#donate").bind("click", function() {
		$("#donate_form").submit();
		return false;
	});

	$("a#single_1").fancybox();
		
	$("a#single_2").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: false,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500
	});
	
	$("a#single_3").fancybox({
		//'overlayShow'			: false,
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack'
	});
	
	$("a.fancyhide").fancybox({
		'hideOnContentClick': false
	});

});






// BK Position Only Head

		var scrollSpeed = 20; 		// Velocita' in millisecondi
			var step = 1; 				// Quanti pixel muovere per ciascuno step
			var current = 0;			// La riga di pixel corrente
			var imageWidth = 3000;		// Larghezza immagine di Background
			var headerWidth =500;		// Larghezza header
			
			//La riga di pixel da cui far partire il loop
			var restartPosition = -(imageWidth - headerWidth);
			
			function scrollBg(){
				//Vai alla prossima riga di pixel
				current -= step;
				//Definisci il CSS della header
				$('.wrapperfx').css("background-position",current+"px 0");
			}
			
			//Chiama ciclicamente la funzione di scroll
			var init = setInterval("scrollBg()", scrollSpeed);
	
	//Setup Arrays that will hold the x,y,z of each element.
	var x = new Array();
	var y = new Array();
	var z = new Array();
	
	//Get the list of items.
	var items = $('ul.3d li');
	
	//Animate the items.
	function animate()
	{
		
		//Step through each item.
		for(i = items.length - 1; i >= 0; i--){
			
			
			//variables for movement.			
			var xVar = 30 + x[i] 			// x value
			var yVar = 10 + y[i] * z[i]++;	// y value, move towards bottom of screen
			var zVar = 10 * z[i]++;			// z value, text get larger.
			
			
			//Check to see if text position is still on the screen.
			// the #'s are %.   100 is far right or bottom, 0 is top or left.
			// for z value it's the font size in %.
			if (!xVar | xVar < 0 | xVar > 300| 
				yVar < 0 | yVar > 40 | 
				zVar < 0 | zVar > 500)
			{
				//if it's off the screen randomly pick a starting place.
				x[i]= Math.random() * 2 - 1;
				y[i] = Math.random() * 2 - 1;
				z[i] = 2; 
				
			}
			else
			{
				//if it's still on the screen apply the appropiate styles.
				
				$(items[i]).css("position", "absolute"); // make sure we can move the text around.
				$(items[i]).css("top", xVar+"%");  // y value
				$(items[i]).css("left", yVar+"%"); // x value
				
				$(items[i]).css("fontSize", zVar+"%"); // font size (illusion of perspective.)
				$(items[i]).css("opacity",(zVar)/1500); // fade in from the distance.
			}
		}
	
		setTimeout(animate, 100);
	}

animate();



// JQuery UpScroll  
  
$(document).ready(function(){ 
$('a.upscroll[href*=#]').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var $target = $(this.hash);         
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']'); if ($target.length) { var targetOffset = $target.offset().top;              
$('html,body').animate({scrollTop: targetOffset}, 1000); return false; } } });});
              

