$(document).ready(function() {
	
	if ($('#slider_content').length > 0)
		$('#slider_content').cycle({
			fx: 'fade',
			timeout: 5000,
			pager: '#slider_nav',
			pagerAnchorBuilder: function(index, DOMelement) {
				return '<a href="#"></a>';
			},
			slideExpr: 'img'
		});
	
	if ($('#newsy').length > 0)
		$('#newsy').cycle({
			fx: 'fade',
			timeout: 5000,
			speed: 300,
			slideExpr: '.news',
			prev: '#glowna_news_prev',
			next: '#glowna_news_next'
		});
	
	$('#news_next').click(function() {
		if ($('.lastnews_top.active').next().hasClass('lastnews_top'))
			$('.lastnews_top.active').removeClass('active').next().addClass('active');
		if ($('.news_content.active').next().hasClass('news_content'))
			$('.news_content.active').removeClass('active').next().addClass('active');
	});
	
	$('#news_prev').click(function() {
		if ($('.lastnews_top.active').prev().hasClass('lastnews_top'))
			$('.lastnews_top.active').removeClass('active').prev().addClass('active');
		if ($('.news_content.active').prev().hasClass('news_content'))
			$('.news_content.active').removeClass('active').prev().addClass('active');
	});
	
	$('#search_, #nazwa, #firma, #email, #telefon').focus(function() {
		if (this.value == this.defaultValue)
			this.value = '';
	});
	$('#search_, #nazwa, #firma, #email, #telefon').blur(function() {
		if (this.value == '') {
			this.value = this.defaultValue;
		}
	});
	
	$('textarea#tresc').focus(function() {
		if (this.innerHTML == 'Treść wiadomości')
			this.innerHTML = '';
	});
	$('textarea#tresc').blur(function() {
		if (this.innerHTML == '')
			this.innerHTML = 'Treść wiadomości';
	});
	
	if ($('#mapa_google').length > 0) {
		var address = 'Poland, Grudusk';
		var geocoder = new google.maps.Geocoder();
	
		var options = {
			zoom: 10,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			disableDefaultUI: true,
			draggable: true,
			scrollwheel: true
		};
		var map = new google.maps.Map(document.getElementById("mapa_google"), options);
		
		geocoder.geocode( { 'address': address}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: map, 
					position: results[0].geometry.location
				});
			} else {
				alert("Nie można zlokalizować adresu: " + status);
			}
		});
	}
});

