/*
 * Mikhail Kozlov
 * http://www.315design.com/ 
 *  
 */
		var lastTip = '';

        $(document).ready(function() {
			$(".ToolTipAjax").click(function(){
				return false;
			});
			$('.ToolTipAjax').hover(function(e) {
				$caller = $(this);
				$caller.css("cursor","progress");
				if (lastTip != $caller.attr('ref')) {
					lastTip = $caller.attr('ref');
					$("#info").load(this.href, {}, function(){
						$(this).fadeIn(200);
						$caller.css("cursor", "pointer");
					});
				}else{
					$("#info").fadeIn(200);
					$caller.css("cursor", "pointer");
				}
				$('#info').css('top', e.pageY + +20).css('left', e.pageX -250);
					
			}, function() {
				$('#info').hide();
			});
			$('.ToolTipAjax').mousemove(function(e) {
				$('#info').css('top', e.pageY + +20).css('left', e.pageX -250);
			});

        	$("#cur_form div:last").hide();
			$("#cur_form").show();
			$("#res_wraper a").click(function(){
				$("#res_wraper a").toggleClass("current");
	        	$("#cur_form div").toggle();
				return false;
			});
			$("form.searchForm").submit(function(){
				$(this).find("input:submit").addClass("pressed").val("Searching...");
				return true;
			});

            $("#promo div a.link").hover(function() {
	                $(this).find("img").fadeTo(100, 0.75);
	                $(this).append($("<div>Click here for<br /> rental details and floor plans</div>"));
				},function(){
	                $(this).find("img").fadeTo(100, 1);
					$("#promo a").find("div:last").remove();
				}
            );
			$("input, select, textarea").live("click",function(){
				if($(this).parent().hasClass("inputRed")){
					$(this).parent().removeClass("inputRed");
				}
			});
			$("input, select, textarea").focus(function(){
				if($(this).parent().hasClass("inputRed")){
					$(this).parent().removeClass("inputRed");
				}
			});
			
       });
	function onSubmit(source,req) {
		var flag = true;
		$("input:text, select, textarea").each(function (i) {
			for (x in req){
				minlength = 2;
				if(parseInt($(this).attr("minlength")) > minlength){
					minlength = parseInt($(this).attr("minlength")) - 1;
				}
				if(req[x] == $(this).attr("id") && $(this).val().length < minlength){
					flag=false;
					$(this).parent().addClass("inputRed");
				}
			}
		});
		if(flag){
			return true;
		}
		else{
			alert("Required fields are empty!\nPlease correct fields marked with red border and submit this form again.");
			return false;
		}
		return false;      	
	}
	function roundNumber(number,decimal_points) {
		if(!decimal_points) return Math.round(number);
		if(number == 0) {
			var decimals = "";
			for(var i=0;i<decimal_points;i++) decimals += "0";
			return "0."+decimals;
		}
	
		var exponent = Math.pow(10,decimal_points);
		var num = Math.round((number * exponent)).toString();
		return num.slice(0,-1*decimal_points) + "." + num.slice(-1*decimal_points)
	}
