//Configure
var whereFrom = "http://www.marketingtipsuk.com";
var title = "Latest Internet Marketing News";

// Constructor -- pass a REST request URL to the constructor
//
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

function displayResults(jsonData){
	sText = "Data returned from JSON:";
	if(oDiv = document.getElementById("output")){
		if(title.length > 0){
			oDiv.innerHTML = "<p style='color:"+textColor+"; font-size:"+textFontSize+"; font-family:"+font+"; font-weight:bold; text-align:"+titleAlign+";' align='center'><a href='"+whereFrom+"' title='"+title+"' style='color:"+textColor+"; font-size:"+textFontSize+"; font-family:"+font+"; font-weight:bold; text-decoration:none;'>"+title+"</a></p>";
		}else{
			oDiv.innerHTML = "";
		}
		for(var i=0; i<jsonData.length; i++){
			postLink = "<a href='"+jsonData[i].link+"' style='color:"+urlColor+"; font-size:"+urlFontSize+"; font-weight:"+boldTitle+"; font-family:"+font+";'>"+jsonData[i].title+"</a>";
			postDescription = "<p style='color:"+textColor+"; font-size:"+textFontSize+"; font-family:"+font+";'>"+ postLink + "<br/>" + jsonData[i].description +"</p>";
			oDiv.innerHTML += postDescription;
		}
	}else{
		alert("Script Error: There is no Output DIV.\nPlease create div with id='output'.");	
	}
	//alert(sText);
	bObj.removeScriptTag();
}

function getBlogContent(url){
	var req  = url + "?callback=displayResults"; 
	bObj = new JSONscriptRequest(req); 
	bObj.buildScriptTag(); 
	bObj.addScriptTag();
}