var fontsize = 13;
var savedFontSize = 13;

$(document).ready(function () {
		setFontSize(); 
		
		if (document.getElementById("map1")) GetMap();
		loadBoxes();
	}
);
function setFontSize() {
	if (savedFontSize)
	{
		savedFontSize = Get_Cookie("FontSize");
		if (parseInt(savedFontSize)) fontsize = savedFontSize;
		el = document.getElementsByTagName("body");
		if (el)
		{
			try
			{
				el[0].style.fontSize = fontsize + "px";	
			}
			catch (ex)
			{
				;
			}
			
		}
	}
}

function changeFontSize(direction) {
	el = document.getElementsByTagName("body");
	if (direction == 0)
	{
		el[0].style.fontSize = "13px";
		fontsize = 13;
	} else {
		if (fontsize >= 19 && direction > 0) return true;
		if (fontsize <= 11 && direction < 0) return true;
		fontsize = parseInt(fontsize) + parseInt(direction); 
		el[0].style.fontSize = fontsize + "px";
	}
	direction = 1 - direction;
	Set_Cookie("FontSize", fontsize, 1);
}

function alert2(msg, title) {
	txt = "<div class='alert' onclick='closeWait();'>";
	if (title)
	{
		txt += "<div class='title'>" + title + "</div>";
	}
	txt += "<div class='message'>" + msg + "</div>";
	message2(txt);
}

function alert3(msg) {
	showOverlay();
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 24px; left: -3px;" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ "<div class='msgalert' style='background-color:#fff; -moz-border-radius: 0.6em;	-webkit-border-radius: 0.6em;	border-radius: 0.6em; border: 2px solid #f10000; padding: 0px;'>" + msg+"</div></div>");
}

function checkKey(e) {
	try
	{
		if (e.keyCode == 13) doSearch();	
	}
	catch (ex)
	{
	}
	
}

function doSearch() {
	window.location="/index.php?o=search-results&query=" + $("#Search").val();
}

var boxes = [1,1,1,1,1,1,1,1,1,1];
function toggleBox(obj) {
	try
	{
		boxid = obj.attr("id").substring(3);
		if (boxid == 1) return true;
		if (boxes[boxid])
		{
			obj.hide('slow', 'swing');
			if (boxid != 2) obj.parent().find(".boxhead").css("background-image", "url(images/triangle-red-right.png)");
		} else {
			obj.show('fast', 'swing');
			if (boxid != 2) obj.parent().find(".boxhead").css("background-image", "url(images/triangle-red-up.png)");
		}
		boxes[boxid] = 1 - boxes[boxid];
		Set_Cookie("Boxes", boxes.concat(), 30);		
	}
	catch (ex)
	{
	}

}

var sliderLeft = 0;
var sliderCount = 4;
var slideInterval;
var slideTimer = 150;
var slideDirection = 0;
var slideStep = 0;
var slideSteps = 0;
var stepDuration = 10;
var slideLength = 0; //pixels

function slideLeft() {
	if (sliderLeft>=-100) return false;
	slideDirection = 1;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
	$("#pageno").html("1/2");
}

function slideRight() {
	slideDirection = -1;
	el = document.getElementById("slider");
	slideLength = el.offsetWidth * -1 + 990;
	if (sliderLeft <= slideLength) return false;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
	$("#pageno").html("2/2");	
}

function slide() {
	slideStep ++;
	if (slideStep > slideSteps)
	{
		slideStep = 0;
		clearInterval(slideInterval);
		return true;
	}
	increment = Math.abs(855) / slideSteps;
	el=document.getElementById('slider'); 
	sliderLeft = sliderLeft + increment * slideDirection;
	el.style.marginLeft= sliderLeft + 'px';
	
}


function enableTab(id, pages) {
	for (i=1; i<=pages ;i++ )
	{
		if (i==id) continue;
		$("#page" + i).css("display", "none");
		$("#tab" + i).removeClass("active")
	}
	$("#page" + id).css("display", "block");
	$("#tab" + id).addClass("active")
	return true;
}

function highlight(obj) {
	$(obj).addClass("active");
}

function unhighlight(obj) {
	$(obj).removeClass("active");
}

var currentMode;
function searchCondos(mode) {
	showWait2();
	if (!mode) mode = currentMode;
	if (!mode) mode = getQueryVariable("mode");
	if (!mode) mode = "city";
	currentMode = mode;
	criteria = "";
	criteria = $("#price").val() + "|" + $("#sqft").val();
	txt = [];
	el = document.getElementsByName("Bedrooms");
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Features");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("Occupancy");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");

	el = document.getElementsByName("City");
	txt = [];
	for (i=0;i<el.length ;i++ )
	{
		if (el[i].checked)
		{
			txt[txt.length] = el[i].value;
		}
	}
	criteria += "|" + txt.join(";");
//	alert(mode);
	url = "/index.php?s=main&o=get-results&criteria=" + criteria + "&mode=" + mode;
