/* start of menu hovering */
$(function(){
	$('#nav ul li').hover(function(e){
		$(this).children('ul').css({'display':'block','right':0,'top':18})
							  .hide()
				              .fadeIn(400);
		},function(){
			$(this).children('ul').hide()
				   .fadeOut(100)
				   .css('display','none');
		}
		);
		return false;
});
/* end of menu hovering */


/* start of showing whole profile */
$(function(){
	$('#profile small #more').click(function(){
		$('<img src="images/interface/loading.gif" alt="loading..." id="loadingImage" />').appendTo('#profile');
		$(this).parent().hide();
		$('#wholeProfile').hide().slideDown(500).addClass('inline');
		$('#loadingImage').fadeOut(500,function(){
			$(this).remove();
		});

	});
});

/* end of showing whole profile */

/* start of displaying adverter's profile option2 */
$(function(){
	var offsetY=5;
	var offsetX=5;

   $('#mycarouselAdv li a').hover(function(e){
	   // $('#advertiserDetails').remove();

		var name=$(this).attr('name');
		var details=$(this).attr('id');
		var html='<div id="advertiserDetails">';
			html+='<div id="advTitle" >المعلن:'+name+'</div>';
			html+='<div id="details" >'+details+'</div>';
			html+='</div>';

	   $(html).css('top',e.pageY + offsetY)
		      .hide()
		      .fadeIn(200)
		      .css('left',e.pageX + offsetX)
		      .appendTo('body');
      },function(){
		  $('#advertiserDetails').remove();
	  });

	$('#mycarouselAdv li a').mousemove(function(e){
		$('#advertiserDetails')
		.css('top',e.pageY + offsetY)
		.css('left',e.pageX + offsetX);
	});

$('#mycarouselAdv li a').click(function(e){
	return false;
})

});

/* end of displaying adverter's profile option 2 */

/* start of coding required fields */
$(function(){
      $('#send').click(function(){  
		  var requiredA=".requiredFieldA";
		  var requiredB=".requiredFieldB";
		  var requiredC=".requiredFieldC";
		  var requiredD=".requiredFieldD";
		  if(!requiredField(requiredA) || !requiredField(requiredB) || !requiredField(requiredC) || !requiredField(requiredD)){
			  return false;
		  }
	  });

      $('.requiredField').blur(function(){
		  var required=$(this);
		  if(!requiredField(required)){
			  return false;
		  }
	  });

  });
		function requiredField(th){
		    if($(th).val().length < 1){
		       $(th).addClass('error');
		       return false;
		    }
		    else {
	       $(th).removeClass('error');
		     return true;
		    }
		}	
/* end of coding required fields */

/* start of comment sliding */
$(function(){
	$('#sendFriend').click(function(){
		$('#toFriend').toggle();
		$('#userAction li img').toggleClass('sendFriendImage');

		return false;
	});
});
/* end of comment sliding */

/* poll scripting*/
$(function(){
   $('#poll_submit').click(function(){
	   $('<img src="images/interface/loading.gif" id="loadingImage" alt="loading..."/>').appendTo('#loading');
		var poll_submit=$('#poll_submit').val();
		var theanswer=$('#theanswer').val();
		$.ajax({
			url:'poll.php',
			type:'post',
			data: 'poll_submit='+poll_submit+'&theanswer='+theanswer,
			success:function(res){
				$('#container').html(res);
				$('#loadingImage').fadeOut(500,function(){
				   $(this).remove;
				});
			}
		}); 

	}); return false;
});

// view the result
$(function(){
   $('#showresult').click(function(){
	   $('<img src="images/interface/loading.gif" id="loadingImage" alt="loading..."/>').appendTo('#loading');
	   	$.ajax({
		//	url:'poll.php',
		//	type:'post',
			success:function(res){
				$('#loadingImage').fadeOut(500,function(){
				   $(this).remove;
				});
			}
		});  

	}); return false;
	
});
/*end of poll scripting */
