// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

$(window).ready(function() {
	$('.focus').focus();
	
	$('table tbody tr:odd').addClass('alternating');	
	
	$('.comments').each(function() {
		var c = $(this);
		
		if (c.height() > 175) {
			c.height(175).css('overflow-y', 'scroll');
		}
		c.find('.comment:odd').css('background-color', '#F4F6ED');
	});	
	
	$('.checkbox-list div').ellipsis();
	$('.checkbox-list div a').click(function() {
		$(this).prev().attr('checked', !$(this).prev().attr('checked'));		
		return false;
	});
	
	$('div.buttons button').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); } )
	$('div.sub-nav a').hover(function() { $(this).addClass('selected'); }, function() { $(this).removeClass('selected'); } );
});

ua   = navigator.userAgent.toLowerCase();
isIE  = (ua.indexOf("msie") && document.all && ua.indexOf("netscape") == -1);

/* add index of function for stupid IE */
if(isIE){
  Array.prototype.indexOf = function(k){
    var len = this.length;
    for(i=0;i<len;i++){
      if(this[i] == k){
        return i;
      }
    }
    return -1;
  };
}

if(isIE){
  Array.prototype.lastIndexOf = function(k){
    var len = this.length;
    for(i=len-1;i>-1;i--){
      if(this[i] == k){
        return i;
      }
    }
    return -1;
  };
}

jQuery.preloadImages = function() {
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
}

function highlightTable(table_body_id) {
	$(table_body_id + ' tr:odd').addClass('alternating');	
	// $('table tbody tr').bind('mouseover', function() { $(this).addClass('HighlightRow'); });
	// $('table tbody tr').bind('mouseout', function() { $(this).removeClass('HighlightRow'); });
}

function focusSearch(input) {
	input.parent().toggleClass('focused');
	
	if (input.val() == default_search_text)
		input.val('');
}

function blurSearch(input) {
	input.parent().removeClass('focused');
	
	if (input.val() == '')
		input.val(default_search_text);
}

function pageLoading() {
	$('#content').css('opacity', 0.4); 
}

function pageDoneLoading() {
	$('#content').css('opacity', ''); 
}