var TabUtil =
{
	onMouseOver: function( tabElement )
	{
		if( tabElement.className != "tabSelected" ) {
			tabElement.className = "tabHover";
		}
		TabUtil.onClick( tabElement );
	},

	onMouseOut: function( tabElement )
	{
		if( tabElement.className == "tabHover" ) {
			tabElement.className = "tabDefault";
		}
	},

	onClick: function( tabElement )
	{
		TabUtil.selectTab( tabElement );
		TabUtil.showTabPanel( tabElement );
	},
	
	selectTab: function( tabElement )
	{
		var parent = tabElement.parentNode;
		for( var i = 0; i < parent.childNodes.length; i++ ) {
			var child = parent.childNodes[i];
			child.className = "tabDefault";
		child.style.zIndex = TabUtil.zIndexTab;
		}
		tabElement.className = "tabSelected";
		tabElement.style.zIndex = TabUtil.zIndexTab + 1;
	},
	
	getTabPanel: function( tabElement )
	{
		var tabId = tabElement.id;
		var panId = "tabPanel" + tabId.replace( "tab", "" );
		var element = document.getElementById( panId );
		return element;
	},
	
	showTabPanel: function( tabElement )
	{
		var panel = TabUtil.getTabPanel( tabElement );
		var parent = panel.parentNode;
		for( var i = 0; i < parent.childNodes.length; i++ ) {
			var child = parent.childNodes[i];
			child.style.display = 'none';
		}
		panel.style.zIndex = TabUtil.zIndexTab;
		panel.style.display = 'inline'
	},
	
	zIndexTab: 1
}

function TabPanel( name, width, height, tabwidth, tabheight )
{
	this.display = __TabPanel_display;
	this.addTab = __TabPanel_addTab;
	this.setPanel = __TabPanel_setPanel;
	this.getPanel = __TabPanel_getPanel;
	this.getPanels = __TabPanel_getPanels;
	this.hidePanels = __TabPanel_hidePanels;
	this.setBackgroundImages = __TabPanel_setBackgroundImages;
	this.name = name;
	this.width = width;
	this.height = height;
	this.tabwidth = tabwidth;
	this.tabheight = tabheight;
	this.tabs = new Array();
	this.panels = new Array();
	this.tabcount = 0;
}

function __TabPanel_setBackgroundImages( )
{
	var tabWidth = config["tab_width"] ? config["tab_width"] : 70;
	var tabHeight = config["tab_height"] ? config["tab_height"] : 25;

	document.write( "<" + "style" + ">" );
	document.write( ".tabDefault " );
	document.write( "{ " );
	document.write( "background: url('" + mm_global_location + "/eminimalls/global/images/" + tabWidth + "x" + tabHeight + ".tab.v3.png') no-repeat top;" );
	document.write( "} " );

	document.write( ".tabSelected " );
	document.write( "{ " );
	document.write( "background: url('" + mm_global_location + "/eminimalls/global/images/" + tabWidth + "x" + tabHeight + ".tab.active.v3.png') no-repeat top;" );
	document.write( "} " );

	document.write( "</" + "style" + ">" );
}

function __TabPanel_addTab( name )
{
	this.tabs[name] = this.tabcount++;
}

function __TabPanel_display()
{
	var tabs = '';
	var style = "";

	style += "width: " + this.width + "px; ";
	style += "height: " + this.height + "px; ";
	tabs += '<div style="' + style + '" id="' + this.name + 'Group" class="tabPanelGroup">';
	tabs += '<div class="tabGroup">';

	// adds tabs
	var tabPosition = 0;
	for( var name in this.tabs ) {
		var type = ( tabPosition == 0 ) ? "tabSelected" : "tabDefault";
		var zIndex = ( tabPosition == 0 ) ? TabUtil.zIndexTab : 0;
		var id = "tab" + tabPosition;
		var style = "left:" + ( this.tabwidth * tabPosition ) + ";";
		style += "z-index:" + zIndex + ";"
		tabs += '<div onmouseover="TabUtil.onMouseOver(this)" onmouseout="TabUtil.onMouseOut(this)" style="' + style + '" id="' + id + '" class="' + type + '" onclick="TabUtil.onClick(this)"><div id="tabLabel" class="tabLabel">' + name + '</div></div>';
		tabPosition++;
	}

	tabs += '</div>';

	// adds tab panels
	tabs += '<div>';
	var panelPosition = 0;
	for( var name in this.panels ) {
		var id = "tabPanel" + panelPosition;
		var data = this.panels[name];
		var style = "display: " + (( panelPosition == 0 ) ? "inline" : "none" );
		style += "; height: " + (this.height - this.tabheight ) + "px; ";
		style += "width: " + this.width + "px; "
		style += "top: " + ( this.tabheight - 1 ) + "px;"
		tabs += '<div style="' + style + '" id="' + id + '" class="tabPanel">' + data + '</div>';
		panelPosition++;
	}
	tabs += '</div>';
	tabs += '</div>';

	var container = document.getElementById( this.name );
	if( container == null ) {
		container = document.createElement( "div" );
		container.setAttribute( "id", this.name );
		document.body.appendChild( container );
	}
	container.innerHTML = tabs;
}

