//SUB NAV for single-3.php

//globals:
var subnav_nm = '/wp-content/themes/laudanum/images/button_nm.gif';
var subnav_hv = '/wp-content/themes/laudanum/images/button_hv.gif';
var subnav_active = '/wp-content/themes/laudanum/images/button_active.gif';
var last_div = 1; //used to hide last media div
var last_btn = 1; //used to erase last active state of sub nav button
var browser=navigator.appName; //detect IE for frame_change()

//functions to hide/show divs:
function set_display(id,display) {
	document.getElementById(id).style.display = display;
}
function show_bio() {
	change_frame('240px'); //bios are short
	set_display('essay','none');
	set_display('artwork','none');
	set_display('bio','block');
}
function show_essay() {
	change_frame('auto'); 
	set_display('bio','none');
	set_display('artwork','none');
	set_display('essay','block');
}
function show_mono_bio() {
	change_frame('240px'); //bios are short
	set_display('essay','none');
	set_display('bio','block');
}
function show_mono_essay() {
	change_frame('auto'); 
	set_display('bio','none');
	set_display('essay','block');
}
function show_artwork() { //artwork meta data
	set_display('bio','none');
	set_display('essay','none');
	set_display('artwork','block');
}
function show_media(id) {
	change_frame('240px');
	if (id!=last_div) {
		if(document.getElementById('media_' + last_div)){ //media last
			document.getElementById('media_' + last_div).style.display = 'none';
			document.getElementById('media_' + id).style.display = 'block';
		} 
	}
}

//functions to handle button images:
function change_button(id) {
	if (id!=last_btn) {
		document.getElementById('subnav_' + last_btn).src = subnav_nm;
		document.getElementById('subnav_' + id).src = subnav_active;
	}
}
function over_button(id) {
	if (id!=last_btn) {
		document.getElementById('subnav_' + id).src = subnav_hv;
	}
}
function off_button(id) {
	if (id!=last_btn) {
		document.getElementById('subnav_' + id).src = subnav_nm;
	}
}

//function to handle frame for essay/bio:
function change_frame(height) {
	if (height=='auto') {
		document.getElementById('frame').style.height = height;
		if (browser=="Microsoft Internet Explorer") {
			document.getElementById('frame').style.overflow = 'auto';
		}
	} else { //fixed height
		document.getElementById('frame').style.height = height;
		if (browser=="Microsoft Internet Explorer") {
			document.getElementById('frame').style.overflow = 'hidden';
		}
	}
	
}

//main sub nav function called on click:
function subnav(type,id,src) {
	switch(type) {
		case 'image':
		show_media(id);
		show_artwork();
		change_button(id);
		last_div = id;
		last_btn = id;
		break;
		
		case 'video':
		show_media(id);
		show_artwork();
		change_button(id);
		last_div = id;
		last_btn = id;
		break;
		
		case 'audio':
		show_media(id);
		show_artwork();
		change_button(id);
		last_div = id;
		last_btn = id;
		break;
		
		case 'essay':
		show_essay();
		change_button(id);
		last_btn = id;
		break;
	}
}
