$(document).ready(function(){

	if(typeof(men_hl)=='number') {
		$("ul#LavaG li:eq("+(men_hl)+")").addClass("selected");
	} else {
		$("ul#LavaG li:eq(0)").addClass("selected");
	}


var c = $('ul.lamp').size();
var isie6 = false;
if (typeof document.body.style.maxHeight == "undefined")  { isie6 = true; }
if(isie6 == false) {
for(var i=0; i<c; i++) {
	$('#lavaL'+(i+1)).lavaLamp({
		fx: 'easeOutExpo',//easeInQuad , easeOutElastic
		speed: 300,
		homeTop:8,
		homeLeft:9,
		returnHome:true,
		setOnClick: false
		//homeWidth:193,
		//homeHeight:30
	});
}
}

$("ul.lamp").removeClass("lm_mod");



//$('#tabs div').hide(); // Hide all divs
//$('#tabs div:first').show(); // Show the first div
//$('#tabs div').hide(); // Hide all divs



$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
$('#tabs2 ul li:first').addClass('active');

$('span#wpisz').removeClass('tc2');
$('span#wpisz').hide();


if (typeof(from) !== 'undefined') {

var type=from;

if(type == 'wpisz') { $("#sfrom").val('#wpisz'); } else {
$("#sfrom").val('#lista');
}

//spr
if($("#miejsc").val()) {
	$("#sfrom").val('#wpisz');
	var type='wpisz';
}

$('#tabs2 span').hide(); // Hide all divs
$('#tabs2 span#'+type).show(); // Show the first div
$('#tabs2 ul li').removeClass('active');
$('#tabs2 ul li#li_'+type+'').addClass('active');
}



var sel_box = 0;
$('#tabs2 ul li a').click(function(){ //When any link is clicked
	$('#tabs2 ul li').removeClass('active'); // Remove active class from all links
	$(this).parent().addClass('active'); //Set clicked link class to active
	var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
	$('#tabs2 span').hide(); // Hide all divs
	$(currentTab).show(); // Show div with id equal to variable currentTab
	sel_box = currentTab;
	$("#sfrom").val(sel_box);
	return false;
});


$.extend({
	getUrlVars: function() {
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; });
		return vars;
	}
});

var wx = window.location.href;
if(wx.indexOf('.html') > 0) {
	if(wx.indexOf('na_sprzedaz')>0 || wx.indexOf('do_wynajecia')>0 || wx.indexOf('wyszukiwarka')>0) {
		var id = 'search';
	}	
} else {
	var id = $.getUrlVars()['id'];
}
if(id == 'search') {
	if(wx.indexOf('.html')) {
		var type;
		if(wx.indexOf('mieszkania')>0) type = 'mieszkania'; 
		if(wx.indexOf('domy')>0) type = 'domy'; 
		if(wx.indexOf('dzialki')>0) type = 'dzialki'; 
		if(wx.indexOf('lokale')>0) type = 'lokale'; 
		if(wx.indexOf('obiekty')>0) type = 'obiekty'; 
	} else {
	var type = $.getUrlVars()['type'];
	}
	
}

if(typeof(type) !== 'undefined' || typeof(stype) !== 'undefined') {
	if(typeof(stype) !== 'undefined' && stype != 'all') { type = stype+'#a';  }
	type = type.split("#");
	lab = type[1];
	type = type[0];
	var arr = [ "mieszkania", "domy", "dzialki", "lokale", "obiekty" ];
	if(jQuery.inArray(type, arr) != -1) {
		//$('#tabs div').hide(); // Hide all divs
		//$('#tabs div#'+type).show(); // Show the first div
		$('#tabs ul li.t1').removeClass('active');
		$('#tabs ul li#li_'+type+'').addClass('active');
	}
}

$("#control").css("cursor", "pointer");

$("#control").click(function () {
	$("div.search_box_cont").slideToggle("fast");
});

function fhideSearchBox() {
	$("div.search_box_cont").fadeOut(0,function() {
	//$(this).remove();
	//$(this).fadeIn();
	});
}

if(typeof hideSearchBox !== 'undefined') {
	if (hideSearchBox == 1) fhideSearchBox();
}

//var urlanchor = self.document.location.hash.substring(1);


$('.big_img a').lightBox();
$('table.contact_img a').lightBox();
$('.info_dzien a').lightBox();

$('.images a').click(function() {
	src = $(this).attr('href');
	$('div.big_img a.current img').attr('src',src);
	$('div.big_img a.current').attr('href',src);
	return false;
});


$(function() {
	function format(data) {
		return data.gmi + ', '+data.pow;
	}
	$("#miejsc").autocomplete('location.php', {
		multiple: false,
		dataType: "json",
		parse: function(data) {
			return $.map(data, function(row) {
				return {
					data: row,
					value: row.gmi,
					result: row.gmi
				}
			});
		},
		formatItem: function(item) {
			return format(item);
		}
	}).result(function(e, item) {
	//
	});
});

var sub_help1 = 'Wpisz <b>miejscowość</b>, <b>gminę</b> lub <b>powiat</b> <br />(np dębicki) <br /> Można wpisać do 6 lokalizacji, <br>oddzielając je przecinkami <br>(np Tarnowiec,Zgłobice,dębicki)'; 

$('img.help').tooltip({
    delay: 0, 
    showURL: false, 
    bodyHandler: function() { 
        return sub_help1; 
    } 
});
});
