var ie6;

Cufon.replace('#contentText h2, .ft-title h2, #leadNews h2, #groupTable h3, #bottomAbout h2, #bottomTestimonials h2', {textShadow: '#000 1px 1px'});
Cufon.now();

$('.topMenu li a').each(function() {
	$(this).html('');
});

$(document).ready(function() {
	if ($.browser.msie && $.browser.version <= 6 ) {
		ie6 = true;
		$('#overlay').fadeTo('slow', 0.8);
		$('#modalIe').fadeIn();
	}
	
	$('#showcase').jqFancyTransitions({width: 850, height: 270, stripDelay: 100, titleOpacity: 1, strips: 10, position: 'top', direction: 'left'});
	
	$('a.fancy, a.seeMap').fancybox({
		titleShow : false,
		overlayColor : '#000',
		overlayOpacity : 0.5
	});
  
	$('#modalKariera').css('left', $(window).width()/2-$('#modalKariera').width()/2);
	$('#modalIe').css('left', $(window).width()/2-$('#modalIe').width()/2);
	$('#overlay').css('height', $(document).height());
	
	$('li.kariera').click(function() {
		$('#overlay').fadeTo('slow', 0.8);
		$('#modalKariera').fadeIn();
		return false;
	});

	$('#overlay').click(function() {
		if (!ie6) {
			$('#overlay').fadeOut();
			$('#modalKariera').fadeOut();
			return false;
		}
	});
	
	$('.closeDialog').click(function() {	
		$('#overlay').fadeOut();
		$('#modalKariera').fadeOut();
		return false;
	});
	
	$('.boxgrid').hover(function(){
		$('.cover', this).stop().animate({top:'58px'}, {queue:false, duration:400, easing:'easeOutQuint'});
	}, function() {
		$('.cover', this).stop().animate({top:'110px'}, {queue:false, duration:400, easing:'easeOutQuint'});
	});
	
	$('#breadTools ul li span.print').hover(
		function() {
			$('#breadTools ul li.tip').hide().html('Wydrukuj stronę').fadeIn('fast');
		},
		function() {
			$('#breadTools ul li.tip').html('');
		}
	);
	
	$('#breadTools ul li span.smaller').hover(
		function() {
			$('#breadTools ul li.tip').hide().html('Zmniejsz tekst').fadeIn('fast');
		},
		function() {
			$('#breadTools ul li.tip').html('');
		}
	);
	
	$('#breadTools ul li span.bigger').hover(
		function() {
			$('#breadTools ul li.tip').hide().html('Powiększ tekst').fadeIn('fast');
		},
		function() {
			$('#breadTools ul li.tip').html('');
		}
	);
	
	$('#breadTools ul li span.smaller').click(function() {
		$('#content').css('font-size', '11px');
		return false;
	});
	
	$('#breadTools ul li span.bigger').click(function() {
		$('#content').css('font-size', '13px');
		return false;
	});
	
	$('#breadTools ul li span.print').click(function() {
		window.print();
		return false;
	});
	
	function showFirstInstall() {
		$('#contentText.installations li').slice(0,9).each(function(index) {
			$(this).show();
		});
	}
	
	function addMiddleClass() {
		var i = 1;
		$('#contentText.installations li').each(function() {
			$(this).removeClass('middle');
			if ($(this).index() == 1) {
				$(this).addClass('middle');
				i = i + 3;
			}
			
			if ($(this).index() == i) {
				$(this).addClass('middle');
				i = i + 3;
			}
		});
	}
	
	addMiddleClass();
	showFirstInstall();
	
	$('#contentText.installations .sortLinks span').click(function() {
		$('#contentText.installations li').hide();
		switch($(this).attr('class')) {
			case 'sortDate':
				$("#contentText.installations li").tsort("span.investDate", {order:'desc'});
			break;
			case 'sortObject':
				$("#contentText.installations li").tsort("span.investTitle");
			break;
			case 'sortClient':
				$("#contentText.installations li").tsort("span.investDesc");
			break;
			case 'sortLocation':
				$("#contentText.installations li").tsort("span.investLocation");
			break;
		}
		
		addMiddleClass();
		showFirstInstall();
		
		$('#contentText.installations .sortLinks span').removeClass('selected');
		$(this).addClass('selected');
		
		$('#contentText.installations .paginator span').removeClass('selected');
		$('#contentText.installations .paginator span.1').addClass('selected');
		return false;	
	});
	
	$('#contentText.installations .paginator span').click(function() {
		var no = $(this).attr('class').substring(0,1);
		
		$('#contentText.installations li').fadeOut(100);
		
		$('#contentText.installations li').slice((no-1)*9,no*9).each(function(index) {
			$(this).delay(110).fadeIn(300);
		});
		
		$('#contentText.installations .paginator span').removeClass('selected');
		
		$(this).addClass('selected');
		addMiddleClass();
		return false;
	});
	
	$('#contentText.testimonials').accordion({
		header: 'div.testimonialTrigger',
		active: 0,
		alwaysOpen: false,
		autoHeight: false,
		collapsible: true
	});
});