function __TabPanel_setPanel( name, data )
{
	this.panels[name] = data;
}

function __TabPanel_hidePanels()
{
	var panels = this.getPanels();
	for( var i = 0; i < panels.length; i++ ) {
		var panel = panels[i];
		panel.style.display = 'none';
	}
}

function __TabPanel_getPanels()
{
	var panelPosition = 0;
	var panels = new Array();
	for( var n in this.panels ) {
		var id = "tabPanel" + panelPosition;
		panels[panelPosition] = document.getElementById( id );
		panelPosition++;
	}
	return pannels;
}

function __TabPanel_getPanel( name )
{
	var panelPosition = 0;
	for( var n in this.panels ) {
		if( n == name ) {
			var id = "tabPanel" + panelPosition;
			return document.getElementById( id );
		}
		panelPosition++;
	}
}

var LineUtil =
{
	createLine: function( p1, p2 )
	{
		var m = LineUtil.computeSlope( p1, p2 );
		var b = LineUtil.computeIntercept( p1, m );
		return new Line( p1, m, b );
	},
	computeIntercept: function( point, slope )
	{
		return point.y - ( slope * point.x );
	},
	computeSlope: function( p1, p2 )
	{
		return ( p2.y - p1.y ) / (p2.x - p1.x);
	},
	computeDistance: function( p1, p2 )
	{
		var l1 = p2.x - p1.x;
		var l2 = p2.y - p1.y;
		return Math.sqrt( (l1 * l1) + (l2 * l2) );
	}
}

function Point( x, y )
{
	this.x = x;
	this.y = y;
}

function Line( p, m, b )
{
	this.point = p;
	this.slope = m;
	this.intercept = b;
	this.get_y = _Line_get_y;
}

function _Line_get_y( x )
{
	return ( this.slope * x ) + this.intercept;
}

var Animate =
{
	in_motion: false,
	objs: null,
	target_to_x: 0,
	target_to_y: 0,
	target_from_x: 0,
	target_from_y: 0,
	line: null,
	set_obj: function( pos, value )
	{
		if( Animate.objs == null ) {
			Animate.objs = Array(4);
		}
		Animate.objs[pos] = value;
	},
	get_obj: function( pos )
	{
		return( Animate.objs[pos] );
	},
	slide: function( to_pos, from_pos, first )
	{
		var idFrom = Animate.get_obj( from_pos );
		var idTo = Animate.get_obj( to_pos );
		if( idTo == idFrom ) return;
		if( first == true ) {
			if( Animate.in_motion == true ) {
				return false;
			}
		}

		var elementTo = document.getElementById(idTo);
		var elementFrom = document.getElementById(idFrom);

		var x1 = parseInt(elementFrom.style["top"], 10);
		var y1 = parseInt(elementFrom.style["left"], 10);
		var p1 = new Point( x1, y1 );

		var x2 = parseInt(elementTo.style["top"], 10);
		var y2 = parseInt(elementTo.style["left"], 10);
		var p2 = new Point( x2, y2 );
		if( first == true ) {
			// from has to get to to
			Animate.target_from_x = x2;
			Animate.target_from_y = y2;
			// to has to get to from
			Animate.target_to_x = x1;
			Animate.target_to_y = y1;
			elementTo.style.zIndex = 1;
			elementFrom.style.zIndex = 0;
			var p3 = new Point( Animate.target_from_x, Animate.target_from_y );
			var p4 = new Point( Animate.target_to_x, Animate.target_to_y );
			Animate.line = LineUtil.createLine( p3, p4 );
			Animate.in_motion = true;
		}
		var line = Animate.line; 
		var new_from_x = p1.x + 4;
		var new_from_y = line.get_y( new_from_x );
		var new_to_x = p2.x - 4;
		var new_to_y = line.get_y( new_to_x );
		var distance = LineUtil.computeDistance( new Point( Animate.target_to_x, Animate.target_to_y ), new Point( new_to_x, new_to_y ) );
		distance = parseInt( distance, 10 );
		var closeEnough = new_to_x < Animate.target_to_x;
		if( !closeEnough ) {
			elementTo.style.top = new_to_x + "px";
			elementTo.style.left = new_to_y + "px";
			var new_width = parseInt( elementTo.style.width, 10 );
			new_width = new_width > 100 ? 100 : new_width + 2;
			elementTo.style.width = new_width + "px";
			elementTo.style.height = new_width + "px";
			elementFrom.style.top = new_from_x + "px";
			elementFrom.style.left = new_from_y + "px";
			var new_width2 = parseInt( elementFrom.style.width, 10 );
			new_width2 = new_width2 < 50 ? 50 : new_width2 - 2;
			elementFrom.style.width = new_width2 + "px";
			elementFrom.style.height = new_width2 + "px";
			setTimeout( "Animate.slide('" + to_pos + "', '" + from_pos + "')", 0 );
		} else {
			elementTo.style.top = Animate.target_to_x + "px";
			elementTo.style.left = Animate.target_to_y + "px";
			elementTo.style.width = "100px";
			elementTo.style.height = "100px";
			elementFrom.style.top = Animate.target_from_x + "px";
			elementFrom.style.left = Animate.target_from_y + "px";
			elementFrom.style.width = "50px";
			elementFrom.style.height = "50px";
			var element = elementFrom;
			if( elementFrom.id == "img_0" ) {
				element = elementTo;
			}

			Animate.set_obj(from_pos, idTo );
			Animate.set_obj(to_pos, idFrom );

			Animate.in_motion = false;
		}
	}
}

