function make_count_down()
{
	$('.newoffer').countDown(
	{
		startNumber: 900,
		endNumber:650
	});
}

$(function()
{



	// Slide effects for projects categories
	$.fn.slideLeftShow = function( speed, callback ) { this.animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, speed, callback ); }
	$.fn.slideLeftHide = function( speed, callback ) { this.animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, speed, callback ); }

	function projectSlider(stop) {

		var customTimeout;
		if(stop === true) {
			customTimeout = 0;
		} else {
			customTimeout = 3000;
		}

		$('#projects-slider').gridnav
		({
			rows : 4,
			type : {
				mode    : 'sequpdown',
				speed   : 350,
				easing  : 'easeOutCubic',
				factor  : 50,
				reverse : false,
				timeout : customTimeout
			}
		});

	}

	$('.all a').addClass('active');
	// Init
	projectSlider();

	$('.projects-categories a').click(function(e)
	{
		var $items		   = $(this).parents('#projects-slider').find('.projects-slider-gallery li'),
			category		 = $(this).attr('data-categories'),
			$currentCategory = $(this).parent();



		if($currentCategory.hasClass('all'))
		{
			$('.projects-categories li a').removeClass('active');
			$('.all a').addClass('active');
			$items.removeClass().css({'position' : '', 'top' : '', 'left' : '', 'display' : 'block'})
								.stop(true, true).animate({opacity: 1}, 300, 'easeOutCubic');
			projectSlider(true);
			return false;
		}

		$('.projects-categories li a').removeClass('active');
		$(this).addClass('active');

		$items.each(function()
		{
			var $item = $(this);
			if($item.attr('data-categories') && $item.attr('data-categories').indexOf(category) != -1)
			{
				$item.removeClass().fadeIn('slow').css({'position' :'', 'top' : '', 'left' : '', 'display' : 'block'})
								   .stop(true, true).animate({opacity: 1}, 300, 'easeOutCubic');
			}
			else
			{
				$item.addClass('hidden').animate('slow').css({'display' : 'none'})
										.stop(true, true).animate({opacity: 0}, 300, 'easeOutCubic');
			}
		});

		projectSlider(true);

		e.preventDefault();
	});










	//input tip
	$('.input input').focus(function()
	{

		var position = $(this).position();
		var this_name = $(this).attr('name');

		if(this_name == 'fullname')
		{
			$('.input_tip').html('من فضلك أدخل اسمك الكريم')
		}

		if(this_name == 'email')
		{
			$('.input_tip').html('من فضلك أدخل بريدك الإلكتروني')
		}


		if(this_name == 'mobile')
		{
			$('.input_tip').html('من فضلك أدخل رقم جوالك  ')
		}


		if(this_name == 'website')
		{
			$('.input_tip').html('أدخل موقعك الشخصي')
		}

		$('.input_tip').animate({
			display: 'block',
			left: (position.left - 8),
			top:(position.top - 55),
			height: 'toggle',
			opacity:0.8
		}, 200, function() {

		 });
	});

	$('.input input').blur(function()
	{
		$('.input_tip').hide();

	});


	$('.projects-slider-gallery').find("li").each(function()
	{
		 if (jQuery.browser.msie && parseInt(jQuery.browser.version, 7) < 6)
		 {

		 }
		 else
		 {
		   $(this).find('a').append($('<div class="imgOverlay"><div class="symbolPlay"></div></div>'));
		 }

	});

    $("#menu li li a span").hover(function() {
        $(this).stop().animate({ marginRight: "5px" }, 200);
    },function(){
        $(this).stop().animate({ marginRight: "0px" }, 200);
	});

    $(".service_links a span").hover(function() {
        $(this).stop().animate({ marginRight: "5px" }, 200);
    },function(){
        $(this).stop().animate({ marginRight: "0px" }, 200);
	});
    $(".bdayhLink").hover(function() {
        $(this).stop().animate({ marginRight: "5px" }, 200);
    },function(){
        $(this).stop().animate({ marginRight: "0px" }, 200);
	});

    $(".bdayhLinks li").hover(function() {
        $(this).stop().animate({ marginRight: "5px" }, 200);
    },function(){
        $(this).stop().animate({ marginRight: "0px" }, 200);
	});

    $(".box_skitter").hover(function() {
        $('.prev_button').stop().show();
		$('.next_button').stop().show();
    },function(){
        $('.prev_button').stop().hide();
		$('.next_button').stop().hide();
	});

    $(".submenu").stop().hover(function() {


			$('.submenu ul').slideDown(0, function()
			{
				if(!$('.submenu ul li.vB').is(':visible'))
				{
					$('.submenu ul li.vB').show(0, function()
					{
						$('.submenu ul li.cms').show(0, function()
						{
							$('.submenu ul li.wordpress').show(0, function()
							{
								$('.submenu ul li.images').show(0, function()
								{
									$('.submenu ul li.logos').show(0, function()
									{
										$('.submenu ul li.business_cards').show(0, function()
										{
											$('.submenu ul li.business').show(0, function()
											{
												$('.submenu ul li.scripts').show(0, function()
												{
													$('.submenu ul li').css('display','block');
												});
											});
										});
									});
								});
							});
						});
					});
				}
			});

    },function(){
        $('.submenu ul').hide();
		$('.submenu ul li').css('display','block');
	});


	make_count_down();

	$('div.timer').countdown("2012/01/15" , function(event)
	{
		switch(event.type)
		{
			case "seconds":

			case "minutes":

			case "hours":

			case "days":

			case "daysLeft":

				$(this).find('#'+event.type).html(event.value);

			break;

			case "finished":

			//$(this).hide();

			break;
		}

	});


	$('.box_skitter_large').skitter(
		{animation: 'random'}
	);


	$('.gotop').click(function() {
		$('body,html').animate({scrollTop:0},500);
	});

	$(".projects-slider-gallery a").click(function(e)
	{
		//$(this).attr('target','_blank');
		//e.preventDefault();
		return false;

	})

	$('.notxt').html('');




    $(".projects-slider-gallery a").hover(function()
	{
		$('.projects-slider-gallery a div.imgOverlay').css('opacity',1);
        $(this).children('div').stop().fadeIn('slow');
    },function(){
        $(this).children('div').stop().fadeOut('fast');

	});

	$("#send_msg").click(function()
	{
		contactBdayh();
	})


})



	function contactBdayh()
	{


		var fullname 	   = $("#fullname").val();
		var email 		  = $("#email").val();
		var mobile 		 = $("#mobile").val();
		var message 		= $("#message").val();
		var website 		= $("#website").val();

		var sendvar = [fullname, email, mobile, message,website];

		$("#fullname").removeClass("error");
		$("#email").removeClass("error");
		$("#mobile").removeClass("error");
		$("#message").removeClass("error");



		jQuery.ajax( {
			async :true,
			type :"POST",
			url :"wp-content/themes/bdayh/contact.php?action=send&rand=" + Math.random(),
			data: "msg=" + sendvar + "",

			success : function(data)
			{
			var selectedIndex = 0;

				if(data == 1)
				{
					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/error.png" alt="" /><br />من فضلك ادخل اسمك').fadeIn(100).fadeOut(100);
					$("#fullname").addClass("error").fadeOut(100).fadeIn(500).fadeOut(100).fadeIn(500);

				}
				else if(data == 2)
				{
					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/error.png" alt="" /><br />من فضلك ادخل بريد الإلكتروني').fadeIn(100).fadeOut(100);
					$("#email").addClass("error").fadeOut(100).fadeIn(500).fadeOut(100).fadeIn(500);
				}
				else if(data == 3)
				{
					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/error.png" alt="" /><br />من فضلك أدخل رقم هاتفك ').fadeIn(100).fadeOut(100);
					$("#mobile").addClass("error").fadeOut(100).fadeIn(500).fadeOut(100).fadeIn(500);
				}
				else if(data == 4)
				{
					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/error.png" alt="" /><br />من فضلك أدخل رسالتك ').fadeIn(100).fadeOut(100);
					$("#message").addClass("error").fadeOut(100).fadeIn(500).fadeOut(100).fadeIn(500);
				}
				else if(data == 5)
				{
					$("#website").addClass("error").fadeOut(100).fadeIn(500).fadeOut(100).fadeIn(500);
					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/error.png" alt="" /><br />من فضلك أدخل موقعك الشخصي').fadeIn(100).fadeOut(100);
				}
				else
				{

					$("#contact_msg").html('<img src="wp-content/themes/bdayh/assets/images/success.png" alt="" /><br />تم إرسال الرسالة بنجاح').fadeIn('slow').delay(2000).fadeOut('slow');

					$("#fullname").val('');
					$("#email").val('');
					$("#mobile").val('');
					$("#message").val('');
					$("#website").val('');


				}


			},
			beforeSend : function(data) {

				$("#contact_msg").fadeIn('slow').html('<img src="wp-content/themes/bdayh/assets/images/loading.gif" alt="" /><br />من فضلك إنتظر جاري إرسال الرسالة');

			},
			error : function() {
					return true;
				}
			});


	}
	$(function(){

		$(".bdayh").stop().fadeTo("slow", 1);

		$(".bdayh").hover(function(){
			$(this).stop().fadeTo("slow", 0.6);
		},function(){
	   		$(this).stop().fadeTo("slow", 1);
		});
	});


