

// ==========  CODE FOR SMART TEMPLATE - Start  ====================================================================

/*
http://www.somedomain.gov.or.com.au/living-here/doing-business.jsp

http://www.somedomain.gov.or.com.au/council/about-council/organisation-structure.jsp
http://www.somedomain.gov.or.com.au/council/about-council/your-mayor.jsp
http://www.somedomain.gov.or.com.au/council/meetings-agendas/calendar.jsp
http://www.somedomain.gov.or.com.au/council/council-governance.jsp
http://www.somedomain.gov.or.com.au/council/council-projects.jsp
...

http://www.somedomain.gov.or.com.au/discover/no-subpage-as-yet.jsp
*/

// David To Do 1/2/2010 : Check if an /onka/ top level folder is inserted. Wait for static hybrid & proper URL to check this script.





// allFileFolderNames.length = 4 (four of '/')  :  means root level    :  https://elderscms.prod.groundhog.com.au/mysite/home.jsp
// allFileFolderNames.length = 5 (five of '/')  :  means 1 tier down   :  https://elderscms.prod.groundhog.com.au/mysite/documents/documents.jsp
// allFileFolderNames.length = 6 (six of '/')   :  means 2 tiers down  :  https://elderscms.prod.groundhog.com.au/mysite/documents/next-level/documents.jsp

// Info we want to return:
document.GHMajorSectionName = "";  // ie  'documents',  'home',  'agent-to-agent'  etc
document.GHNumOfLevels = 0; 	//    0 = home.jsp
								// ie 1 = documents.jsp
								//    2 = documents/subpage.jsp
								//    3 = documents/subfolder/subpage.jsp
								//    4 = documents/subfolder/subfolder/subpage.jsp
document.GHCleanSectionTitle = "";  // 'Agent to Agent:'
document.GHBannerNum = "";		// ie "1", "12" etc from a pool of banner images
document.GHParentBelowLvl3 = "";	// If a level 4+ page, this returns .../sub.jsp  from  .../sub/page.jsp  for use on the dynamic  ^- BACK
document.GHAdminMode = 0;		//    1 = In CMS Admin, so SHOW news release panels. URL  ...com.au/elders-main-template.jsp?xcid=92&edi..
document.GHProductSection = false;   // true if in /eib/products.jsp and subpages. Turns Sibling/Child links off.
document.GHUnderwritersSection = false;   // true if in /eib/underwriters.jsp and subpages. Turns Sibling/Child links off.





var hrefRaw = document.location.href; 
var hrefSplitOnVars = hrefRaw.split("?");  // **May cause probs if URLs with no filename "nnn/nnn/?vars.."
var hrefNoVars = hrefSplitOnVars[0];

//alert("hrefRaw = " + hrefRaw);
//alert("hrefNoVars = " + hrefNoVars);



// An old Elders fn. Not used yet but may come in handy.
/*
// Determine Parent Page for ^- Back Up button
function GHGetParentPage(sInputURL) {
	// Assume a valid URL and with no ?vars on end. ie https://elders..au/mysite/my-state/victoria-and-tasmania/fsl-stamp-duties/sa.jsp
	// Find last '/', Split BEFORE that & add .jsp
	sOutputURL = sInputURL.substr(0, sInputURL.lastIndexOf('/')) + ".jsp";
	return (sOutputURL);
}
document.GHParentBelowLvl3 = GHGetParentPage(hrefNoVars);
*/




// May not need this.
/*
// Determine one of Three Main Sections
// This is to set  1. Living Here,  2. Council,  3. Discover  top graphic menus to active or  0. None of these.
function GHGetMajorSectionName(sInputURL) {
	alert(sOutputURL);
	sOutputURL = sInputURL.substr(0, sInputURL.lastIndexOf('/')) + ".jsp";
}
document.GHMajorSectionNameName = GHGetMajorSectionName(hrefNoVars);
*/





// Start Counting the Levels:
var allFileFolderNames = hrefNoVars.split( "/" );

