
var mmlist = new Array();
var imageUrl = 'http://i.expansys.com/i/s/s';
var productUrl = 'd.aspx?i=';

// MiniMall class

function miniMall(id, classname, basesite) {
    this.id = id;
    this.classname = classname;
    this.basesite = basesite;
    this.products = new Array();
    this.add = addProduct;
    this.render = renderMiniMall;
    this.switchProduct = switchProduct;
    this.ordinal = mmlist.length;
    this.locked = false;
    mmlist.push(this);
}

function addProduct(id, title, price, description, partner) {
    var p = new miniMallProduct(id, title, price, description, partner);
    this.products.push(p);
}

function renderMiniMall() {
    document.write('<div id="'+ this.id +'" class="'+ this.classname +'">');
    document.write('<ul class="productList">');
    if (this.classname == 'w728') document.write('<h3><a href="' + this.basesite + '/smartphone?top20=1&partner=mobig">Most Popular Devices</a></h3>');
    for(var x in this.products) 
    {
        if (this.classname == 'w728')
        {
            document.write('<li><a id="'+ this.id +'prdlink'+ x +'" href="' + this.basesite + '/d.aspx?i=' + this.products[x].id + '&partner=mobig">' + this.products[x].title + '</a></li>');
        }
        else if (this.classname == 'w270')
        {
            document.write('<li><a id="'+ this.id +'prdlink'+ x +'" href="' + this.basesite + '/d.aspx?i=' + this.products[x].id + '&partner=' + this.products[x].partner + '" target="_blank"">' + this.products[x].title + '</a></li>');
        }
        else
        {
            document.write('<li><a id="'+ this.id +'prdlink'+ x +'" href="' + this.basesite + '/d.aspx?i=' + this.products[x].id + '&partner=' + this.products[x].partner + '" target="_blank" onmouseover="mmlist['+ this.ordinal +'].switchProduct('+ x +');"">' + this.products[x].title + '</a></li>');
        }
    }
    document.write('</ul>');
    
    if (this.classname != 'w728' && this.classname != 'w270') {
        for(var x in this.products) this.products[x].render(x, this.id);
    }
    
    document.write('</div>');
}

function switchProduct(product) {
    if (!this.locked) {
        for(var x in this.products) document.getElementById(this.id + 'prd' + x).style.display = 'none';
        for(var x in this.products) document.getElementById(this.id + 'prd' + product).style.display = 'block';
    }
}


// MiniMallProduct class

function miniMallProduct(id, title, price, description, partner) {
    this.id = id;
    this.partner = partner;
    this.title = title;
    this.price = price;
    this.description = description;
    this.image = imageUrl + this.id + '.jpg';
    this.render = renderMiniMallProduct;
}

function renderMiniMallProduct(ord, parentid) {
    document.write('<div class="product" id="'+ parentid +'prd'+ ord +'"');
    if (ord != 0) document.write(' style="display:none;"');
    document.write('>');
    document.write('<a href="'+ productUrl + this.id + "&partner=" + this.partner +'" target="_blank"><img class="productImage" src="' + this.image + '" alt="' + this.title + '"/></a>');
    document.write('<h3><a href="'+ productUrl + this.id + "&partner=" + this.partner +'" target="_blank">'+ this.title +'</a></h3>');
    
    document.write('<p>'+ this.description +'</p>');
    document.write('<div class="button"><a href="'+ productUrl + this.id + "&partner=" + this.partner + '" target="_blank"><img src="/j/6c/images/minimall/buy-now.png"></a></div>');
    document.write('<h4>'+ this.price +'</h4>');
    document.write('</div>');
}