function makeHttpRequest(url, callback_function, return_xml,container)
{
   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,"'+container+'")');
               } else {
                   eval(callback_function + '(http_request.responseText,"'+container+'")');
               }
           } else {
//               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
   }
   http_request.open('GET', url, true,container);
   http_request.send(null);
}

function loadBanner(xml,container)
{
    var html_content = xml.getElementsByTagName('content').item(0).firstChild.nodeValue;
    var reload_after = xml.getElementsByTagName('reload').item(0).firstChild.nodeValue;
    document.getElementById(container).innerHTML = html_content;

    try {
        clearTimeout(to);
    } catch (e) {}
	if(container_index==5)
		container_index=0;
    to = setTimeout("nextAd('"+currentPath+"','"+containers[container_index]+"')", parseInt(reload_after));


}

function nextAd(currentPath,container)
{
	// banner_page comes from html which includes this file

    var url = '../../index.php/getBanner/'+banner_page+'/'+positions[containers[container_index]];
    makeHttpRequest(url, 'loadBanner', true,container);
	
	if(index)
		container_index++;	
}

function init(regime){
	nextAd(currentPath,'topBanner');
	if(regime==1){
		nextAd(currentPath,'rightBanner1');
		nextAd(currentPath,'rightBanner2');
		nextAd(currentPath,'rightBanner3');
		nextAd(currentPath,'rightBanner4');			
	}
}

var containers=new Array('topBanner','rightBanner1','rightBanner2','rightBanner3','rightBanner4');
positions=new Array();
positions['topBanner']='top';
positions['rightBanner1']='right1';
positions['rightBanner2']='right2';
positions['rightBanner3']='right3';
positions['rightBanner4']='right4';
var container_index=0;