/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// NAVIGATION :: Toggle the navigation menus
var nav_openMenu = null;
var nav_duration = 0.25;
var nav_current	 = null;
var nav_open	 = new Array();

function nav_toggleMenu(id) {
	id = (id == null) ? null : id;
	if( $(id) ) {
		nav_checkMenu(id);
		new Effect.toggle( id, 'blind', {
			duration: nav_duration,
			afterFinish: function() {
				nav_current	= id;
			}
		}); // end Effect
	}
}

function nav_checkMenu(id) {
	for(var i=0; i < nav_open.length; i++) {
		if(nav_open[i] != id) {
			new Effect.BlindUp( nav_open[i], {
					duration: nav_duration
				});
		}
	}
	nav_open = new Array();
	nav_open.push(id);
	return true;
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// LOGO :: EXPAND & CONTRACT
var logo_duration	= 0.15;
function logo_ExpandContract(id, action) {
	
	var id		= (id == null) ? null : id;
	var action	= (action == null) ? 'contract' : action;
	
	if( $(id) ) {
		
		// EXPAND
		if(action == 'expand') {
			new Effect.Morph( id, { 
					style: {
						width: '15.5em',
						cursor: 'pointer'
					},
					duration: logo_duration
			}); // end Effect
			
		// CONTRACT
		} else {
			new Effect.Morph( id, { 
					style: {
						width: '3.5em',
						cursor: 'pointer'
					},
					duration: logo_duration
			}); // end Effect
		}
	}
	
	return false;
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// TRUNCATE :: Hide/Show text that's been truncated with the [hide] tag
var truncate_duration = 0.15;
function text_truncate(id, action) {
	
	var id		= (id == null) ? null : id;
	var action	= (action == null) ? 'contract' : action;
	
	if( $('truncate_'+id) ) {
		
		// EXPAND
		if(action == 'expand') {
			
			$('see_more_'+id).style.display = 'none';
			$('truncate_'+id).style.display = 'inline';
			
		//	new Effect.toggle( $('truncate_'+id), 'blind', {
		//		duration: truncate_duration,
		//		afterFinish: function() {
		//			
		//		}
		//	}); // end Effect
			
			
		// CONTRACT
		} else {
			
			$('see_more_'+id).style.display = 'inline';
			$('truncate_'+id).style.display = 'none';
			
		//	new Effect.toggle( $('truncate_'+id), 'blind', {
		//		duration: truncate_duration,
		//		afterFinish: function() {
		//			
		//		}
		//	}); // end Effect
		}
		
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// POP WINDOW :: Pop Up windows for animation based projects
var pop_default_height = 640;
var pop_default_width  = 480;

function pop_window(directory, height, width) {
	var directory = (directory == null) ? null : directory;
	var height	  = (height == null) ? null : height;
	var width	  = (width == null) ? null : width;
	
	var switch_height = pop_default_height;
	var switch_width  = pop_default_width;
	
	if( directory ) {
		switch(directory) {
			case 'amnh':
				switch_height	= 480;
				switch_width	= 600;
			break;
			
			case 'espn':
				switch_height	= 405;
				switch_width	= 540;
			break;
			
			case 'espn_banner':
				switch_height	= 350;
				switch_width	= 500;
			break;
			
			case 'knoll_auto':
				switch_height	= 410;
				switch_width	= 800;
			break;
			
			case 'knoll_neo':
				switch_height	= 410;
				switch_width	= 800;
			break;
			
			case 'macys':
				switch_height	= 350;
				switch_width	= 500;
			break;
			
			case 'maypop':
				switch_height	= 550;
				switch_width	= 750;
			break;
			
			case 'reuters_cow':
			case 'reuters_gmo':
			case 'reuters_oil':
			case 'reuters_sars':
				switch_height	= 380;
				switch_width	= 536;
			break;
			
			case 'unite':
				switch_height	= 380;
				switch_width	= 630;
			break;
		}
		
		if(height) {
			switch_height = height;
		}
		if(width) {
			switch_width = width;
		}
			
		var y_coord = posTop();
			y_coord = ((y_coord+100)*1);
		
		var x_coord = posLeft();
			x_coord = ((x_coord+290)*1);
			
		var __URL__ = _URL.replace(/\/index.php/,"");
		new_window = window.open(__URL__+"popups/"+directory+"/index.html", directory,"height="+switch_height+", width="+switch_width+", top="+y_coord+", left="+x_coord+", titlebar=no, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, status=no, menubar=no, copyhistory=no, personalbar=no");
		// new_window.moveTo(x,y);
		new_window.focus();
	}
}

function posLeft() {
	// FOR IE
	// X - window.screenLeft
	return window.screenX;	
}

function posTop() {
	// FOR IE
	// Y - window.screenTop
	return window.screenY;
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// SLIDESHOWS :: EXPAND & CONTRACT
var slide_duration	= 0.15;
var slide_max_width	= 590;
var slide_z_index	= 100;
function slide_ExpandContract(id, height_original, width_original, link) {
	var id 				= (id == null) ? null : id;
	var height_original	= (height_original == null) ? null : height_original;
	var width_original	= (width_original == null) ? null : width_original;
	var link			= (link == null) ? null : link;
	slide_z_index		= slide_z_index+1;
	
	if( $(id)) {
		
		// EXPAND
		var slide_open = $('slide_open').value;
		
		if( $('slide_open').value == 'false' ) {
			
			$('slide_open').value = 'true';
			$(id).style.zIndex = slide_z_index;
			
			// slide_InternetExplorer(id, expand);
			new Effect.Morph( id, { 
					style: {
						cursor: 'pointer', 
						width: '59.0em'
					},
					duration: slide_duration,
					afterFinish: function() {
						$('slide_lock').value = 'false';
						$('slideshow_summary').style.cursor = "pointer";
					}
			}); // end Effect
			
			slide_menu = document.getElementsByClassName('slideshow_accordian_link');
			for(i=0; i < slide_menu.length; i++) {
				$( slide_menu[i].id ).href = ($( slide_menu[i].id ).href).replace(/expand:false/,"expand:true");
			}
			
			
		// CONTRACT
		} else {
			$('slide_open').value = 'false';
			new_width = '44.0em';
			switch(width_original) {
				case 440:	new_width = '44.0em'; break;
				case 290:	new_width = '29.0em'; break;
				case 140:	new_width = '14.0em'; break;
			}
			new Effect.Morph( id, { 
					style: {
						cursor: 'pointer', 
						width: new_width
					},
					duration: slide_duration,
					afterFinish: function() {
						// slide_InternetExplorer(id, expand);
						$('slide_lock').value = 'false';
						$('slideshow_summary').style.cursor = "default";
					}
			}); // end Effect
			
			slide_menu = document.getElementsByClassName('slideshow_accordian_link');
			for(i=0; i < slide_menu.length; i++) {
				$( slide_menu[i].id ).href = ($( slide_menu[i].id ).href).replace(/expand:true/,"expand:false");
			}
			
		}
	}
}

function slide_InternetExplorer(id, expand) {
	// HACK FOR IE 6 - The image scaling w/ relative positioning will push elements below it, downward, rather than overlap
	// test for MSIE x.x;
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		var ie_version = new Number(RegExp.$1) // capture x.x portion and store as a number
		if (ie_version >= 8) {
			// IE8 +
		} else if (ie_version >= 7) {
			// IE7
		} else if (ie_version >= 6) {
			// IE6
		} else if (ie_version < 6) {
			// IE5 -
		}
	}
}



/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// SLIDESHOWS :: Toggle Relational Dropdown Menus

function slideshow_toggleMenu(id) {
	id = (id == null) ? null : id;
	
	if( $(id) ) {
		new Effect.toggle( id, 'blind', {
			delay: 0, 
			duration: .25,
			afterFinish: function() {
				
			}
		});
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// EXTERNAL FLV TOGGLES
// NOTE - use ID only for <object> and NAME only for <embed> tags to avoid errors with FireFox
var flv_timeout;
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return $(movieName);
	}
}
function sendToActionScript() {
	flv_timeout = setTimeout('flv_timer()', 3500);
}
function flv_timer() {
	if( thisMovie("flvPlayer") ) {
		thisMovie("flvPlayer").flvCallback();
	}
}

function flv_externalJsFunction() { // the FLV calls this function
	clearTimeout(flv_timeout);
	loadLayer_Hide();
	return false;
}
function flv_externalJsKillTimer() { // the FLV calls this function
	clearTimeout(flv_timeout);
	return false;
}




/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
// LOAD LAYER - display function, used for showing images and slides at true scale, 
//				via a global top layer with an semi-opaque background
var load_childLoaded = null;
function loadLayer_Show(id) {
	id = (id == null) ? null : id;
	if( id ) {
		loadLayer_Move();
		$('load_layer_data').appendChild( $(id) );
		$(id).style.display = "block";
		$(id).setAttribute('style', 'text-align: center;'); // just appending the element aligns it left...
		new Effect.toggle('load_layer', 'appear', { duration: 0.4 });
		new Effect.toggle('body_fog', 'appear', { duration: 0.4 });
		load_childLoaded = id;
	}
}

function loadLayer_Hide() {
	new Effect.toggle('load_layer', 'appear', { duration: 0.4, afterFinish: function() { 
			if(load_childLoaded) { 
				$(load_childLoaded).style.display = "none";
				$('load_layer').appendChild( $(load_childLoaded) );
				load_childLoaded = null;
			}
			$('load_layer_close').style.display = "block";
			$('load_layer_data').innerHTML = "";
		}
	});
	
	new Effect.toggle('body_fog', 'appear', { duration: 0.4, afterFinish: function() {  } });
}


function loadLayer_Move() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		// IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
//	window.alert( 'Width = ' + myWidth );
//	window.alert( 'Height = ' + myHeight );
	
	
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		// Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		// DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		// IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
//	window.alert( 'scrOfX = ' + scrOfX );
//	window.alert( 'scrOfXY = ' + scrOfY );
//	return [ scrOfX, scrOfY ];

	load_layer_move = scrOfY;
	$('load_layer').style.top = load_layer_move+'px';
}
