// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

Event.observe(window,'load', function() {
  tables = $$('table.stripe');
  for(current=0; tables.length > current; current++) { 
    table = tables[current];
    var tbodies = table.getElementsByTagName("tbody");

    for (var h = 0; h < tbodies.length; h++) {
      // find all the <tr> elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {  
        if((i % 2) == 0) { style = 'even'; } else { style = 'odd'; }
        Element.addClassName(trs[i],style);
      }
    }
  }
});

Event.observe(window,"load", function() {
  //click to clear functionality
  $$('input.clear\_on\_click').each(function(element) {
    new ClearOnClick(element);
  });
});

var ClearOnClick = Class.create();
  Object.extend(ClearOnClick.prototype, {
  initialize: function(element) {
    this.element = $(element);
    this.originalValue = $F(element);
    this.element.observe("blur", this.onBlur.bind(this));
    this.element.observe("focus", this.onFocus.bind(this));
    var form = this.element.up("form");
    if(form) $(form).observe("submit", this.onFocus.bind(this));
  },
  onFocus: function(event) {
    if($F(this.element) == this.originalValue) {
      this.element.value = "";
      this.element.removeClassName("clear\_on\_click");
    }
  },
  onBlur: function(event) {
    if($F(this.element).match(/^\s*$/)) {
      this.element.value = this.originalValue;
      this.element.addClassName("clear\_on\_click");
    }
  }
}
);

Event.onReady(function() {
	items =  $$('#gallery ul.fullsize li');
		items.each(function(item) {
		  if (!item.hasClassName('first_gallery_photo')) {
			  item.hide();
			}
	});
});

Event.addBehavior({
  '#gallery ul.thumbnails li a:click' : function(e) {  
		showPhoto(this.getAttribute('href').split('#')[1]);
		return false;
  }
});

function showPhoto(photo_id) {
  items =  $$('#gallery ul.fullsize li');
  items.each(function(item) {
    item.hide();
  });
  Effect.Appear(photo_id);
  return false;
}

