/*
* Main nav menu dropdowns
*/
// Create array of avialable dropdown nav1 ids
var navDropdowns = new Array("1a","1b","1c","1d","1e","1f","1g","1h");

// Display nav dropdown
function ir_showNav(nav) {
	ir_hideOtherNavs(nav);
	setNav1Carrot(nav);
	var showItem = '#nav_' + nav + '_nav';
    $(showItem).show();
    if ($.browser.msie) {
        $('select').css('visibility', 'hidden');
    }
}
// Hide one nav dropdown (not currently used)
function ir_hideNav(nav) {
	var hideItem = '#nav_' + nav + '_nav';
	$(hideItem).hide();
	if ($.browser.msie) {
		$('select').css('visibility', 'hidden');
	}
	clearNav1Carrot(nav);
}
// Hide all navs (used when user leaves main nav area)
function ir_hideAllNavs() {
	for (x in navDropdowns)
	{
		var hideItem = '#nav_' + navDropdowns[x] + '_nav';
		$(hideItem).hide();
		if ($.browser.msie) {
			$('select').css('visibility', 'visible');
		}
		clearNav1Carrot(navDropdowns[x]);
	}	
}
// Hide other navs (used to close dropdowns as user goes from one main nav item to another)
function ir_hideOtherNavs(nav) {
	for (x in navDropdowns)
	{
		if (navDropdowns[x] != nav)
		{
			var hideItem = '#nav_' + navDropdowns[x] + '_nav';
			$(hideItem).hide();
			if ($.browser.msie) {
				$('select').css('visibility', 'visible');
			}
			clearNav1Carrot(navDropdowns[x]);
		}
	}	
}

// Clears carrot as user moves away from selected nav item
function clearNav1Carrot(nav) {
	var loc = 'nav_' + nav;
	var x = document.getElementById(loc).style.backgroundImage="";
	var y = document.getElementById(loc).style.backgroundPosition="";
	var z = document.getElementById(loc).style.backgroundRepeat="";
}

// End main nav dropdown code

/* Secondary Navigation JavaScript */
/*onload=setCurrentDirArrow;*/

// Create array of available secondary navigation ids
// SDHardesty 09.15.11 extended this to clean it up and make it more dynamic. Can add more items than can fit without breaking the script
var nav2ids = new Array('2a','2b','2c','2d','2e','2f','2g','2h','2i','2j','2k','2l','2m','2n','2o','2p','2q','2r','2s','2t','2u','2v','2w','2x','2y','2z');

/* this function is used to move the white bar based on selected nav */
function moveWhiteBar(left,right) {
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	var offset = 5.5;
	var origin = findLeftSide('nav2_white');
	var leftElem = findLeftSide(left);
	var rightElem = findLeftSide(right);
	var distance = (leftElem - origin) + ((rightElem - leftElem)/2) - offset;
	var distance = distance + 'px';
	//alert(distance);
	var x = document.getElementById('nav2_white').style.borderLeftWidth=distance;	
}

/* this fuction is used to change the nav arrow based on a user's selection */
function setNavArrow(dir) {
	// SDHardesty 09.15.11 Dynamically figure out what div to set the carrot for rather than havning a long hard carded switch statement
	// Can't find the passed div ID so go with the default 2nd level nav selection
	if ($.inArray(dir,nav2ids) < 0){
		var this2Nav = 'nav_2a';
		var this2NextNav = 'nav_2b';
	} else {
		// Figure out the value of the array position we found the passed variable in and get the next one too for positioning the status bar
		var this2Nav = 'nav_' + nav2ids[$.inArray(dir,nav2ids)];
		var this2NextNav = 'nav_' + nav2ids[$.inArray(dir,nav2ids) + 1];
	}
	
	setNav2Carrot(this2Nav);
	moveWhiteBar(this2Nav,this2NextNav);
	ir_hideOtherSecNavs(nav2ids[$.inArray(dir,nav2ids)]);
	
}

