﻿
var timer;
var timer2;
var activeMenu = '';
var activePage;


function closeMenu(timeout,id,removeClass){
	if (timeout == false){
		close_id = id
	}
	else {
		close_id = id.id
	}
	
	if (close_id != activePage){
		$("#"+close_id).removeClass('parent_items_over').addClass('parent_items');
	}
	$("#"+close_id).find('.child_items_holder').stop(true,true).slideUp('medium');
	activeMenu = '';
}
function closeMenuOver(timeout,id){
	close_id = id.id
	
	$("#"+close_id).find('.child_items_holder').stop(true,true).slideUp('medium');
	activeMenu = '';
}


$(document).ready(function () {
	$('A[rel="_blank"]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	
	// START MENU
	
	
	
	$('.parent_items').each(function(a) {
		
		$(this).hover(
			function () {
				clearTimeout(timer);
				id = this.id;
				if (activeMenu != id && activeMenu != ''){
					//text = document.getElementById('home_left').innerHTML;
					//document.getElementById('home_left').innerHTML = text + "<br>" + activeMenu + " " + id;
					closeMenu(false,activeMenu);
				}
				
				if (activeMenu == ''){
					activeMenu = id;
					if ($(this).children().size() > 0){						
						$(this).removeClass('parent_items').addClass('parent_items_over');
						$(this).find('.child_items_holder').stop(true,true).slideDown('fast');
					}
					else{
						activeMenu = id;
						$(this).removeClass('parent_items').addClass('parent_items_over');
					}
				}
				
			}, 
			function () {
				id = this.id;
				if (activeMenu == id){
					if ($(this).children().size() > 0){
						timer = setTimeout('closeMenu(true,'+ id +')',1000);
					}
					else{
						activeMenu = '';
						$(this).removeClass('parent_items_over').addClass('parent_items');
					}
				}
			}
		);
		
	});
	$('.parent_items_over').each(function(a) {
		activePage = this.id;
		$(this).hover(
			function () {
				clearTimeout(timer);
				id = this.id;
				if (activeMenu != id && activeMenu != ''){
					closeMenu(false,activeMenu);
				}
				
				if (activeMenu == ''){
					activeMenu = id;
					if ($(this).children().size() > 0){
						$(this).find('.child_items_holder').stop(true,true).slideDown('fast');
					}
					else{
						activeMenu = id;
					}
				}
				
			}, 
			function () {
				id = this.id;
				if (activeMenu == id){
					if ($(this).children().size() > 0){
						timer = setTimeout('closeMenuOver(true,'+ id +')',1000);
					}
				}
			}			
		);
	});

	$('.child_items').each(function(b) {
		
		if (b%2 != 0){
			$(this).removeClass('child_items').addClass('child_items2');
		};
		
		$(this).hover(
			function () {
				$('.parent_items').each(function(a) {
					$(this).find('.child_items_holder').stop(true,true);
				});
				$(this).addClass('child_items_over');
			}, 
			function () {
				$(this).removeClass('child_items_over');
			}
		);
	});
	// FINISH MENU

	// LEFT MENU
	var activeSlide;
	var currentSlide;
	var noScroll = true;

	$('.lmp').each(function(c) {
		this.className = $(this).attr('class')
		
		/*if (c%2 != 0){
			if ($(this).attr('class') != 'lmp left_menu_parent_over'){
				$(this).removeClass('left_menu_parent').addClass('left_menu_parent2');
			}
		};*/
		if ($(this).attr('class') == 'lmp left_menu_parent_over'){
			$(this).parent().children('.lmc_holder').children('a').each( 
				function(){ 
					if ($(this).attr('class') == 'lmc_hover'){
						noScroll = false;
					}
				}
			);
			if (noScroll == true){
				$(this).parent().children('.lmc_holder').stop(true,true).slideToggle('medium');
			}
			else {
				$(this).parent().children('.lmc_holder').css('display','block');
			}
			activeSlide = c;
		};
		
		$(this).parent().hover(
			function () {
				if ($(this).find('.lmp').attr('class') != 'lmp left_menu_parent_over'){
					$(this).find('.lmp').addClass('left_menu_parent_over');

				};
			}, 
			function () {
				if ($(this).find('.lmp').attr('class') != 'lmp left_menu_parent_over'){								
					$(this).find('.lmp').removeClass('left_menu_parent_over').addClass(this.className);			
				};
				
			}
		);
		/*
		$(this).click(
			function () {
				//alert($(this).attr('class'))
				if ($(this).attr('class') != 'lmp left_menu_parent_over'){
					$('#lmp_' + currentSlide).parent().find('.lmc_holder').slideToggle('medium');
					
					$(this).parent().find('.lmc_holder').stop(true,true).slideToggle('medium');
					currentSlide = c;
				}
			}
		);*/	
	});

	$('.lmc_holder a').each(function(c) {
		this.className = $(this).attr('class')
		if ($(this).attr('class') != 'lmc_hover'){
			$(this).hover(
				function () {
					$(this).addClass('lmc_hover');
				}, 
				function () {
					$(this).removeClass('lmc_hover').addClass(this.className);
				}
			);
		};
	});
	
	var active_state = '';
	
	function activate_state(state,state_abr){
		if(state != active_state){		
			if (active_state != ""){
				$("#"+active_state).stop().fadeTo('fast', 0, function() {
					active_state = state;
					$("#"+state).stop().fadeTo('fast', 1, function() {
						// Animation complete.
					});
					document.getElementById('state').value = state_abr;
					return false;
				});
			}
			else{
				active_state = state;
				$("#"+state).stop().fadeTo('fast', 1, function() {
					// Animation complete.
				});
				document.getElementById('state').value = state_abr;
				return false;
			}
		}
	}
	
	$("#QLD").hover(
		function () {
			$("#home_search_map_qld").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_qld'){
				$("#home_search_map_qld").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_qld','QLD');
			return false;
		}
	);
	$("#NSW").hover(
		function () {
			$("#home_search_map_nsw").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		},
		function () {
			if (active_state != 'home_search_map_nsw'){
				$("#home_search_map_nsw").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_nsw','NSW');
			return false;
		}
	);
	$("#VIC").hover(
		function () {
			$("#home_search_map_vic").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_vic'){
				$("#home_search_map_vic").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_vic','VIC');
			return false;
		}
	);
	$("#TAS").hover(
		function () {
			$("#home_search_map_tas").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_tas'){
				$("#home_search_map_tas").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_tas','TAS');
			return false;
		}
	);
	$("#SA").hover(
		function () {
			$("#home_search_map_sa").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_sa'){
				$("#home_search_map_sa").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_sa','SA');
			return false;
		}
	);
	$("#WA").hover(
		function () {
			$("#home_search_map_wa").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_wa'){
				$("#home_search_map_wa").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_wa','WA');
			return false;
		}
	);
	$("#NT").hover(
		function () {
			$("#home_search_map_nt").stop().fadeTo('fast', 1, function() {
				// Animation complete.
			});
		}, 
		function () {
			if (active_state != 'home_search_map_nt'){
				$("#home_search_map_nt").stop().fadeTo('fast', 0, function() {
					// Animation complete.
				});
			}
		}			
	).click(
		function () {
			activate_state('home_search_map_nt','NT');
			return false;
		}
	);
	
	
	$('#go_btn').click(function() {
		document.search.submit();
	});
	
	$('#search_go_btn').click(function() {
		document.search.submit();
	});
	
});

function imagePopup(propertyID,photoID){
	window.open("images.php?propertyID="+propertyID+"&photoID="+photoID,null,"height=760,width=818,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");

}
