/*
Script Dependencies: common.js
*/

// The variable http will hold our new XMLHttpRequest object.
var http = CreateRequestObject(); 
// The variable will indicate which featured property to update
var propertyIndex = 1;
var innerHTML = '';

window.onload = function()
{
    // Set a timeout of 3 seconds for featured property refresh
    self.setTimeout( 'RequestFeaturedProperties()', 3000 );
}

function RequestFeaturedProperties()
{
	http.open('get', baseDirectory + '/property_rotate.php' );
	http.onreadystatechange = CycleFeaturedProperties; 
	http.send(null);
}

function CycleFeaturedProperties()
{
    if( http.readyState == 4 )
    {
        var response = http.responseText;

        // If our response text contains data update the featured property list
		if( response.length != 0 )
		{
		    if( document.getElementById( propertyIndex.toString() ))
			{
			    new Effect.Fade( propertyIndex.toString() );
			    innerHTML = response;
			    self.setTimeout( 'FadeIn()', 1000 );
            }
		}
    }
}

function FadeIn()
{
	document.getElementById( propertyIndex.toString() ).innerHTML = innerHTML;
    new Effect.Appear( propertyIndex.toString() );

    propertyIndex++;
    
    // Rest the property index
    if( propertyIndex == 7 )
    {
         propertyIndex = 1;
    }

    self.setTimeout( 'RequestFeaturedProperties()', 4000 );
}

