function trim(str){
	return jQuery.trim(str);
}

function changeActionAndSubmit(url,elementID)
{
   	var form = jQuery( elementID );
	   				form.action=url;
   					form.submit();
}

function replace(s, t, u) {
  	i = s.indexOf(t);
  	r
  	if (i == -1) return s;
	r += s.substring(0,i) + u;
	if ( i + t.length < s.length)
    		r += replace(s.substring(i + t.length, s.length), t, u);
	return r;
}

// get value of query string param
function getQueryParamValue(param) {
  var q = document.location.search || document.location.href.split("#")[1];
  if (q) {
         var detectIndex = q.indexOf(param +"=");
         var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
             if (q.length > 1 && detectIndex > -1) {
                 return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
                 } else {
              return "";
                 }
      }
}

//make rounded corners - by BjarniJ
function roundElement(element) {
   jQuery.each(jQuery(element), function() {
       $(this).html('<div class="rounded"><div class="content"><div class="t"/> '+$(this).html()+'<br class="clear"/></div><div class="b"><div/></div></div>');
   });
}

//equalizes height of grids, one row at a time - by bthj
var HeightEqualizer = function() {
	this.uiGridTypes = { ".ui-gb":2, ".ui-gc":3, ".ui-gd":4 };
	this.contentClass = ".content";
	this.uiGridCategoriesToEqualHeight = HeightEqualizer.uiGridCategoriesToEqualHeight;
	this.uiGridCategoryToEqualHeight = HeightEqualizer.uiGridCategoryToEqualHeight;
}
HeightEqualizer.uiGridCategoriesToEqualHeight = function( uiGridClass ) {
	if( uiGridClass === undefined ) {
		var _this = this;
		jQuery.each(this.uiGridTypes, function(i,n) {
			_this.uiGridCategoryToEqualHeight( i, n );
		});
	} else {
		this.uiGridCategoryToEqualHeight( uiGridClass, this.uiGridTypes[uiGridClass] );
	}
}
HeightEqualizer.uiGridCategoryToEqualHeight = function( uiGridClass, columnsInClass ) {
	var _this = this;
	jQuery.each($(uiGridClass), function() {
		var contentDivsWithinOneGrid = jQuery(this).find( _this.contentClass );
		var rowCount = Math.ceil( contentDivsWithinOneGrid.size() / columnsInClass );
		for( i=0; i<rowCount; i++ ) {
			var currentRowStartIndex = i * columnsInClass;
			var contentDivsInOneRow = contentDivsWithinOneGrid.slice( currentRowStartIndex, currentRowStartIndex + columnsInClass );
			contentDivsInOneRow.equalHeight(); //BjarniJ's plugin called here for one row
		}
	});
}

jQuery(document).ready(function() {
//first round elements
roundElement('#rounded .ui-u');

//jquery tabs
$('div.jquerytabs').tabs();

//modal for images
$(".modal-images").colorbox();
$(".modal-iframe").colorbox({width:"500px", height:"410px", iframe:true});


//run input hints
$('.inputHint').inputHint();

//color alternate rows.
$('.alternate_rows tr:even').addClass('even');
$('.alternate_rows tr:odd').addClass('odd');

});

/*lets eq and round*/
$(window).load(function(){
	var heightEqualizer = new HeightEqualizer();
	heightEqualizer.uiGridCategoriesToEqualHeight();
});