cssObj_menuActiveState = { 'color' : '#2e4e24' };
cssObj_menuInactiveState = { 'color' : 'black' };
cssObj_menuActiveState_about = { 'color' : '#8d0513' };
cssObj_menuActiveState_connect = { 'color' : '#2f527d' };
var basePath = "https://www.commchap.org/";
var windowlocation = window.location;
if (windowlocation.host === 'cca.net-by-design.com') {
	basePath = 'https://cca.net-by-design.com/';
}

var dotnetnukelocation;


jQuery.noConflict();
jQuery(document).ready(function () {	

	var fadeTime = 5000;
	
	/* Fancy Box */
	jQuery("a.fancy").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'showNavArrows' : false
	});
	
	/* Statement of faith */
	jQuery("a.sof").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'width'			: '400',
		'height'		: '400'
		
	});
	
	jQuery("a.sof").click(function() {
		 dotnetnukelocation = jQuery(this).attr('class').split(' ').slice(-1);
	});
	
	
	jQuery("#login_form").bind("submit", function() {
		if (jQuery("#agree_statementoffaith").attr('checked')) {
			var pathtodotnetnuke;
			if(dotnetnukelocation == "church") {
				pathtodotnetnuke = basePath + "Registration/Church.aspx";
			} else if(dotnetnukelocation == "business") {
				pathtodotnetnuke = basePath + "Registration/Business.aspx";
			} else if(dotnetnukelocation == "community") {
				pathtodotnetnuke = basePath + "Registration/Organization.aspx";
			} else if(dotnetnukelocation == "individual") {
				pathtodotnetnuke = basePath + "Registration/Individual.aspx";
			} else {
				pathtodotnetnuke = basePath + dotnetnukelocation + ".aspx"
			}
			
			jQuery("#login_form").attr("action", pathtodotnetnuke);
			href="Registration/Church.aspx"
			

		    return true;
		} else {
			jQuery("#sof_error").show();
		    return false;	
		}

	});
	
	
	jQuery("a.missionandvisionstatement").click(function() {
		jQuery('li#aboutUs').click();
		jQuery('li#menu_ourvisionmission').click();
		
	});
	
	jQuery('#page-wrap').fadeIn(
		fadeTime,
		function callback() {
	    	jQuery('.slideshow').cycle({
				//fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			});
		}
	);

	jQuery('#whatIsCommChap').fadeIn(fadeTime);
	jQuery('#churchLeaders').fadeIn(fadeTime);
	jQuery('#socialmedia').fadeIn(fadeTime);
	jQuery('#neighborhood').fadeIn(fadeTime);
	jQuery('#fadein').fadeIn(fadeTime);

	var cssObj = '';
	
	
	hideAll();


	jQuery('#menu_about_home').click(function() {
		gotoHome();
	});
	jQuery('#gettingstarted_menu_home').click(function() {
		gotoHome();
	});
	jQuery('#connectonline_home').click(function() {
		gotoHome();
	});

	//Masthead click
	jQuery('#masthead').click(function() {
		hideAll();
		jQuery('#menutriangleclick').remove();
		jQuery('#homePage').show();
		if(jQuery.browser.msie) {
			if(jQuery('#businessLeaders').css('margin-left') == '475px') {
				jQuery('#businessLeaders').css('margin-left','476px');
			} else {
				jQuery('#businessLeaders').css('margin-left','475px');
			}
		}
		
	});
	
	// goto products page
	jQuery('.gotoproductspage').click(function() {
		jQuery('#gettingStarted').click();
		jQuery('#section_gettingstarted_products').show();
		jQuery('#section_gettingstarted_landing').hide();
	});
		
	/* Viewbook */
	jQuery('.viewbook').click(function() {
		    var options = {
		        caption: 'View Book',
		        center_win: false,
		        height: 625 || 625,
		        width: 468 || 468,
		        fullscreen: false,
				top: 0,
				show_loading: true,
				overlay_click_close: false,
		        callback_fn: viewbook()
		    }
			
		    var win = new GB_Window(options);
			
			
		    win.show('../../bookview/viewbook.html');
			jQuery(".header").hide();
			
			return false;
			
	 });
	 
	 function viewbook() {
		
	 }
	 
	 /* MP3 Player */
	 jQuery('.listen').click(function() {
		openmp3player();	
	 });
	 
	 jQuery('.listenimpact').click(function() {
		openmp3playerimpact();	
	 });
	 
	 
	 
	//Goto Business partner
	jQuery('#linktobusinesspartner').click(function() {
		jQuery('#gettingStarted').click();
		jQuery('img#businesspartnermenuimage').click();	
	});
	
	
	jQuery('#businessLeaders').click(function() {
		jQuery('li#gettingStarted').click();
		jQuery('img#businesspartnermenuimage').click();
		
	});
		
	//START home page menu
	jQuery('#privacypolicylink').click(function() {
		hideAll();
		
		//Set the triangle
		jQuery('#menutrianglehover').remove();
		jQuery('#menutriangleclick').remove();
		
		jQuery('#homePage').hide();
		jQuery('#privacypolicy').show();
	});
	
	jQuery('li#aboutUs').hover(
		function() {
			//Check to see if we have already clicked
			if(jQuery('li#aboutUs a img').length == 0) {	
				//Set the triangle
				jQuery('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo(jQuery('#aboutUs a'));
			}
		},
		function() {
			jQuery('#menutrianglehover').remove();
		}
	);

	jQuery('li#aboutUs').click(function() {
		jQuery('#homePage').hide();
		jQuery('#section_gettingstarted').hide();
		jQuery('#section_connectonline').hide();
		jQuery('#section_whatisacommunitychaplain').hide();
		
		jQuery('#section_aboutus').show();
		jQuery('#section_aboutus_landing').show();
		jQuery('#section_aboutus_story').hide();
		jQuery('#section_aboutus_vision_mission').hide();
		jQuery('#section_aboutus_sof').hide();
		jQuery('#section_aboutus_faq').hide();
		jQuery('#privacypolicy').hide();
		
		//Set the triangle
		jQuery('#menutrianglehover').remove();
		jQuery('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo(jQuery('#aboutUs a'));
	
		//Set the state of the menu
		jQuery('#aboutMenu ul li a').css(cssObj_menuInactiveState);
		

		
		clearAllMenuItems();
	});
	
	jQuery('#gettingStarted').hover(
		function() {
			//Check to see if we have already clicked
			if(jQuery('li#gettingStarted a img').length == 0) {
				//Set the triangle
				jQuery('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo(jQuery('#gettingStarted a'));
			}
		},
		function() {
			jQuery('#menutrianglehover').remove();
		}
	);

	jQuery('li#gettingStarted').click(function() {
		jQuery('#homePage').hide();
		jQuery('#section_aboutus').hide();
		jQuery('#section_gettingstarted').show();
		jQuery('#section_connectonline').hide();
		jQuery('#section_whatisacommunitychaplain').hide();
		
		jQuery('#section_gettingstarted_landing').show();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
		jQuery('#privacypolicy').hide();
		
		//Set the triangle
		jQuery('#menutrianglehover').remove();
		jQuery('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo(jQuery('#gettingStarted a'));
		
		//Set the state of the menu
		jQuery('#gettingstartedMenu2 ul li a').css(cssObj_menuInactiveState);
		
		clearAllMenuItems();
	});
	
	jQuery('#connectOnline').hover(
		function() {
			//Check to see if we have already clicked
			if(jQuery('li#connectOnline a img').length == 0) {
				//Set the triangle
				jQuery('#menutrianglehover').remove();
				getTriangleImageObjectOnHover().appendTo(jQuery('#connectOnline a'));
			}
		},
		function() {
			jQuery('#menutrianglehover').remove();
		}
	);

	jQuery('li#connectOnline').click(function() {
		jQuery('#homePage').hide();
		jQuery('#section_gettingstarted').hide();
		jQuery('#section_aboutus').hide();
		jQuery('#section_whatisacommunitychaplain').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#privacypolicy').hide();
		
		jQuery('#section_connectonline').show();
		
		//Set the triangle
		jQuery('#menutrianglehover').remove();
		jQuery('#menutriangleclick').remove();
		getTriangleImageObjectOnClick().appendTo(jQuery('#connectOnline a'));
		
		clearAllMenuItems();
	});
	
	//END home page menu
	
	//START Sub menu actions About Us
	jQuery('li#menu_ourstory').click(function() {
		jQuery('#section_aboutus_story').show();
		jQuery('#section_aboutus_landing').hide();
		jQuery('#section_aboutus_vision_mission').hide();
		jQuery('#section_aboutus_sof').hide();
		jQuery('#section_aboutus_faq').hide();
	});
	jQuery('li#menu_ourvisionmission').click(function() {
		jQuery('#section_aboutus_story').hide();
		jQuery('#section_aboutus_landing').hide();
		jQuery('#section_aboutus_vision_mission').show();
		jQuery('#section_aboutus_sof').hide();
		jQuery('#section_aboutus_faq').hide();
	});
	jQuery('li#menu_ourstatementoffaith').click(function() {
		jQuery('#section_aboutus_story').hide();
		jQuery('#section_aboutus_landing').hide();
		jQuery('#section_aboutus_vision_mission').hide();
		jQuery('#section_aboutus_faq').hide();
		jQuery('#section_aboutus_sof').show();
	});
	jQuery('li#menu_faq').click(function() {
		jQuery('#section_aboutus_story').hide();
		jQuery('#section_aboutus_landing').hide();
		jQuery('#section_aboutus_vision_mission').hide();
		jQuery('#section_aboutus_sof').hide();
		jQuery('#section_aboutus_faq').show();
	});
	
	
	//pppppppppppppppppppppppp
	jQuery('ul.menusmall img').hover(
			function() {
				var src = jQuery(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";
					jQuery(this).attr("src", src);	
				}
			},
			function() {
				var src = jQuery(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 (jQuery(this).attr("isclicked") != "true") {
						//replace off src with on src
						src = src.substring(0, src.length-6);
						src = src + "off.png";
						jQuery(this).attr("src", src);	
					}
				}
			}
		);
		
		jQuery('ul.menusmall img').click(function() {
			var src = jQuery(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
			jQuery( "ul.menusmall img" ).each(function(){
				jQuery(this).attr("isclicked", "false");		
			});
			
			jQuery(this).attr("isclicked", 'true');
			jQuery(this).attr("src", src);		
		});
	
	function clearAllMenuItems() {
		jQuery("ul.menusmall img").each(function(){
			var tempsrc = jQuery(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";
				jQuery(this).attr("src", tempsrc);	
			}
		});
	}
	
	
	//ppppppppppppppppppppppppppppppppppppp
	
	
	

	//END Sub menu actions About Us
	
	//START Sub menu actions Getting Started 
	jQuery('li#menu_amiqualified').click(function(event) {
		jQuery('#section_amiqualified').show();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_howdoigetstarted').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_howdoigetstarted').show();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_communitypartner').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').show();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_churchpartner').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').show();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_businesspartner').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').show();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_products').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').show();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').hide();
	});
	jQuery('li#menu_individual').click(function() {
		jQuery('#section_amiqualified').hide();
		jQuery('#section_products').hide();
		jQuery('#section_howdoigetstarted').hide();
		jQuery('#section_communitypartner').hide();
		jQuery('#section_churchpartner').hide();
		jQuery('#section_gettingstarted_landing').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_businesspartner').hide();
		jQuery('#section_individual').show();
	});
	
	

	//END Sub menu actions Getting Started
	
	
	// START Home Page
	jQuery('img#whatIsCommChap').click(function() {
		jQuery('li#aboutUs').click();
	});
	jQuery('img#churchLeaders').click(function() {
		jQuery('li#gettingStarted').click();
		jQuery('#img_menu_churchpartner').click();
	});
	
	
	//END Home Page
	
	//START fixed menu
	jQuery('div#fixedmenu').click(function() {
		
	});
	//END fixed menu
	
	//fixed postion div
    jQuery('#fixedmenu').css('top', 0 + "px");
    
	jQuery(window).scroll(function() {
	    jQuery('#fixedmenu').css('top', jQuery(this).scrollTop() + "px");
	});
	
	//Get the Url Parameter(.NetNuke)
	var page = getUrlVars()["page"];
	if (page == 'aboutus') {
		jQuery('li#aboutUs').click();
	} else if (page == 'gettingstarted') {
		jQuery('#gettingStarted').click();
	} else if (page == 'connectonline') {
		jQuery('#connectOnline').click();
	}
	
	function gotoHome() {
		hideAll();
		clearAllMenuItems();
		jQuery('#homePage').show()
	}
	
	function hideAll() {
		jQuery('#section_aboutus').hide();
		jQuery('#section_aboutus_story').hide();
		jQuery('#section_aboutus_vision_mission').hide();
		jQuery('#section_aboutus_sof').hide();
		jQuery('#section_aboutus_faq').hide();
		jQuery('#section_gettingstarted').hide();
		jQuery('#section_connectonline').hide();
		jQuery('#section_gettingstarted_products').hide();
		jQuery('#section_whatisacommunitychaplain').hide();	
		jQuery('#privacypolicy').hide();
		
	}
	
	var isSafari3 = null;
	if( window.devicePixelRatio &&  window.getMatchedCSSRules ){
		//you need 	put html {list-style-image:none;} in yout Safari 3 only stylesheet first
		//we detect whether if it's Safari 3 by checking if it read some Safari 3 only styles 
		isSafari3  =  !!window.getMatchedCSSRules(document.documentElement,'');
	}

	if (isSafari3) {
		jQuery("head").append("<link>");
	    var css = jQuery("head").children(":last");
	    css.attr({
	      rel:  "stylesheet",
	      type: "text/css",
	      href: "css/webkit.css"
	    });

	}
});