for ( var i = 2; i <= ( allFileFolderNames.length-1 ); i++ ) { 

	//alert(" i = " + i +"\n allFileFolderNames.length = " + (allFileFolderNames.length));


	// Prepare common variables for various tests below
	var sCurrentFileFoldername = allFileFolderNames [ i ];  //ie home.jsp  or  documents  or  documents.jsp
	//alert(sCurrentFileFoldername);
	var sFilenameSections = sCurrentFileFoldername.split( "." );
	

	if (i==3) {
	
		// Test for Admin Mode
		if (sCurrentFileFoldername == "onka-main-template---.jsp") {
				// We're in CMS Admin. URL has NO folder levels!  ...com.au/onka-main-template---.jsp?xcid=92&edi..
				document.GHAdminMode = 1;
		}
		
		// document.GHMajorSectionNameName = sCurrentFileFoldername;

// No /onka/ at top
//		document.GHMajorSectionName = sFilenameSections[0];

	} else if (i==4) {
	
		// Allowing for /onka/ at top
		document.GHMajorSectionName = sFilenameSections[0];

	} else if (i==5) {
		
		// Pull out sub level filename or folder (the one UNDER /living-here/ etc)
			
			//alert(" i = " + i +"\n sCurrentFileFoldername = " + sCurrentFileFoldername);
		
			//document.GHSubSectionName = sCurrentFileFoldername;
			

			//alert("sCurrentFileFoldername = " + sCurrentFileFoldername);
			//alert("within the level 1/2 test");
			if (sFilenameSections.length > 1) {
				
				//alert("within > 1");
					//alert(sFilenameSections.length);
				// It's likely a Filename not a Folder, ie 'about-council.jsp'
				document.GHSubSectionName = sFilenameSections[0];
				//document.GHNumOfLevels = 1;
			
			} else {
				
				// It's a folder for lower levels, ie /'about-council'/      // To Test: ... WORKS: https://elderscms.prod.groundhog.com.au/mysite/documents/carols-test-page.jsp
				document.GHSubSectionName = sFilenameSections[0];
				//document.GHNumOfLevels = 2;
				
			}

	}

}


//alert(" document.GHMajorSectionName = " + document.GHMajorSectionName + " \n\n sFilenameSections[0] = " + sFilenameSections[0] );				
//alert(" document.GHMajorSectionName = " + document.GHMajorSectionName + " \n\n document.GHSubSectionName = " + document.GHSubSectionName );				


// Clean up Title Prefix (goes at top of content section) & prepare Banner STYLE name for header image. 
if (document.GHMajorSectionName != "") {
	
	switch (document.GHSubSectionName) {
		
		// case "eia": 					document.GHCleanSectionTitle = "EIA";							document.GHBannerNum = "bannereib";					break;
		
		// LIVING HERE - Sub section titles
		case "doing_business":			document.GHCleanSectionTitle = "Doing business";				break;
		case "rates_property":			document.GHCleanSectionTitle = "Rates &amp; property";			break;
		case "planning_development":	document.GHCleanSectionTitle = "Planning &amp; development";	break;
		case "permits_regulations":		document.GHCleanSectionTitle = "Permits &amp; regulations";		break;
		case "pets_animals":			document.GHCleanSectionTitle = "Pets &amp; animals";			break;
		case "waste_recycling":			document.GHCleanSectionTitle = "Waste &amp; recycling";			break;
		case "libraries":				document.GHCleanSectionTitle = "Libraries";						break;
		case "community":				document.GHCleanSectionTitle = "Community";						break;
		case "our_environment":				document.GHCleanSectionTitle = "Our Environment";				break;
		
		// COUNCIL _ Sub section titles
		case "about_council":			document.GHCleanSectionTitle = "About Council";					break;
		case "meetings_agendas":		document.GHCleanSectionTitle = "Meetings &amp; Agendas";		break;
		case "council_governance":		document.GHCleanSectionTitle = "Council Governance";			break;
		case "council_projects":		document.GHCleanSectionTitle = "Council projects";				break;
		case "policies_strategies":		document.GHCleanSectionTitle = "Policies &amp; Strategies";		break;
		case "community_engagement":	document.GHCleanSectionTitle = "Community Engagement";			break;
		case "grants_awards":			document.GHCleanSectionTitle = "Grants &amp; Awards";			break;
		case "employment_tenders":		document.GHCleanSectionTitle = "Employment &amp; Tenders";		break;

		// DISCOVER _ Sub section titles
		case "food_wine":				document.GHCleanSectionTitle = "Food &amp; wine";				break;
		case "beaches":					document.GHCleanSectionTitle = "Beaches";						break;
		case "trails_recreation":		document.GHCleanSectionTitle = "Trails &amp; recreation";		break;
		case "research_statistics":		document.GHCleanSectionTitle = "Research &amp; statistics";		break;
		case "history_heritage":		document.GHCleanSectionTitle = "History &amp; heritage";		break;
		case "parks_open_spaces":		document.GHCleanSectionTitle = "Parks &amp; open spaces";		break;
		case "visitor_information":		document.GHCleanSectionTitle = "Visitor information";			break;
		case "arts_culture":			document.GHCleanSectionTitle = "Arts &amp; culture";			break;
		case "events_festivals":		document.GHCleanSectionTitle = "Events &amp; festivals";		break;
		
		// Catch any thing else..
		//default:			 			document.GHCleanSectionTitle = "";								break;

	}
	
	/*
	//	2nd level pages:				1st level pages under HOME category:
	if (document.GHNumOfLevels > 1  ||  (document.GHNumOfLevels == 1 && document.GHCleanSectionTitle == "INSURANCE - MySite") ) {
		document.GHCleanSectionTitle += ":&nbsp";
	}
	*/
}

