$(document).ready(function(){
	// sets a label for a text field
	$(".labelify").labelify({ labelledClass: "labelHighlight" });
	
	// styles buttons with the Jquery UI library
	$('.ui-button').button({
		disabled: false
	});
	
	// used as a toggle to show/hide content
	$('.expand_button').toggle(function() {
		$(this).parent().parent().next().show();
		$(this).text('-');
	}, function() {
		$(this).parent().parent().next().hide();
		$(this).text('+');
	});

	// displays a hidden button for list items
	$('.list_item').hover(
		function () {
			$(this).find('a.hidden_button').show();
		}, 
		function () {
			$(this).find('a.hidden_button').hide();
		}
	);
	
	// displays decision information
	$('.decision_button').toggle(function() {
			$(this).parent().next().show();
			$(this).text('Hide Decision');
		}, function() {
			$(this).parent().next().hide();
			$(this).text('View Decision');
	});

	// autocomplete field for administrators
	
	$('#s').autocomplete('/index.php/admin/search', {
		matchContains: true,
		minChars: 1,
		dataType: 'json',
		parse: function(data){
			var rows = new Array();
			
			for(var i=0; i<data.length; i++){
				rows[i] = {
					data:data[i],
					value:data[i].name,
					value:data[i].url,
					value:data[i].school,
					value:data[i].icon,
					result:data[i].value
					};
			}
			return rows;
		},
		formatItem: function( data, i, n, value) {
			var item = "<img style='float:left;margin-right:5px;padding:7px;vertical-align:top' src='images/";
			item = item + data.icon + ".png' />" + data.name + "</div><div>" + data.school + "</div>";
			return item;
		},
		formatMatch: function(data, value) {
			return data.name + " " + row.school;
		},
		formatResult: function(data, value) {
			return data.name;
		}
		}).result(function(event, row) {
			location.href = "/index.php" + row.url;		
	});
	
	// diplays a datepicker for schedule input fields
	$(".datepicker").datepicker();

	// used to fade out messages
	$(".fadeout").delay(2000).fadeOut(1000);

	// the clicked event for the element #genpass
	// generates a password, then sets the value of the element #password
	$('#genpass').click(function() {
		$("#password").val($.password(8));
	});
	
	//use meiomask to set input masks
	jQuery.mask.masks = jQuery.extend(jQuery.mask.masks,{
		pricemask:{ 
		mask: '99.99', 
			type : 'reverse'
		},
		 budgetmask:{ 
			mask: '999,999,99', 
			type : 'reverse'
		},
		phonemask:{
			mask: '(999) 999-9999'
		}
	});
 
	//then call this to activate masks lib
	jQuery('input:text').setMask();
	
	// assigns a list as a ticker
	$('.ticker').list_ticker({
		speed:5000,
		effect:'fade'
	});
	
	//
	$("#teams").pagination();
});

