// used to blow up images and other content
$(document).ready(function(){
	//Examples of how to assign the ColorBox event to elements
	$("a[rel='blowup']").colorbox({opacity:0.7});
	$("a[rel='blowup_fixed']").colorbox({height:"90%", opacity:0.7});
	$(".blowup").colorbox({opacity:0.7});
	$(".blowup_fixed").colorbox({width:"90%", height:"90%", iframe:true, opacity:0.7});
	$(".blowup_poll").colorbox({width:"270", height:"90%", iframe:true, opacity:0.7});
});

// used for login
$(document).ready(function(){$(".signin").click(function(e){e.preventDefault();$("fieldset#signin_menu").toggle();$(".signin").toggleClass("menu-open");});$("fieldset#signin_menu").mouseup(function(){return false;});$(document).mouseup(function(e){if($(e.target).parent("a.signin").length==0){ $(".signin").removeClass("menu-open");$("fieldset#signin_menu").hide();}});});
(function(){$('.submitBtn').hover(function(){ $(this).addClass('submitBtnHover'); },function(){ $(this).removeClass('submitBtnHover');});});

// used for tabs
$(document).ready(function(){
	
	$('#tabs div').hide();
	$('#tabs div:first').show();
	$('#tabs ul li:first').addClass('active');
	$('#tabs ul li a').click(function(){
		$('#tabs ul li').removeClass('active');
		$(this).parent().addClass('active');
		var currentTab = $(this).attr('href');
		$('#tabs div').hide();
		$(currentTab).show();
		return false;
	});
	
	$('#tabs1 div').hide();
	$('#tabs1 div:first').show();
	$('#tabs1 ul li:first').addClass('active');
	$('#tabs1 ul li a').click(function(){
		$('#tabs1 ul li').removeClass('active');
		$(this).parent().addClass('active');
		var currentTab = $(this).attr('href');
		$('#tabs1 div').hide();
		$(currentTab).show();
		return false;
	});
	
	$('#tabs2 div').hide();
	$('#tabs2 div:first').show();
	$('#tabs2 ul li:first').addClass('active');
	$('#tabs2 ul li a').click(function(){
		$('#tabs2 ul li').removeClass('active');
		$(this).parent().addClass('active');
		var currentTab = $(this).attr('href');
		$('#tabs2 div').hide();
		$(currentTab).show();
		return false;
	});
	
	$('#tabsblack div').hide();
	$('#tabsblack1 div:first').show();
	$('#tabsblack ul li:first').addClass('active');
	$('#tabsblack ul li a').click(function(){
		$('#tabsblack ul li').removeClass('active');
		$(this).parent().addClass('active');
		var currentTab = $(this).attr('href');
		$('#tabsblack div').hide();
		$(currentTab).show();
		return false;
	});
	
});

/**
 * Usage:
 *
 * From JavaScript, use:
 *     $(<node>).TextAreaExpander(<minHeight>, <maxHeight>);
 *     where:
 *       <node> is the DOM node selector, e.g. "textarea"
 *       <minHeight> is the minimum textarea height in pixels (optional)
 *       <maxHeight> is the maximum textarea height in pixels (optional)
 *
 * Alternatively, in you HTML:
 *     Assign a class of "expand" to any <textarea> tag.
 *     e.g. <textarea name="textarea1" rows="3" cols="40" class="expand"></textarea>
 *
 *     Or assign a class of "expandMIN-MAX" to set the <textarea> minimum and maximum height.
 *     e.g. <textarea name="textarea1" rows="3" cols="40" class="expand50-200"></textarea>
 *     The textarea will use an appropriate height between 50 and 200 pixels.
 */
