﻿/*
---------------------------------------------------------
Main jQuery

Revision:      002
Last Updated:  09/11/2009 by kevinmarmolinero@redweb.com
Created:       09/06/2009 by scottdarby@redweb.com
---------------------------------------------------------
*/



//open all links with rel attribute of _blank in new window to allow validation
function newWindow(){
	$('a[rel="blank"]').attr({
            target: '_blank',
            title: 'This link opens in a new window'
        });
}

/*------------------------------------------------
jQuery FAQ Accordian/slider.
--------------------------------------------------

Relies on classes of question/answer being added
classes are pre-defined in Editor.css so can be 
used "out-of-the-box" by users. 

------------------------------------------------*/

$(window).ready(function board() {
    var $boardTitle = $('p.question');
    $boardTitle.nextAll('p.answer').hide();
    
    
    $boardTitle.click(function() {
    
            $('.questionOpen').removeClass('questionOpen');
            $(this).addClass('questionOpen');
            
        if ($(this).next().is(':visible')) return false;
        $('p.answer:visible').slideUp(400, function() {
            
        });
        $(this).next('p.answer').slideDown(400, function() {
            
        });
        return false;
    });
    
    
    $boardTitle.hover(
            function() {
                $(this).css({ 'cursor': 'pointer', 'text-decoration': 'underline' });
            },
            function() {
                $(this).css({ 'text-decoration': 'none' });
            }
        );

});

$(window).ready(function() {
    var $monthNimate = $('a.month');
    $monthNimate.click(function() {

        if ($(this).next('ul').hasClass('openMonth'))

            $('ul.openMonth').slideUp(400, function() {
                $(this).removeClass('openMonth');
            });

        else
            $(this).next('ul').slideDown(400, function() {
                $(this).addClass('openMonth');
            });

        return false;
    });
});



/*
quickTree 0.4 - Simple jQuery plugin to create tree-structure navigation from an unordered list
*/
jQuery.fn.quickTree = function() {
    return this.each(function() {
        var $tree = $(this);
        var $roots = $tree.find('li');

        $tree.find('li:last-child').addClass('last');
        $tree.addClass('tree');
        $tree.find('ul').addClass('hide');
        $roots.each(function() {
            if ($(this).children('ul').length > 0) {
                $(this).addClass('root');
            }
        });

        $roots.each(function() {
            if ($(this).hasClass("root")) {
                $(this).prepend('<span class="expand" />');
            }
        });
        
    });
};

jQuery.fn.expander = function() {
$('span.expand').toggle(
            function(e) {
                var $clicked = $(e.target);
                $clicked.toggleClass('contract').nextAll('ul').slideDown();
           },
           function(e) {
            var $clicked = $(e.target);
            $clicked.toggleClass('contract').nextAll('ul').slideUp();
           }
        );
};

/*
/////////////quickTree 0.4 - Simple jQuery plugin to create tree-structure navigation from an unordered list
*/

jQuery.fn.equalHeight = function(){
    return this.each(function(){
        var $li = jQuery(this),
			$nextLi = $li.next();

		if ($nextLi.length > 0){
			firstHeight = $li.height();
			secondHeight = $nextLi.height();
			var highest = Math.max(firstHeight, secondHeight);
			$li.height(highest);
			$nextLi.height(highest);			
		}

	});
};

$(function() {
    var highestCol = Math.max($('ul.locationDetails').height(), $('ul.locationDetailsRight').height());
        $('body.ContactUs #content ul.locationDetailsRight').height(highestCol);
        $('body.ContactUs #content ul.locationDetails').height(highestCol);
});
		
$(function(){
            $('#sitemap ul:first').quickTree().show();
});

$(document).ready(function() {
    $('.noJs').removeClass('noJs');
    $('#hub-listing li:even').equalHeight();
    $('#hub-listing').css({ left: '0', position: 'static' });
    $('ul#nav li:first-child').addClass('first');
    $('ul#nav li:last-child').addClass('last');
    $('ul#subNav ul#sixthLevel li:last-child').addClass('remove');
    $('ul#subNav ul#fifthLevel li ul#sixthLevel').parent().addClass('remove');
    $('span.expand').expander();
});

function WireAutoTab(CurrentElementID, NextElementID, FieldLength) {
    //Get a reference to the two elements in the tab sequence.
    var CurrentElement = $('#' + CurrentElementID);
    var NextElement = $('#' + NextElementID);

    CurrentElement.keyup(function(e) {
        //Retrieve which key was pressed.
        var KeyID = (window.event) ? event.keyCode : e.keyCode;

        //If the user has filled the textbox to the given length and
        //the user just pressed a number or letter, then move the
        //cursor to the next element in the tab sequence.   
        if (CurrentElement.val().length >= FieldLength &&
            ((KeyID >= 48 && KeyID <= 90) ||
            (KeyID >= 96 && KeyID <= 105)))
            NextElement.focus();
    });
}