// ga.gallery.js


function fix_components(action) {
    if (action != ACTION_SHOWITEM) return;
    
//    e1 = document.getElementById('infobox_td');
    e1 = document.getElementById('infobox_td');
    e2 = document.getElementById('infobox_div');
    e2.style.height = e1.offsetHeight.toString() + "px";
    e2.style.width = e1.offsetWidth.toString() + "px";
    //alert('e1.offsetheight:' + e1.offsetHeight);
}


// not sure what this is for:::
function adjust_tabs(page_action) {
	alert ("adjusting tabs for page action: " + page_action);
	if (page_action == ACTION_WELCOME) {
		tid='tab_welcome';
	}
	else if (page_action == ACTION_DIRECTIONS) {
		tid='tab_directions';
		directions_load();
	}
	else if (page_action == ACTION_GALLERY) {
		tid='tab_photos';
	}
	else tid='tab_none';
	
	// make selected tab special
	var e = document.getElementById(tid);
	if (e) {
		//e.style.backgroundColor = '#898989';
		e.className = 'subtabselect';
	}
}


function chip_mouseover(o) {
//    o.style.borderColor='#00FF00';
}

////    ////    ////    ////    ////    ////    ////    ////    ////    ////
// for search textbox

function go_onClick(st) {
	////alert('action_search is:' + ACTION_SEARCH);
	submitForm(ACTION_SEARCH);
}

var default_search_text = '';
var already_clicked = false;

function searchtext_onClick(st) { // st stands for sEARCHtEXT
    if (!already_clicked && (st.value == default_search_text) ) {
        already_clicked = true;
        st.value='';
    }
    document.frmMain._form_action.value = ACTION_SEARCH;
}


/////////////////
// slider
//
// sets the size of the thumbnails
//
function slider(val) {

	if (val == -1) { // make even bigger
		// if not at limit, ask if they want to make even bigger
	//	maxval = increase maxval
		alert('will ask to make size even bigger!');
		tsize = val;
	} else {
		tsize = val;
	}
	//alert("new thumbnail size is "+tsize);

	// set thumbsize and submit form
	
	document.frmMain.thumb.value = tsize;
//	submitForm( ACTION_NONE );
	submitForm( CHOSEN_ACTION );

	return;
}


function fixeee(ename) {
	var e = document.getElementById(ename);
	if (e) e.innerHTML = '<a href="javascript:alert(\'will send email...\');">email goes here</a>';
}


function showitem(itemID) {
	////alert('will show item ' + itemID);
	
		// set itemID hidden POST field to itemID before submitting form
	setField(document.frmMain.itemID, itemID);
	setField(document.frmMain.selectedItem, ''); // clear selectedItem field for this item
	
	submitForm(ACTION_SHOWITEM);
}

function showGallery() {
	//alert('will show gallery with filter \'' + sFilter + '\'');
	
	document.frmMain.itemfilterSUBTYPE.value = '';
	document.frmMain.itemfilterTYPE.value = '';
	//... i guess we could massage sFilter...
	
	submitForm(ACTION_GALLERY);
}


function showGallerySearch() {	
	document.frmMain.itemfilterSUBTYPE.value = '';
	document.frmMain.itemfilterTYPE.value = '';
//	document.frmMain.searchtext.value = '';
	
	submitForm(ACTION_GALLERY);
}


function showGallerySubtype(subtype, type) {
	//alert('will show gallery with filter \'' + sFilter + '\'');
	
	document.frmMain.itemfilterSUBTYPE.value = subtype;
	document.frmMain.itemfilterTYPE.value = type;
	try {document.frmMain.searchtext.value = '';} catch(e) {}
	//... i guess we could massage sFilter...
	document.frmMain.sub_action.value = '';
	
	submitForm(ACTION_GALLERY);
}


function showGalleryType(type) {
	
	document.frmMain.itemfilterSUBTYPE.value = '';
	document.frmMain.itemfilterTYPE.value = type;
	try {document.frmMain.searchtext.value = '';} catch(e) {}
	//... i guess we could massage sFilter...
	document.frmMain.sub_action.value = '';
	
	submitForm(ACTION_GALLERY);
}