/* Get url paramenter Example: var meParameter = getUrlVars()["me"]; */
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function getTriangleImageObjectOnClick() {
	return jQuery('<img id="menutriangleclick" class="menutriangle" src="images/menu/menu_triangle.png" />');function openmp3player() {
	var mywindow = window.open('mp3/mp3.html', null,"status=no,toolbar=no,menubar=no,width=200,height=100");
	mywindow.moveTo(0,250);
	//window.open('mp3/mp3.html', 'MP# Player', 'height=100, width=200, innerHeight=100, innerWidth=200, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no', 'false');
}
}

function getTriangleImageObjectOnHover() {
	return jQuery('<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'});
}

/* Viewbook */
function viewbookClose() {
	jQuery('#GB_window').remove();
	//jQuery('#viewbook_selected img').attr("src", viewbookoff);
	viewbook_selected = false;
	viewbook_ishovered = false;
	jQuery('#GB_overlay').css('z-index', -1);
	
}

function openmp3player() {
	var mywindow = window.open('mp3/mp3.html', null,"status=no,toolbar=no,menubar=no,width=200,height=100");
	mywindow.moveTo(0,250);
	//window.open('mp3/mp3.html', 'MP# Player', 'height=100, width=200, innerHeight=100, innerWidth=200, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no', 'false');
}

function openmp3playerimpact() {
	var mywindow = window.open('mp3/mp3impact.html', null,"status=no,toolbar=no,menubar=no,width=300,height=180");
	mywindow.moveTo(0,250);
	//window.open('mp3/mp3.html', 'MP# Player', 'height=180, width=300, innerHeight=180, innerWidth=300, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no', 'false');
}

	
