$.ajaxSetup({
	type: "POST",
	contentType: "application/json; charset=utf-8",
	data: "{}",
	dataType: "json"
});

$(document).ready(function () {
	/* Button Hover Effects */
	$(".home_buttons a").hover(ReplaceImage, ReplaceImage);

	/* Slide Show */
	$('.slidecontainer .slideshow').cycle({
		fx: 'scrollLeft',
		next: '.next',
		prev: '.prev',
		timeout: 5000,
		delay: 200,
		before: beforeImageChanged,
		after: afterImageChanged 
	});

	$('.slidecontainer .slideshow a').hover(function () {
		$('.slidecontainer .slideshow').cycle("pause");
	}, function () {
		$('.slidecontainer .slideshow').cycle("resume");
	});

	function beforeImageChanged() {
		$('.slidecontainer .slidetitle').html("");
		$('.slidecontainer .slidedescription').html("");
	}
	function afterImageChanged() {
		var a = $(this);
		var i = $("img", this);
		$('.slidecontainer .slidetitle').html("<a href=\"" + a.attr("href") + "\">" + i.attr("title") + "</a>");
		$('.slidecontainer .slidedescription').html("<a href=\"" + a.attr("href") + "\">" + i.attr("desc") + "</a>"); //.html(i.attr("desc"));
	} 

	/* Employee Directory Search */
	$('input#sq,.staffdir_deptbox').live("keydown", function (e) {
		/* ENTER PRESSED*/
		if (e.which == 13) {
			window.location = $(".staff_searchbutton").attr("href");
			return false;
		}
	});

	$("input#sq").live("keyup", function (e) {
		var qev = $("input#sq").val();
		var qe = encodeURIComponent(qev);

		$(".staff_searchbutton").attr("href", "index.aspx?page=" + $("input#hdnStaffPage").val()
			+ "&search=" + encodeURIComponent(qe) + "&dept="
			+ encodeURIComponent($(".staffdir_deptbox option:selected").val()));
	});

	$(".staffdir_deptbox").change(function () {
		var qev = $("input#sq").val().replace($("input#sq").attr("title"), "");
		var qe = encodeURIComponent(qev);

		$(".staff_searchbutton").attr("href", "index.aspx?page=" + $("input#hdnStaffPage").val()
			+ "&search=" + encodeURIComponent(qe) + "&dept="
			+ encodeURIComponent($(".staffdir_deptbox option:selected").val()));
	});
		
	/* Calendar 
	$(".home_calendar").datepicker({
	dayNamesMin: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
	showOtherMonths: true,
	onSelect: function (dateText, inst) {
	window.location.href = "index.aspx?page=" + $("#hdnEventListFrontPage").val() + "&date=" + dateText;
	},
	onChangeMonthYear: function (year, month, inst) {
	// get events for the current selected month here			
	GetMonthlyEvents(month + "/01/" + year);
	}
	});

	GetMonthlyEvents(new Date().toDateString());

	$(".home_calendar .ui-datepicker-title").live("dblclick", function () {
	setTimeout(function () { $(".home_calendar").datepicker("setDate", new Date()); }, 100);
	});
	*/
});

function ReplaceImage(imgSrc) {
	var oldsrc = $("img", this).attr("src");
	var isHover = oldsrc.indexOf('_over') > -1;
	var from = !isHover ? "" : "_over";
	var to = !isHover ? "_over" : "";
	if (oldsrc.match(/.jpg$/))
		$("img", this).attr("src", oldsrc.replace(from + ".jpg", to + ".jpg"));
	else if (oldsrc.match(/.png$/))
		$("img", this).attr("src", oldsrc.replace(from + ".png", to + ".png"));
	else if (oldsrc.match(/.gif$/))
		$("img", this).attr("src", oldsrc.replace(from + ".gif", to + ".gif"));
}

/*
function GetMonthlyEvents(date)
{
	$.ajax({
        url: "Index.aspx/ListMonthlyEvents",
        data: "{'date':'" + date + "'}",
        success: GetMonthlyEventsCompleted,
        error: GetMonthlyEventsFailed
    });
}

function GetMonthlyEventsCompleted(r) 
{
	$(".ui-datepicker td").not(".ui-state-disabled").each(function (i, e) {
		var text = $(".ui-state-default", e).html();

		$.each(r.d, function (j, f) {
			var a = "^" + f + "$"
			var regex = new RegExp(a, "i");
			if (text && text.match(regex)) {
				$(".ui-state-default", e).css("font-weight", "bold");
			}

		});
	});
}

function GetMonthlyEventsFailed(r) 
{
	console.log(r);
}
*/