function setCurrentDirArrow(currentdir) {
	/* currentDir gets set based on the current secondary directory. commonspot provides */	
	// SDHardesty 09.15.11 Dynamically figure out what div to set the carrot for rather than havning a long hard carded switch statement
	// Can't find the passed div ID so go with the default 2nd level nav selection
	if ($.inArray(currentdir,nav2ids) < 0){
		var this2Nav = 'nav_2a';
		var this2NextNav = 'nav_2b';
	} else {
		// Figure out the value of the array position we found the passed variable in and get the next one too for positioning the status bar
		var this2Nav = 'nav_' + nav2ids[$.inArray(currentdir,nav2ids)];
		var this2NextNav = 'nav_' + nav2ids[$.inArray(currentdir,nav2ids) + 1];
	}
	
	setNav2Carrot(this2Nav);
	moveWhiteBar(this2Nav,this2NextNav);
	//alert(this2Nav + ' ' + this2NextNav);
}

// Hide other secondary nav indicators
function ir_hideOtherSecNavs(nav) {
	for (x in nav2ids)
	{
		if (nav2ids[x] != nav)
		{
			// SDHardesty 09.15.11 make sure nav exists before trying to clear it
			if ($('#nav_' + nav2ids[x]).length){
				clearNav2Carrot(nav2ids[x]);
			}
		}
	}

}


// Displays carrot for curent navigation area
function testSetNav2Carrot() {
	var loc = 'nav_2a';
	var x = document.getElementById(loc).style.backgroundImage="url(/templateassets/arrow-blue-on-black-up.gif)";
	var y = document.getElementById(loc).style.backgroundPosition="center bottom";
	var z = document.getElementById(loc).style.backgroundRepeat="no-repeat";
}

// Clears carrot as user moves away from selected nav item
function clearNav2Carrot(nav) {
	var loc = 'nav_' + nav;
	var x = document.getElementById(loc).style.backgroundImage="";
	var y = document.getElementById(loc).style.backgroundPosition="";
	var z = document.getElementById(loc).style.backgroundRepeat="";
}

/* this function finds the left side of the passed div */
function findLeftSide(elemID){
var obj = document.getElementById(elemID);
var posX = obj.offsetLeft;
while(obj.parentNode){
posX=posX+obj.parentNode.offsetLeft;
if(obj==document.getElementsByTagName('body')[0]){break}
else{obj=obj.parentNode;}
}
return posX;
}

/* End Secondary Navigation JavaScript */


/**
* Rollovers simple solution -- rollover img should have class "rollover"
* and id = rollover src
*/

//image swap code
function dj_rollover() {
    var temp = this.src;
    this.src = this.id;
    this.id = temp;
}

function ir_bindRollovers(context) {
    //preload rollover images
    $('img.rollover', context).each(function() {
        var ii = new Image();
        ii.src = this.id;
    });

    //bind image swapping to all images with class "rollover"
    $('img.rollover', context).hover(dj_rollover, dj_rollover);
}


function killBrightcovePlayback() {
	try {
		callFlash('pauseAd', true); 
		callFlash('stopVideo');
	} catch (err) {
		// do nothing
	}
}

function findIdx(item, arr) {
// find index position of {item}
// in Array {arr} - return -1, if
// item not found
var idx;
var last = arr.length;
for (var i = 0; i < last; i++) {
idx = (item == arr[i])?i:-1;
// quit on first "found"
if (-1 != idx) break;
}
return idx;
}


// TABBED NAVIGATOR 
// quick browser tests
var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ie6 = (document.all && document.getElementById) ? true : false;
var ie7 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function show(sw,obj) {
	// show/hide the divisions
	if (sw && (ie4 || ie5 || ie6 || ie7) ) document.all[obj].style.display = 'inline';
	if (!sw && (ie4 || ie5 || ie6 || ie7) ) document.all[obj].style.display = 'none';
	if (sw && ns4) document.layers[obj].display = 'inline';
	if (!sw && ns4) document.layers[obj].display = 'none';
}

function on(i) { document.getElementById(i).className="show"; }
function off(i){ document.getElementById(i).className="hide"; }

