function onRollOver(obj_img){	
	obj_img.src = obj_img.src.split("-off").join("-on");
}

function onRollOut(obj_img){
	obj_img.src = obj_img.src.split("-on").join("-off");
}

/*News & Media function to enable active categories */
function filterCategoriesBySelection(parent_form_id, listing_id, bln_multiple_forms) {  
	var int_index_zero_count = 0;
	var arr_visible_items = new Array();
	
	$('.noresults').each(function() { $(this).remove(); });
	
	$(parent_form_id + ' select').each(function() {
		if ($(this).attr('selectedIndex') != '0') {
			var current_val = $(this).attr('value');  
			$(listing_id).each(function() {
				var str_classes = $(this).attr('class');
				var arr_classes = str_classes.split(' ');
				var bln_found_match = false; 

				for (var i = 0; i < arr_classes.length; i++) {
					if (current_val == arr_classes[i]) {
						bln_found_match = true;
					} 
				}
				if (!bln_found_match) {
					$(this).fadeOut(300, function() { getVisibleImageCount(listing_id); });
				} else {
					arr_visible_items[arr_visible_items.length] = $(this);
					$(this).fadeIn(300, function() { getVisibleImageCount(listing_id); });	
				}
			});
		} else {
			$(listing_id).each(function() {
				arr_visible_items[arr_visible_items.length] = $(this);
			});
			int_index_zero_count++;
		}
	});
	if (bln_multiple_forms) {
		if (int_index_zero_count == 2) { //Both selects have no limits, show all
			$(listing_id).each(function() { $(this).show() });	
		}
	} else {
		if (int_index_zero_count == 1) {
			$(listing_id).each(function() { $(this).show() });	
		}
	}
	filterMediaTypes("#show_images", 'type-image', parent_form_id, arr_visible_items, bln_multiple_forms);
	filterMediaTypes("#show_videos", 'type-video', parent_form_id, arr_visible_items, bln_multiple_forms);	
}

function getVisibleImageCount(listing_id) {
	if ($(listing_id +':visible').size() == 0) {
		if ($('.noresults').size() == 0) {
			$(listing_id).parent().parent().eq(0).prepend('<div class="noresults">No results exist for this category. Please select another.</div>');	
		}
	} else {
		$('.noresults').each(function() { $(this).remove(); });
	}
}

//Filters by image & video checkboxes
function filterMediaTypes(checkbox_id, matching_class, parent_form_id, arr_visible_items, bln_multiple_forms) {
	if ($(parent_form_id + ' ' + checkbox_id)) {
		if ($(parent_form_id + ' ' +checkbox_id+':checked').length == 0) {
			for (var a = 0; a < arr_visible_items.length; a++) {
				var str_classes = arr_visible_items[a].attr('class');
				var arr_classes = str_classes.split(' ');
				var bln_filter_found = false; 

				for (var i = 0; i < arr_classes.length; i++) {
					if (matching_class == arr_classes[i]) {
						bln_filter_found = true;
					} 
				}
				if (bln_filter_found) {
					arr_visible_items[a].fadeOut(300);
				} 
			}
		}
	}
}

// mit license. paul irish. 2010.
// webkit fix from Oren Solomianik. thx!

// callback function is passed the last image to load
//   as an argument, and the collection as `this`

$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'), len = elems.length;
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,this); }
  }).each(function(){
     // cached images don't fire load sometimes, so we reset src.
     if (this.complete || this.complete === undefined){
	  	//alert('here');
	    var src = this.src;
        // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
        // data uri bypasses webkit log warning (thx doug jones)
        this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
        this.src = src;
     }  
  }); 
  return this;
};

function shuffle(arr) {
	for(var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
	return arr;
}
