$(document).ready(function(){
	// Purpose: sets the alternating row colors for any tables, lists or definition lists with a class of "altrows"
	$(".altrows tr:even").addClass('even');
	$(".altrows tr:odd").addClass('odd');
	$(".altrows li:even").addClass('even');
	//$(".altrows li:nth-child(4n)").addClass('even');
	//$(".altrows li:nth-child(4n-1)").addClass('even');
	$(".altrows li:odd").addClass('odd');
	$(".altrows dt:even").addClass('even');
	$(".altrows dd:even").addClass('even');
	$(".altrows dt:odd").addClass('odd');
	$(".altrows dd:odd").addClass('odd');
	
	
	// Purpose: adds the appropriate class for each link depending on the extension. used for adding icons in links in .files lists
	$("a[href$='.gif'], a[href$='.jpg'], a[href$='.jpeg'], a[href$='.png'], a[href$='.bmp'], a[href$='.tif']").addClass("img");
	$("a[href$=swf], a[href$=fla], a[href$=flv]").addClass("flash");
	$("a[href$=mov], a[href$=m4a], a[href$=mp4]").addClass("qt");
	$("a[href$=eps], a[href$=ai]").addClass("vector");
	$("a[href$=mp3], a[href$=aif]").addClass("audio");
	$("a[href$=wma], a[href$=wmv]").addClass("wma");
	$("a[href$=pdf]").addClass("pdf");
	$("a[href$=txt]").addClass("txt");
	$("a[href$=zip]").addClass("zip");
	$("a[href$=psd]").addClass("psd");
	$("a[href$=xls]").addClass("xls");
	$("a[href$=doc]").addClass("doc");
	$("a[href$=pub]").addClass("pub");
	$("a[href$=ppt]").addClass("ppt");
	$("a[href$=com], a[href$=com/], a[href$=net], a[href$=net/]").not("[href^=#]").not("[href*=http://www.noicon.com]").addClass("link") /*.attr({ target: "_blank" })*/;
	
	
	// Purpose: Adds/Removes the word "Search" from the search box in the header
	$("#dnn_dnnSEARCH_txtSearch").val("SEARCH");
	$("#dnn_dnnSEARCH_txtSearch").focus(function(){
		if ($(this).val() == "SEARCH") {
			$(this).val('');
		}
	});
	$("#dnn_dnnSEARCH_txtSearch").blur(function(){
		if ($(this).val() == '') {
			$(this).val("SEARCH");
		}
	});
	$("#dnn_dnnSEARCH_cmdSearch").click(function(){
		if ($("#dnn_dnnSEARCH_txtSearch").val() == 'SEARCH') 
			return false;
	});


	// Purpose: Initiates dropdown function for navigation
	$("ul.dropdown li").dropdown();


});



$.fn.dropdown = function() {
	$(this).hover(function(){
		$(this).addClass("hover");
		$('> .dir',this).addClass("open");
		$('ul:first',this).css('visibility', 'visible');
	},function(){
		$(this).removeClass("hover");
		$('.open',this).removeClass("open");
		$('ul:first',this).css('visibility', 'hidden');
	});
}



// places focus on the first form input field (don't let this globally 'onload'. breaks anchoring and any page (in IE) when first text element is hidden.)
function formFocus(){
    try {
        if (document.forms.length > 0) {
            var myForm = document.forms[0];
            for (i = 0; i < myForm.length; i++) {
                myElement = myForm.elements[i];
                if ((myElement.type == "text") || (myElement.type == "textarea")) {
                    myElement.focus();
                    break;
                }
            }
        }
    } 
    catch (exception) {
    }
}

// advances focus (phone numbers)
function focusNext(elmnt, content){
    if (content.length == elmnt.maxLength) {
        next = elmnt.tabIndex
        if (next < document.forms[0].elements.length) {
            document.forms[0].elements[next].focus()
        }
    }
}

// shows or hides a specific element
function showHide(elementid){
    if (document.getElementById(elementid).style.display == 'none') {
        document.getElementById(elementid).style.display = '';
    }
    else {
        document.getElementById(elementid).style.display = 'none';
    }
}

// popup windows
function MM_openBrWindow(theURL, winName, features, myWidth, myHeight, isCenter){ //v3.0
    if (window.screen) 
        if (isCenter) 
            if (isCenter == "true") {
                var myLeft = (screen.width - myWidth) / 2;
                var myTop = (screen.height - myHeight) / 2;
                features += (features != '') ? ',' : '';
                features += ',left=' + myLeft + ',top=' + myTop;
            }
    window.open(theURL, winName, features + ((features != '') ? ',' : '') + 'width=' + myWidth + ',height=' + myHeight);
}

