// JavaScript Document

function commonSetup () {
		//When you click on a link with class of poplight and the href starts with a # 
		$('a.poplight[href^=#]').click(function() {
			var popID = $(this).attr('rel');
			var popURL = $(this).attr('href'); 
			var query= popURL.split('?');
			var dim= query[1].split('&');
			var popWidth = dim[0].split('=')[1];
			$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) });
			
			centerPopup($('#' + popID));
			
			$('body').append('<div id="fade"></div>');
			$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();		
			return false;
		});	
		
		$('a.poplight[href^=#]').hover(function(){$(this).fadeTo("fast",0.50);$(this).fadeTo("fast",1.00);});
		
		$('.popClose').live('click touchstart', function() { //When clicking on the close or fade layer...
			$('#fade , .popup_block').fadeOut(function() {
				$('#fade, a.close').remove();  
			}); //fade them both out
			
			return false;
		});
}

function centerPopup(popup) {
	
	var marginTop = (popup.height() + 50) / 2 - 40;
	var marginLeft = (popup.width() + 20) / 2 - 220;
	
	popup.css({ 
		'margin-top' : -marginTop,
		'margin-left' : -marginLeft
	});
}

function quicksandItUp() {
	var i=1;
	$('div[id^=thumb]').each(function(index) {
		$(this).delay(i*100);
    	$(this).fadeIn(500);
		i++;
	});
}
