
function createRequestObject() {
   var ro;
   var browser = navigator.appName;
   if(browser == "Microsoft Internet Explorer"){
      ro = new ActiveXObject("Microsoft.XMLHTTP");
   }else{
      ro = new XMLHttpRequest();
   }
   return ro;
}

var http = createRequestObject();

function sndReq(skip,count, newAnchor, newLi, ulElem) {
   http.open('get', '/getmore.php?skip='+skip+'&count='+count);
   http.onreadystatechange = handleResponse;
   http.send(null);
}

function handleResponse() {
   if (http.readyState == 4) { 
      var response = http.responseText;
      
      var update = new Array();
      var listItem = "";

      if (response.indexOf('|' != -1)) {
         update = response.split('|');
         listItem = "<div style=\"font-size: 0.8em; margin-bottom: 0;\">"+update[2]+"</div><div style=\"font-weight: normal; font-size: .75em; margin-bottom: 6px;\">by "+update[1]+"</div><img class=\"preview\" style=\"margin-left: 30px; border: 1px solid black;\"src=\"http://209.85.64.50/wallpaper/previews/01471_birdiebythelake.jpg\" alt=\"image loading...\" width=\"240\" height=\"150\" />";
      }
   }
}


/**
 * @author mmalone
 */
// used by the incremental list loading Sample
var controller = null;
function insertProgress()
{
	var progContainer = document.getElementById("progressCont");
	var can = document.createElement("canvas");
	can.setAttribute("height", 100);
	can.setAttribute("width", 100);
	can.setAttribute("style", "background:#transparent;");
	progContainer.appendChild(can);

	controller = getLoading(can.getContext("2d"), 12, {x:20, y:20}, 6, {width: 2, height: 5}, {red: 50, green: 79, blue: 133});
}
// used by the incremental list loading Sample
function loadMore()
{
	var progContainer = document.getElementById("progressCont");
	// remove progress indicator
	if(progContainer.firstChild)
	{
		controller.stop();
		progContainer.removeChild(progContainer.firstChild);
	}

	// insert progress indicator
	var progContainer = document.getElementById("progressCont");
	var can = document.createElement("canvas");
	can.setAttribute("height", 100);
	can.setAttribute("width", 100);
	can.setAttribute("style", "background:#transparent;");
	progContainer.appendChild(can);

	controller = getLoading(can.getContext("2d"), 12, {x:20, y:20}, 6, {width: 2, height: 5}, {red: 50, green: 79, blue: 133});
	
	setTimeout("appendItems()", 1000);
}
// used by the incremental list loading Sample
function appendItems()
{

	var moreItemLI = document.getElementById("moreListItem");
	var ulElem = moreItemLI.parentNode;
	
	childCount = ulElem.getAttribute("count");
	
	// remove more item
	ulElem.removeChild(moreItemLI);
	// append more items
	for(var appendCount=0;appendCount < 5;appendCount++)
	{
		var newLi = document.createElement("Li");
		var newAnchor = document.createElement("A");
		var updateArray = new Array();
		newAnchor.setAttribute("href","#");
		newAnchor.setAttribute("onClick","window.location.href='/wallpaper/details.php?id=1471'");
		childCount++;
		newAnchor.setAttribute("id",childCount);
		//newAnchor.innerHTML = "Wallpaper " + (++childCount) + "";
		sndReq(10,1);
		newAnchor.innerHTML = "<div style=\"font-size: 0.8em; margin-bottom: 0;\">aa</div><div style=\"font-weight: normal; font-size: .75em; margin-bottom: 6px;\">by bb</div><img class=\"preview\" style=\"margin-left: 30px; border: 1px solid black;\"src=\"http://209.85.64.50/wallpaper/previews/01471_birdiebythelake.jpg\" alt=\"image loading...\" width=\"240\" height=\"150\" />";
		newLi.appendChild(newAnchor);
		ulElem.appendChild(newLi);
	}
	//put back more item
	ulElem.appendChild(moreItemLI);
	ulElem.setAttribute("count", childCount);
	
	var progContainer = document.getElementById("progressCont");
	// remove progress indicator
	if(progContainer.firstChild)
	{
		controller.stop();
		progContainer.removeChild(progContainer.firstChild);
	}
}
// used by the toggle button in the button samples
function toggleBtn(which)
{
	which.className = (which.className.indexOf('togButtonOff') > 0) ? 'togButton togButtonOn noHighlight' : 'togButton togButtonOff noHighlight';
}
// used by the orientation sample
if("orientation" in window)
{
	setTimeout("updateOrientation()",10000);
}
// used by the orientation sample
function updateOrientation()
{
	var displayStr = "Orientation " + "(" + window.orientation + "): ";
	
	switch(window.orientation)
	{	
		case 0:
			displayStr += "Portrait";
		break;
		
		case -90:
			displayStr +=  "Landscape (right, screen turned clockwise)";
		break;
		
		case 90:
			displayStr += "Landscape (left, screen turned counterclockwise)";
		break;
		
		case 180:
			displayStr += "Portrait (upside-down portrait)";
		break;
		
	}
	document.getElementById("orientationBucket").innerHTML = displayStr;
}

var startDate = null;

// used by the window sample
var win = null;
function showChild() {
	
	var loc = "child.html";	
	var winStr = "resizable=1,status=yes,scrollbars=yes,toolbar=no,location=no,menu=no";
	var winName = "iPhone";
	win = window.open(loc, winName , winStr);
}

// used by the window sample
function windowCheck() {
	try 
	{
		if(!win.name) {
			alert("Child is Closed");	
			return false;
		}
	}
	catch(e) {
		alert("Child is Closed");	
		return false;
	}
	return true;
}