//alert("END \n\n" + hrefRaw);
//alert(document.GHMajorSectionName);
//alert(document.GHNumOfLevels);

// ==========  CODE FOR SMART TEMPLATE - End  ====================================================================




// Will this work from here or for performance need it go within the template?

jQuery(document).ready(function() {


		// Dynamic Rollovers at top of page
		jQuery("#mainnavlivingheredown").hide();
		jQuery("#mainnavcouncildown").hide();
		jQuery("#mainnavdiscoverdown").hide();


		// Set up roll-down listeners
		var config = {    
			 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 50, // number = milliseconds for onMouseOver polling interval    
			 over: overFunction, // function = onMouseOver callback (REQUIRED)    
			 timeout: 0, // number = milliseconds delay before onMouseOut    
			 out: outFunction // function = onMouseOut callback (REQUIRED)    
		};

		jQuery("#hotspotlivinghere").hoverIntent( config );

		var config2 = {    
			 sensitivity: 3,
			 interval: 50,
			 over: overFunction2,
			 timeout: 0,
			 out: outFunction2
		};

		jQuery("#hotspotcouncil").hoverIntent( config2 );

		var config3 = {    
			 sensitivity: 3,
			 interval: 50,
			 over: overFunction3,
			 timeout: 0,
			 out: outFunction3
		};

		jQuery("#hotspotdiscover").hoverIntent( config3 );


		// On Hover (mouse over)
		function overFunction() {
				// hoverIntent sets the timer / delay so all don't open on a casual pass over
		//		jQuery("#mainNavLivingDown").show();
				jQuery("#mainnavlivingheredown").css('visibility','visible');
				jQuery("#mainnavlivingheredown").slideDown(300);
		}
		function outFunction() {
				jQuery("#mainnavlivingheredown").slideUp(150);
		}
		
		function overFunction2() {   jQuery("#mainnavcouncildown").css('visibility','visible');  jQuery("#mainnavcouncildown").slideDown(300);  }
		function outFunction2()  {   jQuery("#mainnavcouncildown").slideUp(150);    }
		
		function overFunction3() {   jQuery("#mainnavdiscoverdown").css('visibility','visible');  jQuery("#mainnavdiscoverdown").slideDown(300);  }
		function outFunction3()  {   jQuery("#mainnavdiscoverdown").slideUp(150);    }



		// Turn the MAJOR section on, ie Living Here,  Council  or  Discover
		if (document.GHMajorSectionName == "living_here") {
			jQuery("a#livinghere").addClass("on");
			// document.getElementById('livinghere').innerHTML = "<p><strong>" + document.GHCleanSectionTitle + "</strong></p>";
		} else if (document.GHMajorSectionName == "council") {
			jQuery("a#council").addClass("on");
		} else if (document.GHMajorSectionName == "discover") {
			jQuery("a#discover").addClass("on");
		}
		
		

		// Set the Subsection Title
		if (document.GHCleanSectionTitle != "") {
			// Do we need to test if it's a subpage of the big three Major sections?
			jQuery("h1#H1SubsectionHeading").html(document.GHCleanSectionTitle);
		}

  
		
		// FAMILY LINKS
		
		// Strip top level out from Ancestry structure
		
		// The template has:
		//		<centric_control type="family_links" id="" show_ancestry="true" show_siblings="true" show_children="true">
		// Which creates this:
		// 		<div id="navcontainer">
		//			<ul id="navlist">
		//				...
		
		// Note: This transfers the new Nav from a hidden DIV to a visible one, to avoid an on screen flicker!
		
		
		//for(var i = 0; i < $('ul#navlist ul').length; i++) {
			// do something
		//}
	
	
		// Test if this template has a Target DIV for custom Navigation
		if ( jQuery('div #navcontainerCustom').length > 0 ) {
			
			//var outputHTML = [];
			var outputHTMLstring = "<ul id=\"navlist\" >";
			
			jQuery('ul#navlist ul').each(function(index) {
				// The 'each' fn will auto increment 'index'
				//outputHTML[index] = jQuery(this).html();
				if (index == 0) {
					// Just go over list ONCE, don't crawl each deeper nested UL.
					outputHTMLstring += jQuery(this).html();
				}
			});
			
			outputHTMLstring += "</ul>";
				
			// Alerts for debugging.
			//alert(index + ': ' + jQuery(this).text());
			//alert(index + ': ' + jQuery(this).html());
			
			jQuery('div #navcontainer').html("");  /* Clear the old Family Links list */
			// jQuery('ul#navlist').html(outputHTMLstring);
			jQuery('div #navcontainerCustom').html(outputHTMLstring);  /* Insert modified list into the visible DIV */
			
			// Alternate code
			//var myObj = jQuery('ul#navlist ul').get(index);
			//alert( jQuery(myObj).html() );

		} else {
		
			// Unhide first Nav if no
			if ( jQuery('div #navcontainer').length > 0 ) {
	
				 jQuery('div #navcontainer').css('visibility', 'visible'); 
				
			}
			
		}

});




