﻿// Variables
// ChangeBanner
var imageNumber = 1;
var maxImages = 1; // Value set on load

// Onload Task
jQuery(document).ready(function() {
    MM_preloadImages('/media/mst_nav_home_f2.jpg', '/media/mst_nav_about_f2.jpg', '/media/mst_nav_services_f2.jpg', '/media/mst_nav_resources_f2.jpg', '/media/mst_nav_news_f2.jpg', '/media/mst_nav_contact_f2.jpg');
    SetOverStates();
    SetLinkableLists();
    SetLinkableDivs();
    //SetLinkableListsProto();
    //StartBanners();
    maxImages = Number(jQuery('#bannerPanel').attr('max'));
    var alt = true;
    
    $("#login_content .password").attr("value","password");
    $("table.AlternatingTable").find("tr:eq(0)").addClass("firstrow");
    $("table.AlternatingTable tr").each(function() {
    if (alt) {
        $(this).addClass("rowa");
    } else {
        $(this).addClass("rowb");
    }
    alt = !alt;
    });
    //$('#generalContent').equalHeights();
    //$("table.AlternatingTable").find("tr:last").after('<tr class="rowa"><td style="padding:0px;">&nbsp;</td><td style="padding:0px;">&nbsp;</td></tr>');
});

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
    }

    function SetOverStates() {
        jQuery('img[hoverSrc]').bind('mouseover', function() {
            var naturalState = $(this).attr('hoverSrc');
            var hoverState = $(this).attr('src');
            jQuery(this).attr('src', naturalState);
            jQuery(this).attr('hoverSrc', hoverState);
        });
        jQuery('img[hoverSrc]').bind('mouseout', function() {
            var naturalState = $(this).attr('hoverSrc');
            var hoverState = $(this).attr('src');
            jQuery(this).attr('src', naturalState);
            jQuery(this).attr('hoverSrc', hoverState);
        });
    }

    function SetLinkableLists() {
        jQuery('li[src]').bind('click', function() {
        //jQuery('#sideDesign li').bind('click', function() {
            window.location.href = jQuery(this).attr('src');
        });
        jQuery('li[src]').bind('mouseover', function() {
            jQuery(this).css('text-decoration', 'underline');
        });
        jQuery('li[src]').bind('mouseout', function() {
            jQuery(this).css('text-decoration', 'none');
        });
    }
    
	function SetLinkableDivs(){
	
		jQuery('div[href]').bind('click', function(){
		
			window.location.href = jQuery(this).attr('href');
		
		});
	
	}
	
    function SetLinkableListsProto() {
    
        //Event.observe('sideDesign', 'click', function(){
        
       //     alert('hi');
        
       // });
    
    }

    function StartBanners() {
        // Start the timer.

        jQuery('img[link]').css('cursor', 'pointer');
        
        jQuery('img[link]').bind('click', function() {

            var thisLink = jQuery(this).attr('link');

            if (thisLink.length > 0) { window.location.href = thisLink; }

        });
        
        var timeOffset = 6000;
        setTimeout('ChangeBanner()', timeOffset);
    }
    
    function ChangeBanner() {
        

        // Fade Current banner out
       // jQuery('#banner' + imageNumber).fadeOut(1000, function() {
        jQuery('#banner' + imageNumber).animate({ opacity: 0.5 }, 1000, null, function() {

            jQuery('#banner' + imageNumber).attr('class','hideBanner');

            // Next Number
            imageNumber = imageNumber + 1;

            // Override
            if (imageNumber > maxImages) { imageNumber = 1; }

            //jQuery('#banner' + imageNumber).attr({
            //class: 'showBanner',
            //style: 'opacity: 0;'
            //});
            
            jQuery('#banner' + imageNumber).attr('class', 'showBanner');
            jQuery('#banner' + imageNumber).attr('opacity', '0.5');

            //jQuery('#banner' + imageNumber).fadeIn(1000, function() {
            jQuery('#banner' + imageNumber).animate({ opacity: 1 }, 1000, null, function() {
                
                StartBanners();

            });

        });


    }

    function HighNetWorth() {

        jQuery('div[selector]').bind('mouseover', function() {

            // Get Id
            var selectedId = jQuery(this).attr('selector');

            jQuery('.imgNatural').css('display', 'inline');

            jQuery('.imgHover').css('display', 'none');

            // Set State on Image
            //var currentImage = jQuery(this).find('img');
            //var hoverPath = jQuery(currentImage).attr('hoverPath');
            //jQuery(currentImage).attr('src', hoverPath);

            jQuery('#' + selectedId + '_natural').css('display', 'none');
            jQuery('#' + selectedId + '_hover').css('display', 'inline');

            // Hide all.
            jQuery('div[text]').css('display', 'none');

            // Show one
            jQuery('div[text=' + selectedId + ']').css('display', 'block');

        });
    
    }
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

// just in case you need it...
$.fn.equalWidths = function(px) {
	$(this).each(function(){
		var currentWidest = 0;
		$(this).children().each(function(i){
				if($(this).width() > currentWidest) { currentWidest = $(this).width(); }
		});
		if(!px || !Number.prototype.pxToEm) currentWidest = currentWidest.pxToEm(); //use ems unless px is specified
		// for ie6, set width since min-width isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'width': currentWidest}); }
		$(this).children().css({'min-width': currentWidest}); 
	});
	return this;
};


/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};

