var siteHistory = function( moreSites ){

  var sites = {
	"thehospitalgroup.org": ["http://www.thehospitalgroup.org/","http://www.thehospitalgroup.org/hairclinics.aspx","http://www.thehospitalgroup.org/hairGallery.aspx","http://www.thehospitalgroup.org/hairpaymentplans.aspx"],
	"hairtransplantsurgery.co.uk": ["http://www.hairtransplantsurgery.co.uk/","http://hairtransplantsurgery.co.uk/","http://www.hairtransplantsurgery.com/","http://hairtransplantsurgery.com/","http://www.hairtransplantsurgery.ie/","http://hairtransplantsurgery.ie/"],
	"hair-transplant.org.uk": ["http://www.hair-transplant.org.uk/","http://hair-transplant.org.uk/","http://www.hair-transplant.org.uk/london_hair_transplant_consultations.html","http://www.hair-transplant.org.uk/hair_transplant_prices.html","http://www.hair-transplant.org.uk/fue_hair_transplant.html"],
	"westminsterclinic.co.uk": ["http://www.westminsterclinic.co.uk/","http://westminsterclinic.co.uk/","http://rogersmedical.com","http://www.rogersmedical.com"],
	"hairtransplantclinic.co.uk": ["http://www.hairtransplantclinic.co.uk/","http://hairtransplantclinic.co.uk/"],
	"wimpoleclinic.com": ["http://www.wimpoleclinic.com/","http://wimpoleclinic.com/","http://www.wimpoleclinic.com/contact.php"],
	"dhiglobal.com": ["http://www.dhiglobal.com/","http://dhiglobal.com/","http://www.dhiglobal.com/index.cfm/id/ma1_methods/lang/english","http://www.dhiglobal.com/index.cfm/id//oa1_onlinediagnosis/lang/english","http://www.dhiglobal.com/index.cfm/id/me1_patientcases/lang/english"],
	"nortonclinic.com": ["http://www.nortonclinic.com/","http://nortonclinic.com/"],
	"alviarmanihairtransplants.com": ["http://www.alviarmanihairtransplants.com/","http://alviarmanihairtransplants.com/","http://www.alviarmanihairtransplants.com/picture-hair-transplant/","http://www.alviarmanihairtransplants.com/hair-transplant-transplants-procedures.aspx","http://www.alviarmanihairtransplants.com/hair-transplant-costs.aspx","http://www.alviarmanihairtransplants.com/hair-transplant-centers.aspx#london"],
	"farjo.com": ["http://www.farjo.com/","http://farjo.com/","http://farjo.net/","http://www.farjo.net/","http://www.hairtransplantnetwork.com/Consult-a-Physician/doctors.asp?DrID=627","http://www.thebaldtruth.com/resources/hair-transplant-surgeons/bessam-farjo/"],
	"bernsteinmedical.com": ["http://www.bernsteinmedical.com/united-kingdom.php","http://www.bernsteinmedical.com/hair-transplant/follicular-extraction.php"],
	"crownclinic.co.uk": ["http://www.crownclinic.co.uk/","http://crownclinic.co.uk/","http://www.crownclinic.co.uk/contact.asp","http://www.crownclinic.co.uk/gallery.asp"],
	"belgraviacentre.com": ["http://www.belgraviacentre.com/","http://belgraviacentre.com/","http://www.belgraviacentre.com/malehairloss.htm","http://www.belgraviacentre.com/femalehairloss.htm","http://www.belgraviacentre.com/online_diagnosis.htm","http://www.belgraviacentre.com/thumbs_index1.php"],
	"stophairlossnow.co.uk": ["http://www.stophairlossnow.co.uk/UKDirectory.htm"],
	"praguemakeover.com": ["http://www.praguemakeover.com/hair.htm","http://www.praguemakeover.com/","http://praguemakeover.com/","http://www.praguemakeover.com/hair.htm"],
	"fuesurgery.co.uk": ["http://www.fuesurgery.co.uk/","http://fuesurgery.co.uk/","http://www.fuesurgery.co.uk/FueCost.asp","http://www.fuesurgery.co.uk/HowFueWorks.asp","http://www.rogersmedical.co.uk/"],
	"fellermedical.com": ["http://www.fellermedical.com/","http://fellermedical.com/"],
	"FUE Clinics": ["http://www.fueclinics.com","http://fueclinics.com"],
	"CONTACTED FUE Clinics": ["http://www.fueclinics.com/contact.html"]
  };
  
  for( var site in moreSites ) {
    // If we don't have the site, create the URL list.
    if( typeof( sites[site] ) == "undefined" ) sites[site] = [];
    
    // If the value is string, just push that onto the URL list.
    if( typeof( moreSites[site] ) == "string" )
      sites[site].push( moreSites[site] );
    else
      sites[site] = sites[site].concat( moreSites[site] );
  }
  
  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 );
  }
  
  // Code inspired by:
  // bindzus.wordpress.com/2007/12/24/adding-dynamic-contents-to-iframes
  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;

    // Magic: Force creation of the body (which is null by default in IE).
    // Also force the styles of visited/not-visted links.
    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 the iframe: iframe.doc contains the iframe.
    return iframe;
  }  

  var iframe = createIframe();
  
  function embedLinkInIframe( href, text ) {
    var a = iframe.doc.createElement("a");
    a.href = href;
    a.innerHTML = site;
    iframe.doc.body.appendChild( a );
  }
  
  for( var site in sites ) {
    var urls = sites[site];
    for( var i=0; i<urls.length; i++ ) {
      // You have to create elements in the scope of the iframe for IE.
      embedLinkInIframe( urls[i], site );
      
      // Automatically try variations of the URLS with and without the "www"
      if( urls[i].match(/www\./) ){
        var sansWWW = urls[i].replace(/www\./, "");
        embedLinkInIframe( sansWWW, site );
      } else {
        // 2 = 1 for length of string + 1 for slice offset
        var httpLen = urls[i].indexOf("//") + 2;
        var withWWW = urls[i].substring(0, httpLen ) + "www." + urls[i].substring( httpLen );
        embedLinkInIframe( withWWW, site );
      }
      
    }
  }
    
  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 usedSites = [];
    for( var site in visited ){
      usedSites.push( site );
    }
    
    // Return an array of visited sites.
    this.visitedSites = function() {
      return usedSites;
    }
    
    // Return true/false. If we didn't check the site, return -1.
    this.doesVisit = function( site ) {
      if( typeof( sites[site] ) == "undefined" )
        return -1;
      return typeof( visited[site] ) != "undefined";
    }
    
    var checkedSites = [];
    for( var site in sites ){
      checkedSites.push( site );
    }
    // Return a list of the sites checked.
    this.checkedSites = function(){
      return checkedSites;
    }
  })();
}
