// JavaScript Document
window.onload=function(){
	Nifty("#projanmo","tl bottom big fixed-height");
	Nifty("#forum","tl bottom big fixed-height");
	Nifty("#hawker","tl bottom big fixed-height");
	Nifty("#search","tl bottom big fixed-height");
	Nifty("#web","tl bottom big fixed-height");
	Nifty("#help","tl bottom big fixed-height");
	Nifty("#rupantar","tl bottom big fixed-height");
	Nifty("#others","tl bottom big fixed-height");
	$("#screenshot > .shots").fadeOut('slow');
	$("#text > .box").fadeOut('slow');
	$("#loading").fadeOut("slow");
	$("#imgholder").fadeIn('slow');	
	$("#projanmo").fadeIn('slow');
	lazyload();
};

$(document).ready(function() {
	//show progress bar when an ajax request is called
	$(document).ajaxStart(function() {
		$("#loading").show();
	});
		
	
	//hide progress bar when ajax requeste is completed
	$(document).ajaxStop(function() {
		$("#loading").fadeOut();
	});
	
	//hide all elements under screenshots and text
	$("#nav > li").click(function(){
		$("#screenshot > div").hide();
		$("#screenshot > img").hide();		
		$("#text > .box").hide();
		$("#iothers").hide();
	});
	
	
	$("#navprojanmo").click(function() {
		//$("#iprojanmo").fadeIn('slow');
		imgshow("home.jpg");
		$("#projanmo").fadeIn('slow');
	});
	$("#navforum").click(function() {
		imgshow("forum.jpg");
		$("#forum").fadeIn('slow');
	});
	$("#navhawker").click(function() {
		imgshow("hawker.jpg");
		$("#hawker").fadeIn('slow');
	});
	$("#navsearch").click(function() {
		imgshow("search.jpg");
		$("#search").fadeIn('slow');
	});
	$("#navrupantar").click(function() {
		imgshow("rupantar.jpg");
		$("#rupantar").fadeIn('slow');
	});
	
	$("#navweb").click(function() {
		imgshow("web.jpg");
		$("#web").fadeIn('slow');
	});	

	$("#navhelp").click(function() {
		$("#screenshot > div").fadeOut('slow');
		$("#screenshot > img").fadeOut('slow');		
		$("#text > .box").fadeOut('slow');
		$("#iothers").fadeOut("slow")
		imgshow("bnghelp.jpg");
		$("#help").fadeIn('slow');
	});	
	
	$("#navothers").click(function() {
		$("#iothers > div").fadeOut();
		$("#iothers").fadeIn('slow');
		$("#iothers-intro").fadeIn();
		$("#others").fadeIn('slow');
	});	
	
	

	//hide all div under iothers div
	$("#others > ul > li").click(function() {
		$("#iothers > div").hide();
	});
	
	
	$("#licont").click(function() {
		$("#icontributors").fadeIn("slow");
	});
	$("#liourwords").click(function() {
		$("#iothers-intro").fadeIn("slow");
	});
	$("#lifeedback").click(function() {
		$("#ifeedback").fadeIn("slow");
	});
		
	//load friends' page using ajax call
	$("#lifriend").click(function() {
		$.ajax({
		  url: "ourfriends.htm",
		  cache: true,
		  success: function(html){
			$("#ajaxtext").html(html);
			$("#ajaxtext").fadeIn();
		  },
		  error: function(XMLHttpRequest, textStatus, errorThrown){
			alert('Sorry! we faced error while loading our friends list');
		  }
		});
	});

$("#loadlayout").click(function() {
		$("#loadlayout").fadeOut();
		//$("#imgloading").fadeIn();
		$.ajax({
		  url: "layout.htm",
		  cache: true,
		  success: function(html){
			$("#bnload").html(html);
			
		  },
		  error: function(XMLHttpRequest, textStatus, errorThrown){
			alert('Sorry! we faced error while loading Bangla typing script');
		  }
		});
	});
	
	$("#cmdSubmit").click(function() {

		if(!validateEmail($("#yourEmail").val())) {
			alert('Invalid Email');
			return false;
		}
		var str=$("#frmfeedback").serialize();
		$.ajax({
			   url: "contact.php",
			   cache:false,
				data: str,
			   success: function(html){
				   $("#feedbackmsg").html(html);
				   $("#frmfeedback").fadeOut("slow");
			   },
			  error: function(XMLHttpRequest, textStatus, errorThrown){
				$("#bnload").fadeOut("slow");
				alert('Sorry! we faced error while sending your message');
			  }
		});
	});
});

function validateEmail(email){
	var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
	if (!regEx.test(email)) {
		return false;
	} 
return true;
}

function imgshow(image){
	image='screenshots/'+image;
	$.ajax({
		   url: image,
		   cache:true,
		   success:function(){
				$("#imgholder").html('<img src="'+image+'" alt="Loading Screenshot" class="shots">');
				$("#imgholder").fadeIn("slow");
		   },
		  error: function(XMLHttpRequest, textStatus, errorThrown){
			$("#imgholder").fadeOut("slow");
			alert('Sorry! we faced error while loading data.');
		  }
	  });
	
}

function lazyload(){
	$("#cachebox").append('<img src="screenshots/bnghelp.jpg" alt="screenshots" />');
	$("#cachebox").append('<img src="screenshots/forum.jpg" alt="screenshots" />');
	$("#cachebox").append('<img src="screenshots/web.jpg" alt="screenshots" />');
	$("#cachebox").append('<img src="screenshots/rupantar.jpg" alt="screenshots" />');
	$("#cachebox").append('<img src="screenshots/hawker.jpg" alt="screenshots" />');
	$("#cachebox").append('<img src="screenshots/search.jpg" alt="screenshots" />');

}