$(document).ready(function() {
	$( 'a._blank' ).click( function() {
		window.open( this.href, this.title );
		return false;
	});
	$( '#langChange' ).change( function() {
		$(this).submit();
	});
	try {
		$( '#propSearchForm' ).submit( function() {
			try {
				$.cookie( 'searchLoc',  $( '#city' ).find( 'option:selected' ).val( ), { expires : 31, path : '/' } );
			} catch( e ) {}
			try {
				$.cookie( 'searchType', $( '#type' ).find( 'option:selected' ).val( ), { expires : 31, path : '/' } );
			} catch( e ) {}
			try {
				$.cookie( 'prop_type', $( '#propSearchForm input:radio:checked' ).val( ), { expires : 31, path : '/' } );
			} catch( e ) {}
		});
	} catch( e ) {}
	$( '#langChange' ).find( 'option:first' ).remove( );
	$( '#langChange' ).find( 'input:submit' ).remove( );
	$( '#langChange' ).find( 'legend' ).remove( );
	$( '.imageHolder' ).find( 'img' ).css( 'cursor', 'pointer' );
	$( '.imageHolder' ).find( 'img' ).click( function( ) {
		window.open( this.src, this.title );
	});
	$( '.imageHolder' ).find( 'img' ).hover( function() {
		return window.status = this.src;
	}, function() {
		return window.status = '';
	});
	if ( $.cookie( 'searchLoc' ) || $.cookie( 'searchType' ) || $.cookie( 'prop_type' ) ) {
		var loc		= $.cookie( 'searchLoc' );
		var type	= $.cookie( 'searchType' );
		var propT	= $.cookie( 'prop_type' );
		try {
			$( '#city' ).find( ' option[value= ' + loc + ']' ).attr( 'selected', 'selected' );
		} catch( e ) {}
		try{
			$( '#type' ).find( 'option[value= ' + type + ']' ).attr( 'selected', 'selected' );
		} catch( e ) {}
		try {
			$( '#propSearchForm input:radio[value="' + propT + '"]' ).attr( 'checked', 'checked' );
		} catch( e ) {}

	}
	if( location.host != 'cbhc') {
		rotateImages( );
	}
	var sortTables	= $( '.sortableTable' );
	$.each( sortTables, function( n, v ) {
		if( $(this).attr( 'id' ) == 'rent' ) {
			$(this).tablesorter( 	{ headers : { 0 : { sorter : false },
												  4 : { sorter : false }
												}
			});
		} else {
			$(this).tablesorter( 	{ headers : { 0 : { sorter : false },
												  5 : { sorter : false }
												}
			});
		}
	});
});
