cssObj_menuActiveState = { 'color' : '#2e4e24' };
cssObj_menuInactiveState = { 'color' : 'black' };
cssObj_menuActiveState_about = { 'color' : '#8d0513' };
cssObj_menuActiveState_connect = { 'color' : '#2f527d' };

$(document).ready(function() {		
	var cssObj = '';
	
	//$("body").css("overflow", "hidden");

	
	//$('#homePage').hide();
	$('#section_aboutus').hide();
	$('#section_aboutus_story').hide();
	$('#section_aboutus_vision_mission').hide();
	$('#section_aboutus_sof').hide();
	$('#section_gettingstarted').hide();
	$('#section_connectonline').hide();
	$('#section_whatisacommunitychaplain').hide();

	//START home page menu
	$('li#aboutUs').hover(
		function() {
			//Check to see if we have already clicked
			if($('li#aboutUs a img').length == 0) {	
				//Set the triangle
				$('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo($('#aboutUs a'));
			}
		},
		function() {
			$('#menutrianglehover').remove();
		}
	);

	$('li#aboutUs').click(function() {
		$('#homePage').hide();
		$('#section_gettingstarted').hide();
		$('#section_connectonline').hide();
		$('#section_whatisacommunitychaplain').hide();
		
		$('#section_aboutus').show();
		$('#section_aboutus_landing').show();
		$('#section_aboutus_story').hide();
		$('#section_aboutus_vision_mission').hide();
		$('#section_aboutus_sof').hide();

		//Set the triangle
		$('#menutrianglehover').remove();
		$('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo($('#aboutUs a'));
	
		//Set the state of the menu
		$('#aboutMenu ul li a').css(cssObj_menuInactiveState);
		

		
		clearAllMenuItems();
	});
	
	$('#gettingStarted').hover(
		function() {
			//Check to see if we have already clicked
			if($('li#gettingStarted a img').length == 0) {
				//Set the triangle
				$('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo($('#gettingStarted a'));
			}
		},
		function() {
			$('#menutrianglehover').remove();
		}
	);

	$('li#gettingStarted').click(function() {
		$('#homePage').hide();
		$('#section_aboutus').hide();
		$('#section_gettingstarted').show();
		$('#section_connectonline').hide();
		$('#section_whatisacommunitychaplain').hide();
		
		$('#section_gettingstarted_landing').show();
		$('#section_amiqualified').hide();
		$('#section_products').hide();
		$('#section_howdoigetstarted').hide();
		$('#section_communitypartner').hide();
		$('#section_churchpartner').hide();
		
		//Set the triangle
		$('#menutrianglehover').remove();
		$('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo($('#gettingStarted a'));
		
		//Set the state of the menu
		$('#gettingstartedMenu2 ul li a').css(cssObj_menuInactiveState);
		
		clearAllMenuItems();
	});
	
	$('#connectOnline').hover(
		function() {
			//Check to see if we have already clicked
			if($('li#connectOnline a img').length == 0) {
				//Set the triangle
				$('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo($('#connectOnline a'));
			}
		},
		function() {
			$('#menutrianglehover').remove();
		}
	);

	$('li#connectOnline').click(function() {
		$('#homePage').hide();
		$('#section_gettingstarted').hide();
		$('#section_aboutus').hide();
		$('#section_whatisacommunitychaplain').hide();
		$('#section_gettingstarted_landing').hide();
		
		$('#section_connectonline').show();
		
		//Set the triangle
		$('#menutrianglehover').remove();
		$('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo($('#connectOnline a'));
		
		clearAllMenuItems();
	});
	
	//END home page menu
	
	//START Sub menu actions About Us
	
	//Start About
	$('li#menu_about_home').click(function() {
		goToHome();
	});
	$('li#menu_ourstory').click(function() {
		$('#section_aboutus_story').show();
		$('#section_aboutus_landing').hide();
		$('#section_aboutus_vision_mission').hide();
		$('#section_aboutus_sof').hide();
	});
	$('li#menu_ourvisionmission').click(function() {
		$('#section_aboutus_story').hide();
		$('#section_aboutus_landing').hide();
		$('#section_aboutus_vision_mission').show();
		$('#section_aboutus_sof').hide();
	});
	$('li#menu_ourstatementoffaith').click(function() {
		$('#section_aboutus_story').hide();
		$('#section_aboutus_landing').hide();
		$('#section_aboutus_vision_mission').hide();
		$('#section_aboutus_sof').show();
	});
	//End About
	
	//pppppppppppppppppppppppp
	$('ul.menusmall img').hover(
			function() {
				var src = $(this).attr("src");
		
				//switch fom off to on. Unless already on
				if (src.substring(src.length-6, src.length) === "ff.png") {
					//replace off src with on src
					src = src.substring(0, src.length-7);
					src = src + "on.png";
					$(this).attr("src", src);	
				}
				//alert('onhover');
			},
			function() {
				var src = $(this).attr("src");
				
				//switch fom off to on. Unless already on
				if (src.substring(src.length-6, src.length) === "on.png") {

					//check if the image has the clicked attribute
					if ($(this).attr("isclicked") != "true") {
						//replace off src with on src
						src = src.substring(0, src.length-6);
						src = src + "off.png";
						$(this).attr("src", src);	
					}
				}
				//alert('onhover out');
			}
		);
		
		$('ul.menusmall img').click(function() {
			var src = $(this).attr("src");
			//switch fom off to on. Unless already on
			if (src.substring(src.length-6, src.length) === "ff.png") {
				//replace off src with on src
				src = src.substring(0, src.length-7);
				src = src + "on.png";	
			}


			// Clear all other menu items that may be on
			clearAllMenuItems();

			//Now set the current selection to on
			$( "ul.menusmall img" ).each(function(){
				$(this).attr("isclicked", "false");		
			});
			
			$(this).attr("isclicked", 'true');
			$(this).attr("src", src);		
		});
	
	function clearAllMenuItems() {
		$( "ul.menusmall img" ).each(function(){
			var tempsrc = $(this).attr("src");
			if (tempsrc.substring(tempsrc.length-6, tempsrc.length) === "on.png") {

				//replace off src with on src
				tempsrc = tempsrc.substring(0, tempsrc.length-6);
				tempsrc = tempsrc + "off.png";
				$(this).attr("src", tempsrc);	
			}
		});
	}
	
	
	//ppppppppppppppppppppppppppppppppppppp
	
	
	
	
	//END Sub menu actions About Us
	
	//START Sub menu actions Getting Started 
	$('li#gettingstarted_menu_home').click(function() {
		goToHome();
	});
	$('li#menu_amiqualified').click(function() {
		$('#section_amiqualified').show();
		$('#section_products').hide();
		$('#section_howdoigetstarted').hide();
		$('#section_communitypartner').hide();
		$('#section_churchpartner').hide();
		$('#section_gettingstarted_landing').hide();
	});
	$('li#menu_howdoigetstarted').click(function() {
		$('#section_amiqualified').hide();
		$('#section_products').hide();
		$('#section_communitypartner').hide();
		$('#section_churchpartner').hide();
		$('#section_howdoigetstarted').show();
		$('#section_gettingstarted_landing').hide();
	});
	$('li#menu_communitypartner').click(function() {
		$('#section_amiqualified').hide();
		$('#section_products').hide();
		$('#section_howdoigetstarted').hide();
		$('#section_communitypartner').show();
		$('#section_churchpartner').hide();
		$('#section_gettingstarted_landing').hide();
	});
	$('li#menu_churchpartner').click(function() {
		$('#section_amiqualified').hide();
		$('#section_products').hide();
		$('#section_howdoigetstarted').hide();
		$('#section_communitypartner').hide();
		$('#section_churchpartner').show();
		$('#section_gettingstarted_landing').hide();
	});
	$('li#menu_products').click(function() {
		$('#section_amiqualified').hide();
		$('#section_products').show();
		$('#section_howdoigetstarted').hide();
		$('#section_communitypartner').hide();
		$('#section_churchpartner').hide();
		$('#section_gettingstarted_landing').hide();
	});

	//END Sub menu actions Getting Started
	
	//Start Connect Online
	$('li#connectonline_home').click(function() {
		goToHome();
	});
	//End Connect Online
	
	// START Home Page
	$('img#whatIsCommChap').click(function() {
		$('li#aboutUs').click();
	});
	$('img#churchLeaders').click(function() {
		$('li#gettingStarted').click();
		$('#img_menu_churchpartner').click();
	});
	
	
	//END Home Page
	
	//START fixed menu
	$('div#fixedmenu').click(function() {
		
	});
	//END fixed menu
	
	//fixed postion div
    $('#fixedmenu').css('top', 0 + "px");
    
	$(window).scroll(function() {
	    $('#fixedmenu').css('top', $(this).scrollTop() + "px");
	});
});

function goToHome() {
	$('#homePage').show();
	$('#section_gettingstarted').hide();
	$('#section_connectonline').hide();
	$('#section_whatisacommunitychaplain').hide();
	
	$('#section_aboutus').hide();
	$('#section_aboutus_landing').hide();
	$('#section_aboutus_story').hide();
	$('#section_aboutus_vision_mission').hide();
	$('#section_aboutus_sof').hide();
	
	$('#menutrianglehover').remove();
	$('#menutriangleclick').remove();
}

function getTriangleImageObjectOnClick() {
	return $('<img id="menutriangleclick" class="menutriangle" src="images/menu/menu_triangle.png" />');
}

function getTriangleImageObjectOnHover() {
	return $('<img id="menutrianglehover" class="menutriangle" src="images/menu/menu_triangle.png" />');
}

function changeSubMenuColorActive($element) {
	$element.children("a").children("p").css({'color': 'rgb(46,78,36)'});
}

function changeSubMenuColorInActive($element) {
	$element.css({color:'black'});
}



	