$(document).ready(function() {	
	$('#selectState').change(function(){
		if($(this).val() != "")
			document.location = $(this).val();
	});

       
	$('a[name=modal]').live('click',function(e) {
		e.preventDefault();
		var listing_id = $(this).attr('href');
		var id = "#dialog";
		var date_now = new Date();
		$(id).html('Loading...');
		$.ajax({
		    url: listing_id+'/'+date_now.getTime(),
		    type: 'GET',	   
		    success: function(data){
			
		        $(id).html(data);
		        
		        setTimeout("$('#images a').lightBox();", 500);
		    }			
		});				
		
	
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		$('#mask').css({'width':maskWidth,'height':maskHeight});
 
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);

        $('#dialog-header').css('top', (winH/2-$(id).height()/2)-30);
        $('#dialog-header').css('left', $(id).css('left'));
        $('#dialog-header').css('width', '770px');
        $('#dialog-header').fadeIn(2000);

		$(id).fadeIn(2000); 
	return false;
	});
        


	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
                $("#dialog").hide();
                $("#dialog-header").hide();
	});	
});

function close_window() {
		
	$('#mask').hide();
	$('.window').hide();
        $("#dialog").hide();
        $("#dialog-header").hide();
	
};

