$(function () {
	$("#UserLogin").submit(function() {
		$("#UserLogin #authMessage").remove();
		$("#UserLogin").prepend('<center><span id="loading"></span></center>');
		$.post($("#UserLogin").attr('action'), $("#UserLogin").serialize(), function(data){
			var $data = data.split('#');
			if($data[0]=='success')
			 $("#UserLogin").html($data[1]);
			else{
			 $("#UserLogin").prepend($data[1]);
			 $("#UserLogin #loading").remove();
			}
		});
		return false;
	});
	$('#user_search').bind('keyup', function(e) {
			var keyCode = (e.keyCode ? e.keyCode : e.which);
			if ( keyCode == 13 ) {
				$('#loading').remove();
				$(this).after('<span id="loading"></span>');
				$.post('/managers/user_search',{query : $(this).val()} ,function (data){
						$("#usersContainer").html(data);
						$('span#loading').fadeOut('fast');
					});
			}
		});
	$('#register_search').bind('keyup', function(e) {
			var keyCode = (e.keyCode ? e.keyCode : e.which);
			if ( keyCode == 13 ) {
				$('#loading').remove();
				$(this).after('<span id="loading"></span>');
				$.post('/managers/register_search',{query : $(this).val()} ,function (data){
						$("#usersContainer").html(data);
						$('span#loading').fadeOut('fast');
					});
			}
		});
	$("input[id$='Y']").click( function(){
			detail_elem = $(this).attr('id');
			detail_elem = detail_elem.replace("Y", "Detail");
			
			if($("#"+detail_elem+":visible").length==0) $("#"+detail_elem).fadeIn("slow");
			else $("#"+detail_elem).fadeOut("slow")
	});
	
	$("input[id$='Y']:checked").each( function(){
			detail_elem = $(this).attr('id');
			detail_elem = detail_elem.replace("Y", "Detail");
			
			if($("#"+detail_elem+":visible").length==0) $("#"+detail_elem).fadeIn("slow");
			else $("#"+detail_elem).fadeOut("slow")
	});
	
	if($('#slideshow').length > 0){
		$('#slideshow').nivoSlider({
				controlNav:false
		});
	}
	
	$('#RegisterToDegree2, #RegisterToDegree3, #RegisterToDegree4, #RegisterToDegree5').attr('disabled',true);
	
	if($('img.toolTip').length > 0){
		$('img.toolTip').qtip({
			content: {text: true},
			position: {
				  corner: {
							target: 'rightTop',
							tooltip: 'leftBottom'
				  }
			},
			style:{  
				name: 'light',
				color: '#E50000',
				tip: 'leftBottom',
				textAlign: 'right',
				border: {
						color: '#E50000',
						width: 4
				}
			}
		});
	}
});
