function start_slideshow(start_frame, end_frame, delay) {
    setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
}
                        
function switch_slides(frame, start_frame, end_frame, delay) {
    return (function() {
        Effect.Fade('slideshow' + frame);
        if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
        setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
        setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
    })
}


function toggle_scrim(element) {
  $('scrim').toggle();
  var to_hide = $(element)
  $('scrim').style.height = $(element).height + 'px';
  //center the throbber
  $('detail_throbber').style.paddingLeft = $(element).width/2 + 'px';
  $('detail_throbber').style.paddingTop  = $(element).height/2 + 'px';
}

/*
 function: will_paginate_remote
 This function updates all the links within a pagination div to make them remote calls instead.
*/
function will_paginate_remotely(elm, token) {
  element = $(elm);
  if(element) {
    if(links = element.getElementsByTagName("a")) {
      for (var i = 0; i < links.length; i++) { 
              
        // Remove any parameters from the link
        var links_and_params = links[i].getAttribute("href").split('?')
        var params = ''
        var link = links_and_params[0]
        if(links_and_params.length > 1) {
          params = '&'
          for(var x = 1; x < links_and_params.length; x++) {
            params += links_and_params[x];
          }
          params = '&' + links[i].getAttribute("href")
        }
        ajax = "new Ajax.Request('" + link + "', {asynchronous:true, evalScripts:true, method:'get', parameters:'authenticity_token=' + encodeURIComponent('"+ token +"') + '" + params + "' }); return false;";
        links[i].setAttribute('onclick', ajax)
        links[i].setAttribute('href','#');
        links[i].removeAttribute('target');
      }  
    }
  }
}

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
/*
  Class: TabMenu
  This class will show or hide a tab sub menu based on mouse clicks.
*/

/*
  Constructor: TabMenu
  Initializes the class
*/
TabMenu = function() {
  this.tabs     = ['projects_tab','search_tab', 'about_tab'];
  this.triggers = ['projects_trigger','search_trigger', 'about_trigger'];
  this.menus    = ['projects_menu','search_menu', 'about_menu'];
  this.to_s     = "TabMenu";
}

/*
  Function: init
  Initializes the class to its default values.
*/
TabMenu.prototype.init = function() {
  obj = window
  var target = this;
  if (obj.addEventListener) {
    obj.addEventListener("click", function(e){target.handleClick(e)}, false);
  }else if (obj.attachEvent) { 
    document.attachEvent( "onclick", function(){target['handleClick']();} ); 
  }
}

/*
  Function: onLoad
  This function can be given to a page observer as a callback to execute when the page load is complete.
*/
TabMenu.prototype.onLoad = function() {
  this.init();
}

/*
  Function: handleClick
  This function can be assigned as a callback method to a listener watching for mouse clicks. This function
  is assigned in the init function of the class to an event listener.
  
  Parameters:
  
    e - The event that triggered this function.
*/
TabMenu.prototype.handleClick = function(e) {
  var id;
  (typeof window.event!="undefined")? id = event.srcElement.id : id = e.target.id;

  this.hideMenus();
  for(var x =0; x < this.triggers.length; x++) {
    if(id == this.triggers[x]){
      this.showMenu(this.menus[x],this.tabs[x])
    }
  }
}

/*
  Function: showMenu
  This menu will display a DOM element by setting the style to "block".
  
  Parameters:
  
    menu - The DOM element corresponding to the menu.
    tab -  The DOM element corresponding to the tab.
*/
TabMenu.prototype.showMenu = function(menu, tab) {
  this.hideMenus();
  var t = document.getElementById(tab)
  var m = document.getElementById(menu)
  if(m && t) {
      m.style.display='block';
   }
}

/*
  Function: hideMenu
  This function will hide a menu that is currently visible.
*/
TabMenu.prototype.hideMenus = function() {
  for(x in this.menus) {
    var m = document.getElementById(this.menus[x])
    if(m) m.style.display = 'none';
  }
}

/****************************************************
 * OnLoad Handler
 ****************************************************/
// Dean Edwards/Matthias Miller/John Resig

function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);
  tab_menu.onLoad();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = init;

// Instanciate before page load is complete.
tab_menu = new TabMenu();