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

  show: function(url) {
    $('photo').src = url;
    $('mask').show(  );
    $('photo-wrapper').visualEffect('appear', {duration:0.5});
  },

  hide: function(  ) {
    $('mask').hide(  );
    $('photo-wrapper').visualEffect('fade', {duration:0.5});
  },

  currentIndex: function(  ) {
    return this.urls(  ).indexOf($('photo').src);
  },

  prev: function(  ) {
    if(this.urls()[this.currentIndex(  )-1]) {
      this.show(this.urls()[this.currentIndex(  )-1])
    }
  },

  next: function(  ) {
    if(this.urls()[this.currentIndex(  )+1]) {
      this.show(this.urls()[this.currentIndex(  )+1])
    }
  },

  urls: function(  ) {
    if (!this.cached_urls) {
      this.cached_urls = $$('a.show').collect(function(el){
        var onclick = el.onclick.toString(  );
        return onclick.match(/".*"/g)[0].replace(/"/g,'');
      });
    }
    return this.cached_urls;
  },

	popUp: function(URL) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=700,height=268,left = 0,top = 0');");
	}

}

