/*
BRE.Locum
ver. 1.0.0    
24.03.2011
*/
function popup (win, x, y, n, p) {
	if (!win) return false;
	var winName = n ? n : 'BRE Locum';
	var params = p ? p : 'menubar=no,resizable=no,toolbar=no,status=no,location=no,menubar=no,personalbar=no,scrollbars=yes';
	window.open(win, winName, 'width=' + x + ',height=' + y + ',' + params);
	return false;
}
$(document).ready(function(){
	// $("a.image img").each(function(){
    		// var img = $(this);
    		// var pad = (120 - img.height())/2;
    		// $(this).parent().css("padding-top",pad);
			// if(img.height() == 107){
				// $(this).parent().css("max-height",106);
			// }
			// if(img.height() > 160){
				// $(this).parent().css("max-height",160);
			// }
	// });
	$(".image_container img").each(function(){
    		var img = $(this);
    		var pad = (120 - img.height())/2;
    		$(this).css("padding-top",pad);	
	});
	$("ul#nav li:last-child").addClass("last");
	$(".sitemap-col ul li:last-child").each(function(){
		hc = $(this).parent().parent().hasClass("custom");
			if(!hc){
			var html = $(this);
			$(this).parent().prepend(html);
			$(this).addClass("bold");
			}
	});
	
	
	Cufon.replace('#nav li a,.home_boxes h2,h3',{"hover": true,"fontFamily":'MetaPro'});
	Cufon.replace('#top_nav li a',{"hover":true,"fontFamily":'MetaProBold'});
	
	var ctnActive = $("ul#nav li.active").size();
	if(ctnActive > 1){
		$("ul#nav li.active").each(function(){
			$(this).removeClass("active");
		});  
	}
	var ctnTabs = $("ul.tabs").size();
	if(ctnTabs > 0){
		$(".right_col").addClass("right_tab_spacer");
	}

	$("table.listing tbody tr:odd").addClass("even");
	$("table tr:odd").css("background-color","#f7f7f7");
	
	$(".center_col #searchBox #pokazBtn,.home_boxes #searchBox #pokazBtn").click(function(){
		var Miasto	= $("#Miasto option:selected");
		var Inwestycja	= $("#Inwestycja option:selected");
		var Pokoje	= $("#Pokoje option:selected");
		var Metraz	= $("#Metraz option:selected");
		var get = "";
		Miasto = Miasto.attr("value").split(',');
		Miasto = Miasto[3];
		Inwestycja = Inwestycja.attr("value").split(',');
		Inwestycja = Inwestycja[3];
		Pokoje = Pokoje.attr("value");
		Metraz = Metraz.attr("value");
		if(Pokoje != '0') get += "?pokoje="+Pokoje;
		if(get != '') get += "&";
		if(Metraz != '0') get += "metraz="+Metraz;
		if(Miasto == undefined) Miasto = '';
		if(Inwestycja == undefined) {Inwestycja = '';}else{Inwestycja+="/";}
		separator = "/";
		if(Inwestycja == '' && Miasto == '') {
			//alert('Wybierz inwestycję');
			return false;
		}else {
			var Url = "/sprzedaz_mieszkan/"+Miasto+separator;
			if (Inwestycja != '') {
				Url += Inwestycja+"znajdz-mieszkanie"+separator+get;
			}
			document.location = Url;
		}
	});

	// header's height fix
	var strLen = $(".left_col h3 span").text().length
	if(strLen > 21){
		if(strLen > 31){
			$(".left_col h3").addClass("longer");
			$(".page_header h2").addClass("extrapadded");
			$(".left_col h3 span").addClass("long");
		}else{
			$(".left_col h3 span").addClass("long");
		}
	}
	$("ul.side_navigation li:last").addClass("last");
	
	var url = location.href;
	var splitArr = url.split(".pl");
	var url = splitArr[1];

	$("ul#nav li a").each(function(){
		var link = $(this).attr("href");
		if(url.indexOf(link) != -1){
			$(this).parent().addClass("active");
		}

	});  
	

	
	//print
	$("#print").click(function(){
		popup('/bin/print.php',800,600);
	});

        
       $('select').selectmenu({
		style: 'dropdown', 
		open: function(e, data){
           var menu = $('ul#'+$(this).attr('id')+'-menu');
           menu.find('li:first-child.disabled').remove();
           }
	});
	
	if($("a[class=zoom]").size() > 0){	
	    $("a[class=zoom]").fancybox({
		'transitionIn'	:'fade',
		'transitionOut'	:'fade',
		'speedIn'	:600,
		'speedOut'	:200,
		'overlayShow'	:true
	    });
	}

});
