FastInit.addOnLoad ( 	

						//regular stuff
						clickToAddCommentEvents , 
						formFocusEvents,
						InitialiseMap,

						//admin stuff		
						//clickToAddNewsEvents,
                        //clickToAddImageEvents,
                        clickToAddStuffEvents,
						//clickToEditNewsEvents, 
						//clickToDeleteNewsEvents, 

                        buttonEvents,
                        //testing,
						//clickToApproveCommentEvents, 
						//clickToEditCommentEvents, 
						//clickToDeleteCommentEvents, 

						fadeAdminMessage,
						sendMessageNotify			
					);

function sendMessageNotify ()
{

    if ( location.href.match("contact") )
    {
		var input = document.getElementById('sendMessage')
		input.onclick = function()
		{
			//alert ("test");
			input.value = "Sending message... please wait";
			//input.disabled = true;
		}
	}
}



function testing ()
{
    var lis = document.getElementsByTagName ( 'li' ) ;    //Read all input tags on the page
    for ( var i=0 ; i < lis.length ; i++ )                 //Go thru all said input tags
    {
        switch ( lis[i].className )
        {
            case 'addGallery':
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    //alert ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
                }
            break;
        }
    }
    return false;
}


function buttonEvents( buttonAction, buttonIsFor ) 
{
    var lis = document.getElementsByTagName ( 'li' ) ;     //Read all li tags on the page
    for ( var i=0 ; i < lis.length ; i++ )                 //Go thru all said li tags
    {
        switch ( lis[i].className )
        {
            case 'delete_news':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this news item'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
                };
            break;
            
            case 'edit_news':
                lis[i].onmouseover =
                function()
                { window.status = 'Edit this news item'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };    
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown ( getNextSibling ( getNextSibling ( this.parentNode.parentNode ) ) , {duration:0.5});
                }
            break;

            case 'delete_gallery':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this gallery'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
                };

            break;
            
            case 'edit_gallery':
                lis[i].onmouseover =
                function()
                { window.status = 'Edit this gallery'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };    
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown ( getNextSibling ( getNextSibling ( this.parentNode.parentNode ) ) , {duration:0.5});
                }
            break;
            
            case 'delete_link':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this link'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };
                
                lis[i].onclick =
                function()
	                {
	                    //new Effect.DropOut ( this.parentNode.parentNode.parentNode );
                    	new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode.parentNode ) , {duration:0.5});
                	};
            break;
            
            case 'edit_link':
                lis[i].onmouseover =
                function()
                {
                	window.status = 'Edit this link'; 
                };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };    
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown ( getNextSibling ( getNextSibling ( this.parentNode.parentNode.parentNode ) ) , {duration:0.5});
                }
            break;

            case 'approve_new comment':
                lis[i].onmouseover =
                function()
                { window.status = 'Approve this comment'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };

                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode.parentNode ) , {duration:0.5});
                };
            break;

            case 'delete_new comment':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this comment'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };

                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling( getNextSibling ( this.parentNode.parentNode.parentNode ) ), {duration:0.5});
                };
            break;


            case 'delete_comment':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this comment'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };

                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
                };    
            break;

            case 'delete_image':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this image'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };

                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
                };    
            break;
            
            case 'edit_image':
                lis[i].onmouseover =
                function()
                { window.status = 'Edit this image\'s details'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };    
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown ( getNextSibling ( getNextSibling ( this.parentNode.parentNode ) ) , {duration:0.5});
                }
            break;
 
            case 'delete_email':
                lis[i].onmouseover =
                function()
                { window.status = 'Delete this email'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };

                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode.parentNode ) , {duration:0.5});
                };    
            break;
     
            case 'edit_comment':
                lis[i].onmouseover =
                function()
                { window.status = 'Edit this comment'; };
                
                lis[i].onmouseout =
                function()
                { window.status = ''; };
                
                lis[i].onclick =
                function()
                {
                    new Effect.DropOut ( this.parentNode.parentNode );
                    new Effect.SlideDown ( getNextSibling ( getNextSibling ( this.parentNode.parentNode ) ) );
                };
            break;
            
        }
    }
    return false;
}


function clickToAddStuffEvents()
{
    var lis = document.getElementsByTagName ( 'li' ) ;    //Read all input tags on the page
    for ( var i=0 ; i < lis.length ; i++ )                 //Go thru all said input tags
    {
        if ( lis[i].className == 'addGallery' || lis[i].className == 'addImage'  || lis[i].className == 'addNews' )
        {           
            lis[i].onclick =
            function()
            {
                new Effect.DropOut ( this.parentNode.parentNode );
                new Effect.SlideDown  ( getNextSibling ( this.parentNode.parentNode ) , {duration:0.5});
            }
        }
    }
    return false;
}

function fadeAdminMessage()
{
    if (document.getElementById("adminMessage")) 
    {
        var adminMessageDiv = document.getElementById('adminMessage');
        if ( adminMessageDiv.className != 'nofade' )
        {
            /*new Effect.Pulsate ( adminMessageDiv, { duration : 2 });
            test=setTimeout ( "new Effect.Fade ( document.getElementById('adminMessage'), { duration : 2 });", 4000 );
            test=setTimeout ( "document.getElementById('adminMessage').childNodes.item(0).data = \"Currently logged in as staff member\"", 6000);
            test=setTimeout ( "new Effect.Appear ( document.getElementById('adminMessage'), { duration : 2 });", 6000 );*/
        }
    }
}

function createMarker(point, html)
{
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
	return marker;
}

