$(document).ready(function(){

// ----------------------------------------------------------------------------
// Begin SMF Comments Portlet Code
// ----------------------------------------------------------------------------
	// Depending on the browser, set preview sizes for comments
	if ($.browser.msie){
		var preview_height = 21;
		var preview_check = 11;
		var expand_compensate = 13;
	}else{
		var preview_height = 11;
		var preview_check = 11;
		var expand_compensate = 0;
	}

	// Loop through the DIV's and make sure they are all preview height
	$("div.SlideBody").each(function(){
		// $(this).css("height", $(this).height() + "px");
		$(this).css("height", preview_height + "px");
	});

	// Hook the mouseup events to each DIV header
	$("div.SlidePanel").children(
		"div.SlideHeader").mouseup(function(){

		// Find the body whose header was clicked
		var body = $(this).parent().children("div.SlideBody");
		var footer = $(this).parent().children("div.SlideFooter");
		var button = $(this).parent().find("div.SlideButton");

		// If the panel is small
		if(body.css("height") == preview_check + "px"){

			// Switch the button
			button.removeClass("SlideButtonExpand");
			button.addClass("SlideButtonShrink");

			// Expand the DIV
			body.animate({height: body.children("span").height() + expand_compensate}, 1000);
			footer.slideDown();

		}else{ // If the panel is expanded

			// Switch the button
			button.removeClass("SlideButtonShrink");
			button.addClass("SlideButtonExpand");

			// Shrink the DIV
			body.animate({height: preview_height}, 1000);
			footer.slideUp();

		}
	});

	// Change background color on header mouse over
	$("div.SlideHeader").hover(
		function () {
			$(this).addClass("SlideHeaderHover");
		},
		function () {
			$(this).removeClass("SlideHeaderHover");
		}
	);

	// Change text color on body mouse over
	$("div.SlideBody").hover(
		function () {
			$(this).addClass("SlideBodyHover");
		},
		function () {
			$(this).removeClass("SlideBodyHover");
		}
	);
// ----------------------------------------------------------------------------
// End SMF Comments Portlet Code
// ----------------------------------------------------------------------------
});

// Restricts input in text boxes
// EXAMPLE: onkeypress="return restrictKeys(event, '[a-zA-Z0-9.]');"
function restrictKeys(objEvent, regexPattern) {
	// Find the key that was pressed
	var keyCode;
	if (window.event) {
		keyCode = window.event.keyCode;
	} else if (objEvent) {
		keyCode = objEvent.which;
	} else {
		return true;
	}
	var keyChar = String.fromCharCode(keyCode);

	// Check for control keys
	if ((keyCode==null) || (keyCode==0) || (keyCode==8) ||
		(keyCode==9) || (keyCode==13) || (keyCode==27) ) {
		return true;
	}

	// Check the regex pattern
	var objRegex = new RegExp(regexPattern);
	if (! objRegex.test(keyChar)) {
		return false;
	}

	return true;
}

// Add a bookmark to this site
function bookmarksite(title, url) {
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

