addEvent(window, 'load', addListeners, false);



function addListeners(e)
{
	// set up filmstrip on click image change for details.php
	var linkholder = document.getElementById('detail_filmstrip');
	var all_links = getElementsByClassName(linkholder, 'thumbpop');
	for (var i=0; i<all_links.length; i++)
	{
	addEvent(all_links[i], 'click', thumbpop, false);
	all_links[i].onclick = cancelClick;
	}
	
	// set up virtual tour icon to launch window [details.php]
	var virtual_tour_link = document.getElementById('virtual_tour_link');
	if(virtual_tour_link)
	{
		addEvent(virtual_tour_link, 'click', popUrlToWindow, false);
		virtual_tour_link.onclick = cancelClick;
	}

	// set up slideshow icon to launch window [details.php]
	var slideshow_icon = document.getElementById('slideshow_icon');
	if(slideshow_icon)
	{
		addEvent(slideshow_icon, 'click', popUrlToWindow, false);
		slideshow_icon.onclick = cancelClick;
	}
	
	// set up print icon to open print dialogue
	var print_icon = document.getElementById('print_icon');
	if(print_icon)
	{
		addEvent(print_icon, 'click', printPage, false);
		print_icon.onclick = cancelClick;
	}
	
	if($('mortgage')){
		Event.observe($('mortgage'), 'click', function(){
		Element.toggle($('mortform'))
		})
	}
	
	if($('closemort')){
		Event.observe($('closemort'), 'click', function(){
		Element.toggle($('mortform'))
		})
	}

	
}



function thumbpop(e)
{
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el)
		return;
	
	var str = el.src.replace(/\/thumb\//, '/large/')
	document.getElementById('bigphoto').src = str;
}

function popUrlToWindow(ff)
{
	var el;
	// I.E.
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	
	if (ff && ff.target)
	// target is the click target of the link, i.e. an image (slideshow.gif), not the link URL
	// by climbing back up a level with parent.Node we get the actual link itself
	//W3C
		el = ff.target;
	if (!el)
		return;
		
	//just added from book wedn
	while (el.nodeName.toLowerCase() != 'a' && el.nodeName.toLowerCase() != 'body')
	el = el.parentNode;
		
	slideshow_window = window.open(el, "SlideShowWindow", "scrollbars=yes, width=640, height=480, top=100,left=100,");
}

function printPage()
{window.print();}





//----------------------------------------
// the functions below are very useful and
// enable proper event handling 
// in IE and modern browsers
//----------------------------------------
function addEvent(elm, evType, fn, useCapture)
{ 	// cross-browser event handling for IE5+, NS6+, 
	// and Mozilla/Gecko
	if(elm.addEventListener)
	{
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} 
	else if (elm.attachEvent)
	{
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else { elm['on' + evType] = fn; }
}



function handleLink (e)
{
	var el;
	if (window.event && window.event.srcElement)
		el = window.event.srcElement;
	if (e && e.target)
		el = e.target;
	if (!el)
		return;
}



function getElementsByClassName(node, classname)
{
    var a = [];
    var re = new RegExp('(^| )'+classname+'( |$)');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

function cancelClick()
{
return false;
}