// DF1.1 :: domFunction 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
// GNU Lesser General Public License -- http://www.gnu.org/licenses/lgpl.html
//******************************************************

function domFunction(f, a)
{
	var n = 0;
	
	var t = setInterval(function()
	{
		var c = true;

		n++;
			if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
		{
			c = false;

			if(typeof a == 'object')
			{
				for(var i in a)
				{
					if
					(
						(a[i] == 'id' && document.getElementById(i) == null)
						||
						(a[i] == 'tag' && document.getElementsByTagName(i).length < 1)
					) 
					{ 
						c = true; 
						break; 
					}
				}
			}
			if(!c) { f(); clearInterval(t); }
		}
		
		if(n >= 60)
		{
			clearInterval(t);
		}
		
	}, 250);
};

//******************************************************
/*  
    Makes sure the content area is as tall as the left 
    hand navigation.
    
    document.minHeightProp is overridden in a conditional comment 
    in the HEAD for IE6 to use the height property as it doesn't 
    understand min-height.
    
    Could just use the height property for all browsers, except that's 
    causing weird results in IE7 with the content getting bunched on top
    of itself.
*/

document.minHeightProp = 'minHeight';

function setContentHeight(){

    if(!document.getElementById) return;
    var navLeft = document.getElementById('navLeft');
    var content = document.getElementById('content');
    if(null == navLeft || null == content) return;
    var navHeight = navLeft.offsetHeight;
    var contentHeight = content.offsetHeight;
    if(navHeight > contentHeight){
        var result = content.style[document.minHeightProp] = (navHeight-36)+'px';
    }    
}

// Run when DOM is ready
domFunction(setContentHeight,{'navLeft':'id','content':'id'});


//******************************************************
/*
    This function will add rollovers to image inputs. The function fires
    on window.load and rollovers will be added to all inputs with the type
    attribute "image". It requires addEvent.js (http://ejohn.org/projects/flexible-javascript-events/).
    
    The filename of the image for the over state should be the same
    as the one for the up state, but with 'On' appended.
    e.g. if the name of the up state image is 'btnSearch.gif' the over
    image must be called 'btnSearchOn.gif'
    
*/


function addSubmitRollovers(){
    
    var inps = document.body.getElementsByTagName('INPUT');
    
    if(null != inps){
        
        var onRollOver = function(){ 
                            if(this.hasFocus) return false; 
                            this.src = this.over_img.src;
                            this.hasFocus = true; 
                        };
        
        var onRollOut =  function(){ 
                            this.src = this.up_img.src; 
                            this.hasFocus = false; 
                        };
                        
        for(var i=0,l=inps.length;i<l;i++){         

            // Skip anything but image inputs
            var inp = inps[i];
            if(inp.type != 'image') continue;

            // Preload and assign images to input
            inp.up_img = new Image();
            inp.up_img.src = inp.src;
            inp.over_img = new Image();            
            // Work out over image based on naming convention 
            inp.over_img.src = inp.src.replace(/\.([a-z][a-z][a-z])$/,'On.$1');

            // Assign functions
            inp.onmouseover = inp.onfocus = onRollOver;
            inp.onmouseout = inp.onblur = onRollOut;
        }
    }
}
// Run when DOM is ready
domFunction(addSubmitRollovers,{'terms':'id'});



