var J = jQuery.noConflict();

J(document).ready(function(){
						   
	/*
	 * Horizontal Layout Navigation Script
	 *
	 * Copyright (c) 2008 Veera Sundar (http://veerasundar.com)
	 *
	 * Date: Aug 17 2008
	 */
	
	//Global Constants
	var JSPACER = 1280;
	var JNOTACTIVEOPACITY = 1;
	
	//Get the number of page elements in current web page
	var JnumberOfPages = J(".page").size();
	var JpageLeftDistance = "0";
	var JcurrentPage = J(".page:first");
	
	//Set Current page as active
	JcurrentPage.addClass("activePage");
	for(var i=1; i<=JnumberOfPages; i++)
	{
		JcurrentPage.css("left",JpageLeftDistance+"px");
		//Calculate the  left distance for the next page
		JpageLeftDistance = parseInt(JcurrentPage.css("left")) + parseInt(JcurrentPage.css("width"))+ JSPACER;
		JcurrentPage = JcurrentPage.next(".page");
		JcurrentPage.addClass("notActivePage");
	}
	
	J("#MessagePanel").click(function(){
		J("#MessagePanel").slideToggle("slow");
	});
	
	J(".moveBackward").click(function(){
	
		if(J(".activePage").prev().size() == 0)
		{
			J("#MessagePanel").html("Sorry! You can not go to previous page, as this is the first page! Click here to close this message.");
			J("#MessagePanel").slideDown("medium");
			return;
		}
		//This function will take care of moving to previous pages
		var JcurrPage,JtmpLeft, JallPages;
		var JnumberOfPages = J(".page").size();
		JallPages = J(".page");
		for(var Ji=0; Ji<JnumberOfPages;Ji++)
		{
			if(Ji==0)
			{
				JtmpLeft = parseInt(J(".page:last").css("left"));
				J(".page:last").animate({
					left: (JtmpLeft + parseInt(J(".page:first").css("width")) + JSPACER)+"px",
					opacity:JNOTACTIVEOPACITY
				},500);
				JcurrPage = J(".page:last");
			}else
			{
				JcurrPage = JcurrPage.prev(".page");
				JcurrPage.animate({
					left: JtmpLeft + "px",
					opacity:JNOTACTIVEOPACITY
				},500);
				JtmpLeft = JtmpLeft - parseInt(JcurrPage.css("width")) - JSPACER;
			}
		}
		
		JcurrPage = J(".activePage");
		JcurrPage.removeClass("activePage");
		JcurrPage.addClass("notActivePage");
		JcurrPage.prev(".page").removeClass("notActivePage");
		JcurrPage.prev(".page").addClass("activePage");		
		J(".activePage").animate({
			opacity:1
		},200);

	});
	J(".moveForward").click(function(){
		if(J(".activePage").next().size() == 0)
		{
			J("#MessagePanel").html("Sorry! You can not go to next page, as this is the last page! Click here to close this message.");
			J("#MessagePanel").slideDown("medium");
			return;
		}
		//This function will take care of moving to next pages
		var JcurrPage,JtmpLeft, JallPages;
		var JnumberOfPages = J(".page").size();
		JallPages = J(".page");
		for(var Ji=0; Ji<JnumberOfPages;Ji++)
		{
			if(Ji==0)
			{
				JtmpLeft = parseInt(J(".page:first").css("left"));
				J(".page:first").animate({
					left: (JtmpLeft- parseInt(J(".page:first").css("width")) - JSPACER)+"px",
					opacity:JNOTACTIVEOPACITY
				},500);
				JcurrPage = J(".page:first");
			}else
			{
				JcurrPage = JcurrPage.next(".page");
				JcurrPage.animate({
					left: JtmpLeft + "px",
					opacity:JNOTACTIVEOPACITY
				},500);
				JtmpLeft = JtmpLeft + parseInt(JcurrPage.css("width")) + JSPACER;
			}
		}
		
		JcurrPage = J(".activePage");
		JcurrPage.removeClass("activePage");
		JcurrPage.addClass("notActivePage");
		JcurrPage.next(".page").removeClass("notActivePage");
		JcurrPage.next(".page").addClass("activePage");		
		J(".activePage").animate({
			opacity:1
		},200);
		
	});							
});
