var reqPhotoScroller;
var myNextActionPhotoScroller;
var myFutureActionsPhotoScroller;
var myActionURLPhotoScroller;
var myActionDIVPhotoScroller;
var delimiterPositionPhotoScroller;

function LeftPhotoScroller(strPhotoScroller, nPhotoScroller){
	if (nPhotoScroller <= 0)
	    return "";
	else if (nPhotoScroller > String(strPhotoScroller).length)
	    return strPhotoScroller;
	else
	    return String(strPhotoScroller).substring(0,nPhotoScroller);
}
function RightPhotoScroller(strPhotoScroller, nPhotoScroller){
    if (nPhotoScroller <= 0)
       return "";
    else if (nPhotoScroller > String(strPhotoScroller).length)
       return strPhotoScroller;
    else {
       var iLenPhotoScroller = String(strPhotoScroller).length;
       return String(strPhotoScroller).substring(iLenPhotoScroller, iLenPhotoScroller - nPhotoScroller);
    }
}

function updateDIVPhotoScroller(myActionsPhotoScroller) {
	//alert(myActionsPhotoScroller);
	
	//myActions format: actionURL~actionORSC|actionURL~actionORSC|actionURL~actionORSC|
	
	//alert(myActionsPhotoScroller);
	myActionsArrayPhotoScroller = myActionsPhotoScroller.split("|");
	myNextActionPhotoScroller = myActionsArrayPhotoScroller[0];
	//alert("myNextAction:"+myNextActionPhotoScroller);

	myFutureActionsPhotoScroller = RightPhotoScroller(myActionsPhotoScroller,myActionsPhotoScroller.length-myNextActionPhotoScroller.length-1)
	//alert("myFutureAction:"+myFutureActionsPhotoScroller);

	myActionArrayPhotoScroller = myNextActionPhotoScroller.split("~");
	myActionURLPhotoScroller = myActionArrayPhotoScroller[0];
	myActionDIVPhotoScroller = myActionArrayPhotoScroller[1];
//	alert(myActionURL+" : "+myActionDIVPhotoScroller);

	reqPhotoScroller = false;

    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			reqPhotoScroller = new XMLHttpRequest();
        } catch(e) {
			reqPhotoScroller = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	reqPhotoScroller = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		reqPhotoScroller = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		reqPhotoScroller = false;
        	}
		}
    }
	if(reqPhotoScroller) {
    //alert(req.readyState);
    myRandomNumberPhotoScroller = parseInt(Math.random()*999999999);
		reqPhotoScroller.onreadystatechange = replaceDIVcontentPhotoScroller;
		//alert(myActionURL + "&rand=" + myRandomNumber);
		reqPhotoScroller.open("GET", myActionURLPhotoScroller + "&rand=" + myRandomNumberPhotoScroller, true);
		reqPhotoScroller.send("");

	}
}



function replaceDIVcontentPhotoScroller() 
	{
  // only if req shows "loaded"
  //alert(req.readyState);
  if(reqPhotoScroller.readyState == 4) 
  	{
    // only if "OK"
		//alert(reqPhotoScroller.statusText);
    if(reqPhotoScroller.status == 200) 
    	{
			//alert("hi");
			var myTextPhotoScroller = reqPhotoScroller.responseText;
			//alert(myTextPhotoScroller);
			//document.getElementById('testtarget').innerHTML = myTextPhotoScroller;
			document.getElementById(myActionDIVPhotoScroller).innerHTML = myTextPhotoScroller;
			if (myFutureActionsPhotoScroller.length>6)
				{
				//alert(myFutureActions);
				updateDIVPhotoScroller(myFutureActionsPhotoScroller);
				}
    	}
    else 
    	{
			alert("There was a problem retrieving the data:\n" +
			reqPhotoScroller.statusText);
    	}
  	}
	}