var ContentUtil =
{
	elements: null,
	trim: function( s )
	{
		s = new String( s );
		s = s.replace( /^ +/g, "" );
		s = s.replace( / +$/g, "" );
		return s;
	},

	getBranding: function( s )
	{
		var l = document.createElement( "a" );
		l.target = "_blank";
		var c = formfields['client'] ? formfields['client'] : "";
		l.href = "http://chitika.com/mm_overview.php?refid=" + c;
		l.className = "mmBranding";
		l.id = "mmBranding";
		var branding = s;
		l.innerHTML = branding;
		l.title = branding;
		return l;
	},

	addStyle: function( element, style )
	{
		if( element != null ) {
			var styles = new String( style ).split( ";" );
			for( var i = 0; i < styles.length; i++ ) {
				var nvp = new String( styles[i] ).split( ":" );
				if( nvp != null ) {
					if( nvp.length > 1 ) {
						var name = ContentUtil.trim( nvp[0] );
						var value = ContentUtil.trim( nvp[1] );
						element.style[name] = value;
					}
				}
			}
		}
	},
	getElementsByClassName: function( className )
	{
		ContentUtil.elements = [];
		var elements = null;
		if( document.all ) {
			elements = document.all;
		} else
		if( document.getElementsByTagName ) {
			elements = document.getElementsByTagName( "*" );
		}
		for( var i = 0; i < elements.length; i++ ) {
			var element = elements[i];
			if( element != null ) {
				if( element.className == className ) {
					var elements = ContentUtil.elements;
					elements[elements.length] = element;
				}
			}
		}
		return ContentUtil.elements;
	},
	getContentById: function( id )
	{
		var element = document.getElementById( id );
		return element ? element.innerHTML : "";
	},
	getOuterHTML: function( element )
	{
		var properties = { "name": "name", "id": "id", "class": "class" };
		var buffer = "<" + element.tagName;
		for( var property in properties ) {
			var value = null;
			switch( property ) {
				case "class" :
					value = element.className;
				break;
				default:
					value = element[property];
				break;
			}
			if( ( value != null ) && ( value != "" ) ) {
				buffer += " " + property + "='" + value + "'";
			}
		}
		buffer += ">";
		buffer += element.innerHTML;
		buffer += "</" + element.tagName + ">";
		return buffer;
	}
}

var JSONUtil =
{
	hasKey: function( obj, name )
	{
		for( var k in obj ) {
			if( k == name ) {
				return true;
			}
			if( typeof( obj[k] ) == "object" ) {
				JSONUtil.hasKey( obj[k], name );
			}
		}
		return false;
	}
}