function notUsedCode() {

		// Activate Tabs

//		$('#au-promo-tabs > ul').tabs();


		// Dynamic Panels
		
//		$("#SingleCol .sectionPanelOn").hide();


		
	
		// Insert a new Hotspot before each .sectionPanelOff - this will become hotspot for mouse on & off.
		//$("#SingleCol .sectionPanelOff").before('<div class="hotspot" style="border:1px solid red"><a href="#" class"hotspot"><!-- Comment -->Lets try some text</a></div>');  
		// style="border:1px solid red"
		// style="cursor:pointer;"
		$("#SingleCol .sectionPanelOff").before('<div class="hotspot"><a href="#"><img src="/images/transparent.gif" height="42" width="319"></a></div>');
		

		// Could combine 'bind' to make the hotspots clickable .. no = then client can't edit links!
		// Stick to A HREF on panel header.

		// Copy HREF from panel to the inserted Hotspot
		$("#SingleCol .hotspot").each(function(){
			var theLinkURL = $(this).next().find('a').attr('href');
			$(this).find('a').attr('href',theLinkURL);
		 });

 
		// *	Keep DIVs where they are for easy client updating
		// *	jQuery initialises & hides them
		// *	jQuery sets up the following listeners/actions:

		// CSS: Mixing Abs & Rel positioning doesn't work.  Must use Absolute positioning only on the On state (so floats over), then measure & position the element.

		var config = {    
			 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 100, // number = milliseconds for onMouseOver polling interval    
			 over: overFunction, // function = onMouseOver callback (REQUIRED)    
			 timeout: 0, // number = milliseconds delay before onMouseOut    
			 out: outFunction // function = onMouseOut callback (REQUIRED)    
		};

		//$("#SingleCol .sectionPanelOff").hoverIntent( config );
		$("#SingleCol .hotspot").hoverIntent( config );



		// On Hover (mouse over)
		function overFunctionASIDE() {
				// hoverIntent sets the timer / delay so all don't open on a casual pass over.
				
				//alert($(this).html());
				//alert($(this).attr('class'));
				
				var pos = $(this).offset();
				var posParent = $("#sectionPanelArray").offset();
  				// var width = $(this).height();
 				// Put the hover state over the top of this button.
				//$(this).next("#SingleCol .sectionPanelOn").css( { "top": (pos.top - posParent.top) + "px" } );  //   < Failed in jquery 1.2.6
 				$(this).next().next().css( { "top": (pos.top - posParent.top) + "px" } );  //   < Works in 1.2.6
 				
				// .show();
				
				// Next line sets a Reveal effect on .next() element
				//$(this).next("#SingleCol .sectionPanelOn").slideDown(100);
				$(this).next().next().slideDown(100);
		}

		function outFunctionASIDE() {
				//$(this).next("#SingleCol .sectionPanelOn").slideUp(1);
				$(this).next().next().slideUp(1);
		}

	};






function printpage() {
	window.print();  
}

function openPopup(x) {
	if (x != "null") {
		window.open(x, 'Cavpower','width=700,height=580,toolbar=no,directories=no,status=no,menubar=no,scrollbars=auto');
	}
}
