// // Place your application-specific JavaScript functions and classes here
// // This file is automatically included by javascript_include_tag :defaults
// 
// function collapse(selector){
//  items = $$(selector)
//  
//  items.each(function(item){
//    item.hide();
//  });
// }
// 
// function expand(selector){
//  items = $$(selector)
//  
//  items.each(function(item){
//    item.show();
//  });
// }
// 
// document.observe("dom:loaded", function() {
//   // the element in which we will observe all clicks and capture
//   // ones originating from pagination links
//   var container = $(document.body)
// 
//   if (container) {
//     var img = new Image
//     img.src = '/images/spinner*.jpg'
// 
//     function createSpinner() {
//       return new Element('img', { src: img.src, 'class': 'spinner' })
//     }
// 
//     container.observe('click', function(e) {
//       var el = e.element()
//       if (el.match('.pagination a')) {
//         el.up('.pagination').insert(createSpinner())
//         new Ajax.Request(el.href, { method: 'get' })
//         e.stop()
//       }
//     })
//   }
// })

/////////jQuery functions
//Adds the .js mime to URLs, so that Rails fires the correct respond_to response.
var mimeifyUrl = function(url){
 if (/\.js/.test(url)){
   return url
 } else if (/\?/.test(url)) {
   return url.replace('?', '.js?')
 } else {
   return url + '.js'
 }
}

$.ajaxSetup({
  dataType: "script",
	// complete: function(response, status){
	//     //$('#loading_indicator').hide()
	//   },
	//   error: function(){
	//     //jQuery.facebox('OMG. Somethin ain\'t right!') // replace this with your own awesome error handler
	//   },
	beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript");}
});

// Similar to the built in 'load' function in jQuery, extended so that it adds the .js mime to
// the url.
// $.fn.railsLoad = function(location){
//   var self = this;
//   $.ajax({
//     url: mimeifyUrl(location),
//     success: function(response, status){
//       $(self).html(response);
//     }
//   });
// }

$(document).ready(function() {
  // All A tags with class 'get', 'post', 'put' or 'delete' will perform an ajax call
  jQuery('a.get').live('click', function() {
    var link = jQuery(this);
    //$(document).trigger('loading.facebox');
    $.get(link.attr('href'), function(data) {
      if (link.attr('ajaxtarget'))
        jQuery(link.attr('ajaxtarget')).html(data);
    });
    return false;
  }).attr("rel", "nofollow");
 
  jQuery('a.post').live('click', function() {
    var link = jQuery(this);
    $.post(jQuery(this).attr('href'), "_method=post", function(data) {
      if (link.attr('ajaxtarget'))
        jQuery(link.attr('ajaxtarget')).html(data);
    });
    return false;
  }).attr("rel", "nofollow");
 
  jQuery('a.put').live('click', function() {
    var link = jQuery(this);
    $.post(jQuery(this).attr('href'), "_method=put", function(data) {
      if (link.attr('ajaxtarget'))
        jQuery(link.attr('ajaxtarget')).html(data);
    });
    return false;
  }).attr("rel", "nofollow");
 
  jQuery('a.delete').live('click', function() {
    var link = jQuery(this);
    $.post(jQuery(this).attr('href'), "_method=delete", function(data) {
      if (link.attr('ajaxtarget'))
        jQuery(link.attr('ajaxtarget')).html(data);
    });
    return false;
  }).attr("rel", "nofollow");
 
  jQuery('a.get, a.post, a.put, a.delete').removeAttr('onclick');

  jQuery('form.ajax').live('submit', function() {
    jQuery(this).ajaxSubmit();
    return false;
  });
})

// getPageScroll() by quirksmode.com
function getPageScroll() {
  var xScroll, yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
    xScroll = self.pageXOffset;
  } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
    xScroll = document.documentElement.scrollLeft;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
    xScroll = document.body.scrollLeft;
  }
  return new Array(xScroll,yScroll)
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
  var windowHeight
  if (self.innerHeight) {	// all except Explorer
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowHeight = document.body.clientHeight;
  }
  return windowHeight
}


//COMPANIES
//SHOW

