$(document).ready(function() {

    var cNewsItems = $('body.home div.news dl dt').size();
    for (i = 1; i <= cNewsItems; i++) {
        $('body.home div.news dl dt#tnt-0' + i).hover(function() {
            var curr_id = $(this).attr('id');
            var my_suffix = curr_id.charAt(curr_id.length - 2) + curr_id.charAt(curr_id.length - 1);
            var my_tag = $('body.home div.news dl dd#tnd-' + my_suffix);
            ClearNews();
            $(this).addClass("active");

			if ($.browser.msie && $.browser.version > 5 ) {
				$(my_tag).css("display","block");
				$(my_tag).children('.background-wrapper').css("background","transparent url('http://staging.nasfaa.org/App_Themes/img/bg_popup_home_todaynews.png') 0px -8px no-repeat").css("filter","none !important");
				$(my_tag).css("filter","none !important");
				if ($.browser.version == 6 ) DD_belatedPNG.fix('body.home div.news dl dd .background-wrapper');
			} else {
				$(my_tag).show("fast");
				//$(my_tag).fadeIn("fast");
			}
			
        });
    }
    for (i = 1; i <= cNewsItems; i++) {
        $('body.home div.news dl dd#tnd-0' + i).hover(function() {

        }, function() {
            var curr_id = $(this).attr('id');
            var my_suffix = curr_id.charAt(curr_id.length - 2) + curr_id.charAt(curr_id.length - 1);
            var my_tag = $('body.home div.news dl dt#tnt-' + my_suffix);
            $(my_tag).removeClass("active");
            //$(this).hide("fast");
            if ($.browser.msie && $.browser.version > 5 ) {
            	$(this).css("display","none");
			} else {
				$(this).hide("fast");
				//$(this).fadeOut("fast");
			}
			
        });
    }
    
    $('body.home div.news dl.dl-news dd').click(function() {
       window.location.replace($("dt#"+ $(this).attr("id").replace("d","t") + " a").attr("href"));
    });
    
   
    // need to reset stuff on box hover, preventing "sticky box" behavior
    $('body.home div#content').hover(function() {
        ClearNews();
    });
    //This line removes folder background in advanced search
    $('div#taxonomy table tr td a img').parent().css('background', 'none').css('padding-left', '0').css('margin-left', '0');

    $('div#taxonomy a#select-alltax').click(function() {
        $('div#taxonomy input').attr('checked', true);
    });

    $('div#taxonomy a#clear-alltax').click(function() {
        $('div#taxonomy input').attr('checked', false);
    });
	
	$('a#clear-search').click(function() {
        clear_form_elements("#search-criteria");
    });
    
    function clear_form_elements(ele) {
        $(ele).find(':input').each(function() {
            switch(this.type) {
                case 'password':
                case 'select-multiple':
                case 'select-one':
                case 'text':
                case 'textarea':
                    $(this).val('');
                    break;
                case 'checkbox':
                case 'radio':
                    this.checked = false;
            }
        });
    }

    $('div.sidebar div.career-center dl dt:first-child').addClass('first');
  /*  var ajax_load = "<img class='loading' src='" + $('#ctl00_ServerPath').attr('value') + "App_themes/img/lightbox-ico-loading.gif' alt='loading...' />";
    var loadUrl = $('#ctl00_ServerPath').attr('value') + "AjaxProxy.ashx?url=" + escape("http://www.jobtarget.com/distrib/jobs/javascript.cfm?code=4zqHff5PjQ9laJeKZSswoJJiEdTzGjlR");
    
    var _timer = setInterval(function () {
        if (/complete/.test(document.readyState)) {
            clearInterval(_timer);
         //   $("#jobs").html(ajax_load).load(loadUrl);

        }
    }, 10);*/
    
    
    

    v = $('#hideItem').attr('value');
    $('#dd' + v).remove();
    $('#dt' + v).remove();
    $("#TopMenu li").hover(
    function() {
        $(this).addClass("iehover");
        $(this).children('iframe').addClass('globalNavIframeHover');
        $(this).children('iframe').width($(this).children('ul').width());
        $(this).children('iframe').height($(this).children('ul').height());
        if ($(this).is(".ekflexmenu_menu_level_2")) {
            $(this).children('iframe').css("top", $(this).children('ul').css("top"));
        }
        $(this).children('iframe').css("left", $(this).children('ul').css("left"));
    },
    function() {
        $(this).removeClass("iehover");
        $(this).children('iframe').removeClass('globalNavIframeHover');
        $(this).children('iframe').addClass('globalNavIframe');
    }
    );

    $('#ctl00_MainContent_textOnly').click(function() {
        if ($('#ctl00_MainContent_textOnly').attr("checked")) {
            $("#ctl00_MainContent_textChecks input").attr("checked", "checked");
            $("#ctl00_MainContent_refChecks input").removeAttr("checked");
            $("#ctl00_MainContent_refOnly").removeAttr("checked");
        }
        else {
            $("#ctl00_MainContent_textChecks input").removeAttr("checked");
        }
    });
    $('#ctl00_MainContent_refOnly').click(function() {
        if ($('#ctl00_MainContent_refOnly').attr("checked")) {
            $("#ctl00_MainContent_refChecks input").attr("checked", "checked");
            $("#ctl00_MainContent_textChecks input").removeAttr("checked");
            $("#ctl00_MainContent_textOnly").removeAttr("checked");
        }
        else {
            $("#ctl00_MainContent_refChecks input").removeAttr("checked");
        }
    });

    $('#ctl00_MainContent_btnClear').click(function() {
        $("#ctl00_MainContent_refChecks input").removeAttr("checked");
        $("#ctl00_MainContent_textChecks input").removeAttr("checked");
        $("#ctl00_MainContent_textOnly").removeAttr("checked");
        $("#ctl00_MainContent_refOnly").removeAttr("checked");
    });

    $('#ctl00_MainContent_btnSelect').click(function() {
        $("#ctl00_MainContent_refChecks input").attr("checked", "checked");
        $("#ctl00_MainContent_textChecks input").attr("checked", "checked");
		$("#ctl00_MainContent_textOnly").removeAttr("checked");
        $("#ctl00_MainContent_refOnly").removeAttr("checked");
    });

    v = $('#hideQuickItems').attr('value');
    if (v != "") {
        $('#' + v).remove();
        v = $('#hideFooterItems').attr('value');
        $('#' + v).remove();
    }
    v = $('#hideLeftItems').attr('value');   
    if (v != "") {
        $('#leftmenu_' + v).remove();
    }

    //Centering Topics and Posts columns in discussion board
    $('div#board-wrap tr.post td[align=center]').css('text-align', 'center');
    $('div#board-wrap tr.post td[align=center][class=smallfont]').css('text-align', 'left');
	
	$('table.data tr:even').addClass("even");
});