function hideForms()
{
    var divs = document.getElementsByTagName ( 'div' ) ;    //Read all input tags on the page
    for ( var i=0 ; i < divs.length ; i++ )                 //Go thru all said input tags
    {
        if ( divs[i].className == 'clickToHideForm' )
        {
            previousSibling = getPreviousSibling ( divs[i] );
            new Effect.Fade ( divs[i], { duration : 0.1 } )
            new Effect.SlideUp ( previousSibling, { duration : 0.1 } );
        }
    }
    return false;
}

function clickToAddCommentEvents()
{
    var divs = document.getElementsByTagName ( 'div' ) ;    //Read all input tags on the page
    for ( var i=0 ; i < divs.length ; i++ )                 //Go thru all said input tags
    {
        switch ( divs[i].className )
        {
            case 'clickToAddComment':
                divs[i].onclick = 
                function()
                {
                    nextSibling = getNextSibling ( this );
                    new Effect.DropOut ( this )
                    new Effect.SlideDown ( nextSibling,  {duration:1} );
                };
            break;
            
            case 'clickToHideForm':
                divs[i].onclick = 
                function()
                {   
                    previousSibling = getPreviousSibling ( this );
                    new Effect.Fade ( this )
                    new Effect.SlideUp ( previousSibling );
                };
            break;  
        }
    }
    return false;
}

function InitialiseMap()
{
    if ( location.href.match("location") )
    {
    	var RJC = new GPoint(-0.9483, 53.3272);
    	var CTR = new GPoint(-0.9455, 53.3232); 
    
    	var map = new GMap(document.getElementById("map"));
    	map.addControl(new GLargeMapControl());
    	map.centerAndZoom(CTR, 3);
       
    	var html = '<p class="infoBox"><strong>Retford Judo Club</strong><br />Army Cadet Centre<br />Hallcroft Road<br />Retford<br />Notts<br /> DN22 7LB</p>';
    	var markerS = createMarker(RJC, html)
    	map.addOverlay(markerS);
    }
};

function formFocusEvents()
{
	var forms = document.getElementsByTagName( 'form' );
	for( var f=0; f < forms.length; f++ )
	{	
		var inputs = forms[f].getElementsByTagName( '*' );
		for( var i=0; i < inputs.length; i++ )
		{
			switch ( inputs[i].type )
			{
				case 'submit':
					inputs[i].onmousedown = function()
					{
				    	mousedownFormButton (this);	
					};
					inputs[i].onsubmit = function()
					{
				    	submittedFormButton (this);	
					};		
				break;
					
				case 'text':
					inputs[i].onfocus = function()
					{
				    	activeFormInput (this);	
					};
					inputs[i].onblur = function()
					{
				    	inactiveFormInput (this);	
					};	
				break;	
				
				case 'textarea':
					inputs[i].onfocus = function()
					{
				    	activeFormInput (this);	
					};
					inputs[i].onblur = function()
					{
				    	inactiveFormInput (this);	
					};
				break;	
				
				case 'password':
					inputs[i].onfocus = function()
					{
				    	activeFormInput (this);	
					};
					inputs[i].onblur = function()
					{
				    	inactiveFormInput (this);	
					};
				break;
				
				case 'button':
					inputs[i].onclick = function()
					{
						new Effect.SlideDown ( document.getElementById("messageBox"), { duration : 0.5 });
					};
				break;				
				
				case 'radio':
					inputs[i].onclick = function()
					{
						var wrongDivs = new Array();
						switch ( this.value )
						{
							case 'history':
								wrongDivs[0] = 'joining';
								wrongDivs[1] = 'running';
								wrongDivs[2] = 'press';
								wrongDivs[3] = 'other';
							break;
							
							case 'joining':
								wrongDivs[0] = 'history';
								wrongDivs[1] = 'running';
								wrongDivs[2] = 'press';
								wrongDivs[3] = 'other';
							break;
							
							case 'running':
								wrongDivs[0] = 'joining';
								wrongDivs[1] = 'history';
								wrongDivs[2] = 'press';
								wrongDivs[3] = 'other';
							break;
							
							case 'press':
								wrongDivs[0] = 'joining';
								wrongDivs[1] = 'running';
								wrongDivs[2] = 'history';
								wrongDivs[3] = 'other';
							break;
							
							case 'other':
								wrongDivs[0] = 'joining';
								wrongDivs[1] = 'running';
								wrongDivs[2] = 'press';
								wrongDivs[3] = 'history';
							break;
						}
						//alert ( this.value );
						for( var j=0; j < wrongDivs.length; j++ )
//						for ( x in wrongDivs )
						{
							//alert ( wrongDivs[j] );
							//new Effect.SlideUp ( document.getElementById(x));
						}
						
						if ( this.value == "other" )
						{
							new Effect.SlideDown ( document.getElementById("messageBox"), { duration : 0.5 });	
						}
						else
						{
							new Effect.SlideDown ( document.getElementById(this.value), { duration : 0.5 });
							test=setTimeout ( "new Effect.Appear ( document.getElementById('furtherQuestion'));", 3000 );
						}
					};
				break;	
				
				case 'default':
					;
				break;	
			}
		}
	}
}

function activeFormInput ( element )
{
	if ((element.value.indexOf ("in this box")) != -1)
	{
		element.value="";
	}
	element.style.backgroundColor="#F5F5C9";
}

function inactiveFormInput ( element )
{
	element.style.backgroundColor="#E0FFDB";
}

function submittedFormButton ( element )
{
	element.disabled=true;
}

function mousedownFormButton ( element )
{
	element.style.backgroundColor="#ff6464";
}

function getNextSibling (startBrother)
{
	endBrother=startBrother.nextSibling;
	while(endBrother && (endBrother.nodeType!=startBrother.nodeType))
	{
		endBrother = endBrother.nextSibling;
	}
	return endBrother;
}

function getPreviousSibling(n)
{
	var x=n.previousSibling;
	while (x.nodeType!=1)
	{
		x=x.previousSibling;
	}
	return x;
}