/*==========================  G L O B A L   V A R I A B L E S  ==================================*/
	var actualY = new Number();		// przechowuje Y myszy.	
	var thumbsArray = new Array();

/*================================  D O C U M E N T  ========================================*/	
$(document).ready( function() {
				
	$("div#photo").hide();
	$(".thumb").mouseover( function (e) {
		actualY = e.pageY;
	}).click( function(){
		var thumbID = $(this).attr('name');
		weblightbox( thumbID );
	});
	
});


/*==============================  W E B L I G H T B O X  ========================================*/

/*____________________________  WEBLIGHT BOX  ____________________________________
------------------------ funckja wyświetla duże zdjęcie po kliknięciu w miniaturke w SWFie ---------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
function weblightbox( thumbID ) {

	var photoURL = thumbsArray[thumbID];

	$(".overlay").show();

	centerImgBox();
	
	$("#photo").html("<img src='" + photoURL + "' class='imgphoto'/>"
		+"<div class='prevArea'><div class='prev'>POPRZEDNIE</div><br class='clear'/></div>"
		+"<div class='nextArea'><div class='next'>NASTĘPNE</div></div>"
		+"<div class='closeArea'><div class='close'>ZAMKNIJ</div></div>");

	$("#photo").ready( function() {
		$("#photo").show();
		hidePhotoAction();		//  odpala na nowo opcję znikania po kliknięciu.
		prevNext(thumbID);
	});

};

// obsługa przycisków następny/poprzedni w widoku foty.
function prevNext( thumbID ) {
	
	$(".prevArea,.nextArea").mouseover( function (e) {
		$(this).children().show();
	}).mouseout( function (e) {
		$(this).children().hide();
	});
	
	$(".prevArea").click( function (e) {
		thumbID--;
		if(thumbID < 0) thumbID = thumbsArray.length-1;
		weblightbox( thumbID );
	});
	
	$(".nextArea").click( function (e) {
		thumbID++;
		if(thumbID > thumbsArray.length-1) thumbID = 0;
		weblightbox( thumbID );
	});
	
};

/*____________________________ CENTER IMG BOX  __________________________________
---------------------------------------- wyśrodkowuje ramke z fotą na stronie ------------------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function centerImgBox() {

		var pageH = $("#Layer4").height() +240;
		var scrH = screen.availHeight;
		var maxH = Math.max(pageH, scrH);

		var photoH = $("#photo").height();

		var posTop  = actualY -photoH/2; //+Math.min(pageH, winH) /2
		
		if(posTop < 20) posTop = 20;
		if(posTop > (maxH-photoH-80) ) posTop = maxH-photoH-80;
		
		$("#photo").css({ 
			"top": posTop, 
			"z-index":"1000"
		});
		
		var fullH = $("#Layer4").height() +300;
		var maxH = Math.max(fullH, scrH);
		
		$(".overlay").css({
			"height":maxH,
			"z-index":"200"
		});

};


/*___________________________  HIDE PHOTO ACTION  _________________________________
---------------------------------- inicjuje akcje zamknięcia fotki po kliknięciu w nią ----------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
function hidePhotoAction() {

	$(".imgphoto").click( function() {
		$("#photo").fadeOut('fast');
		$(".overlay").hide();
	});	
	
	$(".closeArea").mouseover( function(){
		$(this).children().show();
	}).mouseout( function(){
		$(this).children().hide();
	}).click( function() {
		$("#photo").fadeOut('fast');
		$(".overlay").fadeOut('fast');
	});	

};

/*_____________________________ INIT LOADING  ___________________________________
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
function initLoading() {}
