var GB_ANIMATION = true;
$(function(){init();})

function init()
{
	  $("a.greybox").click(function(){
	       var t = this.title || $(this).text() || this.href;
	       check = this.rel;
	       if(check){
	       		param = check.split(':');
	       		if(param[1])
	       		{
	       			height_grey = param[0];
	       			width_grey = param[1];
	       		}else{
	       			height_grey = 470;
	       			width_grey = 600;
	       		}
	       		
	       }else{
	       		height_grey = 470;
	       		width_grey = 600;
	       }
	       GB_show(t,this.href,height_grey,width_grey);
	       return false;
	     });
	
	
	// for left menu buying- renting	
		$('#menu_all #buying_renting .box').click(function(){
			indexs = $('#menu_all #buying_renting .box').index(this);
			indexs = (indexs)?0:1;
			
			$("div").data("type",indexs);
			
			if($(this).not('.box_active'))
			{					
				$.blockUI();
				$('div#innerWrapper0').load( index()+'callback/scholtens.get_suburb/'+indexs,{},function(){
					setTimeout($.unblockUI, 10);
					$('#menu_all #innerWrapper0 a').toggle(
						function () {	
							$('#menu_all #innerWrapper0 a').removeClass('mtm_menu_active');
							$(this).addClass('mtm_menu_active');
							
							indexs = $('#buy_rent').val();
							indexs = (indexs=='buying')?0:1;
							
							suburb = $(this).attr('rel');
							
							$.blockUI();
							$('div#innerWrapper1').load( index()+'callback/scholtens.get_property/'+indexs+'/'+suburb,{},function(){
								setTimeout($.unblockUI, 10);	
								
								$('div#innerWrapper1 a').toggle(
									function () {	
										$('#menu_all #innerWrapper1 a').removeClass('mtm_menu_active');
										$(this).addClass('mtm_menu_active');												
									},
									function () {
										$(this).removeClass('mtm_menu_active');										
									}		
								);
										
							});
						},
						function () {
							$(this).removeClass('mtm_menu_active');				
						}		
					);										 
				});
				
				$(this).addClass('box_active');			
				$('#menu_all #buying_renting .box').eq(indexs).removeClass('box_active');
				value = (indexs)?'buying':'renting';
				$('#menu_all #buy_rent').val(value);
			}	
		})
	
	
	// for left menu min -max	
		/*$('#menu_all #min_max .box').click(function(){
			index = $('#menu_all #min_max .box').index(this);
			index = (index)?0:1;
			if($(this).not('.box_active'))
			{
				$(this).addClass('box_active');			
				$('#menu_all #min_max .box').eq(index).removeClass('box_active');
				value = (index)?'asc':'desc';
				$('#menu_all #min_max_id').val(value);
			}	
		})*/
		
	// for left menu suburb
		$('#menu_all #innerWrapper0 a').toggle(
			function () {	
				$('#menu_all #innerWrapper0 a').removeClass('mtm_menu_active');
				$(this).addClass('mtm_menu_active');
				
				indexs = $('#buy_rent').val();
				indexs = (indexs=='buying')?0:1;
				
				suburb = $(this).attr('rel');
				
				$.blockUI();
				$('div#innerWrapper1').load( index()+'callback/scholtens.get_property/'+indexs+'/'+suburb,{},function(){
					setTimeout($.unblockUI, 10);
					$('div#innerWrapper1 a').toggle(
						function () {
							$('#menu_all #innerWrapper1 a').removeClass('mtm_menu_active');
							$(this).addClass('mtm_menu_active');												
						},
						function () {
							$(this).removeClass('mtm_menu_active');										
						}		
					);			
				});
			},
			function () {
				$(this).removeClass('mtm_menu_active');				
			}		
		);		
	
	// for submit
		$('#menu_all #submit_form').click(function(){
			uid = $(this).attr('title');
			
			list_suburb = '';
			$('#menu_all #innerWrapper0 .mtm_menu_active').each(function(){
				list_suburb += $(this).attr('rel');
			})
			if(!list_suburb)
			{
				alert('Please select suburb');
				return false;
			}else
			{				
				$('#menu_all #suburb_id').val(list_suburb);
			}
				
			
			list_property = '';
			$('#menu_all #innerWrapper1 .mtm_menu_active').each(function(){
				list_property += $(this).text();
			})
			
			if(!list_property)
			{
				alert('Please select property');
				return false;
			}else{
				$('#menu_all #property_id').val(list_property);
			}
			
			__dopostback(uid,'');
		})
	
	// 
		
		$('#signup_table .box').click(function(){
			index = $('#signup_table .box').index(this);
			switch(index)
			{
				case 1:
						value = 'seller';
					break;
					
				case 2:
					value = 'landlord';
					break;
				default:
					value = 'buyer';
				break;	
			}
			
			
			if($(this).not('.box_active'))
			{
				$('#signup_table .box').removeClass('box_active');
				$(this).addClass('box_active');			
				$('#signup_table #signup_type').val(value);
			}
				
		})
		
	
	// submit for signup
	$('#signup_table img').click(function(){
		firstname = $('#signup_table #signup_first_name');
		if(!$.trim(firstname.val()))
		{
			alert('Please fill your first name');
			firstname.focus();
			return false;
		}
		
		lastname = $('#signup_table #signup_last_name');
		if(!$.trim(lastname.val()))
		{
			alert('Please fill your last name');
			lastname.focus();
			return false;
		}
		
		email = $('#signup_table #signup_email');
		if(!$.trim(email.val()))
		{
			alert('Please fill your email');
			email.focus();
			return false;
		}else{
			if(!/^([a-zA-Z0-9_\.])+\@([a-zA-Z0-9\-])+\.([a-zA-Z0-9]{2,4})(\.[a-zA-Z0-9]{2,4})?$/.test(email.val()))
			{
				alert("Your email is invalid!");
				email.focus();
				return false;
			}
		}
		
		uid = $(this).attr('title');
		__dopostback(uid,'');
		
	})
	
}