im_path = "im/" 
skin = ""

function gohash()
{
  location.hash = "view"
}

buttons1 = new Array('but_home', 'but_artists', 'but_contact', 'but_exhibition', 'but_search', 'but_about', 'searchButton.jpg', 'but_terms', 'but_sale', 'but_new_works')

buttons2 = new Array('but_series', 'but_back_to_series', 'but_back_to_works', 'but_back_to_artists',  'but_ex',  'but_back_to_ex', 'but_next', 'but_prev', 'but_see')

function do_load()
{
	return
	page_loaded = 1;
//	im_preload(buttons1, "jpg");
//	im_preload(buttons2, "gif");
//	load_popups(ddmenu_P7_arr);
//	raiseMenuButton();
}

function im_preload(arr, itype)
{
	im = new Array()
	for (n=0; n<arr.length; n++)
	{
		im[n] = new Image()
		im[n].src = im_path + arr[n] + skin + "_f2." + itype
	}
}

var green_mode = 0; //for search button

function highlightSearch(how) //sets search button to green
{
	if (how == "on") 
	{
		document.getElementById('searchButton').src= im_path + skin + "searchButton_f2.jpg"
		green_mode = 1;
	}
	if (how == "off") 
	{
		document.getElementById('searchButton').src= im_path + skin + "searchButton.jpg"
		green_mode = 0;
	}
}

function search_mover()
{
	if (!green_mode) document.getElementById('searchButton').src = im_path + "searchButton_f2.jpg"
}

function search_mout()
{
	if (!green_mode) document.getElementById('searchButton').src = im_path + "searchButton.jpg"
}

function raiseMenuButton() 
{
	if (raised_button) document.images[raised_button].src = im_path + raised_button + '_f2.gif'
}

function jmover(id)
{
	page_id = jmover.arguments[1]
	ext = jmover.arguments[2]
	if (page_id) im = id + "_" + page_id; else im = id
	if (!ext) ext = "_f2"
	document.images[im].src = im_path + skin + id + ext + ".jpg"
}

function jmout(id)
{
	page_id = jmout.arguments[1]
	ext = jmout.arguments[2]
	if (!ext) ext = ""
	if (page_id) im = id + "_" + page_id; else im = id
	document.images[im].src = im_path + skin + id + ext + ".jpg"
}

function gmover(id)
{
	page_id = gmover.arguments[1]
	ext = gmover.arguments[2]
	if (page_id) im = id + "_" + page_id; else im = id
	if (!ext) ext = "_f2"
	document.images[im].src = im_path + skin + id + ext + ".gif"
}

function gmout(id)
{
	page_id = gmout.arguments[1]
	ext = gmout.arguments[2]
	if (!ext) ext = ""
	if (page_id) im = id + "_" + page_id; else im = id
	document.images[im].src = im_path + skin + id + ext + ".gif"
	//  raiseMenuButton() 
}


var win1

function newWin(url,w,h) {
if (win1 && win1.open || win1 && !win1.closed){win1.close()}
win1 = window.open(url,"win1","width="+w+",height="+h+",toolbar=no,location=no,menubar=no,status=no,scrollbars=no,resizable=yes")
}


//--------------------------------------------------------  Expand DIV
var exp_div_moving = new Array();
var exp_offsetHeights = new Array();
var changeTextArr1 = new Array();
var changeTextArr2 = new Array();
var scrolledAlready = 0;
var screenHeight = 0;
var y_offset = 0;
var using_buttons = 0;
var more_button = 'im/show_div.gif'
var less_button = 'im/hide_div.gif'

function changeText (obj, newTextStr) 
{
	if (changeTextArr2[obj.id])
	{
		obj.innerHTML = changeTextArr1[obj.id]; //already displaying newTextStr so go back to showing original str
		changeTextArr2[obj.id] = 0; //unset flag
	}
	else
	{
		changeTextArr1[obj.id] = obj.innerHTML; //store away original textStr for retrieval when re-clicking
		obj.innerHTML = newTextStr; //show newTextStr
		changeTextArr2[obj.id] = 1; //set flag to remember we did this
	}
}
	

