// JavaScript Document// hide any DOM element by ID name

function hide(element) {

	document.getElementById(element).style.display='none';

}



// show (un-hide) any DOM element by ID name

function show(element) {

	document.getElementById(element).style.display='';

}



function show_layover(l_type, calling_object, expand_to_side, l_title,l_image, l_sub_title, l_text, l_extras) {



	// add an 'onmouseout' event to the calling object (usually an anchor tag)

	// onmouseout, hide the layover

	// this will overwrite any existing onmouseout functionality for the calling object (possibly a problem with .net)

	//calling_object.onmouseout = function () { hide('layover'); } 

	

	// l_ represents layover - should help prevent name collision

	

	// make sure that the layover is hidden

	hide('layover');



	// get the position of the calling object (the anchor tag)

	object_position = find_position(calling_object);	

	

	// reposition the layover

	if (expand_to_side == "right") {
		
		// left -- left edge of calling_object, plus the width of the calling object

		// top -- top of calling_object, minus a number to roughly position the 'point' in the correct position

		document.getElementById('layover').style.left = object_position[0] + calling_object.offsetWidth + 10 + 'px';

		document.getElementById('layover').style.top = object_position[1] - 58 + 'px';	



		// hide the right pointer, show the left

		hide('layover_pointer_right');

		show('layover_pointer_left');

	} else {

		document.getElementById('layover').style.left = object_position[0] - 28 + 'px';

		document.getElementById('layover').style.top = object_position[1] - 100 + 'px';	



		// hide the left pointer, show the right

		hide('layover_pointer_left');

		show('layover_pointer_right');

	}

		

	// update the content of the window

	document.getElementById('layover_title_text').innerHTML=l_title;

	//document.getElementById('layover_image').src=l_image;

	document.getElementById('layover_sub_title').innerHTML=l_sub_title;

	document.getElementById('layover_text').innerHTML= eval("\"" + l_text + "\"");

	document.getElementById('layover_extras').innerHTML=l_extras;

	

	// what type of layover is this?

	/*

		1 - directory => title, address, image on right w border, copy, optional extras in footer

		2 - destination => title, empty, image on left no border, copy, empty

		3 - maps and guides => title, empty, image on right w border, copy, empty

		4 - welcome center => title, address, image on left no border, copy, empty

		5 - simple (subscriptions => title, empty, empty, copy, empty

		6 - snow report => title, location, image with border on right, copy, icons

		999 - page preview ==> page url, large image

	*/

	

	switch(l_type) {

		case 1:

			//document.getElementById('layover_image_container').className = 'dir'

			//document.getElementById('layover_image').className = 'dir'; // border and positioning

			document.getElementById('layover_sub_title').className = 'bold'; // address is bold

			break;

		case 2:

			//document.getElementById('layover_image').className = 'dest'; // border and positioning

			//document.getElementById('layover_text').className = 'first_line'; // first line is bold

			//document.getElementById('layover_text').style.marginLeft = '65px';

			

			//document.getElementById('layover_image_container').className = 'float_left';

			document.getElementById('layover_text').className = 'first_line float_right';

			document.getElementById('layover_text').style.width = '215px';			

			

			hide('layover_sub_title');

			hide('layover_extras');

			break;

		case 3:

			//document.getElementById('layover_image_container').className = 'mg float_right';

			//document.getElementById('layover_image').className = 'mg'; // border and positioning

			//document.getElementById('layover_image').style.border = '4px solid #999999'; // ie6 is great!

			hide('layover_sub_title');

			hide('layover_extras');

			break;

		case 4:

			//document.getElementById('layover_image').className = 'dest'; // border and positioning

			//document.getElementById('layover_image_container').className = 'dest float_left';

			document.getElementById('layover_sub_title').className = 'float_right first_line'; // first line of address is bold

			document.getElementById('layover_sub_title').style.height = '40px'; // clear the image - make room for the description

			document.getElementById('layover_sub_title').style.width = '210px';

			document.getElementById('layover_text').style.clear = 'both';

			//hide('layover_extras');

			//document.getElementById('layover_text').style.clear = 'left';

			document.getElementById('layover_text').innerHTML = '<strong>Description</strong><br /> ' + l_text; // prepend

			break;

		case 5:

			hide('layover_sub_title');

			hide('layover_image');

			hide('layover_extras');

			document.getElementById('layover_body').style.paddingBottom = '1px'; // tighten up the bottom

			break;

		case 6:

			//document.getElementById('layover_image_container').className = 'dir' // image on the right

			//document.getElementById('layover_image').className = 'dir'; // border

			document.getElementById('layover_sub_title').className = 'bold inline ie6'; // address is bold

			break;

		case 999:		

			// strip off the http:// ....com/ portion of the name

			l_position = l_title.indexOf('.com');

			document.getElementById('layover_title_text').innerHTML = l_title.substring(l_position + 4);

			hide('layover_sub_title');

			hide('layover_text');

			hide('layover_extras');



			// brief time delay

			//time_delay(500);

			break;

	}

	

	// display the layover

	show('layover');

	

}



// from http://www.quirksmode.org/js/findpos.html#

function find_position(obj) {

	var curleft = curtop = 0;

	if (obj.offsetParent) {

		curleft = obj.offsetLeft

		curtop = obj.offsetTop

		while (obj = obj.offsetParent) {

			curleft += obj.offsetLeft

			curtop += obj.offsetTop

		}

	}

	return [curleft,curtop];

}



// this is used on pages with search filtering that can expand/collapse

function toggle_filter_display(element, calling_item) {

	if (document.getElementById(element).style.display == 'none') {

		document.getElementById(element).style.display = '';

		calling_item.className = 'form_label_open'

	} else {

		document.getElementById(element).style.display = 'none';

		calling_item.className = 'form_label_closed'

	}

}



// makes text search fields nice to use

function smart_clear(element) {

	if (element.defaultValue == element.value) {

		element.value = '';

	}

}



function smart_restore(element) {

	if (element.value == '') {

		element.value = element.defaultValue;

	}

}



// popup window function 

function popUp(URL) {

	day = new Date();

	id = day.getTime();

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=465,height=450,left = 346,top = 135');");

	return false;

}





// time delay borrowed from www.sean.co.uk

function time_delay(millis) {



	var the_date = new Date();

	var current_date = null;



	do { 

		current_date = new Date(); 

	}

	

	while(current_date-the_date < millis);

}



// find the height of the current browser window

// modified version - original from www.howtocreate.co.uk

function find_window_height() {

  var myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE

    myHeight = window.innerHeight;

  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myHeight = document.body.clientHeight;

  }

  return myHeight;

}


