/*
 * Written by CJ Hanson and Alex Petrescu
 * © 2007 The Buddy Group.
 * BUDeSYSTEM and other marks are trademarks or service marks of The Buddy Group.
 * All Rights Reserved.
 * Use subject to terms of a licensing agreement with licensee.
 * Contact The Buddy Group at www.thebuddygroup.com for more information.
*/

$ = jQuery.noConflict();

var active_el = '';
var active_sub_el = '';
var active_sub_sub_el = '';

var profiles = {
	pop_up:{
		width:700,
		height:500,
		center:1,
		createnew:0,
		resizable:0,
		scrollbars:1
	}
};

$(document).ready(function(){
	$(window).resize(function(){setHeight();});
	$('.popupwindow').popupwindow(profiles);
	$(".subNavItem").not(".siteNavItemActive").hover(
		function(){
			i = $(this).find('img').eq(0);
			newp = $(i).attr('src').replace('_up','_over');
			$(i).attr('src',newp);
		},
		function(){
			i = $(this).find('img').eq(0);
			newp = $(i).attr('src').replace('_over','_up');
			$(i).attr('src',newp);
		}
	);
	$(".subSubNavItem").not(".siteNavItemActive").hover(
		function(){
			i = $(this).find('img').eq(0);
			newp = $(i).attr('src').replace('_up','_over');
			$(i).attr('src',newp);
		},
		function(){
			i = $(this).find('img').eq(0);
			newp = $(i).attr('src').replace('_over','_up');
			$(i).attr('src',newp);
		}
	);
	$(".hasSubNav").hover(
		function(){
			showSubNav();
		},
		function(){ 
			return false; 
		}
	);
	$(".subNavItem").not(".hasSubNav").mouseenter(
		function(){
			hideSubNav();
		}
	);
	// set active nav item, if there is one
	if(active_el !== ''){
		makeSelected(active_el);
	}
	if(active_sub_el !== ''){
		makeSelected(active_sub_el);
	}
	if(active_sub_sub_el !== ''){
		makeSelected(active_sub_sub_el+"SubNav");
		showThis(active_sub_sub_el);
	}
	setTimeout("setHeight();",200);
});

function setHeight(){
	var less = ($.browser.msie) ? 181 : 175;
	var ieFix = ($.browser.msie) ? 23 : 0;
	//$('#siteContainer').css('height', '100%');
	//if ($('#siteContainer').outerHeight() - ieFix < $(window).height() - less) {
		//$('#siteContainer').height($(window).height() - less);
		$('#siteContainer').css('minHeight', $(window).height() - less);
	//}
}

function showThis(itm) {
	$(".isSubNavContainer").css('display','block');
	//$(".leadershipSortContainer").css('display',"none");
	$("#leadershipSubNavSub").removeClass('isSubNavContainer');
	if (itm !== '') {
		i = itm + "_nav";
		$("#"+itm).css('display',"block");
	}
}

function showSubNav()
{ 
	$(".isSubNavContainer").css('display','block'); 
}

function hideSubNav()
{ 
	$(".isSubNavContainer").not(".permanant").css('display','none'); 
}

function makeSelected(itm) {
	// set active nav item, if there is one
    if(itm !== ''){
        i = $("#"+itm).find("img:eq(0)");
	   if (i.length > 0) {
        	newp = $(i).attr('src').replace('_up','_selected');
        	$(i).attr('src',newp);
	   } else {
	  	 $('#'+itm+"_radio").attr('checked','checked');
	   }
    }
}

//CAPTCHA
function setFieldValue(myFieldID, myFieldValue){
	//alert('set field: '+myFieldID+', '+myFieldValue);
	document.getElementById(myFieldID).value = myFieldValue;
}