﻿/*

	Javascript class to setup various utility methods
	
	Trace function plugs into firebug in firefox...for development only
	
	required code at the bottom of file instantiates the utility class
	
	This setup keeps js (unobtrusive!) OUT of markup.
	
*/

/*Event.observe(window, 'load', showPage);

function showPage () {
	document.body.removeClassName('hidebody');
}*/

var Utility = Class.create({
	initialize: function(){
		this.trace("Javascript loaded.");
		this.safariFix();
		// if we are in debug mode set debug to false
		// otherwise set it to false if ie, true otherwise
		this.debug = (Prototype.Browser.IE) ? false : false;
		Event.observe(window, 'load', this.loaded.bind(this));
	
	},
	loaded: function(){
		this.trace('DOM loaded and available.');
		// add pseudo classes as classes for unsupported browsers
		//$$('li:last-child').invoke('addClassName', 'last-child');
		$$('li:first-child').invoke('addClassName', 'first-child');
		
		this.setupDropDown();
		
		if($$('.tabs')){
			$$('.tabs').each(function(tab){
				util.trace(tab.id);
				new OTabs(tab);
			});
			
		}
		
		// anchor outline fix
		if(Prototype.Browser.IE){
			$$('a').invoke('observe', 'click', function(event){
				event.target.blur();
			});
		}
		
		// if there is a slideshow element, start it up
		if($('slideshow')){
			new OSlideshow($('slideshow').show(),5, true);
		}
		
		// instantiates collapsible list elements
		if($$('.collapsible')){
			$$('.collapsible').each(function(el){
				new Collapsible(el, true);
			});
		}
		//$$('.sections .collapsible').each(function(el){
			//new Collapsible(el);
		//});
	},
	
	setupDropDown: function(){
		// adds hasSubmenu class if there is a nested list
		$$('#navigation>li').invoke('hide');
		$$('#navigation>li').each(function(node, i){
		 		if(node.select('ul').first()) {
					node.addClassName('hasSubmenu');
				}
		 });
		
		$$('#navigation>li>ul>li').each(function(node, i){						
		 		if(node.select('ul').first()) {
					node.addClassName('hasSubmenu');
				}
		 });
		
		// toggles .anchor hover
		$$("#navigation li>a").each(function(node, i){
			node.onmouseover = node.onmouseout = function(){
				node.toggleClassName('anchor_hover');
			}
		
		});
		
		// toggles .over on submenu
		$$("#navigation li.hasSubmenu").each(function(node, i){
			//node.cleanWhitespace();
			// if there’s a ul
		//	var ul = node.select('ul').first();//$A(node.getElementsByTagName("ul")).first();
			//if(ul != null){ 
					// toggle it’s visibility on these events
					
				node.onmouseover = function(){
					node.select('ul').first().show();
				}
				node.onmouseout = function(){
					node.select('ul').first().hide();
				}
		//	}
			
			
		});
		$$('#navigation>li').invoke('show');
		//reset any stray overs
		
	},
	
	// This function is used for development only
	trace: function($message){
		// Comment out this line for production
		if (this.debug && ((window['console']) || (console['firebug']))) console.log($message);
		
	},
	
	safariFix: function(){
		// if we are in safari, insert a stylesheet into <head>
		if(Prototype.Browser.WebKit){
			document.documentElement.firstChild.insert('<link rel="stylesheet" href="http://www.oracle.com/ocom/fragments/externalnavhorizontal/safari-fixes.css" type="text/css" media="screen" charset="utf-8" />');
		}
	}
});


function change()
{
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		document.searchForm.group.style.visibility='hidden';

	}
	document.getElementById("light").style.display="block";
	document.getElementById("fade").style.display="block";
	document.getElementById("light").innerHTML = "<div id='load' style='margin-right:250px; margin-top:50px;'><img src='/admin/images/sitefinder/sitefinder_loader.gif' width='32' height='32' /></div><iframe src='/admin/sitefinder/sitefinder.html' frameborder='0' width='624' height='455' scrolling='no' allowtransparency='true' id='siteid' style='visibility:hidden'></iframe>";
}



util = new Utility();
