// JavaScript Document
/*--------------------------------------------------------------------------*/
/*---------------- bm lightbox global overrides: --------------------------*/
var fileLoadingImage = "/images/lightbox/lightbox_loading.gif";
var fileBottomNavCloseImage = "/images/lightbox/lightbox_close.gif";
var cornerpic_fade = false;
/*--------------------------------------------------------------------------*/
function initparks() {	
	//**DON'T REVEAL MAINMENU div IN IE6 UNTIL DOM LOADED - TO STOP FLASH OF PRE-FIXED PNG IMAGES.
	if (brIE6) { //GLOBAL SET IN ietest.js
		var menuElement = $('mainmenu');
		document.observe("dom:loaded", 
			function() {
				try {
					menuElement.setStyle({display: 'block'});
				} catch (e) {
					//alert(e); 
				}
			}
		);
	} else { menuElement.setStyle({display: 'block'}); }
	<!---->
	
	//preloadMainMenu();
	
	setActiveMainmenu();
	setActiveSubmenuUnderlay();
	setCornerPic();
	//setScrollOverlay(); //remove 'scroll_gradient_*' divs?
}
/*--------------------------------------------------------------------------*/
function setActiveMainmenu() {
	//currentMainmenuStr GLOBAL VAR SET IN BM CMS TEMPLATE FROM <%___slug%> WIDGET.
	try {
		var bkgdStr = ('url(/images/global/header/menubox-ro.png)');
		$(currentMainmenuStr).setStyle({backgroundImage: bkgdStr});
		$(currentMainmenuStr).addClassName('mainmenuitem_ro');
	} catch (e) {
		//alert(e); 
	}	
}
/*----*/
function setActiveSubmenuUnderlay() {
	document.observe("dom:loaded", function() {
		try {
			//CALCULATE FOLIAGE UNDERLAY TOP, BASED ON POSITION OF ACTIVE SUBMENU TEXT LIST ELEMENT & FOLIAGE DIV HEIGHT
			//currentSubmenuStr GLOBAL VAR SET IN BM CMS TEMPLATE FROM <%sectionslug%> WIDGET.
			var currentListElement = $('submenu').down('li.bmn_sec-' + currentSubmenuStr);
			var foliagHeight = $('subfoliage').getStyle('height');
			var foliageTop = (currentListElement.cumulativeOffset()[1] + 5 - parseInt(parseInt(foliagHeight)*.25))+'px';
			$('subfoliage').setStyle({top: foliageTop});
			$('subfoliage').setStyle({display: 'block'});
		} catch (e) {
			//alert(e); 
		}
	});
}
/*----*/
function setCornerPic() {
	try {
		var bkgdStr = ('url(/images/cornerpic/' + currentSubmenuStr + '.jpg)');
		setCornerPicOpacity(bkgdStr);
	} catch (e) {
		//alert(e);
		
		try {//if currentSubmenuStr is undefined, try currentMainmenuStr (main section page)
			var bkgdStr = ('url(/images/cornerpic/' + currentMainmenuStr + '.jpg)');
			setCornerPicOpacity(bkgdStr);	
		} catch (e) {
			//alert(e);
		}
	
	}
}

function setCornerPicOpacity(bkgdStr) {
	$('cornerpic').setStyle({backgroundImage: bkgdStr});
	if (cornerpic_fade) { 
		new Effect.Fade('cornerpic', { duration:1.0, from:1.0, to:0.15 }); }
}



/*----*/
function setScrollOverlay() {
	document.observe("dom:loaded", function() {
		try {								
			standardHeight = parseInt( $('contentbox').getStyle('height') );
			scrollingHeight = $('contentbox').scrollHeight;
			if ( scrollingHeight > standardHeight ) {
				$('contentbox').setStyle({overflow: 'auto'}); //TO FORCE OVERFLOW V-SCROLL ON SEARCH RESULTS. (pre tallpark Tall Page layout)
				$('scroll_gradient_top').setStyle({display: 'block'});
				$('scroll_gradient_bottom').setStyle({display: 'block'});
			}
		} catch (e) {
			//alert(e);
		}
	});
}


/*--------------------------------------------------------------------------*/
var quickjumpStatus = new Boolean(0);
var pickaparkStatus = new Boolean(0);

