
		function addLoadEvent(f){var ono=window.onload;if(typeof window.onload!='function'){window.onload=f}else{window.onload=function(){ono();f()}}}

		/* Featured property object */
		function FeaturedPropertyModel(details_url, image_url, address, price, description) 
		{
			this.details_url = details_url;
			this.image_url = image_url;
			this.address = address;
			this.price = price.replace("£", String.fromCharCode(163));
			this.description = description;
		};

    function FeaturedProperty(sp,db,err) {
        this.speed = sp;
        this.dbtype = db;
        this.featuredProperties = new Array();
        this.currentIndex = 0;
        this.featureDiv = null;
        this.error = err;
        if (document.getElementById("featureprops")) {
       this.featureDiv = document.getElementById("featureprops");
    } else if  (document.getElementById("featureprops" + this.dbtype)) {
       this.featureDiv = document.getElementById("featureprops"+ this.dbtype);
    }

    }
    
    FeaturedProperty.prototype.ShowNextSlide = ShowNextSlide;
    FeaturedProperty.prototype.AppendFeature = AppendFeature;
    FeaturedProperty.prototype.AddFeature = AddFeature;
    FeaturedProperty.prototype.CreateTextDiv = CreateTextDiv;
    FeaturedProperty.prototype.FeatureLoad = FeatureLoad;      
    FeaturedProperty.prototype.AddFeatureProperty = AddFeatureProperty;  
         

		function ShowNextSlide(me) {
		    if ( me.featuredProperties.length ==0 ) return;
		    if (me.currentIndex >= me.featuredProperties.length) {
			    me.currentIndex = 0;
			}
		    if (me.currentIndex == 0 && me.featuredProperties.length == 1) {
		        me.AddFeature(0);
		    } else if (me.speed == 0 ) {
		        var ul = document.createElement("ul");
		        me.featureDiv.appendChild(ul);
		        for(var i=0; i<me.featuredProperties.length; i++)
		        {
		            var li = document.createElement("li");
		            me.AppendFeature(li, me.featuredProperties[i]);
		            ul.appendChild(li);
		        }
		    } else {
		        var timeout = function () {
		            ShowNextSlide(me);
		        };
	
		        me.AddFeature(me.currentIndex++);
		        window.setTimeout(timeout, me.speed);
		    }

		};
		
		function AppendFeature(targetDiv, fpModel) {
		    var imageDiv = document.createElement("div");
		    imageDiv.className ="fpImage";
		    var imageLink = document.createElement("a");
		    imageLink.setAttribute("href", fpModel.details_url);
		    imageLink.setAttribute("title", "View property details for property in " + fpModel.address + ", " + fpModel.price);
		    var imageTag = document.createElement("img");
		    imageTag.setAttribute("src", fpModel.image_url);
		    imageTag.setAttribute("alt", "Image for property in " + fpModel.address);
		    imageLink.appendChild(imageTag);
		    imageDiv.appendChild(imageLink);
		    var addressDiv = CreateTextDiv("fpAddress", fpModel.address);
		    var priceDiv = CreateTextDiv("fpPrice", fpModel.price);
		    targetDiv.appendChild(imageDiv);
		    targetDiv.appendChild(addressDiv);
		    targetDiv.appendChild(priceDiv);
		};

		function AddFeature(index) {
		    var fpModel = this.featuredProperties[index];
		    var l = this.featureDiv.childNodes.length;
		    for (var i=0; i < l; i++) {
		        var ch = this.featureDiv.firstChild;
		        this.featureDiv.removeChild(ch);
		    }
		    AppendFeature(this.featureDiv, fpModel);
		};
		
	   function AddFeatureProperty(fpModel) {
		    this.featuredProperties[this.featuredProperties.length] = fpModel;
		};

		function CreateTextDiv(id, text) {
		    var textDiv = document.createElement("div");
		    textDiv.className= id;
		    var paraElement = document.createElement("p");
		    textDiv.appendChild(paraElement);
		    var textElement = document.createTextNode(text);
		    paraElement.appendChild(textElement);
		    textDiv.appendChild(paraElement);
		    return textDiv;
		};

		function FeatureLoad() { 
          if (this.error == null && this.featureDiv != null)
          {
            var propCount = this.featuredProperties.length;
            var randomPropIndex = Math.floor(Math.random() * propCount);
            this.currentIndex = randomPropIndex;
            this.ShowNextSlide(this);
	        } 
          else if (this.error != null && this.featureDiv != null)
          {
	          var p = document.createElement("p");
	          p.appendChild(document.createTextNode(error));
	          this.featureDiv.appendChild(p);
	        }
    };
        
		
		
		
		

      // this variable name needs to be unique
      var featuredObj1;
      function initFeaturedProp() {
        featuredObj1 = new FeaturedProperty(0,1, null);
        
      featuredObj1.AddFeatureProperty(  new FeaturedPropertyModel(
      "http://search.thinkproperty.com/morrisco/property/22965748",
      "http://images.vebra.com/morrisandco/sales/ecimage1/001a0196767.jpg",
      "Rosaire, 9 Clos de Priaulx, Brock Road, St Sampson",
      "£479,000",
      ""));
    
      featuredObj1.FeatureLoad();
      
      }
      addLoadEvent(initFeaturedProp);

    