function uncover (div_id, linkId, linkTxt)
{
	changeText (linkId, linkTxt);
	expand_div (div_id, 15); //offset of 15 applied to all sliding divs
}



function init_expanding_divs()
{ /* used to capture full div heights before zapping them to 1 to prevent unsightly blank space below page content */
	args = init_expanding_divs.arguments;
	for (n = 0; n< args.length; n++)
	{
		div_id = args[n];
		elem = document.getElementById(div_id);
//		alert(elem)
		exp_offsetHeights[div_id] = parseInt(elem.offsetHeight);
//		alert(exp_offsetHeights[div_id]);		
		elem.style.height = 1;
//		alert(elem.style.height);
	}
}

function expand_div(div_id)
{
	//vars and arguments
	expanded_height = exp_offsetHeights[div_id]; //height of div when shown fully - array element remembers this between calls
	mode = expand_div.arguments[2];
	if (expand_div.arguments[1]) y_offset = expand_div.arguments[1];
	elem = document.getElementById(div_id);
	if (using_buttons) button = document.getElementById("but_"+div_id);
	
	//initial entry into function - no mode defined
	if (!mode) //&& !exp_div_moving[div_id]
	{
		screenHeight = getScreenHeight()
		if (elem.style.visibility == "visible") mode = "c"; else mode = "e"; //collapse if currently visible, else expand
		if (!exp_offsetHeights[div_id]) exp_offsetHeights[div_id] = parseInt(elem.offsetHeight); //initialise height to expand to - and remember this - height only registered when DIV is relative, not absolute (or something...)
		expanded_height = exp_offsetHeights[div_id];
		scrolledAlready = 0;
		exp_div_moving[div_id] = 1; //signify moving
		
		if (mode == "e")
		{
			elem.style.height = '0px';
			elem.style.position='relative';
			elem.style.visibility='visible';
			if (using_buttons) button.src = less_button;
		}		
		if (mode == "c")
		{
			if (!isNaN(elem.style.height)) elem.style.height = expanded_height; //jump start elem.style-height if initially starting expanded and collapse is first operation - otherwise the current_height line below gets NaN
			if (using_buttons) button.src = more_button;
		}			
	}
	
	if (mode == "e") move_inc = 15; else move_inc = -20;
	current_height = parseInt(elem.style.height);
	current_height += move_inc;

	if (mode == "e" && current_height > expanded_height) //stop expanding
	{
		elem.style.height = expanded_height + "px";
		exp_div_moving[div_id] = 0; //stop moving
	}
	else	if (mode == "c" && current_height < 0) //stop collapsing
	{
		elem.style.height = "0px";
		elem.style.position="absolute"
		elem.style.visibility="hidden"
		exp_div_moving[div_id] = 0; //stop moving
	}
	else if (mode == "c" || mode == "e") //expand or collapse
	{
		elem.style.height = current_height + 'px';
		t1 = setTimeout("expand_div('"+div_id+"', '', '"+mode+"')", 10);
		
		//scroll screen down while expanding if bottom of div disappears off bottom of page. Stop scrolling before top disappears though.
		if (mode == "e" && ((mouseY + y_offset + current_height + move_inc) > screenHeight && (mouseY - scrolledAlready - move_inc) > 0))
		{
			new_scroll_position = getScrollPosition() + move_inc
			window.scroll(0, new_scroll_position);
			scrolledAlready += move_inc;
		}
	}
}

var mouseY = 0;

function getMouseCoords(e) 
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (0) //e.pageX || e.pageY) 	
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	
	{
		posx = e.clientX // + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY // + document.body.scrollTop + document.documentElement.scrollTop;
	}
	mouseY = posy;
}


function getScrollPosition()
{
	pos = window.pageYOffset || document.body.scrollTop || 0;
	return pos
}

function getScreenHeight()
{
	if (window.innerHeight) 
	{
		theHeight=window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		theHeight=document.documentElement.clientHeight;
	}
	else if (document.body) 
	{
		theHeight=document.body.clientHeight;
	}
	return theHeight
}

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.ONCLICK)
document.onclick = getMouseCoords;

//--------------------------------------------------------
