$(function(){
	// zmiana pudelek w rejestracji
	$('#program_id-element input').click(function() {
		$('.about-program').hide();
		$('#about-program-'+$(this).val()).show();
	});
});

$(function() {
	
//	var url = 'http://'+document.domain+'/';
	var url = 'http://tropmy.net/';	

	// usuwanie napisu z logowania
	$('.loginForm #email').click(function() {
		if ($(this).attr('value') == '- email -')
			$(this).attr('value','');
	});
	
	// slideshow logotypów glowna strona
	$('.mainSlidesLogos').cycle({random: 1});

	// sck tooltip
	$('.questionBox img').sckTip();
	
	// zmiana glownego obrazka/video w prezentacji
	$('.pMenu').click(function() {
		var title = $(this).attr('title');
		var lang = $('#topPresentationSlider').attr('class');
		var stats_url = '';
		
		if (lang == 'en')
			lang = lang+'/';
		
		$('.topPresentationLoading').show();
		
		$('.pMenu').each(function() {
		    $(this).removeClass('pTabActive').addClass('pTabInactive');
		  });
				
		$(this).removeClass('pTabInactive').addClass('pTabActive');

		switch (title) {
			case 'bigPic1':
				stats_url = 'stats/tracks';
			break;
			
			case 'bigPic2':
				stats_url = 'stats/heatmap';
			break;
			
			case 'bigPic3':
				stats_url = 'stats/clicks';
			break;
			
			case 'bigPic4':
				stats_url = 'stats/stats';
			break;
			
			case 'bigPic5':
				stats_url = 'stats/geolocation';
			break;
			
			case 'bigPic6':
				stats_url = 'stats/returns';
			break;
			
			default:
				alert('Błąd.')
		}
		$('.statsUrl').attr('href', url+lang+stats_url);
		
		$('#pBigImage').attr('src', url+'/g/presentation/'+title+'.jpg').load(function (){
			$('.topPresentationLoading').hide();
		});
		
		return false;
	});

	// pokaż/ukryj opis wyników
	$('.toggleDescription').toggle(function() {
		$(this).html('Pokaż opis<img src="/g/stats/arrow_medium_down.png" />');
		$('.pToggle').animate({
			height: '0px'
		}, 500);
	}, function() {
		$(this).html('Schowaj opis<img src="/g/stats/arrow_medium_up.png" />');
		$('.pToggle').animate({
			height: '80px'
		}, 500);
	});	
	
	// przewijanie okienek w głównej prezentacji
	$('#topPresentationSlider').cycle({ 
	    fx:     'scrollVert', 
	    prev:   '#prev', 
	    next:   '#next', 
	    nowrap:  0,
	    timeout: 13000
	});
	// przewijanie piszą o nas
	$('#about-us').cycle({ 
	    fx:     'scrollHorz', 
	    nowrap:  0,
	    timeout: 15000,
	    random: true
	});
		
	try {
		$(".bgCennik").tooltip({ 
		    bodyHandler: function() { 
				//return 'ala ma kota';
		        return $(this).find('span').html(); 
		    }, 
		    showURL: false 
		});
	} catch(e) {
		//		
	}
	
});

function showHideInvoiceFields(type)
{
	if (typeof type != 'undefined') {
		if (type == 'hide') {
			$('.invoice').hide();
			$('.invoice label').attr('class','optional');
		} else {
			$('.invoice').show();
			$('.invoice label').attr('class','required');
		}
	} else {
		if ($('.invoice').css('display') == 'block') {
			$('.invoice').hide();
			$('.invoice label').attr('class','optional');
		} else {
			$('.invoice').show();
			$('.invoice label').attr('class','required');
		}
	}
}