function toggleQuickjump() {	
	if (quickjumpStatus == 0) {
		quickjumpStatus = 1;
		if (pickaparkStatus == 1) { togglePickapark(); }
		Effect.SlideDown('servicesbox', {duration: .75, queue: 'end', fps: 30});
	} else {
		quickjumpStatus = 0;
		Effect.SlideUp('servicesbox', {duration: .3, queue: 'end', fps: 30});
	}
}
function togglePickapark() {	
	if (pickaparkStatus == 0) {
		pickaparkStatus = 1;
		if (quickjumpStatus == 1) { toggleQuickjump(); }
		Effect.SlideDown('pickaparkbox', {duration: 1, queue: 'end', fps: 30});
	} else {
		pickaparkStatus = 0;
		Effect.SlideUp('pickaparkbox', {duration: .5, queue: 'end', fps: 30});
	}
}
/*--------------------------------------------------------------------------*/


// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
	){
		var strText = this;
		var intIndexOfMatch = strText.indexOf( strTarget );
		// Keep looping while an instance of the target string
		// still exists in the string.
		while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
		}
		// Return the updated string with ALL the target strings
		// replaced out with the new substring.
		return( strText );
	}





/*--------------------------------------------------------------------------*/
// Establish CSS-driven events via Behaviour script.
// dch note: REM - NO camelCase on event names!
/*--------------------------------------------------------------------------*/
var myrules = {
	'.mainmenuitem' : function(element){
		element.onmouseover = function(){
			if (currentMainmenuStr == element.id) { return; }
			var bkgdStr = ('url(/images/global/header/menubox-ro.png)');
			$(element.id).setStyle({backgroundImage: bkgdStr});	
			$(element.id).removeClassName('mainmenuitem');
			$(element.id).addClassName('mainmenuitem_ro');
		}
		element.onmouseout = function(){
			if (currentMainmenuStr == element.id) { return; }
			var bkgdStr = ('url(/images/global/header/menubox.png)');
			$(element.id).setStyle({backgroundImage: bkgdStr});
			$(element.id).removeClassName('mainmenuitem_ro');
			$(element.id).addClassName('mainmenuitem');	
		}
		element.onclick = function(){
			document.location.href = $(element.id).firstChild;
		}
	},
/*---,comma----*/
	'#quickjump, #services_widget' : function(element){
		element.onmouseover = function(){
			$('quickjump').setStyle({color: '#0099FF'});
		}
		element.onmouseout = function(){
			$('quickjump').setStyle({color: '#1066a5'});
		}
		element.onclick = function(){
			toggleQuickjump();
		}
	},
/*---,comma----*/
	'#pickapark, #pickapark_widget' : function(element){
		element.onmouseover = function(){
			$('pickapark').setStyle({color: '#0099FF'});
		}
		element.onmouseout = function(){
			$('pickapark').setStyle({color: '#1066a5'});
		}
		element.onclick = function(){
			togglePickapark();
		}
	},
/*---,comma----*/
	'#pickaparkbox a' : function(element){
		element.onmouseover = function(){
			$('papwin'+element.id).setStyle({display: 'block'});
		}
		element.onmouseout = function(){
			Effect.Fade(('papwin'+element.id), {duration: .20, position:'front', limit: 1, fps: 15});
		}
		element.onclick = function(){
		}
	},
/*---,comma----*/
	'.paptab' : function(element){
		element.onmouseover = function(){
			$(element.id).setStyle({left: '139px'});
		}
		element.onmouseout = function(){
			$(element.id).setStyle({left: '137px'});
		}
		element.onclick = function(){
			document.location.href = ('/parks-events/' + element.id);
		}
	},		
/*---,comma----*/
	'.whatpdf' : function(element){
		element.onmouseover = function(){
		}
		element.onmouseout = function(){
		}
		element.onclick = function(){
			document.location.href = ('/pdf-info');
		}
	}
	//,
	/*---,comma----*/
/*	'.krohn75Logo' : function(element){
		element.onmouseover = function(){
		}
		element.onmouseout = function(){
		}
		element.onclick = function(){
			window.open('/bm%7Edoc/full-story-krohn-conservatory-history.pdf','_blank');
		}
	}	*/
/*---^--NO comma on last one -------------------------------------*/
};


//alert($w(element.className));