function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
    
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function () {
    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE +'&remoteUrl=' +window.location.href);
    this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}

JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}

function getWidget(jsonData) {     
	var	widgetWidth = "100%";
	var widget = document.getElementById('23MWidget');
	widget.style.width = widgetWidth;
	
    var title = document.createElement('DIV');
    title.style.width = widgetWidth;
    title.style.color = "#" + jsonData.Widget.TextColor.textColor;
    title.innerHTML = "<b><a style=\"padding-left:10px; color:#" + jsonData.Widget.LinkColor.linkColor+ "\" href=\"http://" + jsonData.Widget.ServerAddress.serverAddress + "/?uuid=" + jsonData.Widget.UUID.uuid +"\">" + jsonData.Widget.Title.title + "</a></b>";
    widget.appendChild(title);

    var designs = jsonData.Widget.Designs.Design;

    var designContainer = document.createElement('DIV');

    var designPictures= document.createElement('DIV');
    designPictures.style.padding = "5px";
    designPictures.style.width = widgetWidth;
	designPictures.style.cssFloat = "left";
	designPictures.style.styleFloat = "left"; // for IE
    designPictures.style.backgroundColor = "#" + jsonData.Widget.BackgroundColor.backgroundColor;
    for(var i=0; (i<designs.length) && (i < jsonData.Widget.MaxDesigns.maxDesigns) ; i++){
    	var designPicture = document.createElement('DIV');
    	designPicture.style.backgroundImage="url('http://" + jsonData.Widget.ServerAddress.serverAddress + "/picture/randomProduct/" + designs[i].id + "/150/150')";
    	designPicture.setAttribute("onclick","window.location.href='http://" + jsonData.Widget.ServerAddress.serverAddress + "/designs/" + designs[i].name + "?uuid=" + jsonData.Widget.UUID.uuid+ "&toggleBuy=true'");

    	if (jsonData.Widget.ShowDesignNames.showDesignNames == 'true') {
    		designPicture.setAttribute("title", designs[i].name);
    	}	
    		
    	designPicture.title = designs[i].displayName;
    	designPicture.style.width = "150px";
    	designPicture.style.height = "175px";
    	designPicture.style.backgroundRepeat = "no-repeat";
    	designPicture.style.backgroundPosition = "0px";
    	if (jsonData.Widget.ShowBorder.showBorder == 'true') {
    		designPicture.style.border = "1px";
    		designPicture.style.borderStyle = "solid";
    		designPicture.style.borderColor = "#" + jsonData.Widget.BorderColor.borderColor;
    	}
    	designPicture.style.cssFloat = "left";
    	designPicture.style.styleFloat = "left"; // for IE
    	designPicture.style.marginRight = "6px";
    	designPicture.style.marginBottom = "6px";
    	designPicture.style.cursor = "pointer";
    	designPicture.style.backgroundColor = "#FFFFFF";
       	designPicture.className = "pngtrans";

	    if (jsonData.Widget.ShowPrices.showPrices == 'true') {
	    	var designPrice= document.createElement('DIV');
	        designPrice.style.backgroundImage="url('http://" + jsonData.Widget.ServerAddress.serverAddress + "/gfx/starburstPrice.png')";
	        designPrice.style.backgroundRepeat="no-repeat";
	        designPrice.style.width="46px";
	        designPrice.style.height="46px";
	        designPrice.style.fontSize="xx-small";
	        designPrice.style.color="#FFFFFF";
	        designPrice.style.textAlign="center";
	        designPrice.style.paddingTop="4px";
	        designPrice.style.position="absolute";
	        designPrice.style.zIndex="2";
	       	designPrice.className = "pngtrans";
	        designPrice.innerHTML += "from<br/>" + designs[i].lowestPrice + "<br/>" + designs[i].lowestPriceCurrency + "<br />";
	        
	        designPicture.appendChild(designPrice);
		}
        
        designPictures.appendChild(designPicture);
        
        var buyNow = document.createElement('DIV');
        buyNow.innerHTML = "<center><b><a style=\"color:#" + jsonData.Widget.TextColor.textColor + "; \" href=\"http://" + jsonData.Widget.ServerAddress.serverAddress + "/designs/" + designs[i].name + "?uuid=" + jsonData.Widget.UUID.uuid +"\">&nbsp;&nbsp;Buy Now!</a></b></center>";
        designPicture.appendChild(buyNow);
    }
    designContainer.appendChild(designPictures);
    
    title.appendChild(designContainer);

    var googleAnalytics = document.createElement('DIV');
    googleAnalytics.innerHTML = "<iframe src=\"http://" +jsonData.Widget.ServerAddress.serverAddress +"/widget/myDesignsTracking?remoteUrl=" + jsonData.Widget.RemoteUrl.remoteUrl + "&uuid=" + jsonData.Widget.UUID.uuid+ "\" style=\"border:0px solid #FFFFFF; \" width=\"5\" height=\"5\" frameborder=\"0\" scrolling=\"no\" border=\"0\"></iframe>";
    widget.appendChild(googleAnalytics);
}