function ClearNews() {
	$('body.home div.news dl dd:animated').stop();
	$('body.home div.news dl dd').css("opacity","1").css("display","none").css("width","690px").css("height","95px");
	$('body.home div.news dl dt.active').removeClass("active");
	if ($.browser.msie && $.browser.version > 5 ) {
		$('body.home div.news dl dd').css("filter","none !important");
		$('body.home div.news dl dd .background-wrapper').css("background","transparent url('/App_Themes/img/bg_popup_home_todaynews.png') 0px -8px no-repeat").css("filter","none !important");
		if ($.browser.version == 6 ) DD_belatedPNG.fix('body.home div.news dl dd .background-wrapper');
	}
}
function ReorderList(sDir, List) {
    objList = document.getElementById(List);
    if (objList.selectedIndex != null) {
        nSelIndex = objList.selectedIndex;
        objList.selectedIndex = -1;
        if (nSelIndex > -1) {
            //objList.selectedIndex = 0;
            sSelValue = objList[nSelIndex].value;
            sSelText = objList[nSelIndex].text;
            if (sDir == "up" && nSelIndex > 0) {
                sSwitchValue = objList[nSelIndex - 1].value;
                sSwitchText = objList[nSelIndex - 1].text;
                objList[nSelIndex].value = sSwitchValue;
                objList[nSelIndex].text = sSwitchText;
                objList[nSelIndex - 1].value = sSelValue;
                objList[nSelIndex - 1].text = sSelText;
                objList[nSelIndex - 1].selected = true;
            }
            else if (sDir == "dn" && nSelIndex < (objList.length - 1)) {
                sSwitchValue = objList[nSelIndex + 1].value;
                sSwitchText = objList[nSelIndex + 1].text;
                objList[nSelIndex].value = sSwitchValue;
                objList[nSelIndex].text = sSwitchText;
                objList[nSelIndex + 1].value = sSelValue;
                objList[nSelIndex + 1].text = sSelText;
                objList[nSelIndex + 1].selected = true;
            }
        }
        else {
            alert('Please select an option first');
        }
    }
    finalOrd = "";
    for (ii = 0; ii < objList.length; ii++) {
        finalOrd += objList[ii].value
        if (ii < objList.length - 1) {
            finalOrd += ",";
        }
    }
    $("#ctl00_ContentPlaceHolder1_finalOrder").attr('value', finalOrd);
}

