/*start of jcarsouel action*/
function mycarousel_initCallback(carousel){
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
//	$('#mycarousel li[:last]').css('margin-right',0);
    jQuery('.mycarousel').jcarousel({
	//	auto: 2,
		scroll:4,
		wrap: 'last',
		visible: 9,
		animation:1000,
		initCallback: mycarousel_initCallback

    });

var offsetY=5;
var offsetX=5;

    //$('#mycarousel li a').animate({'opacity':1});//adding animation

	$('#mycarousel li a').hover(function(e){
		//$(this).stop().animate({'opacity':.5});//adding animation
		$(this).parent().addClass('itemBorder');
		var href=$(this).attr('name');
		$('<img src="' +href+ '" name="largeImage" id="largeImage" alt="large Image" />')
			.css('top',e.pageY + offsetY)
			.css('left',e.pageX + offsetX)
			.appendTo('body');
	},function(){
		//$(this).stop().animate({'opacity':1});//animation
		$('#largeImage').remove();
		$(this).parent().removeClass('itemBorder');
	}
	);
	$('#mycarousel li a').mousemove(function(e){
		$('#largeImage')
		.css('top',e.pageY + offsetY)
		.css('left',e.pageX + offsetX);
	});

});

/* end  of jcarsouel action */


/* 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 js for other complaint */
   $(function(){
	   $('#reasons').change(function(){
		   var reason=$(this).val();
		   if(reason=='7'){
			   $('#otherComplaint').hide().slideDown(500);
		   }else{
			   $('#otherComplaint').css('display','none');
		   }
	   });
   });

/* end of js for other complaint */

/* start of js ads measure */
$(function(){
	var offsetY=2;
	var offsetX=2;

	$('#adRecordPage a.selected').css({'color':'#FFFFFF'}).parent().css({'background':'#bf9773','border-left':'1px solid #FFFFFF'});

	var href=$('#adRecordPage .selected').attr('href');

	$('<img src="' +href+ '" name="measureImage" id="measureImage" alt="measureImage" />')
		.css({'left':'60px','width':'180px','height':'250px','padding':'35px 0px'})
		.appendTo('#subContent');

	$('<img src="images/interface/hoveringArrow.gif" name="hoveringArrow" id="hoveringArrow" alt="hoveringArrow" />')
		.appendTo('#adRecordPage a.selected')
		.css({'left':'-10px','top':'12%'});

	$('#adRecordPage a').click(function(){return false;	});

	$('#adRecordPage a').hover(function(e){
		var th=$(this).parent();
		$('#measureImage').remove();
		$('#hoveringArrow').remove();
		$('#adRecordPage a.selected').css({'color':'blue'}).parent().css({'background':'none','border':'none'});

		var href=$(this).attr('href');
		$('<img src="' +href+ '" name="measureImage" id="measureImage" alt="measureImage" />')
			.css({'left':'60px','width':'180px','height':'250px','padding':'35px 0px'})
			.appendTo('#content');
		$(this).parent().css({'background':'#bf9773','border-left':'1px solid #FFFFFF'});

//
		$('<img src="images/interface/hoveringArrow.gif" name="hoveringArrow" id="hoveringArrow" alt="hoveringArrow" />')
		.appendTo(th)
		.css({'left':'-10px','top':'12%'});

//

	},function(){
		$('#measureImage').remove();
		$('#hoveringArrow').remove();
		$(this).parent().css({'background':'none','border-left':'none'});
	}
	);

});
/* end of js ads measure */

/* 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 Nav hovering */
$(function(){
	$('#firstPart #nav #listA li').hover(function(){
		$(this).css({'background':'#41b7e6 url(images/interface/hoveringIconAA.png) no-repeat 6% 50%'});
	},function(){
		$(this).css({'background':'none'});
	});

	$('#firstPart #nav #listB li').hover(function(){
		$(this).css({'background':'#FC6767 url(images/interface/hoveringIconBB.png) no-repeat 6% 50%'});
	},function(){
		$(this).css({'background':'none'});
	});

	$('#firstPart #nav #listC li').hover(function(){
		$(this).css({'background':'#FBD75A url(images/interface/hoveringIconCC.png) no-repeat 6% 50%'});
	},function(){
		$(this).css({'background':'none'});
	});

	$('#firstPart #nav #listD li').hover(function(){
		$(this).css({'background':'#666666 url(images/interface/hoveringIconDD.png) no-repeat 6% 50%'});
	},function(){
		$(this).css({'background':'none'});
	});

});
/* end of Nav hovering */