/* Javascript behaviour specific to Paradise Real Estate */


Event.observe(window, 'load', addListeners);




function addListeners(e)
{
	hideQSForm();
	
	// set up filmstrip on click image change for details.php
	var linkholder = document.getElementById('detail_filmstrip') || $('filmstrip');
	var all_links = linkholder.getElementsByTagName('a');
	for (var i=0; i<all_links.length; i++)
	{
	Event.observe(all_links[i], 'click', thumbpop);
	//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)
	{
		Event.observe(virtual_tour_link, 'click', popSlideShow);
		//virtual_tour_link.onclick = cancelClick;
	}

	// set up slideshow icon to launch window [details.php]
	var slideshow_icon = document.getElementById('slideshow_icon');
	if(slideshow_icon)
	{
		// Event.observe(slideshow_icon, 'click', popSlideShow);
		//slideshow_icon.onclick = cancelClick;
	}

	// set up slideshow icon to launch window [details.php]
	var video_icon = document.getElementById('video_icon');
	if(video_icon)
	{
		Event.observe(video_icon, 'click', popSlideShow);
		//slideshow_icon.onclick = cancelClick;
	}


	// set up print icon to open print dialogue
	var print_icon = document.getElementById('print_icon');
	if(print_icon)
	{
		Event.observe(print_icon, 'click', printPage);
		//print_icon.onclick = cancelClick;
	}
	
	var mortgage_icon = document.getElementById('mortgage_icon');
	if(mortgage_icon)
	{		
		Event.observe(mortgage_icon, 'click', toggleMortgage);
		//mortgage_icon.onclick = cancelClick;
	}
	
	var mortcloser = document.getElementById('closemort');
	Event.observe(mortcloser, 'click', toggleMortgage);
	//mortcloser.onclick = cancelClick;
	
	
	Event.observe($('enquire_icon'), 'click', scrollToEnq);
	//$('enquire_icon').onclick = cancelClick;
	
	
	Event.stop(e);
	
}






function findQSForm()
{
daKid = $('quicksearch').firstChild;
	
	while(daKid.nodeName != 'FORM')
	{
		daKid = daKid.nextSibling;
	}
	return daKid;
}


function toggleQuickSearch()
{	
	
	Effect.toggle(findQSForm(),'blind');
	setTimeout('$("listing_id").focus()',1500);
	//setTimeout('alert("here")',3000);
	//;
}



function hideQSForm() {

findQSForm().style.display="none"; // hide the quicksearch form

Event.observe($('quickactivator'), 'click', toggleQuickSearch, false); // attach onclick to the activator

}

function initCarousel_html_carousel() {
// how many images in list?
var daList = document.getElementById('detail_filmstrip') || $('filmstrip');
var daItems = daList.getElementsByTagName('a').length;
carousel = new Carousel('html-carousel', {animHandler:animHandler, animParameters:{duration:0.5}, buttonStateHandler:buttonStateHandler, nextElementID:'next-arrow', prevElementID:'prev-arrow', size:daItems})};


Event.observe(window, 'load', initCarousel_html_carousel);



function buttonStateHandler(button, enabled) {
 if (button == "prev-arrow") 
   $('prev-arrow').src = enabled ? "images/left3-enabled.gif" : "images/left3-disabled.gif"
 else 
   $('next-arrow').src = enabled ? "images/right3-enabled.gif" : "images/right3-disabled.gif"
}



function animHandler(carouselID, status, direction) {
  
  var region = Element.childrenWithClassName(carouselID,"carousel-clip-region")[0];
  
  if (status == "before") {
    Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
  if (status == "after") {
    Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
}


//--- The functions called by the Add Listeners ---//

function toggleMortgage(e)
{
	Effect.toggle('mortform','Appear');
	Event.stop(e);
}


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;
	Event.stop(e);
}

function popSlideShow(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", "resizable=yes, scrollbars=yes, width=660, height=500, top=100,left=100,");
	Event.stop(ff);
}

function printPage(e)
{window.print(); Event.stop(e); }


function scrollToEnq(e)
{
	new Effect.ScrollTo('enq', {offset: -24});
	Event.stop(e);
	
}

