function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function sendAjaxRequest(url, parameters) {
  // create the AJAX object
  var xmlHttp = undefined;
  if (window.ActiveXObject){
    try {
      xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
    } catch (othermicrosoft){
      try {
        xmlHttp = new ActiveXObject(
            "Microsoft.XMLHTTP");
      } catch (failed) {}
    }
  }    

  if (xmlHttp == undefined && window.XMLHttpRequest) {
    // If IE7, Mozilla, Safari, etc: Use native object
    xmlHttp = new XMLHttpRequest();
  }  

  if (xmlHttp != undefined) {
    // open the connections
    xmlHttp.open("POST", url, true);
    // callback handler
    xmlHttp.onreadystatechange = function() {
      // test if the response was totally sent
      if (xmlHttp.readyState == 4
            && xmlHttp.status == 200) {
        // so far so good
        // do something useful with the response
		HandleResponse(xmlHttp.responseText);
      }
    }  

    // create the parameter string
    // iterate the parameters array
    var parameterString;
	//n = count(parameters);
	if(parameters == null)
		parameterString = null;
	else
		for (var i in parameters) {
		  parameterString += (i > 0 ? "&" : "")
			  + parameters[i][0] + "="
			  + encodeURI(parameters[i][1]);
		}
	
	//alert(parameterString);

    // set the necessary request headers
    xmlHttp.setRequestHeader("Content-type",
        "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length",
        parameterString.length);
    xmlHttp.setRequestHeader("Connection", "close");  

    // send request
    xmlHttp.send(parameterString);
  }
}

function isMyStuffScrolling() {
  //var docHeight = $(document).height();
  //var scroll    = $(window).height() + $(window).scrollTop();
  //return (docHeight == scroll);
  return (document.body.scrollHeight > document.body.clientHeight);
}


function getResolutionWidth() {
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
	 screenW = screen.width;
	 screenH = screen.height;
	}
	else if (navigator.appName == "Netscape" 
		&& parseInt(navigator.appVersion)==3
		&& navigator.javaEnabled()
	   ) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenW = jScreenSize.width;
	 screenH = jScreenSize.height;
	}
	
	return screenW;
}

function getBrowsersWidth() {
	var myWidth;
	var myHeight;
	
	if( typeof( window.innerWidth ) == 'number' ) { 
	
	//Non-IE 
	
	myWidth = window.innerWidth;
	myHeight = window.innerHeight; 
	
	} else if( document.documentElement && 
	
	( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
	
	//IE 6+ in 'standards compliant mode' 
	
	myWidth = document.documentElement.clientWidth; 
	myHeight = document.documentElement.clientHeight; 
	
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
	
	//IE 4 compatible 
	
	myWidth = document.body.clientWidth; 
	myHeight = document.body.clientHeight; 
	
	}
	
	return myWidth;
}

function getObject( obj )
{
	var strObj
	if ( document.all )
	{
		strObj = document.all.item( obj );
	}
	else if ( document.getElementById )
	{
		strObj = document.getElementById( obj );
	}
	return strObj;
}

function RequestVisitorsCount()
{
  var xmlHttp = getXMLHttp();
  //alert('request sent');
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      document.getElementById('visitors_container').innerHTML = xmlHttp.responseText;
	  setTimeout('RequestVisitorsCount()', 10000);
    }
  }

  xmlHttp.open("GET", "/Actions/get_visitors_count.php", true);
  xmlHttp.send(null);
  //sendAjaxRequest('/Views/Admin/getVisitors.php', null);
}

var theTop = 18;

var theHeight = 100;

var theWidth = 127;

var theLeft = 0;

var toClip = 90;


function scrollNews( newsDiv, toMove )
{
	//setting scroling news to a right place according clients display width
	var siteWidth = 1000;
	var scrollBarWidth = isMyStuffScrolling() ? 0 : 8;
	var right = getBrowsersWidth() - ((getBrowsersWidth() - siteWidth) / 2);
	
	if (right < siteWidth) {
		scrollBarWidth = -10;
		right = siteWidth;
	}

	var left = right - 130 - scrollBarWidth;
	$('#news').css({"left":left});

	theDiv = getObject( newsDiv.toString() );
	if ( theDiv == null ) { return; }
	
	if ( document.layers )
	{
		theDiv.clip.top = toMove;
		theDiv.clip.bottom = toMove + toClip;
		theDiv.top = theTop - toMove;
	}
	else
	{
		theDiv = theDiv.style;
		theDiv.clip = "rect(" + toMove + "px " + (theWidth + theLeft) + "px " + (toMove + toClip) + "px 0px)";
		theDiv.top = theTop - toMove + 'px';
	}
	if ( toMove > 700 )
	{
		toMove = 0;
		
		if ( document.layers )
		{
			theDiv.clip.top = theTop;
			theDiv.clip.bottom = toClip;
			theDiv.top = theTop
		}
		else
		{
			theDiv.clip = "rect(" + toMove + "px " + (theWidth + theLeft) + "px " + (toMove + toClip) + "px 0px)";
			theDiv.top = theTop + 'px';
		}
	}
	
	toMove = (toMove + 1);
	setTimeout("scrollNews('" + newsDiv + "'," + toMove + ")", 100);
}