//	wait();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_searchCondos;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _searchCondos() {
	if(checkReadyState(xmlhttp)) {
		closeWait();
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#results").html(getXMLNode(ret));
		window.location="#results";
	}
}



function filterSpotlight(obj, idx) {
	slideLeft();
	$(".spotlight .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	var c = 0;
	$(".slide-cell").each(function () { x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[2]) == parseInt(idx)) { $(this).css("display", "block"); c++}else $(this).css("display", "none"); });
	if (c > 5) { $("#pageno").html("1/2"); $("#pageno").css("display","block");} else {$("#pageno").css("display","none");}

	
	obj2 = $(obj).parent().parent().find('.spotlight-content');
	if (!boxes[obj2.attr("id").substr(3)]) toggleBox(obj2);
	return false;
}

function filterInventory(obj, idx) {
	$("#movetoday .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#movetoday .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function filterFinances(obj, idx) {
	$("#finances .spotlight-nav-button-active").removeClass("spotlight-nav-button-active").addClass("spotlight-nav-button");
	setClass(obj, "spotlight-nav-button-active");
	$("#finances .spotlight-content").each(function () {x = $(this).attr("id"); y = x.split("-");  if (parseInt(y[1]) == parseInt(idx)) $(this).css("display", "block"); else $(this).css("display", "none"); });
	return false;
}

function saveStory() {
	url = "/index.php?s=main&o=save-testimonial&Name=" + $("#Name").val() + "&Email=" + $("#Email").val() + "&Phone=" + $("#Phone").val() + "&Story=" + $("#Story").val();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_saveStory;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _saveStory() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		alert2(getXMLNode(ret));
	}
}


function maintenancePopup(popupid) {
	txt = "<div class='alert'>" + $("#" + popupid).html() + "</div>";
	alert3(txt);
}


var feeds = ["togglestates", 1,1,1,1];
function toggleAppFeed(obj) {
	i = obj.id.split("-");
	if (feeds[i[1]])
	{
		obj.src = obj.src.replace(".png", "-off.png");
	} else {
		obj.src = obj.src.replace("-off", "");
	}
	feeds[i[1]] = 1 - feeds[i[1]];
	updateFeeds();
}

function updateFeeds() {
	$("#feedData").html("<img src='images/spinning.gif' style='margin: 100px 0 0 60px'>");
	url = "/index.php?o=update-feeds&feeds=" + feeds.concat();
	initObj();
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_updateFeeds;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _updateFeeds() {
	if(checkReadyState(xmlhttp)) {

		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("content");
		$("#feedData").html(getXMLNode(ret));
	}
}

function loadBoxes() {
	tmp = "";
	tmp2 = "";
	tmp = Get_Cookie("Boxes");
	if (tmp)
	{
		tmp2 = tmp.split(",");
		for (i=1;i<=boxes.length ;i++ )
		{
			if (!parseInt(tmp2[i])) toggleBox($('#box' + i));
		}
	}

}

function playVideo(filename) {
	txt = '<div style="width: 640px; height: 480px; padding: 0px; background-color: #000000; z-index: 5"><OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" WIDTH="500"HEIGHT="320" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">';
	txt += '<PARAM name="SRC" VALUE="'+filename+'">';
	txt += '<PARAM name="AUTOPLAY" VALUE="true">';
	txt += '<PARAM name="CONTROLLER" VALUE="false">';
	txt += '<EMBED SRC="'+filename+'" WIDTH="640" HEIGHT="480" AUTOPLAY="true" CONTROLLER="false" PLUGINSPAGE="http://www.apple.com/quicktime/download/">';
	txt += '</EMBED>';
	txt += '</OBJECT></div>';
	overlaycolor = "#000000";
	showOverlay();
	overlaycolor = "#ffffff";
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 18px; right: -19px; z-index: 100" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ txt+"</div>");

}

function playYoutube(src, wd, ht) {
	txt = '<iframe width="'+wd+'" height="'+ht+'" src="'+src+'" frameborder="0" allowfullscreen></iframe>';
	overlaycolor = "#000000";
	showOverlay();
	overlaycolor = "#ffffff";
	box("<div>"+'<div class="login-close" style="text-align: right"> <a href="#" onclick="return false"><img style="position: relative; top: 18px; right: -19px; z-index: 100" src="images/icon_delte_up.gif" alt="close" name="closepop"  border="0" id="closepop" onmouseover="MM_swapImage(\'closepop\',\'\',\'images/icon_delte_over.gif\',1)" onmouseout="MM_swapImgRestore()" onclick="closeWait()" /></a></div>'+ txt+"</div>");

}

function showLoginOptions() {
	txt = "<div class='alert'>Please select one the following options: <br><p style='margin-left: 30px; line-height: 200%'><a target='_blank' href='https://www.e-tridel.com/mytridelhome/MyTridelHomeLogin.html'>MyTridelHome</a><br><a target='_blank' href='https://www.e-tridel.com/realtorportal/realtorportallogin.aspx'>Realtor Login</a><br><a href='/homeownercare/staying-connected'>Community Website</a></p></div>";
	alert3(txt);
}
