$(document).ready(function($){
//Navigation
$(function(){
	$('.menu a')
		.css( {backgroundPosition: "0px 0px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0px -94px)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0px 0px)"}, {duration:200, complete:function(){
				$(this).css({backgroundPosition: "0px 0px"})
			}})
		})
});

// Blocks contextual menu
$(document).bind("contextmenu",function(e){
	return false;
});

// Datepicker
$(function() {
	$("#Graduation").datepicker();
	$("#Birthday").datepicker();
	$("#Job_Deadline").datepicker();
	$("#Date").datepicker({ dateFormat: 'yy-mm-dd' });
});


// Fires the fancy box
/* This is basic - uses default settings */
$("a#single_image").fancybox(); /* Using custom settings */
$("a#inline").fancybox({ 'hideOnContentClick': true });
$("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': false });
$("a.miniFrame").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300,'frameWidth': 325, 'frameHeight': 400, 'overlayShow': false });
$("a.siteFrame").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'frameWidth': $(window).width() - 100, 'frameHeight': $(window).height() - 100, 'overlayShow': false });
$("a.flvFrame").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300,'frameWidth': 720, 'frameHeight': 480, 'overlayShow': false });

// Login panel
$(".btn-slide").click(function(){
		$("#panel").slideToggle("slow");
		return false;
});

$(".btn-slide2").click(function(){
		$("#forgottenArea").slideUp(500);
		$("#content").slideDown(500);
		$("#panel").slideToggle("slow");
		return false;
});


// Changes the log and the forgotten password window
$("#forgot_button").click(function(){
	$("#content").slideUp(500);
	$("#forgottenArea").slideDown(500);
	return false;
});

$("#forgottenArea").hide();

$("#back2Login").click(function(){
	$("#forgottenArea").slideUp(500);
	$("#content").slideDown(500);
	return false;
});

// Activate Form Styles for select fields
$('#Degree').selectbox({debug: true});
$('#Alumni').selectbox({debug: true});
$('#Category').selectbox({debug: true});
$('#Access_Level').selectbox({debug: true});
$('#num').selectbox({debug: true});

$('input[type=checkbox],input[type=radio]').prettyCheckboxes({
	checkboxWidth: 17, // The width of your custom checkbox
	checkboxHeight: 17, // The height of your custom checkbox
	className : 'prettyCheckbox', // The classname of your custom checkbox
	display: 'list' // The style you want it to be display (inline or list)
});

// Login functions
$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#feeddback").text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("includes/ajaxFunctions.php?action=1", { username:$('#username').val(),password:$('#password').val() } ,function(data)
        {
			if(data=='yes') //if correct login detail
		  	{
		  		$("#feeddback").fadeTo(200,0.1,function()  //start fading the messagebox
				{ 
				//add message and change the class of the box and start fading
				$(this).html('Logging in.....').fadeTo(900,1, function()
			  	{ 
			  		//redirect to secure page
					document.location='news.php';
				});
			});
		  	}
		  	else if(data=='no') 
		  	{
		  		$("#feeddback").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				//add message and change the class of the box and start fading
				$(this).html('Your membership was not activated.<br />Please open the email that we sent and click on the activation link').fadeTo(900,1);
				});
			}
			else if(data=='sus')
			{
		  		$("#feeddback").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				//add message and change the class of the box and start fading
				$(this).html('You are suspended!').fadeTo(900,1);
				});
			}
			else
			{
		  		$("#feeddback").fadeTo(200,0.1,function() //start fading the messagebox
				{ 
				//add message and change the class of the box and start fading
				$(this).html('Login failed!, Please try again').fadeTo(900,1);
				});
			}
    	});
	return false; //not to post the  form physically
});

// Forgotten password functions
$("#forgotten_form").submit(function()
	{
		$("#feeddback").text('Sending....').fadeIn(1000);
		$.post("includes/ajaxFunctions.php?action=2", { email:$('#email').val() } ,function(data)
        {
			if(data=='sent')
		  	{
		  		$("#feeddback").fadeTo(200,0.1,function() 
				{ 
				$(this).html('Password reset request sent.<br />Please check your email for instructions.').fadeTo(900,1);
				});
		  	}
		  	else if(data=='fail') 
		  	{
		  		$("#feeddback").fadeTo(200,0.1,function()
				{ 
				$(this).html('Failed sending email').fadeTo(900,1);
				});
			}
			else if(data=='nomember')
			{
		  		$("#feeddback").fadeTo(200,0.1,function()
				{ 
				$(this).html('There is no member to match your email.').fadeTo(900,1);
				});
			}
    	});
	return false; //not to post the  form physically
});

});