function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function submitForm(){
	var server = $('#season').val();
    $("#logmein").attr("action",server);
    $("#logmein").submit();
}
$(document).keyup(function(event){
   	if (event.keyCode == 27)
	{
      	closePopUp();
   	}
});

function closePopUp() {
	$("#overlay").fadeOut(function(){
			$('#frame').hide();
			$("#msg").hide();
	});
	window.location ='#';
}
var name = $("#name").val();
var pass = $("#pass").val();
$().ready(function()
{
	//swfobject.embedSWF("images/home_page.swf", "intro", "550", "340", "8.0.35.0");
	createCookie('resolution',screen.width,500);
	$(".season").show().selectbox();
	$("#name,#pass").focus(function() {
		if($(this).val() == name || $(this).val() == pass)
		{
			$(this).val('');
		}
	});
	$("#name,#pass").blur(function() {
		if($(this).val() == '')
		{
			if($(this).attr("id") == 'name')
			{
				$(this).val(name);
			}
			else
			{
				$(this).val(pass);
			}	
		}
	});
	$("#name").focus();
});
function showPopUp(location,content) {
	var iframe = $('#frame');
	iframe.removeClass("framesize");
	iframe.removeClass("framesize2");
	$("#words2").css("padding-top","230px");
	if(location)
	{
		iframe.show();
		if(content == 'register')
		{
			$("#words2").css("padding-top","10px");
			iframe.addClass("framesize");
		}
		else
		{
			$("#words2").css("padding-top","160px");
			iframe.addClass("framesize2");
		}
		iframe.attr('src', content+'.php');
		iframe.load();
		window.location = '#'+content;
	}
	else
	{
		$("#msg").show();
		$("#msg").html(content);
	}
	$("#overlay").fadeIn();
}
jQuery.fn.selectbox = function(options){
	/* Default settings */
	var settings = {
		className: 'jquery-selectbox',
		animationSpeed: 50,
		listboxMaxSize: 20,
		replaceInvisible: false
	};
	var commonClass = 'jquery-custom-selectboxes-replaced';
	var listOpen = false;
	var showList = function(listObj) {
		var selectbox = listObj.parents('.' + settings.className + '');
		listObj.slideDown(settings.animationSpeed, function(){
			listOpen = true;
		});
		selectbox.addClass('selecthover');
		jQuery(document).bind('click', onBlurList);
		return listObj;
	}
	var hideList = function(listObj) {
		var selectbox = listObj.parents('.' + settings.className + '');
		listObj.slideUp(settings.animationSpeed, function(){
			listOpen = false;
			jQuery(this).parents('.' + settings.className + '').removeClass('selecthover');
		});
		jQuery(document).unbind('click', onBlurList);
		return listObj;
	}
	var onBlurList = function(e) {
		var trgt = e.target;
		var currentListElements = jQuery('.' + settings.className + '-list:visible').parent().find('*').andSelf();
		if(jQuery.inArray(trgt, currentListElements)<0 && listOpen) {
			hideList( jQuery('.' + commonClass + '-list') );
		}
		return false;
	}
	
	/* Processing settings */
	settings = jQuery.extend(settings, options || {});
	/* Wrapping all passed elements */
	return this.each(function(i) {
		var _this = jQuery(this);
		if(_this.filter(':visible').length == 0 && !settings.replaceInvisible)
			return;
		var replacement = jQuery(
			'<div class="' + settings.className + ' ' + commonClass + '">' +
				'<div id="morebnt_'+i+'" class="' + settings.className + '-moreButton" />' +
				'<div class="' + settings.className + '-list ' + commonClass + '-list" />' +
				'<span class="' + settings.className + '-currentItem" />' +
			'</div>'
		);
		jQuery('option', _this).each(function(k,v){
			var v = jQuery(v);
			var str = v.attr('title').replace(/\[/g,'<').replace(/\]/g,'>');
			var classn = v.attr('className');
			if(!str){
				str = 	v.text();
			}
			var check_option_state = false;
			check_option_state = v.attr('disabled');
			var listElement =  jQuery('<span rel="'+v.text()+'" class="' + settings.className + '-item value-'+v.val()+' item-'+k+'">' + str + '</span>');	
			listElement.click(function(){
				if(classn=='jumplink'){
					window.location = v.val();
					return;
				}else{	
					var thisListElement = jQuery(this);
					var thisReplacment = thisListElement.parents('.'+settings.className);
					var thisIndex = thisListElement[0].className.split(' ');
					for( k1 in thisIndex ) {
						if(/^item-[0-9]+$/.test(thisIndex[k1])) {
							thisIndex = parseInt(thisIndex[k1].replace('item-',''), 10);
							break;
						}
					};
					var thisValue = thisListElement[0].className.split(' ');
					for( k1 in thisValue ) {
						if(/^value-.+$/.test(thisValue[k1])) {
							thisValue = thisValue[k1].replace('value-','');
							break;
						}
					};
					if(check_option_state==false){
						var thisTitle = thisListElement.attr('rel');
						thisReplacment
							.find('.' + settings.className + '-currentItem')
							.text(thisTitle);
						thisReplacment
							.find('select')
							.val(thisValue)
							.triggerHandler('change');
						var thisSublist = thisReplacment.find('.' + settings.className + '-list');
						if(thisSublist.filter(":visible").length > 0) {
							hideList( thisSublist );
						}else{
							showList( thisSublist );
						}
					}
				}
			}).bind('mouseenter',function(){
				if(check_option_state==false){
					jQuery(this).addClass('listelementhover');
				}
			}).bind('mouseleave',function(){
				if(check_option_state==false){
					jQuery(this).removeClass('listelementhover');
				}
			});
			jQuery('.' + settings.className + '-list', replacement).append(listElement);
			if(v.filter(':selected').length > 0) {
				if(check_option_state==false){
					jQuery('.'+settings.className + '-currentItem', replacement).text(v.text());
				}
			}
		});
		replacement.find('.' + settings.className + '-currentItem, .' + settings.className + '-moreButton').click(function(){
			var thisMoreButton = jQuery(this);
			var otherLists = jQuery('.' + settings.className + '-list')
				.not(thisMoreButton.siblings('.' + settings.className + '-list'));
			hideList( otherLists );
			var thisList = thisMoreButton.siblings('.' + settings.className + '-list');
			if(thisList.filter(":visible").length > 0) {
				hideList( thisList );
			}else{
				showList( thisList );
			}
		}).bind('mouseenter',function(){
			// jQuery(this).addClass('morebuttonhover');
			$('#morebnt_'+i).addClass('morebuttonhover');
			//alert(i);
		}).bind('mouseleave',function(){
			$('#morebnt_'+i).removeClass('morebuttonhover');
		});
		_this.hide().replaceWith(replacement).appendTo(replacement);
		var thisListBox = replacement.find('.' + settings.className + '-list');
		var thisListBoxSize = thisListBox.find('.' + settings.className + '-item').length;
		if(thisListBoxSize > settings.listboxMaxSize)
			thisListBoxSize = settings.listboxMaxSize;
		if(thisListBoxSize == 0)
			thisListBoxSize = 1;	
		var thisListBoxWidth = Math.round(_this.width() + 5);
		/*
		if(jQuery.browser.safari)
			thisListBoxWidth = thisListBoxWidth * 0.94;
		//replacement.css('width', thisListBoxWidth + 'px');
		thisListBox.css({
			width: Math.round(thisListBoxWidth-5) + 'px',
			height: thisListBoxSize + 'em'
		});*/
	});
};
