cCore = function( )
{
	this.pOverlay = false;
	
	this.Init = function( )
	{
		this.clientAlias = $("input[name=clientAlias]").val();
		
		$(".fadeIn").fadeIn("slow");
		$('.row').hover(
			function() {
				$(this).addClass("rowHover");
			},
			function() {
				$(this).removeClass("rowHover");
			}
		);

		$("#groupWeek").change( function ( ) {
			window.location=site_path+cCore.clientAlias+'/schedule/index/'+$("#groupWeek option:selected").text()+'/';
		});
		
		this.pOverlay = $("a[rel]").overlay({
			top: 50,
			expose: 'Black',
			api: true,
			onBeforeLoad: function() 
			{				
				$('div#overlay').html( "Moment please, contacting KNHB..." );
				cCore.loadOverlay( this.getTrigger().attr("href") );
				return true;
			}
		}); 
	};
	
	this.submitForm = function( pForm, fCallBack ) 
	{
		$('body').css('cursor', 'wait'); 
		
		if( typeof( pForm ) == "string" ) 
		{
			var pForm = $( pForm );
		}
		
		var aParams = {};
		pForm.find(':input').each(function() {
			aParams[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		
		$.post
		(
			pForm.attr('action'), 
			aParams,
			function( sResponse ) {
				$('body').css('cursor', 'default'); 
				if( fCallBack ) 
				{
					fCallBack( sResponse );
				}
				return false;
			}
		);
		return false;
	}	
	
	this.fadeTo = function( pId, sString ) 
	{
		var pMessage = $( pId );
		
		if( pMessage )
		{
			if( pMessage.is(":visible") == true )
			{
				pMessage.fadeOut('slow', function() { 
					pMessage.html( sString );
					pMessage.fadeIn('slow');
				});
			} 
			else {
				pMessage.html( sString );
				pMessage.fadeIn('slow');
			}
		}
	};
	
	this.requestPage = function( sAddress, fSuccess, fError ) 
	{
		$('body').css('cursor', 'wait'); 
		
		$.ajax({
			url: sAddress ,
			cache: false,
			success: function( sResponse ){
				$('body').css('cursor', 'default'); 
				if( fSuccess )
				{
					fSuccess( sResponse );
				}
				return true;
			},
			error: function( ) {
				$('body').css('cursor', 'default'); 
				if( fError )
				{
					fError();
				}
				return false;
			}
		});
	}
	
	
	this.loadOverlay = function( sAddress ) 
	{
		cCore.requestPage( sAddress,
		function( sResponse )
		{
			$('body').css('cursor', 'default'); 
				
			$('div#overlay').html( sResponse );	
			$('div#overlay a').click(function() {
				cCore.loadOverlay( this.href ); 
				return false;
			});
			
			$("div.tabs").tabs( "div.panes > div.pane", { tabs: 'div.pane' } );
		},
		function() 
		{
			return false;
		});
	};

}

var cCore = new cCore;

$(document).ready(function () {	
	cCore.Init();
});
