$(document).ready(function(){

	$("#conMainPresentationVideo").flashembed({ 
			src : "_swf/header.swf",
			wmode: 'transparent',
			width: '720',
			height: '299'
		},{ 
			sekcja1: 'http://publicon.pl/strona,zespol.html',
			sekcja2: 'http://publicon.pl/strona,dzialania.html',
			sekcja3: 'http://publicon.pl/casestudy,4.html',
			sekcja4: 'http://publicon.pl/casestudy,5.html',
			sekcja5: 'http://publicon.pl/casestudy,3.html',
			sekcja6: 'http://publicon.pl/casestudy,6.html'
		}
	);
	
	renderTexts();

	// external links hack
	$('a.lnkExternal').click( function(){	window.open(this.href,'_blank'); return false;});
	
	// links outline hack 
	$("a, label, input[type='submit'], input[type='checkbox'], input[type='radio']").bind('focus',function(){if(this.blur)this.blur();});
	// pointer on submit buttons
	$("input[type='submit']").css('cursor', 'pointer');
	
	startLogoCarousel();
	
	$('#btnNewsletter').click(function() {
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		
		if($('#sNewsletterInput').val() == '' || !$('#sNewsletterInput').val()) return false;
		
		if(reg.test($('#sNewsletterInput').val()) == false) {
			$("#conNewsletterInfo").html("<p>Niepoprawny adres e-mail.</p>");
			return false;
		}

		$.ajax({
			type: "POST",
			cache: false,
			url: "index.html",
			data: "sAction=setEmailToNewsletter&sEmail="+$('#sNewsletterInput').val()
		});
		
		$('#sNewsletterInput').hide(500, function(){ $(this).remove() });
		$("#conNewsletterInfo").html("<p>Dziękujemy! Twój adres e-mail<br />został dodany do listy.</p>");
		return false;
	});
	
});

$(window).load(function () {
	resizeCarouselContener();
});



function startLogoCarousel(iNextCarousel){
	
	var iCarousel = 1;
	if(iNextCarousel) iCarousel = iNextCarousel;
	
	var iCarouselMax = $(".conOneLogosPart").length;
	if(iCarousel > iCarouselMax) iCarousel = 1;
	
	$("#conOneLogosPart"+iCarousel).fadeIn(1000, function() {
		
		$(this).find('.conOneLogosPartProgressBar').css('width', '210px').animate({ 
			width: "0px",
		}, 7000, '', function(){
			
			$(this).parent().parent().fadeOut(1000, function() {
				
				iNextCarousel = parseInt($(this).attr('id').replace(/conOneLogosPart/, ""))+1;

				startLogoCarousel(iNextCarousel);
				
			});
			
		} );
		
	});
	
}

function resizeCarouselContener(){
	
	var iHeight = 0;
	
	$("#conMainContentLeftColumn .conOneLogosPart").each(function (i) {
	
		if($(this).height() > iHeight) iHeight = $(this).height();
	
	});

	iHeight = iHeight + 10;
	
	$("#conMainContentLeftColumn").height(iHeight+'px');
}


function sendForm(sFormID){
	$('#'+sFormID).submit();
	return false;
}

function renderTexts() {
	
	Cufon.replace('#conTopMenu a, #conLeftMenu a, #conFooter ul a, .lnkToCufon', {
		fontFamily: 'Myriad Pro',
		hover: true
	});
	
	Cufon.replace('.lnkShadowToCufon', {
		fontFamily: 'Myriad Pro',
		textShadow: '#fff -1px -1px, #fff 1px 1px',
		hover: true
	});
	
	Cufon.replace('.txtToCufon', {
		fontFamily: 'Myriad Pro',
		hover: true
	});
	
	Cufon.replace('h3.txtNormalText, #conSubMenu a', {
		fontFamily: 'Myriad Pro',
		textShadow: '#fff -1px -1px, #fff 1px 1px'
	});
	
}

function renderFormTips() {
	
	$('input').each(function (i) {
		if($(this).next().attr('class') == 'oHint') {
			$(this).focus(function () {
				$(this).parent().children('span').fadeIn("fast");
			}).blur(function () {
				$(this).parent().children('span').fadeOut("fast");
			});
		}
	});
	
}