/////////////////////////////////////
// script for slide show
///////////////////////////////////
var miCurrImgIndex = 0;
var timerRunning = false;
var timerId = null;
var paused = false;
var bFirstPass = true;

function propimgMoveNextDown()
{
//	$('next-button').style.display = 'none';
//	$('next-button-down').style.display = 'inline';
	$('next-button').src='img/property-next-button-down.gif'
}
function propimgMoveNextUp()
{
	$('next-button').src='img/property-next-button.gif';
//	$('next-button-down').style.display = 'none';
//	$('next-button').style.display = 'inline';
	propimgMoveNext();
}
function propimgMovePrevDown()
{
	$('prev-button').style.display = 'none';
	$('prev-button-down').style.display = 'inline';
}
function propimgMovePrevUp()
{
	$('prev-button-down').style.display = 'none';
	$('prev-button').style.display = 'inline';
	propimgMovePrevious();
}
function propimgMoveNext()
{
	hideCurrentImage();
	miCurrImgIndex++;
	if(miCurrImgIndex > imgList.length - 1) miCurrImgIndex = 0;
	propimgDisplayCurrent();
}

function propimgMovePrevious()
{
	hideCurrentImage();
	miCurrImgIndex--;
	if(miCurrImgIndex < 0) miCurrImgIndex = imgList.length - 1;
	propimgDisplayCurrent();
}
function hideCurrentImage()
{
	var oImg = $(imgList[miCurrImgIndex]);
	if(oImg)
		oImg.style.display = "none";
}
function propimgDisplayCurrent()
{
	if(bFirstPass)
	{
		bFirstPass = 0;
		miCurrImgIndex = 0;
		$('baseimg').style.display = "none";
	}

	var oElem = $(imgList[miCurrImgIndex]);
	if(oElem) {
    	oElem.style.display = "inline";
	}
}
function propimgStartTimer()
{
	$('pause-button-down').style.display = "none";
	$('pause-button').style.display = "inline";
	$('play-button').style.display = "none";
	$('play-button-down').style.display = "inline";

	if(paused) {
		paused = false;
		propimgMoveNext();
	}
	timerRunning = true;
	timerID = self.setTimeout("propimgTimerEvent()", 4000);
}
function propimgTimerEvent()
{
	propimgMoveNext();
	propimgStartTimer();
}
function propimgStopTimer()
{
	$('play-button-down').style.display = "none";
	$('play-button').style.display = "inline";
	$('pause-button').style.display = 'none';
	$('pause-button-down').style.display = 'inline';

	if(timerRunning) {
		clearTimeout(timerID);
		paused = true;
	}
	timerRunning = false;

}

propimgStartTimer();


/********************************************************/
function goToPage(iPage)
{
	document.getElementById("txtCurrentPage").value = iPage;
	document.getElementById("txtAction").value = "CHANGEPAGE";
	document.getElementById("frmComplexProp").submit();
}


function homesPerPageChange(iCnt)
{
	document.getElementById("txtCurrentPage").value = 1;
	document.getElementById("txtAction").value = "CHANGEVIEW";
	document.getElementById("txtResultsPerPage").value = iCnt;
	document.getElementById("frmComplexProp").submit();
}

function homesPerPageChangeSelect(cbObj)
{
	document.getElementById("txtAction").value = "CHANGEVIEW";
	document.getElementById("txtCurrentPage").value = 1;
	document.getElementById("txtResultsPerPage").value = cbObj.value;
	document.getElementById("frmComplexProp").submit();
}


function sortChange(sFld)
{
	var frm = document.getElementById("frmComplexProp");
	var oSort = document.getElementById("txtSort");
	var oDir = document.getElementById("txtSortDir");

	sSort = oSort.value;
	sDir  = oDir.value;

	if(sFld == sSort) {
		if(sDir == "asc") sDir = "desc";
		else sDir = "asc";
	} else {
		sSort = sFld;
		sDir = "asc";
	}


	oSort.value = sSort;
	oDir.value = sDir;
	document.getElementById("txtAction").value = "CHANGESORT";
	frm.submit();

}

function emailSearchResults()
{
	var sChkIn = document.getElementById("txtCheckIn").value;
	var sNights = document.getElementById("cbNights").value;
	var sBeds = document.getElementById("cbBedrooms").value;
	var sRent = document.getElementById("cbRent").value;
	var sArea = document.getElementById("cbArea").value;
	var sType = document.getElementById("cbType").value;
	var sAttr = document.getElementById("altattr").value;
	var sSort = document.getElementById("txtSort").value;
	var sSortDir = document.getElementById("txtSortDir").value;

	var sQryStr = "search_results_create.php?date1=" + sChkIn + "&nights=" + sNights + "&beds=" + sBeds +
		"&rent=" + sRent + "&areas=" + sArea + "&types=" + sType + "&attr=" + sAttr + "&sort=" + sSort +
		"&sortdir=" + sSortDir + "&page=quicksearch";
	alert(sQryStr);
	beginEmailProcess(sQryStr);
	return false;
}

function addToFavorites(sPropId)
{
	_gaq.push(['_trackEvent', 'BRE Links', 'Click', 'Visitor Added to Favorites']);
	var trk = null;
//	try {
//		if(ADDTOFAVORITES != "")
//		{
//	        try{
//    		    trk = createITT();
//    		    trk.ACTION = ADDTOFAVORITES;
//    		    trk._S_SKU = sPropId;
//    		    trk.submit_action();
//	        }catch(err){}
//		}
//	} catch (err) {}

	document.getElementById("txtAction").value = "CHANGEPAGE";
	document.getElementById("txtFavPropId").value = sPropId;
	document.getElementById("frmComplexProp").submit();
    return false;
}
function addToComplexFavorites(iCompId)
{
	var trk = null;
//	try
//	{
//		if(ADDTOFAVORITES != "")
//		{
//	        try{
//    		    trk = createITT();
//    		    trk.ACTION = ADDTOFAVORITES;
//    		    trk._S_SKU = iCompId;
//    		    trk.submit_action();
//	        }catch(err){}
//		}
//	} catch (err) {}

	document.getElementById("txtAction").value = "CHANGEPAGE";
	document.getElementById("txtFavCompId").value = iCompId;
	document.getElementById("frmComplexProp").submit();
    return false;
}

function createBookmark()
{
	title = sComplexName;
	url = sBaseUrl + "complexprop.php?cid=" + sComplexId;
	if(window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.external)
	{
		window.external.AddFavorite(url, title);
	}
	else if(window.opera)
	{
		var abk = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
		abk.style.display = "none";
	}
	return false;
}
