function product(eRPId, imageURL, name, description, redirectURL, adsManager)
{
	this.eRPId = eRPId;
	this.imageURL = imageURL;
	this.name = name;
	this.description = description;
	this.redirectURL = redirectURL;
	this.adsManager = adsManager;
}			
product.prototype = {
	eRPId: "",
	imageURL: "",
	name: "",
	description: "",
	redirectURL: "",
	adsManager: null,
	localizeImage: function(imageURL) {
		return imageURL.replace("../", "");
	},
	render: function() {				

		var DIVfeature_content = document.createElement("div");
		DIVfeature_content.id = "feature_" + this.eRPId;
		DIVfeature_content.className = "feature_content";
		DIVfeature_content.product = this;
		DIVfeature_content.onclick = this.buttonOnClick;
		
		var DIVImage = document.createElement("div");
		DIVImage.style.textAlign = "center";	
		
		var IMGAds = document.createElement("img");
		IMGAds.style.border = 0;
		IMGAds.src = this.localizeImage(this.imageURL);
		IMGAds.style.cursor = "pointer";
		
		var PSeparator = document.createElement("p");
		
		var IMGSeparator = document.createElement("img");
		IMGSeparator.style.height = "1px";
		IMGSeparator.style.border = 0;
		IMGSeparator.style.width="200px";
		IMGSeparator.src = "images/home/separator_horiz_line_grey.gif"
		
		var DIVFeature_text = document.createElement("div");
		DIVFeature_text.className = "feature_content_txt";
		
		var H3Title = document.createElement("h3");
		H3Title.innerHTML = this.name;
		H3Title.style.cursor = "pointer";
		
		var PDescription = document.createElement("p");
		PDescription.innerHTML = this.description;
		
		DIVFeature_text.appendChild(H3Title);
		DIVFeature_text.appendChild(PDescription);
		
		PSeparator.appendChild(IMGSeparator);
		
		DIVImage.appendChild(IMGAds);	
		
		DIVfeature_content.appendChild(DIVImage);
		DIVfeature_content.appendChild(PSeparator);
		DIVfeature_content.appendChild(DIVFeature_text);
			
		return DIVfeature_content;
	},			
	buttonOnClick: function()
	{				
		this.product.adsManager.productOnclickHandler(this.product.eRPId, this.product.redirectURL);
	}	
};

function ProductTab(tabIndex, categoryName, adsManager)
{
	this.tabIndex = tabIndex;
	this.categoryName = categoryName;	
	this.adsManager = adsManager; 	
	this.productArray = new Array;
}
ProductTab.prototype = {
	tabIndex: 0,
	productArray: null,
	categoryName: "default",
	adsManager: null,
	
	addProduct: function(product)
	{
		this.productArray.push(product);
	},
	getProduct: function(index)
	{
		return this.productArray[index];
	},
	
	render: function(targetHTMLElementDescription)
	{
		if (targetHTMLElementDescription != null)
		{
			for (var i = 0; i < this.productArray.length; i++)
			{
				targetHTMLElementDescription.appendChild(this.productArray[i].render());
			}
		}
	},
	renderHeader: function()
	{			
		var DIVAdsHeader = document.createElement("div");
		DIVAdsHeader.className = "tab_content_on";
		DIVAdsHeader.style.cursor = "pointer";
		DIVAdsHeader.style.textDecoration = "none";
		DIVAdsHeader.productTab = this;
		DIVAdsHeader.onclick = this.categoryOnclickHandler;
		
		var PAdsTitle = document.createElement("p");
		var AAdsTitle = document.createElement("a");
		AAdsTitle.innerHTML = this.categoryName;
		
		PAdsTitle.appendChild(AAdsTitle);
		DIVAdsHeader.appendChild(PAdsTitle);

		return DIVAdsHeader;
	},
	categoryOnclickHandler: function()
	{
		this.productTab.adsManager.currentTabIndex = this.productTab.tabIndex;
		this.productTab.adsManager.renderDescription();
	}
};

function AdsManager(productOnclickHandler, targetHTMLElementDescription, targetHTMLElementHeader) {	
	this.productOnclickHandler = productOnclickHandler;
	this.targetHTMLElementDescription = targetHTMLElementDescription;
	this.targetHTMLElementHeader = targetHTMLElementHeader;	
}			
AdsManager.prototype = {
	productTabArray: [],
	currentTabIndex: 0,
	productOnclickHandler: null,
	targetHTMLElementDescription: null,
	targetHTMLElementHeader: null,
	
	addProductTab: function(productTab)
	{				
		this.productTabArray.push(productTab);
	},
	firstRender: function()
	{
		this.currentTabIndex = 0;
		this.renderHeader();
		this.renderDescription();		
	},
	renderDescription: function()
	{		
		this.clearDescription();
		if (this.productTabArray.length > 0)
			this.productTabArray[this.currentTabIndex].render(this.targetHTMLElementDescription);
	},	
	renderHeader: function()
	{
		this.clearHeader();
		for (var i = 0; i < this.productTabArray.length; i++)
		{
			this.targetHTMLElementHeader.appendChild(this.productTabArray[i].renderHeader());
		}
	},
	report: function()
	{	
		alert("NoOfTabs:" + this.productTabArray.length);
		for (var i = 0; i < this.productTabArray.length; i++)
		{
			alert("Tab" + i + ": " + this.productTabArray[i].productArray.length);
		}
	},
	clearHeader: function()
	{	        
        if ( this.targetHTMLElementHeader.hasChildNodes() )
        {
            while ( this.targetHTMLElementHeader.childNodes.length >= 1 )
            {
                this.targetHTMLElementHeader.removeChild( this.targetHTMLElementHeader.firstChild );       
            } 
        }
	},
	clearDescription: function()
	{
		 if ( this.targetHTMLElementDescription.hasChildNodes() )
        {
            while ( this.targetHTMLElementDescription.childNodes.length >= 1 )
            {
                this.targetHTMLElementDescription.removeChild( this.targetHTMLElementDescription.firstChild );       
            } 
        }
	}
	
};