var calWin	= null

var handle = null
var event_handle = null


//---------------------------
function hbTopMenu(pageHref){

	var bottomPane 	= dijit.byId("body_content");
	
	if(pageHref != "page_home.html"){
		dojo.disconnect(event_handle)
	}
	
	switch(pageHref){
		
		case "page_home.html":

			bottomPane.attr("href", pageHref);
			
			break;
		
		case "page_contact_us.html":
			
			body_right_href = pageHref;
			bottomPane.attr("href", "asaol_main.html");
			
			break;

		case "page_links.html":
			
			body_right_href = pageHref;
			bottomPane.attr("href", "asaol_main.html");
			
			break;
	
		case "the_good_news.html":
			
			body_right_href = pageHref;
			bottomPane.attr("href", "asaol_main.html");
			
			break;			
	}
}


//-------------------------------------------
function hbAboutMenu(menuLocation, pageHref){

	if(menuLocation == "top"){
		var bottomPane 	= dijit.byId("body_content");
		body_right_href = pageHref;
		bottomPane.attr("href","about_main.html");
	}else{
		var rightPane 	= dijit.byId("body_bottom_right_content");
		rightPane.attr("href", pageHref);
	}

}


//---------------------------------------------
function hbMissionMenu(menuLocation, pageHref){

	if(menuLocation == "top"){
		var bottomPane 	= dijit.byId("body_content");
		body_right_href = pageHref;
		bottomPane.attr("href","mission_main.html");
	}else{
		var rightPane 	= dijit.byId("body_bottom_right_content");
		rightPane.attr("href", pageHref);
	}

}


//-------------------------------------------
function hbAsaolMenu(menuLocation, pageHref){

	if(menuLocation == "top"){
		var bottomPane 	= dijit.byId("body_content");
		body_right_href = pageHref;
		bottomPane.attr("href","asaol_main.html");
	}else{
		var rightPane 	= dijit.byId("body_bottom_right_content");
		rightPane.attr("href", pageHref);
	}

}


//---------------------------------------------
function hbTheWordMenu(menuLocation, pageHref){
	
	if(menuLocation == "top"){
		var bottomPane 	= dijit.byId("body_content");
		body_right_href = pageHref;
		bottomPane.attr("href","asaol_main.html");
	}else{
		var rightPane 	= dijit.byId("body_bottom_right_content");
		rightPane.attr("href", pageHref);
	}
	
}


function fooBar2(){
	
	alert('Cancel');
}

//------------------------------------
function showPopUp(popTitle, popHref){
	
	var popUpPane = dijit.byId("hbPopUpBox");

	dojo.connect(dijit.byId("hbPopUpBox"), 
					"hide", 
					function(evt){
						dojo.destroy(dojo.byId('vidEmbed'));
					});	
	
	popUpPane.attr("href", popHref);
	popUpPane.attr("title", popTitle);
	popUpPane.show();
   	       	
}


/* old - for ez php calendar when not using their ajax options
//----------------------
function showCalendar(){

	if (calWin) {
		if (calWin.closed){
			// do nothing
		} else {
			calWin.focus()
		}
	}

	calWin=window.open('calendarhbc.php','userEditWindow','location=0,status=0,toolbar=0,scrollbars=0,resizable=0,top=200px,left=250px,width=350px,height=300px')
}
*/

//----------------------
function showCalendar(){
	
	var calButton = document.getElementById("calendarButton");
	var x = findPosX(calButton);
	var y = findPosY(calButton);
	
	// align above and left of button
	x = x - 350;
	y = y - 590;

	var calPane = document.getElementById('calendarPopUp');
	calPane.style.left = x + "px";
	calPane.style.top = y + "px";
	calPane.style.display = 'block';
}


//----------------------
function hideCalendar(){
	
	var calPane = document.getElementById('calendarPopUp');
	calPane.style.display = 'none';
}


//---------------------
function findPosX(obj){
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}


