PLH = function(){
  var cookyVal='';
  return {
      init: function(){
        var me = this;
        $('#propSelectTrailer img').click(function(){me.removeAll();});
        this.cookyVal = $.cookie('property_list') || '';
        if(this.cookyVal != ''){
          $.getJSON('pictures.php', {list:this.cookyVal}, function(json){
              $.each(json.row, function(i,n){
                  me.show(n.thumb, n.title, n.ref);
                });
            });
        }
      }
    , go: function(){
        window.location.href='property_selection.php';
      }
    , write: function(){
        $.cookie('property_list', this.cookyVal);
      }
    , add: function(id){
        var me = this;
        if(this.cookyVal.indexOf('|'+id+'|') < 0){
          this.cookyVal += this.cookyVal.length==0 ? '|'+id+'|' : id+'|';
          this.write();
          $.getJSON('pictures.php', {list:id}, function(json){
              $.each(json.row, function(i,n){
                  me.show(n.thumb, n.title, n.ref);
                });
            });
        }
        return false;
      }
    , show: function(img,txt,id){
        var me = this
          , html = '<div class="propSelectItem">';
//        html += '<a name="'+txt+'" href="pictures.php?property='+id+'" class="jqModal_sai">';
        html += '<a name="'+txt+'" href="details.htm?ref='+id+'">';
        html += '<img id="propSelectThumb_'+id+'" class="propSelectThumb" src="'+img+'" alt="'+txt+'" title="'+txt+'" />';
        html += '</a></div>';
        $('#propSelectNone').hide();
        $('#propSelectTrailer:hidden').show();
        $('.showme:hidden').click(function(){me.go();}).show();
        $(html)
            /*.find('a').each(function(){ $('#showAllImages').jqmAddTrigger(this); }).end()*/
            .appendTo('#propSelectList')
            .append('<img src="images/generic_graphics/delete.gif" alt="Remove" title="Remove" class="propSelectRemove" />')
            .hover( function(){
                      $(this).addClass('propSelectHover')
                        .find('img.propSelectRemove').show().one('click', function(){ me.remove($(this).parent(), id); })
                      ;
                    }
                  , function(){
                      $(this).find('img.propSelectRemove').unbind('click').hide().end()
                        .removeClass('propSelectHover')
                        ;
                    }
                  )
            ;
      }
    , removeAll: function(){
        if(confirm('Please confirm that you wish to empty your selection list?')){
          this.cookyVal = '';
          this.write();
          $('.showme').hide().unbind('click');
          $('.propSelectItem').remove();
          $('#propSelectNone').show();
          $('#propSelectTrailer').hide();
        }
      }
    , remove: function(el, id){
        el.remove();
        var tid = '|'+id+'|';
        var newCookyVal = this.cookyVal.substr(0, this.cookyVal.indexOf(tid)) + '|' + this.cookyVal.substr(this.cookyVal.indexOf(tid)+tid.length);
        this.cookyVal = newCookyVal == '|' ? '' : newCookyVal;
        this.write();
        if($('.propSelectItem').size() == 0){
          $('.showme').hide().unbind('click');
          $('#propSelectNone').show();
          $('#propSelectTrailer').hide();
        }
        return false;
      }
    } // end of return object
}();