$(document).ready(function(){
	hs.outlineType = 'rounded-white';

	$("#loading").ajaxStart(function(){
		$(this).show();
	});
	$("#loading").ajaxStop(function(){
		$(this).hide();
	});
     
	$("select[name=convertCurrency],select[name=convertCurrency2]").bind("change", function(){
		$("#priceCurrency1").empty();
		$("#priceCurrency1").append($("option[value="+$(this).val()+"]").text().substring(0,3));
		$(".currencyDetail").empty();
		$(".currencyDetail").append($("option[value="+$(this).val()+"]").text().substring(0,3));
		
		$.ajax({
			type: "GET",
			url: "convertCurrency.php?price="+$("#priceTotal").text()+"&priceRate="+$(this).val(),
			success: function(data){
				$("#priceTotalDescr").empty();
				$("#priceTotalDescr").append(data);
				$("#priceTotalSign").empty();
				$("#priceTotalSign").append(data);
			}
		});
		$.ajax({
			type: "GET",
			url: "convertCurrency.php?price="+$("#pricePerSqm").text()+"&priceRate="+$(this).val(),
			success: function(data){
				$("#pricePerSqmDescr").empty();
				$("#pricePerSqmDescr").append(data);
			}
		});
		$.ajax({
			type: "GET",
			url: "convertCurrency.php?price="+$("#priceStartsFrom").text()+"&priceRate="+$(this).val(),
			success: function(data){
				$("#priceStartsFromDescr").empty();
				$("#priceStartsFromDescr").append(data);
				$("#priceStartsFromSign").empty();
				$("#priceStartsFromSign").append(data);
			}
		});
	});
	
	$(".facilityPic").bind("mouseover", function(){
		$("#facilityDisplay").empty();
		$("#facilityDisplay").append($(this).attr("alt"));
		$("#facilityDisplay").fadeIn("fast");
	});
	
	$(".facilityPic").bind("mouseout", function(){
		$("#facilityDisplay").fadeOut("fast");
	});
	
	$("#sendToAFriend").bind("click", function(){
		if ($("#sendToAFriendFormContent").css("display") == "none"){
			$.ajax({
				type: "GET",
				url: "sendToAFriend.php",
				success: function(data){
					$("#sendToAFriendFormContent").empty();
					$("#sendToAFriendFormContent").append(data);
				}
			});
			$("#sendToAFriendFormContent").slideDown("fast");
		}else{
			$("#sendToAFriendFormContent").slideUp("fast");
		}
	});	
	
	$("#showImages").bind("click", function(){
		$("#picturesRest").slideDown("slow");
		$(this).hide();
		$("#hideImages").show();
	});
	$("#hideImages").bind("click", function(){
		$("#picturesRest").slideUp(500);
		$(this).hide();
		$("#showImages").show(800);
	});
	
	$("#sendData").bind("click", function(){
		
		var accessName     = $("input[name=access_user_name]").val();
		var accessPassword = $("input[name=access_password]").val();
		
		var error1 = false;
		var error2 = false;
		
		if(accessName == ""){
			$("#errorAccessName").css({'display' : 'block'});
			error1 = false;
		}else{
			$("#errorAccessName").css({'display' : 'none'});
			error1 = true;
		}	
	
		if(accessPassword == ""){
			$("#errorAccessPasword").css({'display' : 'block'});
			error2 = false;
		}else{
			$("#errorAccessPasword").css({'display' : 'none'});
			error2 = true;	
		}
		
		if(error1 && error2){
			$("form[id='accessForm']").submit;
		}
		else return (error1 && error2);		
	});
});

function NewWindow(mypage,myname,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=1, resizable=1, scrollbars=1'
	win = window.open(mypage,myname,settings)
}