//---------------------
function findPosY(obj){
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

//------------------------
function mouseOverImage(obj, picSrc){
	obj.src = picSrc;     
}

//------------------------
function mouseOutImage(obj, picSrc){
	obj.src = picSrc;
}




//--------------------------
function pictureSlideShow(){	
    
	//picPane = dijit.byId("body_pictures");

	var slideDelay = 1000;
	var slideDuration = 1500;
	
	var imgTag1 = '<img src="images/flashbannerimgs/_flashimg1.jpg" alt="" width="640px" height="274px" hspace="0" vspace="0" border="0">';
	var imgBG1	= 'url(images/flashbannerimgs/_flashimg1.jpg) no-repeat top';

	var imgTag2 = '<img src="images/flashbannerimgs/_flashimg2.jpg" alt="" width="640px" height="274px" hspace="0" vspace="0" border="0">';
	var imgBG2	= 'url(images/flashbannerimgs/_flashimg2.jpg) no-repeat top';

	var imgTag3 = '<img src="images/flashbannerimgs/_flashimg3.jpg" alt="" width="640px" height="274px" hspace="0" vspace="0" border="0">';
	var imgBG3	= 'url(images/flashbannerimgs/_flashimg3.jpg) no-repeat top';

	var imgTag4 = '<img src="images/flashbannerimgs/_flashimg4.jpg" alt="" width="640px" height="274px" hspace="0" vspace="0" border="0">';
	var imgBG4	= 'url(images/flashbannerimgs/_flashimg4.jpg) no-repeat top';

	var imgTag5 = '<img src="images/flashbannerimgs/_flashimg5.jpg" alt="" width="640px" height="274px" hspace="0" vspace="0" border="0">';
	var imgBG5	= 'url(images/flashbannerimgs/_flashimg5.jpg) no-repeat top';
	
	//chain together some fades
	// PIC 1 -----------------------------------------------
    var pic1_fi = dojo.fadeIn({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.style("body_picture_background", "background", imgBG2);
		}	 
    });
	var pic1_fo = dojo.fadeOut({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.byId('body_pictures').innerHTML = imgTag2;
		}	 
    });
    var pic2_fi = dojo.fadeIn({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.style("body_picture_background", "background", imgBG3);
		}	 
    });
    
	// PIC 2 -----------------------------------------------
	var pic2_fo = dojo.fadeOut({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.byId('body_pictures').innerHTML = imgTag3;
		}	 
    });
    var pic3_fi = dojo.fadeIn({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.style("body_picture_background", "background", imgBG4);
		}	 
    });

	// PIC 3 -----------------------------------------------
	var pic3_fo = dojo.fadeOut({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.byId('body_pictures').innerHTML = imgTag4;
		}	 
    });
    var pic4_fi = dojo.fadeIn({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.style("body_picture_background", "background", imgBG5);
		}	 
    });

	// PIC 4 -----------------------------------------------
	var pic4_fo = dojo.fadeOut({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.byId('body_pictures').innerHTML = imgTag5;
		}	 
    });
    var pic5_fi = dojo.fadeIn({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.style("body_picture_background", "background", imgBG1);
		}	 
    });

	// PIC 5 -----------------------------------------------
	var pic5_fo = dojo.fadeOut({
		node: "body_pictures",
		delay: slideDelay,
		duration: slideDuration,
		onEnd: function(){
			dojo.byId('body_pictures').innerHTML = imgTag1;
		}	 
    });
    
    
    picture_slides = dojo.fx.chain([pic1_fo, pic2_fi, pic2_fo, pic3_fi, pic3_fo, pic4_fi, pic4_fo, pic5_fi, pic5_fo, pic1_fi]);

	handle = dojo.connect(picture_slides, "onEnd", function(){pictureSlideShow();});
    
    picture_slides.play();
        
};


//--------------------------
function eventsSlideShow(){	
    

	var eventSlideDelay = 2100;
	var eventSlideDuration = 1600;
	
	var eventImgTag1 	= '<a href="javascript:void(0)" onClick="hbAsaolMenu(\'top\',\'upcomingevents2.php\')"><img src="images/eventsbannerimgs/fathersoncamp.jpg" 	alt="" width="582" height="274" border="0"></a>';
	var eventImgBG1		= 'url(images/eventsbannerimgs/fathersoncamp.jpg) no-repeat top';

	var eventImgTag2 	= '<a href="javascript:void(0)" onClick="hbAsaolMenu(\'top\',\'upcomingevents3.php\')"><img src="images/eventsbannerimgs/menspa.jpg" 			alt="" width="582" height="274" border="0"></a>';
	var eventImgBG2		= 'url(images/eventsbannerimgs/menspa.jpg) no-repeat top';

	var eventImgTag3 	= '<a href="http://www.ncfic.org/sos" target="_blank"><img src="images/eventsbannerimgs/sos_banner.jpg" 										alt="" width="582" height="274" border="0"></a>';
	var eventImgBG3		= 'url(images/eventsbannerimgs/sos_banner.jpg) no-repeat top';

	
	//chain together some fades
	// PIC 1 -----------------------------------------------
    var eventPic1_fi = dojo.fadeIn({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.style("events_area_background", "background", eventImgBG2);
		}	 
    });
	var eventPic1_fo = dojo.fadeOut({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.byId('events_area').innerHTML = eventImgTag2;
		}	 
    });

    // PIC 2 -----------------------------------------------
    var eventPic2_fi = dojo.fadeIn({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.style("events_area_background", "background", eventImgBG3);
		}	 
    });
    
	var eventPic2_fo = dojo.fadeOut({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.byId('events_area').innerHTML = eventImgTag3;
		}	 
    });

    // PIC 3 -----------------------------------------------
    var eventPic3_fi = dojo.fadeIn({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.style("events_area_background", "background", eventImgBG1);
		}	 
    });
    
	var eventPic3_fo = dojo.fadeOut({
		node: "events_area",
		delay: eventSlideDelay,
		duration: eventSlideDuration,
		onEnd: function(){
			dojo.byId('events_area').innerHTML = eventImgTag1;
		}	 
    });    
    
    var event_slides = dojo.fx.chain([eventPic1_fo, eventPic2_fi, eventPic2_fo, eventPic3_fi, eventPic3_fo, eventPic1_fi]);

	event_handle = dojo.connect(event_slides, "onEnd", function(){eventsSlideShow();});


    event_slides.play();
    
};