(function($) {
	// jQuery plugin definition
	$.fn.TextAreaExpander = function(minHeight, maxHeight) {

		var hCheck = !($.browser.msie || $.browser.opera);

		// resize a textarea
		function ResizeTextarea(e) {

			// event or initialize element?
			e = e.target || e;

			// find content length and box width
			var vlen = e.value.length, ewidth = e.offsetWidth;
			if (vlen != e.valLength || ewidth != e.boxWidth) {

				if (hCheck && (vlen < e.valLength || ewidth != e.boxWidth)) e.style.height = "0px";
				var h = Math.max(e.expandMin, Math.min(e.scrollHeight, e.expandMax));

				e.style.overflow = (e.scrollHeight > h ? "auto" : "hidden");
				e.style.height = h + "px";

				e.valLength = vlen;
				e.boxWidth = ewidth;
			}
			return true;
		};

		// initialize
		this.each(function() {
			// is a textarea?
			if (this.nodeName.toLowerCase() != "textarea") return;

			// set height restrictions
			var p = this.className.match(/expand(\d+)\-*(\d+)*/i);
			this.expandMin = minHeight || (p ? parseInt('0'+p[1], 10) : 0);
			this.expandMax = maxHeight || (p ? parseInt('0'+p[2], 10) : 99999);

			// initial resize
			ResizeTextarea(this);

			// zero vertical padding and add events
			if (!this.Initialized) {
				this.Initialized = true;
				$(this).css("padding-top", 0).css("padding-bottom", 0);
				$(this).bind("keyup", ResizeTextarea).bind("focus", ResizeTextarea);
			}
		});
		return this;
	};

})(jQuery);

// plugin for making blocks equal height
jQuery.fn.setEqualHeight=function(o) {
	var maxHeight=0;
	var maxElement=null;
 	jQuery(this).each(function(i) {
      		if((jQuery(this).height()+parseInt(jQuery(this).css("padding-bottom"))+parseInt(jQuery(this).css("padding-top")))>maxHeight) {
			maxHeight=jQuery(this).height()+parseInt(jQuery(this).css("padding-top"))+parseInt(jQuery(this).css("padding-bottom"));
			maxElement=this;
		}
	});
	jQuery(this).not($(maxElement)).each(function() {$(this).height(maxHeight-parseInt(jQuery(this).css("padding-top"))-parseInt(jQuery(this).css("padding-bottom")));});
};

// initialize all expanding textareas
$(document).ready(function() {
	$("textarea[class*=expand]").TextAreaExpander();
});

// print emails
function print_email(name, domain){
   document.write("<a href=\"mailto");
   document.write(":" + name + "@");
   document.write(domain + "\">" + name + "@" + domain + "<\/a>");
}

// hide and show game results
//$(document).ready(function() {
//	$('#game').find('.gamebody').hide().end().find('#gamehead').click(function() {
// 		$('#game').find('.gamebody').slideToggle();
//	});
//});

// hide and show comments form
$(document).ready(function() {
	$('#form_comment').hide();
	$('#btn_comment').toggle(function() {
		$('#form_comment').show();
	},function() {
		$('#form_comment').hide();
	});
});

// highlight table row
$(document).ready(function(){
	$(".t tr").hover(function() {
		if($(this).hasClass("head")==false) 
			$(this).addClass("tr_hover");
	},function () {
		if($(this).hasClass("head")==false) 
			$(this).removeClass("tr_hover");
	});
});

// calling height plugin on player block for team roster
$(document).ready(function(){
	$(".photoblock").setEqualHeight();
});

// for links to open up in new windows when selected
function myChangeHandler() {
	if (this.options[this.selectedIndex].value != ""){
		window.open(this.options[this.selectedIndex].value, '_blank');
	}
}

// inserts id & name in the message box of guestbook
function insertname(insertion) {
	document.gbform.strMessage.value += insertion;
	document.gbform.strMessage.value += "\n";
	document.gbform.strMessage.focus();
}

//inserts id & name in the message box of fanclub guestbook
function insertnameFC(insertion) {
	document.fanclubform.strMessage.value += insertion;
	document.fanclubform.strMessage.value += "\n";
	document.fanclubform.strMessage.focus();
}

// sorts tables
$(document).ready(function() { 
	$("#sortTable").tablesorter(); 
}); 

