function activeFrame() {
	var idR = /([0-9]+)$/i;
	$(".active").each(function() {
		var id = $(this).attr('id').match(idR);
		$("#active" + id[1]).css('top', $("#image" + id[1]).offset().top);
		$("#active" + id[1]).css('left', $("#image" + id[1]).offset().left);	
	});
}

var banerId = 1;
var maxBanerId = 2;
function banerRotation() {
	$(".baner" + banerId).fadeOut(2000);
	banerId = banerId+1;
	if (banerId > maxBanerId)
		banerId = 1;
	$(".baner" + banerId).fadeIn(2000);
	
	setTimeout("banerRotation();",5000);
}

$(document).ready(function(){
	var altURL = /^(.*)\|([0-9]+)\|([0-9]+)\|([0-9]+)\|([0-9]+)\|([0-9]+)$/i;
	var idR = /([0-9]+)$/i;
	$("#photosGallery .photoItem").each(function(){
		var rodzic = this;
		var alt = $("img", $(rodzic)).attr('alt');
		var desc = $("img", $(rodzic)).attr('title');
		alt = alt.match(altURL);
		$("body").append('<div class="active" id="active' + alt[6] + '" style="width:' + alt[4] + 'px;height:' + alt[5] + 'px;">&nbsp;</div>');
		
		$(".active").click(function(){
			var id = $(this).attr('id');
			id = id.match(idR);
			if($("#big" + id[1]).length == 0) {
				$("body").append(
					'<div class="big" id="big' + id[1] + '">' +
						'<div style="position:relative">' +
							'<img class="pngbeh" src="' + alt[1] + '" alt="" style="width:' + alt[2] + 'px;height:' + alt[3] + 'px;" />' +
							'<div class="description">' + desc + '</div>' +
						'</div>' +
					'</div>'
				);
				$("#big" + id[1]).css('top', $("img", $(rodzic)).offset().top  - ($("#big" + id[1]).outerHeight()/2) + $("img", $(rodzic)).outerHeight()/2);
				$("#big" + id[1]).css('left', $("img", $(rodzic)).offset().left - ($("#big" + id[1]).outerWidth()/2) + $("img", $(rodzic)).outerWidth()/2);
			}
			$("#big" + id[1]).show('fast');
		});
		$(".active").mouseleave(function(){
			var id = $(this).attr('id');
			id = id.match(idR);
			$("#big" + id[1]).hide('fast');
		});
	});
	activeFrame();
	setTimeout("banerRotation();",5000);
});
