$(document).ready(function() {

/*actions for intro page*/

$('a.legal').click(function(){

$('.popup').load('legal.php', function(){$('.popup').css('visibility','visible')});

return false;

});

$('.popup').click(function(){ $(this).css('visibility','hidden')});

//menu actions

$('a img').hover(
 			
 			function()
 			{ this.src = this.src.replace("_off","_on"); },
			
			function() 
			{ this.src = this.src.replace("_on","_off"); }

		);

//removing the no-java alert

$('#java').remove();

//adjusting the news box


//intro only first time

if (first == 'true'){

var welcomeScreen = '<div id="welcome-screen"></div>';
 
$('body').append(welcomeScreen);

$('#welcome-screen').click(function(){ $(this).remove();})

$('#welcome-screen').fadeTo(3000, 1).fadeTo('slow', 0,function () {

$('#welcome-screen').remove(); });

};

/*---- creating the info box and things for lightbox ----*/
	
	$('body').after('<div id="overlay"></div><div id="lightbox"><div id="close-lightbox"><img src="images/cancel_tag.png" alt="close"/><p>click anywhere to close</p></div><img src="" alt="" id="work"/></div>');

	$('#overlay, #lightbox').fadeTo(0, 0);

/* clicking thumbs */
	
	$('#image-wrapper a').click(function () {
	
			var img_url = $(this).attr('href');
	
			overlayIn(img_url);
			
			return false;
			
		}
	
	);
	
	/* event for loading complete lightbox */
	
	$('#work').load(function() {
	
		var left = -( $('#work').width() / 2 );
		
		var top = getScrollTop();
		
		$('#lightbox').css({ 'margin-left': left + 'px', 'top': top+'px' });
		
		$('#lightbox').fadeTo(300, 1);
	
	});
	
	/*---- behaviour for hiding lightbox ----*/

	$('#overlay, #lightbox').click(function() {

		$('#overlay, #lightbox').fadeTo("fast", 0); 
		
		$('#overlay').css({width: '1px', height:'1px' });
		
		$('#work').attr('src', '').attr('alt', '');
	
	});


});

/* function for detecting scrollTop */

function getScrollTop(){
    if(typeof pageYOffset!= 'undefined'){
        //most browsers
        return pageYOffset;
    }
    else{
        var B= document.body; //IE 'quirks'
        var D= document.documentElement; //IE with doctype
        D= (D.clientHeight)? D: B;
        return D.scrollTop;
    }
}

/*---- lightbox function ----*/

function overlayIn (img) {

	var scroll_top = getScrollTop ();

	$('#overlay').css({'width': $('html').width(), 'height': $('html').height()}).fadeTo("slow", 0.66, 

	function(){
	
		$('#work').attr('src', img).attr('alt', img);
		
		
	}); 

}