document.thumbIndex = null;

function makeHttpRequest(url, callback_function, return_xml)
{
   var http_request = false;

   if (window.XMLHttpRequest) { // Mozilla, Safari,...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
           http_request.overrideMimeType('text/xml');
       }

   } else if (window.ActiveXObject) { // IE
       try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
       }
   }

   if (!http_request) {
       alert('Unfortunatelly you browser doesn\'t support this feature.');
       return false;
   }
   http_request.onreadystatechange = function() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               if (return_xml) {
                   eval(callback_function + '(http_request.responseXML)');
               } else {
                   eval(callback_function + '(http_request.responseText)');
               }
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url, true);
   http_request.send(null);
}

function loadTBanner(xml)
{
    var contentID = xml.getElementsByTagName('cID').item(0).firstChild.nodeValue;
	var html_content = xml.getElementsByTagName('content').item(0).firstChild.nodeValue;
    var reload_after = xml.getElementsByTagName('reload').item(0).firstChild.nodeValue;
		
	//document.getElementById('contentRotate').innerHTML = html_content;
	document.getElementById('contentRotate').innerHTML = "<img src='images/spacer.gif' height='100%' width='100%' />";
	$('#contentRotate img').fadeTo(500, 0.0, function() {
                $(this).attr("src",html_content).fadeTo(100, 1.0);
            });
	
	/*$("#contentRotate img").ready(function () {
          $("#contentRotate img").fadeIn(1000);
        });*/
	

	
	//$("#contentRotate").html(html_content);
	//$("#contentRotate").wrapInner() = html_content;
	
	//$("#BannerDiv").children().showdelay();
	
	/*$("#contentRotate").blur(function () {
          $("img").fadeIn(1000);
        });
	
	$("#contentRotate").ready(function () {
          $("img").fadeIn(1000);
        });*/
		
	/*$(document).ready(function () {
          $("#contentRotate img").fadeIn(1000);
        });*/
	
	
	if(document.thumbIndex == 7)
	{
		document.thumbIndex = 0;
	}
	else if(document.thumbIndex == null)
	{
		document.thumbIndex = 1;
	}
	else
	{
		document.thumbIndex = parseInt(contentID) + 1;
	}
	
	
	
	//document.thumbIndex++;
	//alert(document.thumbIndex);
	
    try {
        clearTimeout(to);
    } catch (e) {}

    to = setTimeout("nextThumb()", parseInt(reload_after));
}

function nextThumb(displayid,project, projectid)
{

    var now = new Date();
	if(displayid)
	{
		//alert(displayid);
    	var url = 'thumbRotate.php?cid=' + displayid + '&project='+ project + '&projectid='+ projectid + '&ts=' + now.getTime();
	}
	else if(document.thumbIndex == null)
	{
		document.thumbIndex = 0;
		var url = 'thumbRotate.php?project='+ project + '&projectid='+ projectid + '&ts=' + now.getTime();
	}
	else
	{	
		if(document.thumbIndex == 7)
		{
			document.thumbIndex = 0;
		}
		var url = 'thumbRotate.php?cid=' + document.thumbIndex + '&ts=' + now.getTime();
	}
	//alert(url);
	if(displayid > (document.thumbIndex+1))
	{
		var featureID = "feature"+(displayid+1);
		//alert(featureID);
	}
	else if(displayid == null)
	{
		var featureID = "feature"+(document.thumbIndex+1);;
		//alert(featureID);
	}
	else
	{
		var featureID = "feature"+(displayid+1);
		//alert(featureID);
	}
	
	//menuReset();
	//if(featureID)
	//MM_swapImage(featureID,'','http://www.torontocondos.com/_images/images_n/button_on.gif',1);
	
    makeHttpRequest(url, 'loadTBanner', true); 

}