// Family Camp Registration ------------------
function sendRegistration(familyName){
	
		dojo.xhrPost({ 
	    
		form: dojo.byId("fcRegForm"), 
		
		url : 'upcomingevents.php?savemode=save&familyname=' + familyName, 
	    
		preventCache: true, 
		
		timeout: 15000, 

		handleAs: "text",
		
		// Run this function if the request is successful 
	    load : function(response, ioArgs) { 
	    	
	    	console.log("successful xhrPost", response, ioArgs); 
			
	    	// sending back sql result from PHP
	    	if(dojo.string.trim(response) == "success"){

	    		dojo.byId("id_resultText").innerHTML = "<br><span style='font-weight: bold; color: maroon;'>Your Email Registration has been sent. Thank you.</span>"
	
    			console.log(dojo.string.trim(response));	
    		
			}else{

    			// display error
				dijit.byId("hbPopUpBox").attr({
					title: "MAIL ERROR",
					content:	"<br><br><br>There was a problem sending your email.<br><br>Please try again.<br><br><br>"
				});
				dijit.byId("hbPopUpBox").show(  );
		
    			console.log(dojo.string.trim(response));	

    		}
			/* setTimeout("dojo.byId('tEventName').innerHTML = ''; dojo.style(dojo.byId('mcMsgRow'),'display','none');",1000); */
			return response; //always return the response back 
	    }, 
	
	    // Run this function if the request is not successful 
	    error : function(response, ioArgs) { 

			dijit.byId("hbPopUpBox").attr({
				title: "SERVER ERROR",
				content:	"<br><br><br>ERROR: There was a problem connecting with the server.<br><br>Please try again. <br><br><br>"
			});
			//dijit.byId("dialog").show(  );

	        console.log("failed xhrPost", dojo.string.trim(response), ioArgs);
	        return response; //always return the response back 
	    } 
	});
	

}



//BACKUP OF Father Son Registration.

function sendRegistration_BACKUP(fathersName){
	
		dojo.xhrPost({ 
	    
		form: dojo.byId("fcRegForm"), 
		
		url : 'upcomingevents3.php?savemode=save&fathersname=' + fathersName, 
	    
		preventCache: true, 
		
		timeout: 15000, 

		handleAs: "text",
		
		// Run this function if the request is successful 
	    load : function(response, ioArgs) { 
	    	
	    	console.log("successful xhrPost", response, ioArgs); 
			
	    	// sending back sql result from PHP
	    	if(dojo.string.trim(response) == "success"){

	    		dojo.byId("id_resultText").innerHTML = "<br><span style='font-weight: bold; color: maroon;'>Your Email Registration has been sent. Thank you.</span>"
	
    			console.log(dojo.string.trim(response));	
    		
			}else{

    			// display error
				dijit.byId("hbPopUpBox").attr({
					title: "MAIL ERROR",
					content:	"<br><br><br>There was a problem sending your email.<br><br>Please try again.<br><br><br>"
				});
				dijit.byId("hbPopUpBox").show(  );
		
    			console.log(dojo.string.trim(response));	

    		}
			/* setTimeout("dojo.byId('tEventName').innerHTML = ''; dojo.style(dojo.byId('mcMsgRow'),'display','none');",1000); */
			return response; //always return the response back 
	    }, 
	
	    // Run this function if the request is not successful 
	    error : function(response, ioArgs) { 

			dijit.byId("hbPopUpBox").attr({
				title: "SERVER ERROR",
				content:	"<br><br><br>ERROR: There was a problem connecting with the server.<br><br>Please try again. <br><br><br>"
			});
			//dijit.byId("dialog").show(  );

	        console.log("failed xhrPost", dojo.string.trim(response), ioArgs);
	        return response; //always return the response back 
	    } 
	});
	

}
