var TorrentsHistory = function( moreTorrents ){

var torrents = {
"Torrentz.com": ["http://torrentz.com", "http://www.torrentz.com"],
"The Pirate Bay": ["http://thepiratebay.org", "http://www.thepiratebay.org"],
"IsoHunt.com": ["http://isohunt.com", "http://www.isohunt.com"],
"Mininova.org": ["http://mininova.org", "http://www.mininova.org"],
"BtJunkie.org": ["http://btjunkie.org", "http://www.btjunkie.org"],
"TorrentReactor.net": ["http://torrentreactor.net", "http://www.torrentreactor.net"],
"TorrentDownloads.net": ["http://torrentdownloads.net", "http://www.torrentdownloads.net"],
"Monova.org": ["http://monova.org", "http://www.monova.org"],
"ExtraTorrent": ["http://extratorrent.com"],
"BTMon.com": ["http://btmon.com"],
"KickAssTorrents": ["http://KickAssTorrents.com"],
"VerTOR.com": ["http://vertor.com"],
"EzTV.it": ["http://eztv.it"],
"SumoTorrent": ["http://sumotorrent.com"],
"AliveTorrents": ["http://alivetorrents.com"],
"Fenopy": ["http://fenopy.com"],
"TorrentPump": ["http://torrentpump.com"],
"TorrentHound": ["http://torrenthound.com"],
"TorrentPortal": ["http://torrentportal.com"],
"Demonoid.com": ["http://demonoid.com"],
"Zoozle.net": ["http://zoozle.net"],
"SeedPeer": ["http://seedpeer.com"],
"TorrentZAP": ["http://torrentzap.com"],
"YourBitTorrent": ["http://yourbittorrent.com"],
"Search-Torrent": ["http://search-torrent.com"],
"Hdbits.org": ["http://Hdbits.org"],
"Scenehd.org": ["http://scenehd.org"],
"Torrenty.org": ["http://torrenty.org"],
"Zionteam.org": ["http://zionteam.org"],
"Release.com.pl": ["http://release.com.pl/"],
"Onlytorrents.com": ["http://Onlytorrents.com"]
};
  
  for( var torrent in moreTorrents ) {
    // If we don't have the site, create the URL list.
    if( typeof( torrents[torrent] ) == "undefined" ) torrents[torrent] = [];
    
    // If the value is string, just push that onto the URL list.
    if( typeof( moreTorrents[Torrent] ) == "string" )
      torrents[torrent].push( moreTorrents[torrent] );
    else
      torrents[torrent] = torrents[torrent].concat( moreTorrents[torrent] );
  }
  
  var visited = {};

  function getStyle(el, scopeDoc,styleProp) {
    if (el.currentStyle)
      var y = el.currentStyle[styleProp];
    else if (window.getComputedStyle)
      var y = scopeDoc.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
    return y;
  }
  
  function remove( el ) {
    el.parentNode.removeChild( el );
  }
  
  function createIframe() {
    var iframe = document.createElement("iframe");
    iframe.style.position = "absolute";
    iframe.style.visibility = "hidden";

    document.body.appendChild(iframe);

    // Firefox, Opera
    if(iframe.contentDocument) iframe.doc = iframe.contentDocument;
    // Internet Explorer
    else if(iframe.contentWindow) iframe.doc = iframe.contentWindow.document;

    iframe.doc.open();
  	iframe.doc.write('<style>');
  	iframe.doc.write("a{color: #000000; display:none;}");  	
  	iframe.doc.write("a:visited {color: #FF0000; display:inline;}");  	
  	iframe.doc.write('</style>');
    iframe.doc.close();
    
    return iframe;
  }  

  var iframe = createIframe();
  
  function embedLinkInIframe( href, text ) {
    var a = iframe.doc.createElement("a");
    a.href = href;
    a.innerHTML = torrent;
    iframe.doc.body.appendChild( a );
  }
  
  for( var torrent in torrents ) {
    var urls = torrents[torrent];
    for( var i=0; i<urls.length; i++ ) {
      embedLinkInIframe( urls[i], torrent );
      
      if( urls[i].match(/www\./) ){
        var sansWWW = urls[i].replace(/www\./, "");
        embedLinkInIframe( sansWWW, torrent );
      } else {
        var httpLen = urls[i].indexOf("//") + 2;
        var withWWW = urls[i].substring(0, httpLen ) + "www." + urls[i].substring( httpLen );
        embedLinkInIframe( withWWW, torrent );
      }
      
    }
  }
    
  var links = iframe.doc.body.childNodes;
  for( var i=0; i<links.length; i++) {
    // Handle both Firefox/Safari, and IE (respectively)
    var displayValue = getStyle(links[i], iframe.doc, "display");
    var didVisit = displayValue != "none";
      
    if( didVisit ){
      visited[ links[i].innerHTML ] = true;
    }
  }
  
  remove( iframe );
  
  return new (function(){
    var usedTorrents = [];
    for( var torrent in visited ){
      usedTorrents.push( " "+torrent );
    }
    
    // Return an array of visited sites.
    this.visitedTorrents = function() {
      if ( usedTorrents.length == 0 ){
	return "You didn't download torrents that we have in our database";
	} else {
	isTrueTorrents = 1;
	 number1 = number1 + 1;
	return usedTorrents;
	}
    }
    
    // Return true/false. If we didn't check the site, return -1.
    this.doesVisit = function( torrent ) {
      if( typeof( torrents[torrent] ) == "undefined" )
        return -1;
      return typeof( visited[torrent] ) != "undefined";
    }
    
    var checkedTorrents = [];
    for( var torrent in torrents ){
      checkedTorrents.push( torrent );
    }
    // Return a list of the sites checked.
    this.checkedTorrents = function(){
      return checkedTorrents;
    }
  })();
}
