/*
BRE.Leasing
ver. 1.0.1
11.04.2011
*/

function openTab() {
	var target = document.getElementById("branch").value;
	if (target != '') {
		return true;
	}
	else {
		return false;
	}
}

function popup (win, n, p) {
	if (!win) return false;
	var params = 'menubar=no,resizable=no,toolbar=no,status=no,location=no,menubar=no,personalbar=no,scrollbars=yes';
	window.open(win, "BRE Leasing", 'width=800,height=600,' + 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);	
	});
	if($("#tabbedContent").size() > 0){
		$(".right_col").css("margin-top","70px");
	}
	$("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,#section_name h2 span,.right_col h2',{"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;
		}
	});
        var duplicSel = $("ul.side_navigation li.selected ul.side_navigation li.selected").size();

        if (duplicSel > 0){
            $("ul.side_navigation li.selected ul.side_navigation li.selected").parent().parent().removeClass("selected");
        }
        $("ul.side_navigation li:last-child").css("border-bottom","none");
	// header's height fix
	var strLen = $(".left_col h2 span").text().length
	if(strLen > 21){
		if(strLen > 31){
			$(".left_col h2").addClass("longer");
			$(".page_header h1").addClass("extrapadded");
			$(".left_col h2 span").addClass("long");
		}else{
			$(".left_col h2 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(event){
            var tabs = document.location.toString(), qs = '';
            var tc = $("#tabbedContent");
            if(tc.get(0)){				
	       var tabs = tabs.substring(tabs.indexOf(".pl")+3)+"index.html.tab";
	       var afterTabs = tabs.indexOf("tabs=");
	       if(afterTabs != -1){
		  tabs = tabs.substring(0,afterTabs-1);
		  tabs = tabs+"index.html.tab";
	       }

	       qs = '?print=on&tabs='+tabs;
	       qs = qs.replace("#",'');		
            }			
		popup('/bin/print.php' + qs,800,600,"BRE Leasing");
	});

        
        $('select').selectmenu({
		style: 'dropdown',
		maxHeight: '200'
	});
        $("table tr:odd").addClass("even")	


});
