var hfs = {

  rolloverSuffix: '_on',
  fileExtension: '.gif',
  dataUrl : 'http://www.hfs-clinics.co.uk/hotspots/data/',
  obj:{},
  labelClass : 'hotspot_label',

  currentImage: 'http://hfs.airving.myzen.co.uk/images/uploads/home_page_banner.jpg',
  currentData: false,
  data: [
      {
        alt : 'Physiotherapy',
        image : 'http://www.hfs-clinics.co.uk/images/homepage/man-back.jpg',
        hotspots : [
                     
           ]}
], 

  preload: function( img ){
    var src = img.src.replace(hfs.fileExtension, hfs.rolloverSuffix + hfs.fileExtension);
    var i = new Image();
    i.src = src;
  },

 


  findData: function(el){
     for(var i=0; i<hfs.data.length; i++){
       if( hfs.data[i].alt == el.alt ){
            return i;
       }
     }
  },

  makeAllActive: function(){
     $$('#home_nav img').each( function(el){
         el.store('rollover', 'active');
         hfs.swapOff.attempt('', el);
     });
    },

  
    showLabel: function(){
        var obj = this.retrieve('show');
        var el = $(this.retrieve('txt') );
        var elObj = el.retrieve('show');
        el.morph( elObj );
        this.morph( obj );
         // this.getElement('p').fade('in');
      
            
     },

    hideLabel: function(){
             try{
           var obj = this.retrieve('hide');
        var el = $(this.retrieve('txt') );
        var elObj = el.retrieve('hide');
        el.morph( elObj );
        this.morph( obj );
      }catch(e){}}, 
     
     hideAllLabels: function(){
        $$('.imageholder div').each(function(d){
            hfs.hideLabel.attempt('', d);
        });
    },
        
    removeLabels: function(){
        $$('.imageholder div').each(function(d){
           if( !d.hasClass('adwriteup') ) d.destroy();
       });
    },

  addTextBoxes: function(){
   
     var p, hot ;
     var con = $$('.imageholder')[0];
     hfs.currentData.hotspots.each(function(h, i){
        // create text container
         p = new Element('div');
         p.setStyles({ 'position' : 'absolute', 'overflow' : 'hidden'}); 
         p.setStyles( h.txt.start );
         p.set('html', h.txt.content );
         p.addClass(hfs.labelClass);
         p.store('hide', h.txt.start);
         p.store('show', h.txt.end);         
         p.id = hfs.currentData.alt.toLowerCase().replace(' ', '_') + i;
        // create arrow container
         hot = new Element('div');
         hot.setStyles({'position':'absolute', 'overflow':'hidden' });
         hot.setStyles(h.start);
         hot.setStyles(h.styles);         
         hot.store('hide', h.start);
         hot.store('show', h.end);
         hot.store('txt', p.id); 
         hot.addEvent('mouseover', hfs.showLabel);
         p.inject(con);
         hot.inject(con);
         
     });
    con.addEvent('mouseleave', hfs.hideAllLabels);
  },

  gotoImage: function(el){
     //alert( el.retrieve('index') );
     var obj = hfs.data[el.retrieve('index')];
     hfs.makeAllActive();
     
     hfs.removeLabels();
     if( !$chk(obj) ){ /*alert('data not found!'); */ return; }
     if( hfs.currentData ) hfs.currentImage = hfs.getElementBySrc( hfs.currentData.image ); 
     
     hfs.currentData = obj;
     
     hfs.addTextBoxes();
  
  }, 

 


  init:function(){
      var el = $$('.imageholder').getElement('img');
      el.store( 'index', 0 );
      hfs.currentImage = el;
      hfs.gotoImage(el);
     
  }
}

window.addEvent('domready', hfs.init);   
   
