var uid = 0001;
var statsArray = [];
var windowWidth = 0;
var windowHeight = 0;
var tilesWindowWidth = 0;
var tilesCounter = 0;


$(document).ready(function(){

	//updateContentTop();

	var randomnumber = createRandomNumber();
	loadXml('client/build_news_xml.asp?acctNumber='+uid+'&rnd='+randomnumber, processXml);
	//displayVideo();

});



function loadXml(xmlLocation, callback) {

	try
	{
		$.ajax(
		{
			type: "GET",
			url: xmlLocation,
			dataType: "xml",
			success: function(xml)
			{
				if (callback)
				{
					callback(xml);
				}
			},
			error: function(x, s, e)
			{
				alert("xml loading error "+x+" / "+s+" / "+e+" / "+callback);
			}
		});
	}
	catch (e)
	{
		$.log('ERROR: (loadXml:catch) ' + e);
	}
}






function processXml(theXml) {
	
	statsArray.length = 0;
	
	totalFavorites = 0;
	
	if($("statData", theXml).text() != 'none') {
	
	    $("statData", theXml).each(function(i) {
		
			var statItem = new Object();
	        statItem.id = i;
			statItem.siteDateAdded = $('siteDateAdded', this).text();
			statItem.siteTitle = unescape($('siteTitle', this).text());
			statItem.siteDescription = unescape($('siteDescription', this).text());

	        statsArray.push(statItem);
			
	    });
		
		createTiles();

	}

}






function createTiles() {

	var theDiv = $('#tiles');
	
	$(theDiv).empty();
	
	tilesCounter = 0;
	
	$.each(statsArray, function(i){ 
	
		var theImageName = this.siteName;
		var theId = this.id;
		var theSiteId = this.siteId;
		var theSiteTitle = this.siteTitle;
		var theDateAdded = this.siteDateAdded;
		var theDescription = this.siteDescription;

		
		if(theDescription==''){
			theDescription='&nbsp;'
		}

		var theHtml = '';
		theHtml +='<div class="newsWrapper"><div class="newsBorder"><div class="newsPadding"><div class="newsContent">';
		theHtml += '<div class="newsDetailsWrapper">';

		theHtml += '<div class="newsTitle">'+theSiteTitle+'</div>';
		theHtml += '<div class="newsText">'+theDescription+'</div>';
		theHtml += '<div class="newsDate">Added:&nbsp;'+theDateAdded+'</div>';

		theHtml += '</div>';
		theHtml +='</div></div></div></div>';
		
		theHtml +='<div class="clear vBuffer10"><div></div></div>';
	
		theDiv.append(theHtml);


	});

	
	
	
	
	

}





