﻿
var res = [
               {'label': 'Stat Boost Pet (WAR)','url':'http://store.origin.com/DRHM/store?Action=DisplayProductDetailsPage&SiteID=ea&Locale=en_US&ThemeID=718200&Env=BASE&productID=235694500'},
               {'label': 'X3: Terran Conflict','url':'http://www.amazon.com/Atari-27760-X%C2%B3-Terran-Conflict/dp/B001RIMXCW/ref=sr_1_1?ie=UTF8&qid=1317900726&sr=8-1'},
	       {'label': 'Trusty Mount Pack (WAR)','url':'http://store.origin.com/DRHM/store?Action=DisplayProductDetailsPage&SiteID=ea&Locale=en_US&ThemeID=718200&Env=BASE&productID=218811000'},
               {'label': 'Star Wars: The Old Republic Pre-Order','url':'http://store.origin.com/store/ea/html/pbPage.SWTOR_NA'},
               {'label': 'Razer Nostromo Keypad','url':'http://www.amazon.com/Razer-Nostromo-Gaming-Keypad-RZ07-00490100-R3/dp/B004AM5RB6/ref=sr_1_1?ie=UTF8&qid=1318253247&sr=8-1'},
               {'label':'World of Tanks Retail Pack','url':'http://www.amazon.com/Value-Items-Included-Premium-Account-Currency-Pc/dp/B0055A7SUK/ref=sr_1_1?ie=UTF8&qid=1318254806&sr=8-1'}
           ];

function printobj(x){
    var output = '';
    for (property in x) {
        output += property + ': ' + x[property]+'; ';
    }
    alert(output);
}

function shuff ( myArray ) {
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i ) {
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}


function dostream(cont){
    var $j = jQuery.noConflict(); 
    div = $j('<div id="streams"/>').appendTo(cont);
    //var r = Math.floor(Math.random()*res.length)
    shuff(res);
    out = '<h2>Stuff to Buy</h2><ul>';

		       for(i in res){
			   if(i > 3){
			      break;
			   }

                           //printobj(res[i].title + " " + res[i].misc.viewers + " viewers");
			   //link = "<li><a href='" + res[i].link + "'>" + res[i].title[0] + "</a> (" + res[i].misc.viewers + " viewers)</li>";
			   link = "<li><a href='" + res[i]['url'] + "'>" + res[i]['label'] + "</a></li>";
			   out += link
		       }

		       out += "</ul>";

                        
		       div.append(out);

		       for(i in res){

			   if(i > 3){
			      break;
			   }
			vglnk.link(res[i]['url']);
		       }



}

 function filterData(data){
    // filter all the nasties out
    // no body tags
    data = data.replace(/<?\/body[^>]*>/g,'');
    // no linebreaks
    data = data.replace(/[\r|\n]+/g,'');
    // no comments
    data = data.replace(/<--[\S\s]*?-->/g,'');
    // no noscript blocks
    data = data.replace(/<noscript[^>]*>[\S\s]*?<\/noscript>/g,'');
    // no script blocks
    data = data.replace(/<script[^>]*>[\S\s]*?<\/script>/g,'');
    // no self closing scripts
    data = data.replace(/<script.*\/>/,'');
    // [... add as needed ...]
    return data;
 }



