/* common classes/functions */

/* jquery style nav setup - set all A.navMO under #nav2 to add class 'navHighlight' onmouseover */
var syxmover = {

    plcache: new Array(),

    init: function() {
        var navBoxen = $('#nav2 > div > a');
        //console.log(navBoxen);
        var nonSel = navBoxen.filter( function(e) { return ! this.className.match(/\bnavSel\b/); } );

        //nonSel.mouseover( function(e){ $(this).addClass('navHighlight'); });
        //nonSel.mouseout( function(e){ $(this).removeClass('navHighlight'); });

        nonSel.each( function() { syxmover.preload($(this)); } );

        //navBoxen.filter('.navSel').click( function(e){ return false; });

        var subnav = $('#subnav2');
        if (subnav) {
            var subnavBoxen = $('#subnav2 > ul > li > a');
            var subnonSel = subnavBoxen.filter( function(e) { return ! this.className.match(/\bnavSel\b/); } );

            subnonSel.mouseover( function(e){ $(this).addClass('navHighlight'); });
            subnonSel.mouseout( function(e){ $(this).removeClass('navHighlight'); });

            subnonSel.each( function() { syxmover.preload(this); } );

            //subnavBoxen.filter('.navSel').click( function(e){ return false; });
        }

        syxmover.preload($('#btnLogin'))
        $('#btnLogin').mouseover( function(e){ $(this).addClass('navHighlight'); });
        $('#btnLogin').mouseout( function(e){ $(this).removeClass('navHighlight'); });

    },

    /* hack to create URLs out of background-image prop of each elem, and then
     * preloading them by creating a permanent Image() out of them, as well as
     * the mouseover version given by XXXXXXXX_on.gif */
    preload: function (elem) {
        var def = $(elem).css('background-image').replace(/url\(['"]?([^)"']+)['"]?\)/, '$1');
        if (def != 'none') {
            var onsrc = def.replace(/\.([^.]+)$/, '_on.$1');
            this.imgFactory(def);
            this.imgFactory(onsrc);
        }
    },

    imgFactory: function(src) {
        var i = new Image();
        i.src = src;
        this.plcache[this.plcache.length] = i;
    }

};



$(document).ready(function(){
    syxmover.init();

    /* open all external links in new window (class 'ext') */
    $('a.ext').attr('target', '_new');

});







/* note: following brilliant equalizeCols() jQuery plugin ripped from code at
 * http://www.tomdeater.com/jquery/equalize_columns/ and used in FCEContact.js
 * right now for LC only. */
/**
 *
 * Copyright (c) 2007 Tom Deater (http://www.tomdeater.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */
(function($) {
	/**
	 * equalizes the heights of all elements in a jQuery collection
	 * thanks to John Resig for optimizing this!
	 * usage: $("#col1, #col2, #col3").equalizeCols();
	 */
	 
	$.fn.equalizeCols = function(){
		var height = 0;
  
		return this
			.css("height", "auto")
			.each(function() {
				height = Math.max(height, this.offsetHeight);
			})
			.css("height", height)
			.each(function() {
				var h = this.offsetHeight;
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
})(jQuery);
/** end equalizeCols **/




/**
 * fake a :hover selector in CSS for elements that can't have it (IOW anything
 * other than an <a> in IE6). Will add the specified className to the element
 * when the mouse is over it, and remove when not.
 *
 * 
 * usage: $("#crazyButton").hoverClass('over');
 *
 */
(function($) {
	$.fn.hoverClass = function(className){
        return this.bind('mouseover', function() { $(this).addClass(className) })
                   .bind('mouseout', function() { $(this).removeClass(className) });
	};
})(jQuery);

/* custom extensions to get the true width and height of objects, including any
 * margins or borders. Needed in FCESlideShow */
(function($) {

	$.fn.totalWidth = function() {
        return parseInt(this.width()) + parseInt(this.css('marginLeft')) + parseInt(this.css('marginRight')) + parseInt(this.css('border-left-width')) +  parseInt(this.css('border-right-width'));
	};

	$.fn.totalHeight = function() {
        return parseInt(this.height()) + parseInt(this.css('marginTop')) + parseInt(this.css('marginBottom')) + parseInt(this.css('border-top-width')) +  parseInt(this.css('border-bottom-width'));
	};
})(jQuery);


