var activeColor = '#000000';
var readyColor = '#7b1717';

$(function(){
     $("#poznaj_pelna_oferta").click(function(){
          $("#drzwi_plansza").slideDown();
     });
     
      /*
     $("#fmenuct a").hover(
          function(){
               $(this).animate({fontSize:"19px"},200);
          },
          function(){
               $(this).stop();
               $(this).animate({fontSize:"15px"},200);
          }
     );
     */
});

function page() {
	var pageBox01Height = $('#pageBox01').height();
	var pageBox02Height = $('#pageBox02').height();
	var pageBox03Height = $('#pageBox03').height();
	var pageBoxImgHeight = $('#pageImg').height();
	var pageBoxHeight = pageBox01Height;
	pageBox02Height > pageBoxHeight ? pageBoxHeight = pageBox02Height : pageBoxHeight;
	pageBox03Height > pageBoxHeight ? pageBoxHeight = pageBox03Height : pageBoxHeight;
	pageBoxImgHeight > pageBoxHeight ? pageBoxHeight = pageBoxImgHeight : pageBoxHeight;
	$('#mainPanel').css('height', pageBoxHeight + 120);
	$('#pageLink01').removeClass('pageLinkReady').addClass('pageLinkActive');
	$('#pageLink01').css('color', activeColor).css('font-weight', 'bold').fadeTo(0, 0.5, function(){
		$('#pageLinks').css('display', 'block');
	});
	$('#pageImg').css('display', 'none');
	$('#pageBox01').css('display', 'none');
	$('#pageBox02').css('display', 'none');
	$('#pageBox03').css('display', 'none');
	$('#pageImg').fadeIn(1000, function(){
		$('#pageBox01').fadeIn(1000);
	});

	$('#pageLink01').click(function(){
		var isBox02Visible = $('#pageBox02').css('display');
		var isBox03Visible = $('#pageBox03').css('display');
		activeLink('#pageLink01');
		if(isBox02Visible == 'block') {
			$('#pageBox02').fadeOut(1000, function(){
				$('#pageBox01').fadeIn(1000);
			});
			readyLink('#pageLink02');
		}
		if(isBox03Visible == 'block') {
			$('#pageBox03').fadeOut(1000, function(){
				$('#pageBox01').fadeIn(1000);
			});
			readyLink('#pageLink03');
		}
		titleUpdate($('#pageLink01').text());
	});

	$('#pageLink02').click(function(){
		var isBox01Visible = $('#pageBox01').css('display');
		var isBox03Visible = $('#pageBox03').css('display');
		activeLink('#pageLink02');
		if(isBox01Visible == 'block') {
			$('#pageBox01').fadeOut(1000, function(){
				$('#pageBox02').fadeIn(1000);
			});
			readyLink('#pageLink01');
		}
		if(isBox03Visible == 'block') {
			$('#pageBox03').fadeOut(1000, function(){
				$('#pageBox02').fadeIn(1000);
			});
			readyLink('#pageLink03');
		}
		titleUpdate($('#pageLink02').text());
	});
	
	$('#pageLink03').click(function(){
		var isBox01Visible = $('#pageBox01').css('display');
		var isBox02Visible = $('#pageBox02').css('display');
		activeLink('#pageLink03');
		if(isBox01Visible == 'block') {
			$('#pageBox01').fadeOut(1000, function(){
				$('#pageBox03').fadeIn(1000);
			});
			readyLink('#pageLink01');
		}
		if(isBox02Visible == 'block') {
			$('#pageBox02').fadeOut(1000, function(){
				$('#pageBox03').fadeIn(1000);
			});
			readyLink('#pageLink02');
		}
		titleUpdate($('#pageLink03').text());
	});
	
	if($('#pageLinks').length) {
		titleUpdate($('#pageLink01').text());
	}
}

function activeLink(linkId) {
	$(linkId).removeClass('pageLinkReady').addClass('pageLinkActive');
	$(linkId).css('color', activeColor).css('font-weight', 'bold').css('cursor', 'text');
	$(linkId).fadeTo(500, 0.3);
}

function readyLink(linkId) {
	$(linkId).removeClass('pageLinkReady').addClass('pageLinkActive');
	$(linkId).css('color', readyColor).css('font-weight', 'normal').css('cursor', 'pointer');
	$(linkId).fadeTo(500, 1);
}

function titleUpdate(linkText) {
	if($('#subtitle').length) {
		var title = $('.contentheading').text();
		$('.contentheading').fadeOut(250, function(){
			$('#subtitle').text(' - ' + linkText);
			$('.contentheading').fadeIn(250);
		});
	}
	else {
		var title = $('.contentheading').text();
		$('.contentheading').fadeOut(250, function(){
			$('.contentheading').html(title + '<div id="subtitle"> - ' + linkText + "</div>");
			$('.contentheading').fadeIn(250);
		});
	}
}
