function SetPropertyType(TypeName){
	if (TypeName=="Studio Flat"){
		$("div#containerrooms").hide();
	}else{
		$("div#containerrooms").show();
	}
}
$(document).ready(function(){
	$(".navlistitem").hover(function(){
		$(this).prev().css("background","url(./_images/list-image-over.png) no-repeat right");
		$(this).css("background","url(./_images/list-image-over.png) no-repeat right");
	},function(){
		$(this).prev().css("background","url(./_images/list-image-off.png) no-repeat right");
		$(this).css("background","url(./_images/list-image-off.png) no-repeat right");
	});
	$("select#propertytype").change(function() { SetPropertyType($(this).val()); });
	SetPropertyType($("select#propertytype").val());
	imagescrolly();
	
	$('ul a').collapsor();
	
	$(".viewingform").validate({
	errorClass: "verrorlabel"
	});
	$(".tenantregistrationform").validate({
	errorClass: "errorlabel",
	submitHandler: function(form) {
		// bind to the form's submit event 
		// inside event callbacks 'this' is the DOM element so we first 
		// wrap it in a jQuery object and then invoke ajaxSubmit 
		$(".tenantregistrationform").ajaxSubmit({
			target:			".ajaxform"   // target element(s) to be updated with server response 
			//beforeSubmit: 	showRequest,   // pre-submit callback 
			//success:		showResponse  // post-submit callback 

			// other available options: 
			//url:       "./_scripts/newsletter.php?ajax=Y"         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit 

			// $.ajax options can be used here too, for example: 
			//timeout:   3000
		});
		// !!! Important !!! 
		// always return false to prevent standard browser submit and page navigation 
		return false; 
	}
	});
	$(".landlordregistrationform").validate({
	errorClass: "errorlabel",
	submitHandler: function(form) {
		// bind to the form's submit event 
		// inside event callbacks 'this' is the DOM element so we first 
		// wrap it in a jQuery object and then invoke ajaxSubmit 
		$(".landlordregistrationform").ajaxSubmit({
			target:			".ajaxform"   // target element(s) to be updated with server response 
			//beforeSubmit: 	showRequest,   // pre-submit callback 
			//success:		showResponse  // post-submit callback 

			// other available options: 
			//url:       "./_scripts/newsletter.php?ajax=Y"         // override for form's 'action' attribute 
			//type:      type        // 'get' or 'post', override for form's 'method' attribute 
			//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
			//clearForm: true        // clear all form fields after successful submit 
			//resetForm: true        // reset the form after successful submit 

			// $.ajax options can be used here too, for example: 
			//timeout:   3000
		}); 

		// !!! Important !!! 
		// always return false to prevent standard browser submit and page navigation 
		return false; 
	}
	});
});

function imagescrolly() {
	$(".additionalimgbox").each(function(){
		$(this).width($(this).children("a").length * 198+"px");
	});
	
	//Do the scrolling
	var leftmargin = 0;

	$(".imgscrollleft").click(function(){
	//Check to see if scrolling is possible
	$("img.imgscrollright").attr({"src":($(".additionalimgbox").children("a").length > 3 ? "./_images/button-right-active.jpg":"./_images/button-right-inactive.jpg")});
			if (leftmargin >= 0) {
			} else {
				leftmargin = leftmargin +198;
				$(".additionalimgbox").animate({"left":""+leftmargin+"px"}, 500);
				imgscroll(leftmargin,$(".additionalimgbox"));
			}
	});
	
	$(".imgscrollright").click(function(){
	//Check to see if scrolling is possible
	$("img.imgscrollright").attr({"src":($(".additionalimgbox").children("a").length > 3 ? "./_images/button-right-active.jpg":"./_images/button-right-inactive.jpg")});
		if (leftmargin <= -$(".additionalimgbox").width() + 594) {
			//alert("no more images");
			imgscroll(leftmargin,$(".additionalimgbox"));
		} else {
			leftmargin = leftmargin -198;
			$(".additionalimgbox").animate({"left":""+leftmargin+"px"}, 500);
			//alert($(this).parent().children("div").height());
			imgscroll(leftmargin,$(".additionalimgbox"));
		}
	});
}

function imgscroll(leftmargin,obj) {
	//alert(obj);
	if (leftmargin <= -obj.width() + 594) {
		$("img.imgscrollright").attr({"src":"./_images/button-right-inactive.jpg"});
	} else {
		$("img.imgscrollright").attr({"src":"./_images/button-right-active.jpg"});
	}
	
	if (leftmargin < 0) {
		$("img.imgscrollleft").attr({"src":"./_images/button-left-active.jpg"});
	} else {
		$("img.imgscrollleft").attr({"src":"./_images/button-left-inactive.jpg"});
	}
}