var EMiniMall =
{
	tabs: null,
	onclick: null,

	addCustomStyles: function()
	{
		if (typeof styles == 'undefined') return; 

		for( var id in styles ) {
			var element = document.getElementById(id);
			var style = styles[id];
			if( element != null ) { 
				ContentUtil.addStyle( element, style );
			}
		}
		
		for( var className in styles ) {
			var elements = ContentUtil.getElementsByClassName( className );
			for( var i = 0; i < elements.length; i++ ) {
				var element = elements[i];
				var style = styles[className];
				if( element != null ) {
					ContentUtil.addStyle( element, style );
				}
			}		
		}
	},

	displayImages: function( dataset )
	{
		var wbh50 = "width:50px;height:50px";
		var wbh100 = "top:10px;left:20px;width:100px;height:100px";
	
		var numProds = dataset.length;
		switch( numProds ) {
			case 1:
				var srcMain = dataset[0]["product"]["image"];
				EMiniMall.renderProductImage( 0, srcMain, wbh100 );
			break;
			case 2:
				var srcMain = dataset[0]["product"]["image"];
				var srcImg1 = dataset[1]["product"]["image"];
				EMiniMall.renderProductImage( 0, srcMain, wbh100 );
				EMiniMall.renderProductImage( 1, srcImg1, "top:125px;left:44px;" + wbh50, "top:155px;left:74px;" + wbh50 );
				break;
			case 3:
				var srcMain = dataset[0]["product"]["image"];
				var srcImg1 = dataset[1]["product"]["image"];
				var srcImg2 = dataset[2]["product"]["image"];
				EMiniMall.renderProductImage( 0, srcMain, wbh100 );
				EMiniMall.renderProductImage( 1, srcImg1, "top:125px;left:20px;" + wbh50, "top:155px;left:50px;" + wbh50);
				EMiniMall.renderProductImage( 2, srcImg2, "top:125px;left:70px;" + wbh50, "top:155px;left:100px;" + wbh50);
				break;
			case 4:
				var srcMain = dataset[0]["product"]["image"];
				var srcImg1 = dataset[1]["product"]["image"];
				var srcImg2 = dataset[2]["product"]["image"];
				var srcImg3 = dataset[3]["product"]["image"];
				EMiniMall.renderProductImage( 0, srcMain, wbh100, '' );
				EMiniMall.renderProductImage( 1, srcImg1, "top:125px;left:2px;" + wbh50, "top:155px;left:30px;" +wbh50 );
				EMiniMall.renderProductImage( 2, srcImg2, "top:125px;left:50px;" + wbh50, "top:155px;left:80px;" +wbh50);
				EMiniMall.renderProductImage( 3, srcImg3, "top:125px;left:100px;" + wbh50, "top:155px;left:130px;" +wbh50);
				break;
		}
	},
	
	displayMultiUnit: function( dataset )
	{
		var unit = document.createElement( "div" );
		unit.id = "mm";
		unit.className = "mm";

		var border = document.createElement( "div" );
		border.id = "mmBorder";
		border.className = "mmBorder";
		document.body.appendChild( border );
		document.body.appendChild( unit );

		if ( document.getElementById("mmBranding") == null ) {
			document.body.appendChild( ContentUtil.getBranding("Chitika eMiniMalls") );
		}

		if( dataset != null ) {
			var tab_list = [ "Search" ];
			EMiniMall.hasSearch = 0;
			if( dataset.length > 0 ) {
			var tab_list = [ "Description", "Best Deals" ];
				if ( !(formfields["nosearch"] && formfields["nosearch"] == 1 ) ) {
					tab_list[tab_list.length] = "Search";
					EMiniMall.hasSearch = 1;
				}
			}
			EMiniMall.tabs = new TabPanel( "mmTabs", 299, 153, 69, 25);
			EMiniMall.tabs.setBackgroundImages();
			for( var i = 0; i < tab_list.length; i++ ) {
				var tabname = tab_list[i];
				EMiniMall.tabs.addTab( tabname );
				EMiniMall.tabs.setPanel( tabname, "my " + tabname + " content" );
			}
			EMiniMall.tabs.display();
			if( dataset.length > 0 ) {
				EMiniMallTabs.displayDescription(dataset, 0);
				EMiniMallTabs.displayPrices(dataset, 0);
				if ( EMiniMall.hasSearch ) EMiniMallTabs.displaySearch(dataset, 0);
			} else {
				EMiniMallTabs.displaySearch(dataset, 0);
			}
		}
		EMiniMall.addCustomStyles();
	},

	renderProductImage: function( index, src, style, style2 )
	{
		Animate.set_obj(index, 'img_' + index);
		if( style.indexOf( "width:100px" ) == -1 ) {
			var onclick="EMiniMall.swapProduct('"+index+"', '0');";
			var onmouseover="EMiniMall.showcaseProduct('"+index+"', '0');";
			var onmouseout="EMiniMall.freezeProduct();";
			document.write( '<img src="' + mm_global_location + '/eminimalls/global/images/zoom_gray.gif" id="mag_'+index+'" style="' + style2 + ';z-index:1;width:19px;height:19px;position:absolute"/>' );
			document.write( '<a href="#" onclick="'+onclick+'" onmouseover="'+onmouseover+'" onmouseout="'+onmouseout+'"><img src="' + mm_global_location + '/eminimalls/global/images/cp.gif" id="pad_'+index+'" style="'+style+';border:none;z-index:2;width:50px;height:50px;position:absolute"/></a>' );
		}
		document.write( '<' + 'img src="' + src + '" id="img_' + index + '" style="' + style + ';position:absolute"/>' );
	},
	currentMouseSlot: -1,
	previousMouseSlot: -2,
	showcaseProductPid: null,
	showcaseProductText: null,
	freezeProduct: function()
	{
		if( EMiniMall.showcaseProductText != null ) {
			clearTimeout( EMiniMall.showcaseProductText );
		}
	},
	showcaseProduct: function( from_pos, to_pos )
	{
		var from_id = Animate.get_obj(from_pos);
		var to_id = Animate.get_obj(to_pos);

		EMiniMall.previousMouseSlot = from_id;
		EMiniMall.currentMouseSlot = to_id

		if( EMiniMall.previousMouseSlot != EMiniMall.currentMouseSlot ) {
			EMiniMall.showcaseProductText = setTimeout(
			function() { 
				EMiniMall.swapProduct( from_pos, to_pos );
				EMiniMall.freezeProduct();
			}, 500 );
		}
	},
	swapProduct: function( from_pos, to_pos )
	{
		var from_id = Animate.get_obj(from_pos);
		var to_id = Animate.get_obj(to_pos);
		if( Animate.in_motion == true ){
		    return( false );
		}
		Animate.slide(from_pos, to_pos, true);
		EMiniMallTabs.displayDescription(dataset, from_pos);
		EMiniMallTabs.displayPrices(dataset, from_pos);
		if ( EMiniMall.hasSearch) EMiniMallTabs.displaySearch(dataset, from_pos);
		EMiniMall.addCustomStyles();

		var tmp = dataset[to_pos];
		dataset[to_pos] = dataset[from_pos];
		dataset[from_pos] = tmp;
		return( false );
	}
}

