jQuery(document).ready( function(){
    jQuery('#SearchForm_SearchForm_Search, #Form_DataSearchForm_QuickSearchSearch').focus(function() {
    	jQuery(this).val('');
    });
    
    jQuery('#SearchForm_SearchForm_Search').val('Search');
    
    jQuery('#CategoryGroup li input').change(function() {
    	jQuery('#Form_DataSearchFormPractical').submit();
    });
    jQuery('#Form_DataSearchFormPractical_action_doDataSearch').hide();
    
	jQuery('#Content a, #SearchResults a, #MainHotLinks a, #SideBarContent a, .tablesorter td a').each(function() {
		var fileURL = jQuery(this).attr('href');
		if (fileURL) {
			if (fileURL.match("\.doc$")) {
				jQuery(this).addClass('file');
				jQuery(this).css('background','transparent url(themes/irrigationefficiency/images/icons/icon_doc.gif) no-repeat scroll 0 1px');
			}
			if (fileURL.match("\.pdf$")) {
				jQuery(this).addClass('file');
				jQuery(this).css('background','transparent url(themes/irrigationefficiency/images/icons/icon_pdf.gif) no-repeat scroll 0 1px');
			}
			if (fileURL.match("\.xls$")) {
				jQuery(this).addClass('file');
				jQuery(this).css('background','transparent url(themes/irrigationefficiency/images/icons/icon_xls.gif) no-repeat scroll 0 1px');
			}
			if (fileURL.match("\.ppt$")) {
				jQuery(this).addClass('file');
				jQuery(this).css('background','transparent url(themes/irrigationefficiency/images/icons/icon_ppt.gif) no-repeat scroll 0 1px');
			}
			if (fileURL.match("\.pptx$")) {
				jQuery(this).addClass('file');
				jQuery(this).css('background','transparent url(themes/irrigationefficiency/images/icons/icon_ppt.gif) no-repeat scroll 0 1px');
			}
		}
	});
	
	jQuery('.tablesorter').tablesorter({
		headers: { 0: { sorter: false}, 6: {sorter: false} }
	});
	jQuery('#QuickSearch .qs').quicksearch('#DataContent table tbody tr', {
		'noResults': 'tr#NoResults'
	});
	jQuery('#Form_DataSearchForm_QuickSearchSearch').quicksearch('#Form_DataSearchForm_Keyword li', {
		'noResults': 'tr#NoResults'
	});
	
	jQuery('table.tablesorter tbody tr').hover(function() {
		jQuery(this).addClass('hover');
	}, function() {
		jQuery(this).removeClass('hover');
	});
	
	jQuery('#QS').focus(function() {
		if (jQuery(this).val() == '') {
			jQuery(this).prev().fadeTo('fast',.5);
		}
	}).blur(function() {
		if (jQuery(this).val() == '') {
			jQuery(this).prev().fadeTo('fast',1);
		}
	}).keyup(function() {
		if (jQuery(this).val() == '') {
			jQuery(this).prev().fadeTo('fast',.5);
		} else {
			jQuery(this).prev().fadeOut();
		}
	});
	
    numberOfAds = jQuery('#AdHolder a').length;
    if (numberOfAds > 1) {
    	setTimeout("NextBannerAd();",10000);
    }
});


var numberOfAds = 0;
var currentAd = 1;

function NextBannerAd() {
	jQuery('#BannerAd'+currentAd).fadeOut(2000);
	currentAd++;
	if (currentAd > numberOfAds) {
		currentAd = 1;
	}
	jQuery('#BannerAd'+currentAd).fadeIn(2000);
	setTimeout("NextBannerAd();",10000);
}
