/**
 * HIJAX ACTIONS
 */
/**
 * Initialize Community page onload events
 */
initCommunity = function(){
	/**
	 * Contact Module Content Event Listener
	 */
	var communityContactHijaxLink = $$('.communityContactHijaxLink');
	communityContactHijaxLink.each(
		function(el){
			// Bind showHijaxElement function to each hijaxLink click event
			Event.observe(el, 'click', showContactModule.bind());


		}
	);

	var contactHijaxMain = $$('.contactHijaxMain');
	contactHijaxMain.each(
		function(el){
			// Bind showHijaxElement function to each hijaxLink click event
			Event.observe(el, 'click', showMainContactModule.bind());
		}
	);

	var subCommTabHijaxLinks = $$('.subCommTabHijax');
	subCommTabHijaxLinks.each(

		function(el){

			Event.observe(el, 'click', getSubCommInfo.bind());
		}
	);

}
// Add the init function to the array of init functions (See hijax.js)
initFunctions.push('initCommunity');


function getSubCommInfo(el){
	if($('overviewDropdown').getStyle('display') == 'none'){
		$('overviewDropdown').setStyle({display:'block'});
	}
	if($('contactDropdown').getStyle('display') == 'block'){
		$('contactDropdown').setStyle({display:'none'});
	}
	var updateDiv = $('communityOverviewText');
	var url = this.href;
	new Ajax.Updater(updateDiv, url, {
		method: 'get',
		evalScripts: true
	});
	// Stop the window from spawning
	Event.stop(el);
	return false;
}

function showContactModule(el){
	var updateDiv = 'contactModuleBox';
	if($('contactModuleBox').getStyle('display') != 'block'){
		// Show the update div
		$(updateDiv).setStyle({display:'block'});
		// The url is in the a href attribute

		if(!Event.element(el).href){
			var ancestor = Event.element(el).ancestors();
			//alert(ancestor[0]);
			var url = ancestor[0].href + '&hijax=true';
		}else{
			var url = Event.element(el).href + '&hijax=true';
		}
		//alert(url);

		// The div to update with the ajax response content
		// This will be the next div named hijaxContainer (next div from the hijaxLink)
		// var updateDiv = this.next('.hijaxContent');

		/*alert(updateDiv.id);
		Event.stop(el);
		return false;
		*/
		// Make the ajax request
		//alert(updateDiv.id);
		new Ajax.Updater(updateDiv, url, {
			method: 'get',
			evalScripts: true
		});

	}else{
		$('contactModuleBox').setStyle({display:'none'});
	}
	// Stop the window from spawning
	Event.stop(el);
	return false;
}


function showMainContactModule(el){
	//alert(el);
	var updateDiv = this.up('.hijaxWrapper').down('.hijaxContent');
	if($('contactDropdown').getStyle('display') != 'block'){
		// The url is in the a href attribute
		if(!Event.element(el).hasClassName('hijaxLink')){
			var ancestor = Event.element(el).ancestors();
			//Get the containing a href
			var url = ancestor[0].href + '&hijax=true';
		}else{
			var url = Event.element(el).href + '&hijax=true';
			//alert(url);
		}
		// The div to update with the ajax response content
		// This will be the next div named hijaxContainer (next div from the hijaxLink)
		// var updateDiv = this.next('.hijaxContent');

		/*alert(updateDiv.id);
		Event.stop(el);
		return false;
		*/
		// Make the ajax request
		//alert(updateDiv.id);
		new Ajax.Updater(updateDiv, url, {
			method: 'get',
			evalScripts: true,
			onSuccess: function(transport) {
				$('contactDropdown').setStyle({display:'block'});
				$('overviewDropdown').setStyle({display:'none'});
				$('overviewTabButton').innerHTML = "+";
			}
		});
		// Show the update div
		$(updateDiv).setStyle({display:'block'});
		$('contactTabButton').innerHTML = "-";

	}else{
		$('contactDropdown').setStyle({display:'none'});
		$('contactTabButton').innerHTML = "+";
	}
s.events = "event1";
s.eVar20 = 'regular contact module';
s.t();

	// Stop the window from spawning
	Event.stop(el);
	return false;
}