var EMiniMallTabs =
{	
	displayDescription: function( dataset, i )
	{
		var data = dataset[i];
		var product = data["product"];
		var vendors = data["vendors"];
		var vendorCount = vendors ? vendors.length : 0;
		
		var tabContainer = document.createElement( "div" );
		tabContainer.id = "mmDescription";

		var nameLink = document.createElement( "div" );
		nameLink.id = "mmProductTitle";
		nameLink.className = "mmProductTitle";
		nameLink.innerHTML = product["name"];
		tabContainer.appendChild( nameLink );

		if ( vendorCount > 0 ) {
			var vendor = vendors[0];
			var vendorNameElement = document.createElement( "a" );
			vendorNameElement.id = "mmProductVendor";
			vendorNameElement.className = "mmProductVendor";
			vendorNameElement.innerHTML = "Best Deal at " + 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 );
		}

		var desc = product["description"];
		if( desc && desc != "" ) {
			var descDiv = document.createElement( "div" );
			descDiv.id = "mmProductDescription";
			descDiv.className = "mmProductDescription";
			descDiv.innerHTML = desc;
			tabContainer.appendChild(descDiv);
		}

		var panelContainer = EMiniMall.tabs.getPanel( "Description" );
		panelContainer.innerHTML = ContentUtil.getOuterHTML( tabContainer );
	},

	displayPrices: function( dataset, i )
	{
		var data = dataset[i];
		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";
		var logoUrl = null;
		var title = document.createElement( "div" );
		title.id = "mmVendorTitle";
		title.className = "mmVendorTitle";
		title.innerHTML = "Best Deals from Name Brand Merchants";
		vendorsContainer.appendChild( title );
		if( vendors ) {
			if( vendors.length == 0 ) { return; }
			for( var i = 0; i < vendors.length; i++ ) {
				var vendor = vendors[i];
				logoUrl = vendor["logo"];
				if( logoUrl ) {
					var vendorLogo = document.createElement( "a" );
					vendorLogo.innerHTML = "<img src='" + logoUrl + "' border=0/>";
					vendorLogo.className = "mmVendorLogo";
					vendorLogo.id = "mmVendorLogo";
					vendorLogo.target = "_blank";
					vendorLogo.href = vendor["url"] + "&linkid=mmVendorLogo";
					vendorLogo.onmouseover = function(){ window.status=vendor["display_url"];return true; };
					vendorLogo.onmouseout = function(){ window.status='';return true; };
					var vendorLogoText = document.createElement( "div" );
					vendorLogoText.innerHTML = "Featured Store";
					vendorLogoText.id = "mmVendorLogoText";
					vendorLogoText.className = "mmVendorLogoText";
					vendorsContainer.appendChild( vendorLogo );
					vendorsContainer.appendChild( vendorLogoText );
					break;
				}
			}
			if( vendors.length == 1 ) {
				var vendor = vendors[0];
				var vendorHeaderText = document.createElement( "div" );
				vendorHeaderText.innerHTML = "Best Price at:";
				vendorHeaderText.id = "mmVendorHeaderText";
				vendorHeaderText.className = "mmVendorHeaderText";
				vendorsContainer.appendChild( vendorHeaderText );
				var vendorNameElement = document.createElement( "a" );
				vendorNameElement.innerHTML = vendor["name"];
				vendorNameElement.className = "mmVendorName1";
				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 );
				var offerdesc = (vendorCount > 0 ) ? vendors[0]["offer_details"] : "";
				if( offerdesc && offerdesc != "" ) {
					var vendorOfferText = document.createElement( "div" );
					vendorOfferText.innerHTML = offerdesc;
					vendorOfferText.id = "mmVendorOfferText";
					vendorOfferText.className = "mmVendorOfferText";
					vendorsContainer.appendChild( vendorOfferText );
				} 
			} 
			if( vendors.length > 1 ) {
				for( var i = 0; i < vendors.length; i++ ) {
					var vendor = vendors[i];					
					var vendorNameElement = document.createElement( "a" );
					vendorNameElement.innerHTML = vendor["name"];
					vendorNameElement.className = "mmVendorName" + i;
					vendorNameElement.target = "_blank";
					vendorNameElement.href = vendor["url"] + "&linkid=mmVendorName" + i;
					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 = "mmVendorPrice" + i;
					vendorPriceElement.target = "_blank";
					vendorPriceElement.href = vendor["url"] + "&linkid=mmVendorPrice" + i;
					vendorPriceElement.onmouseover = function(){ window.status=vendor["display_url"];return true; };
					vendorPriceElement.onmouseout = function(){ window.status='';return true; };
					var vendorContainer = document.createElement( "div" );
					vendorContainer.appendChild( vendorNameElement );
					vendorContainer.appendChild( vendorPriceElement );
					vendorsContainer.appendChild( vendorContainer ); 
				}
			}
			var pricesContainer = EMiniMall.tabs.getPanel( "Best Deals" );
			pricesContainer.innerHTML = ContentUtil.getOuterHTML( vendorsContainer );
		} 
	},

	displaySearch: function( dataset, i )
	{
		var searchContainer = document.createElement( "div" );
		searchContainer.className = "mmSearch";
		searchContainer.id = "mmSearch";
			
		var title = document.createElement( "div" );
		title.id = "mmSearchTitle";
		title.className = "mmSearchTitle";
		if ( dataset[i] ) {
			title.innerHTML = "Search for other products without leaving this page";
		} else {
			title.innerHTML = "Your search did not match any products";
		}
	
		var data = dataset[i];
		var searchurl = (data) ? data["search_url"] : "/minimall";
		var formhtml = "<form action='" + searchurl + "' class='mmSearchForm' id='mmSearchForm'>";
		formhtml += "<input name='mquery' type='text' value='" + ( formfields["mquery"] ? formfields["mquery"] : "" ) + "' id='mmSearchTextBox' class='mmSearchTextBox'>";
		formhtml += "<input name='submit' type='submit' value='Find It' id='mmSearchSubmit' class='mmSearchSubmit'>";
	
		var excludeList = [ "query", "mquery", "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 searchPanel = EMiniMall.tabs.getPanel( "Search" );
		searchPanel.innerHTML = ContentUtil.getOuterHTML( searchContainer );
	}
}
