var pictures = new Object;

$(document).ready(function()
{
	//Image Box - Fancybox
	if(_action == "details")
	{
		$("#small #photos a").click(function(e){e.preventDefault();return false;})
				.fancybox({
				 	'padding': 0
				 });
				 
		$("#small #media a.vt").click(function(e){
			e.preventDefault();
			if($.browser.safari==true)
			{
				var vt = window.open(this.href, 'vtour', 'menubar=no,toolbar=no,location=no,srollbars=no,resizable=no,width=480, height=430');
			}
			return false;
		});
		
		if(!$.browser.safari){
			$("#small #media a.vt").fancybox({
					 	'padding': 0,
					 	'frameWidth': 480,
					 	'frameHeight': ($.browser.msie==true)?440:433,
					 	'hideOnContentClick': false
					 });
		}

		$("#small #media a.video").click(function(e){
			e.preventDefault();
			if($.browser.msie==true)
			{
				var video = window.open(this.href, 'vtour', 'menubar=no,toolbar=no,location=no,srollbars=no,resizable=no,status=no,directories=no,width=320, height=320');
			}
			return false;
		});
		
		if(!$.browser.msie)
		{
			$("#small #media a.video").fancybox({
					'padding': 0,
					'frameWidth': 320,
					'frameHeight': 313,
					'hideOnContentClick': false
			 });
		}
				
		$("#small #media a#mb-map").click(function(e){e.preventDefault();return false;})
					 .fancybox({
					 	'padding': 0,
					 	'frameWidth': 420,
					 	'frameHeight': ($.browser.msie==true)?330:320,
					 	'hideOnContentClick': false
					 });
					 
		var data = new Array(
			"fancy_loading.gif",
			"fancy_progress.png",
			"fancy_closebox.png",
			"fancy_left.png",
			"fancy_right.png",
			"fancy_title_left.png",
			"fancy_title_main.png",
			"fancy_title_right.png"
		);	 
		$.each(data, function(i, val){
	 		var src = _baseUrl+"/images/ressources/"+val;
	 		pictures[src] 	= new Image;
       		pictures[src].src = src;
		});
	}
	
	//Currency bottom hover
	$("a.rollOver img").hover(
	function(){
		var id = $(this).attr("id");
		this.src = _baseUrl+"/images/currencies/"+id+"_on.gif";
	},
	function(){
		var id = $(this).attr("id");
		this.src = _baseUrl+"/images/currencies/"+id+".gif";
	}).each(function(i, val){
	 	var src = _baseUrl+"/images/currencies/"+$(val).attr("id")+"_on.gif";
	 	pictures[src] 	= new Image;
       	pictures[src].src = src;
	});

	
	var search = new Object({'on': _baseUrl+'/images/search/search_cz_on.gif', 'off': _baseUrl+'/images/search/search_cz.gif'});
	pictures[search.on] 	= new Image;
    pictures[search.on].src = search.on;
	
	$("#go_search_valid").hover(
	function(){
		$(this).css("background-image", "url("+search.on+")");
	},
	function(){
		$(this).css("background-image", "url("+search.off+")");
	});
	
	/*************************************************/
	/*					Select Box				 	 */
	/*************************************************/
	$(document.getElementsByTagName('select')).linkselect();
	
	/* for entrust-form */
	$("li[id^=propertyType]").click(function (){
		$("#entrust_form").validate().element("#propertyType");
	});
	
	/* for contactus-form */
	$("li[id^=statut]").click(function (){
		$("#contactus_form").validate().element("#statut");
	});
	
	/*************************************************/
	/*		Preloader for images in lists			*/
	/*************************************************/
	 $(".default_ad_img").each(function(i, e){
	 	var osrc = this.src;
	 	this.src = _baseUrl+'/images/common/empty.gif';
	 	$(this).load(function() {
		   	$(this).parent().removeClass('preloading');
		}).attr('src', osrc);
	});
	
	$(".toggle_search .green_button a").click(function(e){
		e.preventDefault;
		$("#search_top").slideToggle(300);
		$("#search_top_params").slideToggle(300);
		return false;
	});
	
	if(_action=='search')
	{ 
		$("#params-details").val("");
	}
	
});

function add_navigation(mode, title, url) {
	switch (mode) {
		case "shortcut" :
			if ($.browser.msie) {
				window.external.AddFavorite(url, title);
			} else if (window.sidebar) {
				window.sidebar.addPanel(title, url, "");
			} else if (window.opera && window.print) { 
				var a = document.createElement('a'); 
				a.setAttribute('href', adres); 
				a.setAttribute('title', tytul); 
				a.setAttribute('rel','sidebar'); 
				a.click(); 
			} else {
				$.weeboxs.open(_translate.navigation.firefox_default_brosware, {type: 'box', timeout: 3, cancelBtnName: _translate.weebox.cancel});
			}
			break;

		case "homepage" :
			if ($.browser.msie) {
				document.body.style.behavior='url(#default#homepage)';
				document.body.setHomePage(url);
			} else {
				$.weeboxs.open(_translate.navigation.firefox_default_brosware, {type: 'box', timeout: 3, cancelBtnName: _translate.weebox.cancel});
			}
			break;
	}
}

function DistrictReload()
{	
	$("#params-locLev").val(0);
	$("#params-locLevMeta").val("");
	$("#params-locIdMeta").val("");
	$("#params-locId").val($("#params-district").val());
	$("#params-town").val("");
	$("#params-details").val(1);
	document.form.submit();
}

function propertyTypeReload()
{	
	$("#params-details").val(1);
	document.form.submit();
}

function ToogleSelect(id)
{
	if( $(".linkselectContainer").is(":visible") ){
		$("#"+id).linkselect("close");
	} else {
		$("#"+id).linkselect("open");
	}
}

function ChangeTypeInMap(type)
{
	propertytype = type;
	setAcExtraParams(type);
	resetSearch();
}