function showCatGallery() {
	//alert('will show category gallery page');
	
	submitForm(ACTION_SHOWCATS);
}

        
function print_item(item_id) {
    item_display_id = item_id;
	if (arguments.length > 1) {
		item_display_id = arguments[1];
	}

    //alert("will show item " + item_id);
    show_popup('item','/print_item.php?itemID=' + item_id + '&item_display_id=' + item_display_id, 725,900);
}
  

  ////    ////    ////    ////    ////    ////    ////    ////    ////    ////
     ////    ////    ////    ////    ////    ////    ////    ////    ////
////    ////    ////    ////    ////    ////    ////    ////    ////    ////

// structures for dropdown (dd) menu

// DropDown Object
function DropDown(tcode) {
    this.state = 0;
    this.code = tcode;
    this.img = document.images['dd_img_'+tcode];
    this.e = document.getElementById('m_c_'+tcode); // i think the m_c stood for "Menu Category"
}
DropDown.prototype.toggle_state = function () {
    this.set_state( this.state == 0 ? 1 : 0 );
}
DropDown.prototype.set_state = function (new_state) {
    if (new_state == 0) this.state = 0; else this.state = 1;
    // show appt dd icon image
    this.img.src = (this.state == 0 ? dd_img_closed.src : dd_img_opened.src);
    // show or hide subtypes for this main type
    if (this.e) this.e.style.display = (this.state == 0 ? 'none' : 'block');
}


// functions for ddmenu

var arrTcodes = new Array(); // should rename to ddmenuCodes
///var arrTobj = new Array(); // not sure this is needed

var ddmenu = new Array();
///var dd_img_closed;
///var dd_img_opened;
var dd_img_closed = newImage('img/dd_icon_closed.gif');
var dd_img_opened = newImage('img/dd_icon_opened.gif');

function init_ddmenu() {
    for (var idx in arrTcodes) {
        tcode = arrTcodes[idx];
        if (tcode.substr(0,2) == 'XX') continue; /* omit XX types in menu */
        ddmenu[tcode] = new DropDown(tcode);
    }
}

function dd_drop(tcode) {
    // drops down or rolls up subtypes menu associated with typecode.

    // expand or collapse all others if ALL was toggled
    if (tcode == '_ALL_') {
        allstate = ( ddmenu['_ALL_'].state == 0 ? 1 : 0 );
        for (var tcode in ddmenu) {
            ddmenu[tcode].set_state(allstate);
        }
    } else {
        ddmenu[tcode].toggle_state();
    }
}

function dd_expand(tcode) {
    // drops down subtypes menu associated with typecode.

    if (tcode == '_ALL_') return;
    //alert('tcode is ' + tcode);
//    ddmenu[tcode].set_state(1);
//    dd_drop(tcode);

    // loop thru all menus - open if chosen one, close if not
    for (var cur_tcode in ddmenu) {
        state = (cur_tcode == tcode)?1:0; 
        ddmenu[cur_tcode].set_state(state);
    }

// alternate: start timer.
// when pnged for 500ms, engage
}

var ddtimer = 0;
function ddtimer_start(tcode) {
//    settimer(500,dd_expand(tcode));
    ddtimer = setTimeout( "dd_expand('" + tcode + "')", 750 );
}
function ddtimer_clear() {
    // clear ddtimer - means 
    clearTimeout( ddtimer );
}

  ////    ////    ////    ////    ////    ////    ////    ////    ////    ////
     ////    ////    ////    ////    ////    ////    ////    ////    ////
////    ////    ////    ////    ////    ////    ////    ////    ////    ////

// for aux picture virewing in single-item display mode

function showItemThumb( itemID, selectedItem ) {
	setField(document.frmMain.itemID, itemID);
	setField(document.frmMain.selectedItem, selectedItem);
	submitForm(ACTION_SHOWITEM);
}

var curSelectedItem = '';

function mouseOverThumb( selectedItem ) {
	// turn last selected item off
	if (curSelectedItem) { curSelectedItem.className= ''; }
	// turn selected item on
	curSelectedItem = $('thumb_' + selectedItem);
	curSelectedItem.className= 'hilite';
}
