
window.addEvent('domready', function(){
  $$('.selectable-thumb').each(function(img){
    img.addEvent('click', function(el){
      if(img.hasClass('selectable-selected')){
        img.removeClass('selectable-selected');
      }else{
        img.addClass('selectable-selected');
      }
    });
  });
});

function submit_callback() {
  var img_ids = '';
  $$('.selectable-selected').each(function(img){
    var id = img.getProperty('id')
    id = id.replace(/^img:/,'');
    img_ids += id+',';
  });
  $('selected-img-ids').setProperty('value',img_ids);
}

function highlight(type){
  var location_tags = '';
  $$('.photo-location-box').each(function(el){
    if(el.getProperty('checked')){
      var id = el.getProperty('id')
      id = id.replace(/^pl:/,'');
      location_tags += id+',';
    }
  });
  location_tags = location_tags.substring(0,location_tags.length-2);
  var subject_tags = '';
  $$('.photo-subject-box').each(function(el){
    if(el.getProperty('checked')){
      var id = el.getProperty('id')
      id = id.replace(/^ps:/,'');
      subject_tags += id+',';
    }
  });
  subject_tags = subject_tags.substring(0,subject_tags.length-2);
  var args = {
    't': type,
    'it': $('image-tag').getValue(), 
    'pl': location_tags,
    'ps': subject_tags,
    'td': $('top-discussed-checkbox').getValue(),
    'tr': $('top-rated').getValue()
  };
  var ajax = new Ajax('ajax_results.php', {data: args, method:'post', onComplete: function(rs){
    var res = Json.evaluate(rs);
    res.each(function(r){
      var img = $('img:'+r);
      img.addClass('selectable-selected');
    });
  }}).request();
}

