$(document).ready(function(){
	var siteurl ='http://konstans.com.pl/';
	
	

	/*
	 * obsługa menu
	 */
	var ciacho = $.cookie("menu");
	if(ciacho!=null){
		
			$("#left .main").find(".plus").each(function(){
				if(ciacho.indexOf($(this).next('a').attr('href'))!=-1){
					$(this).removeClass('plus').addClass('minus');
					$(this).parent().children('.sub').slideToggle('slow',function(){});
				}
			});
	}

	$('#left .plus').click(function(){
		if($(this).parent().children('.sub').is(':visible')){
			$(this).removeClass('minus').addClass('plus');
			
		}else{
			$(this).removeClass('plus').addClass('minus');
		}
			$(this).parent().children('.sub').slideToggle('slow',function(){});
			ciacho = '';
			$("#left .main").find(".minus").each(function(){
				ciacho += $(this).next('a').attr('href')+";";
			});
			$.cookie("menu", ciacho, { path: '/', expires: 1 });
	});
	
	$('#left .minus').click(function(){
		if($(this).parent().children('.sub').is(':visible')){
			$(this).removeClass('minus').addClass('plus');
			
		}else{
			$(this).removeClass('plus').addClass('minus');
		}
		
		$(this).parent().children('.sub').slideToggle('slow',function(){});
		ciacho = '';
			$("#left .main").find(".minus").each(function(){
				ciacho += $(this).next('a').attr('href')+";";
			});
			$.cookie("menu", ciacho, { path: '/', expires: 1 });
	});
	/*
	 * obsługa menu == end ==
	 */

	/*
	 * licznik znaków w formie
	 */
	function checkLength(ob,len){
		if($(ob).val().length<len){
			a = $(ob).val().length;
			b = len-1;
			c = b-a;
			$(".charCount", $(ob).parent().parent().parent()).empty();
			$(".charCount", $(ob).parent().parent().parent()).append(""+c+"");
		}else{
			alert('Przekroczono dozwoloną liczbę znaków!!!');
			$(ob).val($(ob).val().substring(0, len-1));
		}
	}
	
	$(".checkLength").focus(function(){
		checkLength($(this),150);
	});
	
	$(".checkLength").keydown(function(){
		checkLength($(this),150);
	});
	 /*
	  * licznik znaków == end ==
	  */
	  
	/*
	 * form komentowania - pokaż/ukryj
	 */
	 
	 $("#show_hide").toggle(function(){
		$("#komentarz").show('blind',{},700);
	 },
	 function(){
		$("#komentarz").hide('blind',{},700);
	 });
	 
	 /*
	  * form komentowania - pokaż/ukryj == end ==
	  */
	  
	  /*
	   * info dl aie6 ;p
	   */
	  
	  if($.browser.msie && $.browser.version=="6.0")
	  {
			var tresc = '<p style="color:#d00; clear:both; font-weight:bolder; width:500px;">Twoja przeglądarka jest przestarzała i nie wspiera wielu standardów.</p><p style=" width:500px;">Jeśli chcesz przeglądać internet szybciej i bezpieczniej, pobierz nowoczesną przeglądarkę:</p><ul style=" width:500px;"><li><a href="http://www.opera.com/browser/download/">Operę</a></li><li><a href="http://download.mozilla.org/">Firefoksa</a></li><li><a href="http://www.google.pl/chrome/eula.html">Google Chrome</a></li><li>lub ostatecznie <a href="http://www.microsoft.com/poland/windows/internet-explorer/worldwide-sites.aspx">IE 8</a></li></ul>';
			$("body").append('<div id="bkd"></div><div id="foto-big"><a href="#" id="foto-close"></a></div>');
			
			$("#foto-big").append('<div id="foto-mid" style="width:120px; height:120px;">'+tresc+'</div>');
			
			
			$("#bkd").animate({opacity:0.0}, 10, function(){
				$(this).show().animate({opacity:0.7}, 500, function(){
					$("#foto-big").show('scale', {percent: 100},500,function(){
					var totalH = $(document).height()+50;
					$("#bkd").css('height',totalH+"px");
				});
				});				
			});
			
			$("#foto-close").click(function(){
					close();
				}); 
			
			$("#bkd").click(function(){
					close();
			});			
	}
	
	function close(){
		$("#foto-big").hide('scale',{percent: 0},500,function(){
					$("#foto-big").detach();
					$("#bkd").animate({opacity:0.0}, 500, function(){
						$(this).detach();
					});
				});
	}
	/*
	 * info dla ie6 == end ==
	 */
	  
	  
	  
	  
	  
 	if($("#map").length){
		load();
	} 
	
	if($('#rp-pietro').length){
		$(function() {
			$('#rp-pietro').maphilight();
		}); 
	}
	
	
	/*
	 * dropdown w kontakcie
	 */
	 if($(".kontakt-dzial").length){
		$(".kontakt-dzial", $(".up").parent()).hide();
		
		 $(".kontakt-fold").click(function(){
			if($(".kontakt-dzial",$(this).parent()).is(":hidden")){
					$(".kontakt-dzial").hide();
					$(".kontakt-fold").removeClass("down");
					$(".kontakt-fold",$(this).parent()).toggleClass("down");
					$(".kontakt-dzial",$(this).parent()).show('blind', {},200,function(){});
			}else{
				$(".kontakt-fold").removeClass("down");
				$(".kontakt-dzial",$(this).parent()).hide('blind', {},200,function(){});
			}
		});
		
	}
	/*
	 *
	 */
	
	
	
	/*
	 * obsluga slidera ofert specjalnych
	 */
	 
	$("#roll-down").click(function(){
	
		var offset = '';
		var up = 0;
		var ilosc = 0;
		var h = 180;
		$(".special").each(function() {
			ilosc = ilosc +1;
		}); 
			ilosc = ilosc - 3;
		h = h*ilosc;
		
		if($("#roll-down").hasClass('rolldown'))
		{
			offset = '+='+h;
			up = 1;
		}
		else{
			offset = '-='+h;
			up = 0;
		}
		
		
		$('#right-mask').animate({
		height: offset
		}, {
		duration: (ilosc*700), 
		specialEasing: {
		  height: 'easeOutBounce'
		}, 
		complete: function() {
			if(up==1)
			{
				$("#roll-down").removeClass('rolldown').addClass('rollup');
			}
			else{
				$("#roll-down").removeClass('rollup').addClass('rolldown');
			}
		}
		});


	
	});
	/*
	 * obsluga slidera ofert specjalnych
	 */
	
	
	/*
	 * asari typ obiektu
	 */
	$(".rw-obiekt").click(function()
	{
		$.cookie("typObiektu", $(this).text(), {path:'/'} );
		$('a.rw-obiekt-hov').each(function(i){
			$(this).removeClass('rw-obiekt-hov');
		});
		$(this).addClass('rw-obiekt-hov');

	});
	
	if($.cookie("typObiektu")!=null)
	{
		$(".rw-obiekt").each(function(i){
			if ($(this).text()==$.cookie("typObiektu"))
			{
				$(this).addClass('rw-obiekt-hov');
			}
		});

	}
	
	/*
	 * asari typ obiektu
	 */
	
	
	/* 
	 * notes
	 */
	
	$(".notes").click(function()
	{
		if($.cookie("note")!=null)
		{
			var tmpCake = $.cookie("note");
			if(tmpCake.match($(this).attr("href").substring(1,$(this).attr("href").length)))
			{
				alert('Oferta została już dodana');
			}
			else{
				var tmpStr = tmpCake+$(this).attr("href").substring(1,$(this).attr("href").length);
				//alert(tmpStr);
				$.cookie("note",tmpStr+';', {path:'/'});
				
				var temp = new Array(); 
				temp = tmpStr.split(';');
				
				$('a[href$="Notes"]:first').text('NOTES ( '+temp.length+' )');

			}
		}
		else{
			$.cookie("note",$(this).attr("href").substring(1,$(this).attr("href").length)+';', {path:'/'});
			//alert('ciacho!');
			$('a[href$="Notes"]:first').text('NOTES ( 1 )');
		}
	});
	
	$(".notes-del").click(function(){
		if($.cookie("note")!=null)
		{
			var tmpCake = $.cookie("note");
			if(tmpCake.match($(this).attr("href").substring(1,$(this).attr("href").length)))
			{
				tmpCake = tmpCake.replace($(this).attr("href").substring(1,$(this).attr("href").length)+';','');
				$.cookie("note",tmpCake, {path:'/'});

				$(location).attr('href','http://konstans.com.pl/_new/Rynek_Wtorny/Notes');
			}
		}
	});
	
	$("#rw-clear-note").click(function(){
	
		$.cookie("note",null,{path:'/'});
		$(location).attr('href','http://konstans.com.pl/_new/Rynek_Wtorny/Notes');
		
	});
	
	$("#rp-build").change(function()
	{
		$("#rp-build option:selected").each(function()
		{
			$.post(siteurl+'modules/RP_Glowna/panel.RP_Glowna.php?what=rp-build&id='+$(this).attr('value'), function(data) {
				
				var temp = new Array(); 
				temp = data.split(';');
				
				$("#rp-flor").children().remove();
				$("#rp-flor").append('<option value="0">wszystkie</option>');
				for(var i=0; i<temp.length-1;i++)
				{
					var t = new Array(); 
					t = temp[i].split(',');
					
					$("#rp-flor").append('<option value="'+t[0]+'">'+t[1]+'</option>');
				}
			});

		});
	});
	 
	 
	 
	/* 
	 * notes
	 */
	 
	 /* 
	  * rp-lokal box
	  */
	
	$("#rp-lokal").hover(function()
	{
		$("#rp-lokal-box").css('display','block');
		// $("#rp-lokal-box").css('top',e.pageY+'px');
		// $("#rp-lokal-box").css('left',e.pageX+'px');
		
		$("#rp-lokal").mousemove(function(evt){
		$("#rp-lokal-box").css('top',(evt.pageY+20)+'px');
		$("#rp-lokal-box").css('left',(evt.pageX+20)+'px');
		}); 
		
	},function(){
		$("#rp-lokal-box").css('display','none');
		}
	);
	
	

	
	// $("#rp-lokal").mouseleave(function()
	// {
		// $("#rp-lokal-box").css('display','none');
	// });
	
	$(".rp-lokal").hover(function()
	{
		var id = $(this).attr('id');
		var temp = new Array(); 
		
		$.post(siteurl+'modules/RP_Lokal/panel.RP_Lokal.php?what=rp-lokal&id='+id, function(data) {
			temp = data.split(';');
			$("#rp-lokal-box").empty();
			$("#rp-lokal-box").detach();
			$("body").append('<div id="rp-lokal-box" style="display: block;"><p class="header" id="head"></p><p><span class="title">Metraż:</span><span id="metraz"></span><span class="title">Stan:</span><span id="stan"></span></p></div>');
			$("#metraz").text(temp[2]);
			$("#head").text(temp[1]);
			$("#stan").text(temp[4]);
		});
		
		$(".rp-lokal").mousemove(function(evt){
			var left = evt.pageX;
			var top = evt.pageY;
			$("#rp-lokal-box").css('top',(top+20)+'px');
			$("#rp-lokal-box").css('left',(left+20)+'px');
		});
		

	}, function(){
		$("#rp-lokal-box").empty();
		$("#rp-lokal-box").detach();
	});
	
	
	$(".pdf").attr('target','_blank');
	
	/* 
	 * Szukajka
	 */
	 
	$("#tabs").tabs();
	
	
	
	$("#right-mask-slide").slider({vertical:true, speed:30000});
	//$("#partnerzy-slider").slider({vertical:true});
	
});

 
 
  

