// JavaScript Document
	$rg_chars = /^[a-zA-Z\s{1}]+$/;
	$rg_numbers = /^[0-9]+$/;
	$rg_zip = /^[0-9]{5}$/;
	$rg_text = /^[a-zA-Z0-9#\-\,\s{1}]+$/;
	$re_phone = /^[+]?[0-9\s{1}]+$/;
	$re_email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/ ;
$(document).ready(function(){
	$("#main-menu ul li").hover(function(){
		$(this).children("ul:hidden").toggle();
	}, function(){
		$(this).children("ul:visible").toggle();
	});
	$("body").click(function(){
		$("#main-menu ul li").children("ul:visible").toggle();
	});
	$("#txtSearch, #signup_email").focus(function(){
		if($(this).val()==$(this)[0].defaultValue)
			$(this).val("");		
	});
	$("#txtSearch, #signup_email").blur(function(){
		if($(this).val()=="")
			$(this).val($(this)[0].defaultValue);		
	});
	if($("#box_links").length){
		$(window).scroll(function(){
			$top = $(window).scrollTop();
			if($top>170){
				$("#box_links").stop();
				$("#box_links").animate({"top": ($top-170)+"px"}, 500);	
			}else{
				$("#box_links").stop();
				$("#box_links").animate({"top": ($top)+"px"}, 500);
			}
		});
	}
	if($("#tabs").length){
		$(".tab_button").click(function(){
			$number = $(".tab_button").index(this);
			$(".active_tab").removeClass("active_tab");
			$(".active").removeClass("active");
			$(this).addClass("active");
			$(".tab").eq($number).addClass("active_tab");
		});
	}
	if($("#gallery_box").length){
		$gallery = new Array();
		function position_gallery_box(){
			$clientWidth = (document.documentElement.clientWidth/2); 
			$clientHeight = (document.documentElement.clientHeight/2);
			$bodyWidth = $(document).width();
			$bodyHeight = $(document).height();
			$bg = $("#transparent_bg");
			$bg.css({"width": $bodyWidth+"px", "height":  $bodyHeight+"px", "opacity": "0.5"});
			$bg.fadeIn(500);
			
			$boxWidth = 513/2;
			$boxHeight = 506/2;
			$top = $(window).scrollTop();
			$x = parseInt($clientWidth - $boxWidth);
			$y = parseInt($clientHeight - $boxHeight + $top);
			$gallery = $("#gallery_box");
			$gallery.css({"left": $x+"px", "top": $y+"px"});
		}
		$("#btn_next").click(function(){
			$current_img = $("#images img:visible");
			$next = $current_img.next();
			if($next.is("img")){
				$("#images img").fadeOut(200);
				$current_img.css("display", "none");
				//alert($gallery[$("#images img").index($current_img)+1].caption);
				$("#gallery_box #caption").html($gallery[$("#images img").index($current_img)+1].caption);
				$next.fadeIn(1000);
			}
		});
		$("#btn_previous").click(function(){
			$current_img = $("#images img:visible");
			$last = $current_img.prev();
			if($last.is("img")){
				$("#images img").fadeOut(500);
				$current_img.css("display", "none");
				$("#gallery_box #caption").html($gallery[$("#images img").index($current_img)-1].caption);
				$last.fadeIn(1000);
			}
		});
		$("#close_button").click(function(){
			$("#gallery_box").fadeOut(500);
			$("#transparent_bg").fadeOut(500);
		});
	}
	if($(".gallery_thumbnail").length){
		$(".gallery_thumbnail img").css("opacity", "0.8");
		$(".gallery_thumbnail img").hover(function(){
			$(this).css("opacity", "1");
		},function(){
		 	$(this).css("opacity", "0.8");
		});
		$(".gallery_thumbnail img").click(function(){
			$id = $(this).attr("name");
			$("#gallery_box #images").html("");
			$.ajax({
			   async: "false",
			   type: "POST",
			   data: {id: $id},
			   url: "galleries.php",
			   dataType: "json",
			   success: function(json, status){
				   	$gallery = json;		
					if(status=="success"){
						main_image = "";
						for($j=0; $j<$gallery.length; $j++){
							main_image = main_image + "<img src='"+ $gallery[$j].path +"' />";
						}
						$("#gallery_box #images").html(main_image);
						$("#gallery_box #caption").html($gallery[0].caption);
						$("#gallery_box #images img:first").css("display", "block");
					}
			   }
			});
			position_gallery_box();
			$("#gallery_box").fadeIn(500);
		});
	}
	if($("#frm_signup_updates").length){
		$sent = false;
		$("#frm_signup_updates").submit(function(){
			$fname = $("#fname");
			$lname = $("#lname");
			$zip = $("#zip_code");
			$email = $("#email");
			$agree = $("#agree");
			$email_format = $("#email_format");
			if($fname.val() == "" ){
				alert("Please type your first name.");
				$fname.focus();
				return false;
			}else if($lname.val() == "" ){
				alert("Please type your last name.");
				$lname.focus();
				return false;
			}else if($email.val() == "" ){
				alert("Please type your email.");
				$email.focus();
				return false;
			}else if(!$re_email.test($email.val())){
				alert("Please type a valid email.");
				$email.focus();
				return false;
			}else if($zip.val() == "" ){
				alert("Please type ZIP / Postal Code.");
				$zip.focus();
				return false;
			}else if(!$rg_zip.test($zip.val())){
				alert("Please type a valid ZIP / Postal Code.");
				$zip.focus();
				return false;
			}else if(!$agree.is(":checked")){
				alert("Please check the agreement statement for signup.");
				return false;
			}
			if(!$sent){
				$("#message_signup_form").html("Sending your request...");
				$.ajax({
				   async: "false",
				   processData: "false",
				   type: "POST",
				   data: {fname: $fname.val(), lname: $lname.val(), email: $email.val(), zip: $zip.val(), format: $email_format.val()},
				   url: "sendSignupMail.php",
				   dataType: "json",
				   success: function(json, status){
						$("#message_signup_form").html(json.message);
						$sent = json.status;
				   }
				});
			}
		});
	}
	if($("#frm_contact").length){
		$sent = false;
		$("#frm_contact").submit(function(){
			$name = $("#name");
			$email = $("#email");
			$phone = $("#phone");
			$message = $("#message");
			if($name.val() == "" ){
				alert("Please type your name.");
				$name.focus();
				return false;
			}else if($email.val() == "" ){
				alert("Please type your email.");
				$email.focus();
				return false;
			}else if(!$re_email.test($email.val())){
				alert("Please type a valid email.");
				$email.focus();
				return false;
			}else if($phone.val()!="" && !$re_phone.test($phone.val())){
				alert("Please type a valid phone number.");
				$phone.focus();
				return false;
			}else if($message.val() == "" ){
				alert("Please type your message.");
				$message.focus();
				return false;
			}
			
			if(!$sent){
				$("#message_contact_form").html("Sending your message...");
				$.ajax({
				   async: "false",
				   processData: "false",
				   type: "POST",
				   data: {name: $name.val(), email: $email.val(), phone: $phone.val(), message: $message.val()},
				   url: "sendContactMail.php",
				   dataType: "json",
				   success: function(json, status){
						$("#message_contact_form").html(json.message);
						$sent = json.status;
				   }
				});
			}
		});
	}
	/*
	if($("#form_donation_pakistan").length){
		$sent = false;
		$("#form_donation_pakistan").submit(function(){
			$name = $("#name");
			$email = $("#email");
			$phone = $("#phone");
			$message = $("#message");
			window.open('print.php','FWindow','status=no, location=no, titlebar=no, toolbar=no, hotkeys=no, menubar=no, scrollbars=yes, resizable=no, width=500, height=130, screenX=200, screenY=100, alwaysRaised=yes, dependent=yes');
			
			if($name.val() == "" ){
				alert("Please type your name.");
				$name.focus();
				return false;
			}else if($email.val() == "" ){
				alert("Please type your email.");
				$email.focus();
				return false;
			}else if(!$re_email.test($email.val())){
				alert("Please type a valid email.");
				$email.focus();
				return false;
			}else if($phone.val() == "" ){
				alert("Please type your phone.");
				$phone.focus();
				return false;
			}else if(!$re_phone.test($phone.val())){
				alert("Please type a valid phone number.");
				$phone.focus();
				return false;
			}else if($message.val() == "" ){
				alert("Please type your message.");
				$message.focus();
				return false;
			}
			
			if(!$sent){
				$("#message_contact_form").html("Sending your message...");
				$.ajax({
				   async: "false",
				   processData: "false",
				   type: "POST",
				   data: {name: $name.val(), email: $email.val(), phone: $phone.val(), message: $message.val()},
				   url: "sendContactMail.php",
				   dataType: "json",
				   success: function(json, status){
						$("#message_contact_form").html(json.message);
						$sent = json.status;
				   }
				});
			}
		
		});
	}*/
	$(window).load(function(){
		$newsFirst = $("#boxCM div:first").html();
		$("#boxCM div:last").after("<div>"+$newsFirst+"</div>");
		if($("#slider").length){
			sliderCounter = 0;
			startSlider();
		}
		//if($("#boxCM").length){
			newsPosition = 0;
			newsCount = 0;
			startNews();
		//}
	});
});
function startSlider(){
	current = $("#slider img");
	var previous = sliderCounter;
	sliderCounter = (sliderCounter+1)%4;
	$(current[sliderCounter]).fadeIn(3000);
	$(current[previous]).fadeOut(2000);
	x = setTimeout(startSlider, 5000);
}
function swapImg(){
	clearTimeout(x);
	$(current[sliderCounter]).fadeOut(500, startSlider);
}
//News Scroll Box
function startNews(){
	if(newsCount > totalNews){
		newsCount = 1;
		$("#boxCM div").css("top", "0px");
		startNews();
	}else{
		newsPosition = newsCount*160;
		newsCount++;
		$("#boxCM div").animate({top: -newsPosition+"px"}, 3000, 'linear');
		setTimeout(startNews, 7000);
	}
}
