// JavaScript Document

jQuery(document).ready(function() {  
    jQuery("textarea[class*=expandtextArea]").TextAreaExpander();  
}); 
$(document).ready(function()
{
    $('.langChange').click(function(){
        var lang= $(this).attr("id");
        $("#toBeChanged").html("Fetching....");
        $.post("process.php?do=lang",{lang:lang},function(data){
            $("#toBeChanged").html(data);
        });
        
        return false; 
    });  
	$('#regForm .subButton_reg').click(function () {
							  $('.success').hide();
							  $('.error').hide();
							  	var username = $('#usernames').val();
								var password = $('#passwords').val();
								var email = $('#emails').val();
								var re =$('#repassword').val();
							if( (username == '') || (password == '') || (email == '') || (re == ''))
							{	
								$('#regForm .error').html(' You must fill in all of the fields. ').fadeIn('fast'); 
							}
							
							else if (password != re )
							{
								
								$('.error').html(' Incorrect password. ').fadeIn('fast');
							}
							else {
								

							$.post("process.php?do=adduser", { username: username , email : email ,password : password},
								 function(data){
									 if(data.msg == 'not valid mail')
									 {
										 $('.error').fadeIn('fast').html(' not valid mail ').fadeIn(900);
									 }
									 else if (data.msg == 'This mail already taken.')
									 {
										 $('.error').fadeIn('fast').html('This mail already taken.').fadeIn(900);
									 }
									 else if (data.msg == 'yes')
									 {  
									 	$('.error').hide();
										setTimeout( function () {window.location = "index.php"} , 3000);
									 	$('.success').fadeIn('fast').html('Done .... You will be redirect to the home page after 3 seconds.').fadeIn(900);

									 }
									 else
									 {
										 $('.error').fadeIn('fast').html(data.msg);
									 }
								 },"json");
							}
							return false;
				}); /* end of sub button  */
		$('#shoutName').watermark({watermarkText: 'Your name', watermarkCssClass: 'watermarkIn'});
		$('#shoutMsg').watermark({watermarkText: 'Your Message' , watermarkCssClass: 'watermarkIn'});
		$('.expandtextArea').watermark({watermarkText: 'Your Question ??' , watermarkCssClass: 'watermarkIn'});
		$('#shoutSubmit').click(function ()
		{
			var name = $('#shoutName').val();
			var msg = $('#shoutMsg').val();
			$('#shoutSubmit').hide();
			$('.shoutAddForm img').show();
			$.post('process.php?do=addshout',{msg:msg , name:name},function (data)
			{
			//	if(data == 'yes')
				{
					$('.shoutAddForm img').hide();
					$('#shoutSubmit').show();
                    $('<li><h2>'+name+'</h2><p>'+msg+'</p></li>').prependTo('.shoutBoxList');
                    $('#shoutMsg').val("");
				}
				//else
				{
				//	alert(data);	
				}
				
			});
			return false;
		});

		
	
		
		$('.pagingSmallShout a').click(function ()
		{
						$('.shoutContainer img').show();
						var page = $(this).attr('id');
						$.post('process.php?do=showshout',{page:page}, function(data)
						{
							$('.shoutContainer').hide();
							$('.shoutContainer').html(data);
							$('.shoutContainer img').hide();
							$('.pagingSmallShout a').removeClass('current');
							$('#'+page).addClass('current');
							$('.shoutContainer').fadeIn();
						});
						return false;
		});
						  
		
		$('#sharePost').click(function()
		{
			if($('#textPost').val() == '')
			{
				alert('please Fill all the fields');
			}
			else
			{
				
				var userId = $('#userId').val();
				var text = $('#textPost').val();
			    var public = $('#shareWithOthers').val();
				var username = $('#usernamePost').val();

				$.post("process.php?do=addPost",{text:text , userId:userId , public:public},function(data)
				{
					if(data.msg =="yes")
					{
						var html = "<div class='contentDiv'><h1 class='postTitle'>"+username+"</h1><p class='wallparag'>"+text+"</p><div class='clear'></div></div>";
						$('.postUpdates').after(html);	
					}
					else
					{
						alert(data.msg);
					}
				},"json");
			}
			return false;
		});
		
		
								$('.edit_mail').click(function () {
								if ($('.mail_in').is(":visible"))
								{$('.mail_in').slideUp('fast');$('.change_result_mail').slideUp('fast');}
								else
								{$('.mail_in').slideDown('fast');}
											  return false;
										}); /* end of edit mail */
							$('.edit_pass').click(function () {
								if ($('.pass_in').is(":visible"))
								{$('.pass_in').slideUp('fast');$('.change_result_pass').slideUp('fast');}
								else
								{$('.pass_in').slideDown('fast');}
											  return false;
										}); /* end of edit mail */
																	$('.mail_sub').click(function () {
								var new_mail = $('.mail_input').val();						   
								$.post('process.php?do=change_mail',{mail:new_mail}, function (data)
													   {
														   if(data.msg=='yes')
														   {
															   $('.change_result_mail').html('done').fadeIn();
															   
															   $('.mail_in').slideUp('fast',function () {
																	setTimeout(function () {
																						 $('.change_result_mail').slideUp('fast');
																						 $('.mail_txt span').html(new_mail);
																						 } , 2000)});
														   }
														   else if (data.msg == 'no')
														   {
															   $('.change_result_mail').html('This mail is exist in DB').fadeIn('fast');
														   }
														   else if (data.msg =='wrong')
														   {
															   $('.change_result_mail').html('Wrong mail.').fadeIn('fast');
														   }
														   else
														   {
															  $('.change_result_mail').html(data.msg).fadeIn('fast'); 
														   }
													   },"json");
								return false;
														   }); /* end of sub edit mail */
							$('.pass_sub').click(function () {
								var new_pass  = $('.pass_input').val();
								$.post('process.php?do=change_pass',{pass:new_pass}, function (data)
													   {
														   if(data.msg=='yes')
														   {
															   $('.change_result_pass').html('done').fadeIn();
															   
															   $('.pass_in').slideUp('fast',function () {
																	setTimeout(function () {
																						 $('.change_result_pass').slideUp('fast');
																						 $('.pass_txt span').html(new_pass);
																						 } , 2000)});
														   }
														   else
														   {
															  $('.change_result_pass').html(data_back).fadeIn('fast'); 
														   }
													   },"json");
								return false;
														   }); /* end of sub edit pass */

	
});
$(window).load(function() {
    $('#slider').nivoSlider({
        effect:'slideInRight', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:1000, //Slide transition speed
        pauseTime:6000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:false, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity

    });
});
