$(document).ready(function(){
	$("#menu li").hover(function() {
		$(this).find("ul").stop().slideDown(400).show(400, function(){
			$(this).height("auto");
		});
		$(this).addClass("hover");
	} , function() {
		$(this).find("ul").slideUp(250);
		$(this).removeClass("hover");
		Cufon.refresh('.mainMenuItem');
	});
	if($(".slider").length) {
		$('.slider').cycle({
			timeout: 4000,
			speed: 1000
		});
	}
	if($('#mapa').length) {
		if(google_gps_latitude == 0 && google_gps_longitude == 0){
			$('#mapa').gMap({
				zoom: 12,
				markers: [{
					address: google_gps_address,
					html: google_gps_html,
					popup: true
				}] });
		}else{
			$('#mapa').gMap({
				zoom: 12,
				markers: [{
				html: google_gps_html,
				popup: true,
				latitude: google_gps_latitude,
				longitude: google_gps_longitude
			}] });
		}
	}
	if($('#form_kontakt').length) {
		$('#form_kontakt').validate();
	}
	if($('#form_newsletter').length) {
		$('#form_newsletter').validate();
	}
	if($('#left ul li').length) {
		$('#left ul li').hover(function() {
			$(this).addClass("hover");
			Cufon.refresh('#left ul li');
		} , function() {
			$(this).removeClass("hover");
			Cufon.refresh('#left ul li');
		});
	}
	if($('#budynek').length) {
		$('#poziom_select li').hover(function() {
			$('#details').find('.'+$(this).attr('rel')).stop().fadeTo(250, 0.6);
			$(this).addClass("hover");
		} , function() {
			$('#details').find('.'+$(this).attr('rel')).stop().fadeOut(500);
			$(this).removeClass("hover");
		});
		$('#poziom_select li').click(function() {
			window.location = window.location + $(this).attr('rel') + '/';
			return false;
		});
	}
	
	if($('#mieszkania_filtr').length > 0) {
		$('#powierzchnia').change(function() {
			location_a = String(window.location).split('?');
			window.location = location_a[0] + '?powierzchnia='+$('#powierzchnia').val()+'&pokoi='+$('#liczbapokoi').val();
			return false;
		});
		$('#liczbapokoi').change(function() {$('#powierzchnia').change();});
		$('#poziom_select li').click(function() {
			var location_a = window.location;
			location_a = String(location_a).split('?');
			location_a = String(location_a[0]).split('poziom');
			window.location = location_a[0] + $(this).attr('rel') + '/';
			return false;
		});
	}
	if($('#mieszkania_lista').length > 0) {
		$('#poziom_select li').hover(function() {
			$(this).addClass("hover");
		} , function() {
			$(this).removeClass("hover");
		});
		$('#poziom_select li').click(function() {
			var location_a = window.location;
			location_a = String(location_a).split('/');
			var location = '';
			for(i=0; i<location_a.length-2; ++i) location += location_a[i]+'/';
			window.location = location + $(this).attr('rel') + '/';
			return false;
		});

		$('#mieszkania_lista a').hover(function() {
			$('#details').find('.mieszkanie'+$(this).html()).stop().fadeTo(250, 1);
			$(this).addClass("hover");
		} , function() {
			$('#details').find('.mieszkanie'+$(this).html()).stop().fadeOut(500);
			$(this).removeClass("hover");
		});
	}
});

