$(document).ready(function(){
	$("#fast-search").hide();
	$("#menu-links li ul").hide();
	$("#fast-search").show().effect("slide", { direction: "up" }, "slow");
	/* $(function() {
		$(".box-articol").selectable();
	}); */

	$("#menu-links li").click(function() {
		$(this).find("ul").stop()
		.animate({opacity:1}, "slow")
		.css("display","block")
	}, function() {
		$(this).find("ul").stop()
		.animate({opacity: 0}, "fast")
		.css("display","none")
	});
	$(".ilsn_box_ajutor").fancybox({
			'hideOnContentClick': false,
			'frameWidth':			540,
			'frameHeight':			330,
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500
			});

		
		swapValues = [];
    $("#simple #q").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == "") {
                $(this).val(swapValues[i]);
            }
        });
    });
	
	$("#login_form").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Autentificare....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("http://www.ithakamedia.ro/ajax_login.php",{ m:$('#m').val(),p:$('#p').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='05') 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Redirectionare in curs.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 window.location.reload();
			  });
			  
			});
		  }
		   else if(data=='00') // eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Completati email si parola').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='01') // eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Momentan sistemul este inactiv').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='02') // ok dar eroare
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() 
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Va rugam sa confirmati adresa de email (din email-ul primit).').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Nu va putem autentifica...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	//now call the ajax also focus move from 
	$("#p").blur(function()
	{
		$("#login_form").trigger('submit');
	});

$("#autentificarein").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox2").removeClass().addClass('messagebox').text('Autentificare....').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("http://www.ithakamedia.ro/ajax_login.php",{ m:$('#m2').val(),p:$('#p2').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='05') 
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Redirectionare in curs.....').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 window.location.reload();
			  });
			  
			});
		  }
		   else if(data=='00') // eroare
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Completati email si parola').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='01') // eroare
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function()  
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Momentan sistemul este inactiv').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else if(data=='02') // ok dar eroare
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() 
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Va rugam sa confirmati adresa de email (din email-ul primit).').addClass('messageboxerror').fadeTo(900,1);
              
			});
		  }
		  else 
		  {
		  	$("#msgbox2").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Nu va putem autentifica...').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
	
	$("#inregistrare").submit(function(){ inregistrare(); return false; });
	$("#recup_parola").submit(function(){ recuperare_parola(); return false; });
});
