config["tab_width"] = 70;
config["tab_height"] = 25; 
config["tab_panel_width"] = 385; 
config["tab_panel_height"] = 56;

// define how to display each tab panel
var EMiniMallTabs =
{
	product:
	{
		render: function( data )
		{
			var product = data["product"];
			var vendors = data["vendors"];
			var vendorCount = vendors ? vendors.length : 0;
			var tabContainer = document.createElement( "div" );

			if ( vendorCount > 0 ) {
				var vendor = vendors[0];
				if ( document.getElementById("mmProductTitle") == null ) {
					var chitikaLink = document.createElement( "a" );
					chitikaLink.target = "_blank";
					chitikaLink.href = "http://chitika.com/eminimalls";
					chitikaLink.className = "mmBranding";
					chitikaLink.id = "mmBranding";
					var branding = "Chitika | eMiniMalls";
					chitikaLink.innerHTML = branding;
					chitikaLink.title = branding;
					document.body.appendChild( chitikaLink );

					var a = document.createElement( "a" );
					a.id = "mmProductLink";
					a.className = "mmProductLink";
					a.href = vendor["url"] + "&linkid=mmProductImage";
					a.target = "_blank";
					a.onmouseover = 'window.status="' + vendor["display_url"] + '";return true;'
					a.onmouseout = function(){ window.status='';return true; };
		
					var img = document.createElement( "img" );
					img.border = "0";
					img.id = "mmProductImage1";
					if ( product["image"] ) {
						img.src = product["image"];
					} 
					img.className = "mmProductImage1";
					a.appendChild( img );
					document.body.appendChild( a );
				}

				var nameLink = document.createElement( "a" );
				nameLink.id = "mmProductTitle";
				nameLink.className = "mmProductTitle";
				nameLink.innerHTML = product["name"];
				nameLink.target = "_blank";
				nameLink.href = vendor["url"] + "&linkid=mmProductVendor";
				nameLink.onmouseover = 'window.status="' + vendor["display_url"] + '";return true;'
				nameLink.onmouseout = "window.status='';return true;"
				tabContainer.appendChild( nameLink );
				
				var vendorNameElement = document.createElement( "a" );
				vendorNameElement.id = "mmProductVendor";
				vendorNameElement.className = "mmProductVendor";
				
				vendorNameElement.innerHTML = vendor["name"];
				vendorNameElement.target = "_blank";
				vendorNameElement.href = vendor["url"] + "&linkid=mmProductVendor";
				vendorNameElement.onmouseover = 'window.status="' + vendor["display_url"] + '";return true;'
				vendorNameElement.onmouseout = "window.status='';return true;"
				tabContainer.appendChild( vendorNameElement );

			}

			return ContentUtil.getOuterHTML( tabContainer );
		},
		
		dependencies:
		[
			"product"
		]
	},
	
	description:
	{
		render: function( data )
		{
			var product = data["product"];
			var vendors = data["vendors"];
			var vendorCount = vendors ? vendors.length : 0;
			var desctext = "";
			var desc = product["description"];
			var offerdesc = (vendorCount > 0 ) ? vendors[0]["offer_details"] : "";
			if( desc && desc != "" ) {
				desctext = desc;
			} else if( offerdesc && offerdesc != "" ) {
				desctext = offerdesc;
			}

			if( desctext != "" ) {
				var tabContainer = document.createElement( "div" );

				var descContainer = document.createElement( "div" );
				descContainer.id = "mmDescriptionText";
				descContainer.className = "mmDescriptionText";
				descContainer.innerHTML = desctext;
				tabContainer.appendChild( descContainer );

				var nameLink = document.createElement( "a" );
				nameLink.id = "mmDescriptionReadMore";
				nameLink.className = "mmDescriptionReadMore";
				nameLink.innerHTML = "Read More";
				nameLink.target = "_blank";
				nameLink.href  = vendorCount > 0 ? (vendors[0]["url"] + "&linkid=mmDescriptionReadMore") : (product["url"] + "&linkid=mmDescriptionReadMore");
				nameLink.onmouseover = "window.status='" + product["display_url"] + "';return true;";
				nameLink.onmouseout = "window.status='';return true;";
				
				var toolTip = product["name"];
				if( vendorCount > 0 ) {
					var vendor = vendors[0];
					toolTip = "Read More at: " + vendor["name"];
				}
				nameLink.title = toolTip;
				tabContainer.appendChild( nameLink );

				return ContentUtil.getOuterHTML( tabContainer );
			} else {
				// Dont show the tab
				return null;
			}
		},
		
		dependencies:
		[
			"product"
		]
	},

	prices:
	{
		render: function( data )
		{
			var product = data["product"];
			var vendors = data["vendors"];
			var vendorCount = vendors ? vendors.length : 0;
			var vendorsContainer = document.createElement( "div" );
			vendorsContainer.className = "mmVendors";
			vendorsContainer.id = "mmVendors";

			if( vendors ) {
				if( vendors.length == 0 ) { return; }

				var vendor = vendors[0];
				var offerdesc = vendor["offer_details"];
				if( offerdesc && offerdesc != "" ) {
					var vendorOfferText = document.createElement( "div" );
					vendorOfferText.innerHTML = offerdesc;
					vendorOfferText.id = "mmVendorOfferText";
					vendorOfferText.className = "mmVendorOfferText";
					vendorsContainer.appendChild( vendorOfferText );
				}

				var vendorNameElement = document.createElement( "a" );
				vendorNameElement.innerHTML = vendor["name"];
				vendorNameElement.className = "mmVendorName1";
				vendorNameElement.title = "This vendor is rated " + vendor["rating_score"] + " stars";
				vendorNameElement.target = "_blank";
				vendorNameElement.href = vendor["url"] + "&linkid=mmVendorName1";
				vendorNameElement.onmouseover = 'window.status="' + vendor["display_url"] + '";return true;'
				vendorNameElement.onmouseout = "window.status='';return true;"

				var vendorPriceElement = document.createElement( "a" );
				vendorPriceElement.innerHTML = vendor["price"];
				vendorPriceElement.className = "mmVendorPrice1";
				vendorPriceElement.target = "_blank";
				vendorPriceElement.href = vendor["url"] + "&linkid=mmVendorPrice1";
				vendorPriceElement.onmouseover = function(){ window.status=vendor["display_url"];return true; };
				vendorPriceElement.onmouseout = function(){ window.status='';return true; };
					
				var vendorPriceDiv = document.createElement( "div" );
				vendorPriceDiv.appendChild( vendorNameElement );
				vendorPriceDiv.appendChild( vendorPriceElement );

				vendorsContainer.appendChild( vendorPriceDiv );
			}
			return ContentUtil.getOuterHTML( vendorsContainer );
		},
		
		dependencies:
		[
			"product"
		]
	},

	best_deals:
	{
		render: function( data )
		{
			return EMiniMallTabs["prices"].render( data );
		},
		
		dependencies:
		[
			"product"
		]
	},

	search:
	{
		render: function( data )
		{
			var searchContainer = document.createElement( "div" );
			searchContainer.className = "mmSearch";
			searchContainer.id = "mmSearch";

			var title = document.createElement( "div" );
			title.id = "mmSearchTitle";
			title.className = "mmSearchTitle";
			title.innerHTML = "Search: ";
			
			var formhtml = "<form action='" + data["search_url"] + "' class='mmSearchForm' id='mmSearchForm'>";
			formhtml += "<input name='query' type='text' value='" + ( formfields["query"] ? formfields["query"] : "" ) + "' id='mmSearchTextBox' class='mmSearchTextBox'>";
			formhtml += "<input name='submit' type='submit' value='Find It' id='mmSearchSubmit' class='mmSearchSubmit'>";
	
			var excludeList = [ "query", "submit" ]; 
                	for( var name in formfields ) { 
				var excludeField = false; 
				for( var i = 0; i < excludeList.length; i++ ) { 
					if( name == excludeList[i] ) { 
						excludeField = true; 
					} 
				} 
  
				if( excludeField != true ) { 
					formhtml += "<input type='hidden' name='" + name + "' value='" + formfields[name] + "'>"; 
				} 
			} 
			formhtml += "</form>";

			searchContainer.innerHTML = formhtml;
			searchContainer.appendChild( title );

			var outputContainer = document.createElement( "span" );
			outputContainer.appendChild( searchContainer );

			var pb = document.createElement( "div" );
			pb.id = "mmProviderLink";
			pb.className = "mmProviderLink";
			pb.innerHTML = "Powered by ";
			outputContainer.appendChild( pb );

			var img = document.createElement( "img" );
			img.border = "0";
			img.id = "mmProviderImage";
			img.className = "mmProviderImage";
			img.src = mm_global_location + "/eminimalls/global/images/cnet.gif";

			var cnetLink = document.createElement( "a" );
			cnetLink.target = "_blank";
			cnetLink.href = "http://www.cnet.com/?part=chitika-cnet&subj=fd&tag=logo";
			cnetLink.appendChild( img );
			outputContainer.appendChild( cnetLink );
			
			return ContentUtil.getOuterHTML( outputContainer );
		},

		dependencies:
		[
		]
	}
}
