var currentSubpageHeight=0;
function addOnclicks() {
	$("li.onas").click(function() {
		window.location = 'onas.html';
	});
	$("li.oferta").click(function() {
		window.location = 'oferta.html';
	});
	$("li.kontakt").click(function() {
		window.location = 'kontakt.html';
	});
	
	var activePage='zrealizowane_projekty';
	//temp
	$("#iZrealizowaneProjekty").attr('src', 'images/zrealizowane_projekty_a.png');
	
	$("#iZrealizowaneProjekty").click(function(){
		if (activePage == 'zrealizowane_projekty')
			return false;
		$("#iOtrzymaneReferencje").attr('src', 'images/otrzymane_referencje.png');
		$(this).attr('src', 'images/zrealizowane_projekty_a.png');
//		$("#subpage").fadeOut(300);
		mask();
		setTimeout(function() {
			getProject(1);
		}, 400);
		activePage = 'zrealizowane_projekty';
		return false;
	});

	$("#iOtrzymaneReferencje").click(function(){
		if (activePage == 'otrzymane_referencje')
			return false;
		$("#iZrealizowaneProjekty").attr('src', 'images/zrealizowane_projekty.png');
		$(this).attr('src', 'images/otrzymane_referencje_a.png');
//		$("#subpage").fadeOut(300);
		mask();
		setTimeout(function() {
			getReference(1);
		}, 400);
		activePage = 'otrzymane_referencje';
		return false;
	});
	
	//making submenu hovers
	var img;
	$("img[id^='i']").hover(function(){
		img = $(this).attr('src').slice(0,-4);
		if (img.slice(-2)=='_a')	//active
			return false;
		$(this).attr('src', img+'_a.png'); 
	},
	function() {
		if (img.indexOf(activePage)>=0)
			return false;
		$(this).attr('src', img+'.png');
	}
	);
	
}

function mask() {
	$("#subpage").html('<img src="images/ajaxloader.gif" width="32" height="32" alt="loading" style="margin: 100px 100px 0 100px;"/>');
}

function makeFancy() {
	$.fn.fancyzoom.defaultsOptions.imgDir='images/fancyzoom/';
	$("a.fancyzoom").fancyzoom();
}

function getProject(id) {
//	if (currentSubpageHeight > 0)
//		$("#subpage").css('height', currentSubpageHeight);
	mask();
	$.get('zrealizowane_projekty.php?id='+id, function(data){
//		$("#subpage_content").html(data);
//		$("#subpage").animate({height: $("#subpage_content").height()+14}, 500, null, function(){
			$("#subpage").html(data);
//			currentSubpageHeight = $("#subpage").height()+14;
//		});
	});
}

function getReference(id) {
	mask();
	$.get('otrzymane_referencje.php?id='+id, function(data){
		$("#subpage").html(data);									
		makeFancy();
	});
}


$(document).ready(function() {
	noLoad = window.noLoad || false;
	if (noLoad === false) 
		getProject(1);
	makeFancy();
	
});