/*  Drop down menu
************************************************
*/
function startList(nav) {
  if (document.all&&document.getElementById(nav)) {
    navRoot = document.getElementById(nav);
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
        node.onmouseover=function() {
          this.className+=" over";
          this.style.zIndex=200;
        }
        node.onmouseout=function() {
          this.className=this.className.replace(" over", "");
          this.style.zIndex=0;
        }
      }
    }
  }
}
/*  Ajax stuff
************************************************
*/
// Initialize the object:
var ajax = false;
// Choose object type based upon what's supported:
if (window.XMLHttpRequest) {
	// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
	ajax = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Older IE browsers
	// Create type Msxml2.XMLHTTP, if possible:
	try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e1) { // Create the older type instead:
		try {
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e2) { }
	}
}

// Send an alert if the object wasn't created.
if (!ajax) {
	alert ('Some page functionality is unavailable.');
}

function check_code(code) {
	
	// Confirm that the object is usable:
	if (ajax) { 
		// Call the PHP script.
		// Use the GET method.
		// Pass the username in the URL.
		ajax.open('get', 'check_code.php?code=' + encodeURIComponent(code));
		// Function that handles the response:
		ajax.onreadystatechange = handle_check;
		// Send the request:
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('code_label').innerHTML = 'The availability of this username will be confirmed upon form submission.';
	}
} // End of check_username() function.

// Function that handles the response from the PHP script:
function handle_check() {
	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
		// Assign the returned value to a document element:
		document.getElementById('code_label').innerHTML = ajax.responseText;
	}
} // End of handle_check() function.

function check_search(code) {

	if (ajax) { 
		ajax.open('get', 'check_search.php?search=' + encodeURIComponent(code));
		ajax.onreadystatechange = handle_search;
		// Send the request:
		ajax.send(null);
	} else { // Can't use Ajax!
		document.getElementById('searchResultsContent').innerHTML = 'The availability of this username will be confirmed upon form submission.';
  }
}

function handle_search() {
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
		document.getElementById('searchResultsContent').innerHTML = ajax.responseText;
	}
}

/* - Forum Mootools - */
window.addEvent('domready', function() {
  if ($chk($('submitThreadDiv'))) {
  	var submitThread = new Fx.Slide('submitThreadDiv');
  	submitThread.hide();
  	$('submitThread').addEvent('click', function(e){
  		e = new Event(e);
  		submitThread.toggle();
  		e.stop();
  	});	
  }
  if ($chk($('loginDiv'))) {
    var loginDiv = new Fx.Slide('loginDiv');
    loginDiv.hide();
    $('login').addEvent('click', function(e){
      e = new Event(e);
      loginDiv.toggle();
      e.stop();
    });
  }
  if ($chk($('submitPostDiv'))) {
    var submitPost = new Fx.Slide('submitPostDiv');
    submitPost.hide();
    $('submitPost').addEvent('click', function(e) {
      e = new Event(e);
      submitPost.toggle();
      e.stop();
    });
  }
});

/* - Home Page Sliders - */
window.addEvent('domready', function() {

  if ($chk($('forumslide'))) {
    var forumSlide = new Fx.Slide('forumslide');
    forumSlide.hide();
    $('forumslidelink').addEvent('click', function(e) {
      e = new Event(e);    
      forumSlide.toggle();
      e.stop();
    });
  }
  
    if ($chk($('topslide'))) {
    var topSlide = new Fx.Slide('topslide');
    topSlide.hide();
    $('topslidelink').addEvent('click', function(e) {
      e = new Event(e);    
      topSlide.toggle();
      e.stop();
    });
  }

});

/*  This always goes at the bottom
************************************************
*/
function init() {
  //forum();
  startList('nav');
}