$(document).ready(function() {
	
	$("ul#nav li a").css({"opacity" : 0}).hover(function(){
		$(this).stop().animate({"opacity" : 1}, 300);
	
		}, function(){
		$(this).stop().animate({"opacity" : 0}, 800);
	});
	
	if($("a[rel=images]"))
	{
		$("a[rel=images]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		});
	}
	
	$(window).load(function() {
		$('#slider').nivoSlider({captionOpacity: 0.0});
		$('#charakterystyka-slider').nivoSlider({effect:'fade', captionOpacity: 0.0});
	});
	
	$(".picbox").hover(
	function() {
		$(this).find('.photoslide1').stop().animate({"opacity": "0"}, "slow");
	},
	function() {
		$(this).find('.photoslide1').stop().animate({"opacity": "1"}, "slow");
	});

	var imgWrapper = $('.slideshow > img');
	// only show the first image, hide the rest
	imgWrapper.hide().filter(':first').show();
	
	$('ul.recentlist li a').click(function () {
	
		// check if this item doesn't have class "current"
		// if it has class "current" it must not execute the script again
		if (this.className.indexOf('current') == -1){
			imgWrapper.hide();
			imgWrapper.filter(this.hash).fadeIn(500);
			$('ul.recentlist li a').removeClass('current');
			$(this).addClass('current');
		}
		return false;
	});
	
	if($("#contact_form,#contact_form2").attr('id'))
	{
		$.validator.setDefaults({
			errorElement: 'em'
		});
		
		$("#contact_form,#contact_form2").validate({
			rules: {
				temat: {
					required: true,
					minlength: 5,
					maxlength: 150
				},
				email: {
					required: true,
					email: true
				},
				txt: {
					required: true,
					maxlength: 1000
				}
			},
			messages: {
				temat: {
					required: "Pole obowiązkowe",
					minlength: "Temat jest za krótki, min. 5 zn.",
					maxlength: "Temat jest za długi, max. 150 znaków"
				},
				email: {
					required: "Pole obowiązkowe",
					email: "Adres email jest nie prawidłowy"
				},
				txt: {
					required: "Pole obowiązkowe",
					maxlength: "Tekst jest za długi, max 1000 znaków"
				}
			}
		});

	}

	jQuery('#mycarousel').jcarousel({
		wrap: 'circular'
	});

	if($("#mapka").attr('id'))
	{
		var MYMAP = {
				bounds: null,
				map: null
		}
	
		MYMAP.init = function(selector, zoom) {
			
			var myOptions	= {
					zoom:zoom,
					mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			
			this.map = new google.maps.Map($(selector)[0], myOptions);
			
			var mapa	= this.map
			
			var point	= new google.maps.LatLng('54.476064', '17.0199');
			
			mapa.setCenter(point);
			
			var rozmiar             = new google.maps.Size(32,32);
			var rozmiar_cien        = new google.maps.Size(59,32);
			var punkt_startowy      = new google.maps.Point(0,0);
			var punkt_zaczepienia   = new google.maps.Point(16,16);
			 
			var ikona   = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon40.png", rozmiar, punkt_startowy, punkt_zaczepienia);
			var cien    = new google.maps.MarkerImage("http://maps.google.com/mapfiles/kml/pal3/icon40s.png", rozmiar_cien, punkt_startowy, punkt_zaczepienia);
			
			mainmarker = new google.maps.Marker(
			{
				map:        mapa,
				position:   point,
				icon:       ikona,
				shadow:     cien
			});
			
			var dymek = new google.maps.InfoWindow();
	
			dymek.open(mapa, mainmarker);
			dymek.setContent('<strong>RATTANPOL</strong>');
		};
		
		MYMAP.init('#mapka', 15);
	}
	
	Cufon.replace('h1,h2');
});
