function getHttpRequest(url, params, _onload)
{
	var httpRequest = false;
	if (window.XMLHttpRequest) 
	{
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) 
		{
			httpRequest.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) 
	{
		try 
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) 
			{
			}
		}
	}

	if (!httpRequest)
	{
		alert('Unfortunatelly you browser doesn\'t support this feature.');
		return false;
	}

	httpRequest.onreadystatechange = function()
	{
		if (httpRequest.readyState == 4)
		{
			if (httpRequest.status == 200 || httpRequest.status == 0)
			{
				if(elem_main = document.getElementById("ajax-content"))
				{
					elem_main.innerHTML = httpRequest.responseText;
					var _scripts = elem_main.getElementsByTagName('div');
					for(var i = 0; i < _scripts.length; i++)
					{
						if(_scripts[i].className == 'js2run')
						{
							eval(_scripts[i].innerHTML);
              
						}
					}
					try{
            initScrollbars();
            hisliderRun();   // See hislider.js
          }catch(e){};
					if(_onload)
					{
						eval(_onload);
					}
				}
			}
			else
			{
				alert('There was a problem with the request.(Code: ' + httpRequest.status + ')');
			}
		}
	}

	if(params == undefined || params == null)
	{
		httpRequest.open('GET', url, true);
		httpRequest.send(null);
	}
	else
	{
		httpRequest.open('POST', url, true);
		httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpRequest.setRequestHeader("Content-length", params.length);		
		httpRequest.setRequestHeader("Connection", "close");
		httpRequest.send(params);
	}
}

function initAjaxLinks()
{
	var _as = document.getElementsByTagName('a');
	for(var i = 0; i < _as.length; i++)
	{
			var _href = _as[i].href.substr(_as[i].href.lastIndexOf("/")+1);
			if(_href.length > 0 && _as[i].rel == 'ajax' && _as[i].href.indexOf("javascript") == -1)
			{
				_as[i]._href = _as[i].href
				_as[i].href = "javascript:;";
				_as[i].onclick = function()
				{
          var regexp = /^.*\/(.*[^\/])$/g;
          var str = this._href;
          var result = regexp.exec(str);
          location.hash = '#' + result[1];
          if (result[1] == 'home.html' || result[1] == '')
          {
            getHttpRequest(location.protocol + '//' + location.hostname + '/' + 'home-images-slider');
          }
          else
          {
            getHttpRequest(this._href);
          }
					return false;				
				}				
			}
      
      if (location.hostname == SERVER_NAME && !AJAX_Called)
      {
        if (location.hash == '' || location.hash == '#home.html') 
        {
          var path = location.protocol + '//' + location.hostname + '/' + 'home-images-slider';  // See /modules/custom/home_images_slider
        }
        else
        {
          var hash = location.hash;
          var path = location.protocol + '//' + location.hostname + '/includes/' + hash.substr(1);
        }
        getHttpRequest(path);
        AJAX_Called = 1;
      }
	}
}

if (window.addEventListener)
	window.addEventListener("load", initAjaxLinks, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initAjaxLinks);

