$( document ).ready( function()
{
	$( '.corner' ).corner( "10px" );
	/**
	 * A warning message appears everytime you click an object in the page which has
	 * a warning class attached to it
	 */
	$( '.warning' ).click( function()
	{
		if( ! confirm( 'Are you sure? This cannot be undone!' ) )
		{
			return false;
		}
		
		return true;
	});
	
	$( '#subnav li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
	$( '#nav li a' ).each( function() {
		if( $( this ).parent().attr( 'id' ) != 'cart' )
		{
			if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
			{
				$( this ).addClass( 'active' );
			}
		}
	} );
	
	$( '.icons li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).addClass( 'active' );
		}
	} );
	
	$( '#sidebar ul li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
	$( '#captcha' ).click( function() { $( this ).attr( 'src', '/captcha?id=' + Math.random() ) } );

	$.datepicker.setDefaults({showOn: 'button', buttonImageOnly: true, 
    buttonImage: '/img/calendar.png', buttonText: 'Calendar', dateFormat: 'mm-dd-yy'});
    
    $('.date-pick').datepicker();
    
    $( '#list a' ).click( function() {
		
		var image = $( this ).attr( 'rel' );

		$('.photo a img').attr( 'src', '/files/list/' + image );
		var href_print = $('.photo a').attr( 'rel' ) + '/image/' + image;
		$('.photo a').attr( 'href', href_print );
		$('#print a').attr( 'href', href_print );
	
		return false;
	} );
	
	$( '#print a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=500,height=600' ); return false; } );
	$( '.photo a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=500,height=600' ); return false; } );
    $( '.contact_landlord' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=400,height=400' ); return false; } );
    $( '.send_to_friend' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=400,height=400' ); return false; } );
	
    $('.click_ads').each( function() { $( this ).attr( 'href', '/ads/click/params/id/' + $( this ).attr( 'rel' ) ); });
    
});

function redirectTO( url )
{
	document.location=url;
}

function openWindow( theURL, winName, features )
{
	window.open( theURL, winName, features );
}
