function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	var size = new Array();
	size['width'] = myWidth;
	size['height'] = myHeight;
	return size;
}
function textClear(text, element) {
        if(element.value == text)
                element.value = "";
}

function textReset(text, element) {
        if(element.value == '')
                element.value = text;
}
function changeDiv(the_div,the_change) {
        var the_style = getStyleObject(the_div);
        if (the_style != false) {
                the_style.display = the_change;
        }
}//end changeDiv

function hideDiv(the_div) {
        changeDiv(the_div, "none");
}//end hideSpecific

function showDiv(the_div) {
        changeDiv(the_div, "block");
}//end showDiv

function switchDiv(the_div) {
        var the_style = getStyleObject(the_div);
        if(the_style.display == "block") {
                the_style.display = "none";
        }
        else if(the_style.display == "none") {
                the_style.display = "block";
        }
}//end switchDiv

function getStyleObject(objectId) {
        if (document.getElementById && document.getElementById(objectId)) {
                return document.getElementById(objectId).style;
        }
        else if (document.all && document.all(objectId)) {
                return document.all(objectId).style;
        }
        else {
                return false;
        }
}//end getStyleObject
function loadCalendarEventDetails(calendarEventId) {
	$.ajax({
		url: 'http://www.penterraplaza.com/viewCalendarEventDetail.php?detailsId='+calendarEventId,
		cache: false,
		success: function(html) {
			$("#eventCalendar").fadeOut(400, function() { displayCalendarEventDetails(html)});
		}
	});
}
function displayCalendarEventDetails(html) {
	$('#eventDetailsContent').replaceWith(html);
	$('#eventDetails').fadeIn(400);
}
function backToMonth() {
	$('#eventDetails').fadeOut(400, function() { displayCalendar() });
}
function displayCalendar() {
	$('#eventCalendar').fadeIn(400);
}
function swapGroup(groupId) {
	$('#'+groupId).slideToggle(400);
	var setting = $('#'+groupId+'_anchor').html();
	if(setting == "+") {
		$('#'+groupId+'_anchor').html('-');
	} else {
		$('#'+groupId+'_anchor').html('+');
	}
}
function mycarousel_itemLoadCallback(carousel, state) {
	for (var i = carousel.first; i <= carousel.last; i++) {
	        if (carousel.has(i)) {
			continue;
		}
		if (i > mycarousel_itemList.length) {
			break;
		}
		// Create an object from HTML
		var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList[i-1])).get(0);
		// Apply thickbox
		tb_init(item);
		carousel.add(i, item);
	}
}
function mycarousel_getItemHTML(item) {
	return '<a href="' + item.url + '"><img src="' + item.img + '" width="80" height="60" style = "border: 2px solid #FFFCE1;" /></a>';
}
function selectPrice(low, high, range) {
	$('#priceRangeText').html(range);
	$('#homeSize_menu_child').empty();
	$('#floorplans').fadeOut("fast");
	priceLow = low;
	priceHigh = high;
	for(var i = 0; i < 3; i++) {
		activeSquareFeet[i] = false;
		if(prices[i]) {
			for(var x = 0; x < prices[i].length; x++) {
				if(prices[i][x] >= low && prices[i][x] <= high) {
					activeSquareFeet[i] = true;
					$('#homeSize_menu_child').append('<div class = "navItemLarge" onClick = "javascript:selectSquareFeet('+ i +', '+squareFeet[i].low+', '+squareFeet[i].high+', \''+squareFeet[i].range+'\');"><a href = "#">'+squareFeet[i].range +' Square Feet</a></div>');
					break;
				}
			}
		}
	}
	$('#homeSize').fadeIn("slow");
	$('#homeSizeText').html('Please select a home size.');
}
function selectSquareFeet(selectedSquareFeet, low, high, range) {
	$('#homeSizeText').html(range + ' Square Feet');
	$('#floorplanCarouselContainer').empty();
	$('#floorplanCarouselContainer').html('<ul id="floorplanCarousel" class="jcarousel-skin-penterra"></ul>');

	squareFeetLow = low;
	squareFeetHigh = high;
	for(var x = 0; x < floorplans[selectedSquareFeet].length; x++) {
		for(var y = 0; y < floorplans[selectedSquareFeet][x].prices.length; y++) {
			if(floorplans[selectedSquareFeet][x].prices[y] <= priceHigh && floorplans[selectedSquareFeet][x].prices[y] >= priceLow) {
				$('#floorplanCarousel').append('<li style = "text-align:center;"><div style = "line-height:18px;padding-left:25px;padding-right:25px;"><a href = "javascript:floorplanSelected('+floorplans[selectedSquareFeet][x].id+');"><img border = "0" src = "http://www.penterraplaza.com/templateImages/imageLoad.php?parentId='+floorplans[selectedSquareFeet][x].id+'&type=floorplanThumbnail" /></a><br />'+floorplans[selectedSquareFeet][x].name+'<br />'+floorplans[selectedSquareFeet][x].squareFeet+'<br />'+floorplans[selectedSquareFeet][x].homeType+'<br />'+floorplans[selectedSquareFeet][x].priceRange+'</li>');
				break;
			}
		}
	}
	$('#floorplans').fadeIn("slow");
	$('#floorplanCarousel').jcarousel({
		wrap: 'both'
	});
}
function floorplanSelected(id) {
	$('#searchContainer').fadeOut("fast", function() {
		$('#resultsContent').empty();
		$('#loadingScreen').fadeIn('fast', function () {
	$('#resultsContent').load("http://www.penterraplaza.com/loadSearchResults.php", {
			id: id,
			priceLow: priceLow,
			priceHigh: priceHigh,
			squareFeetLow: squareFeetLow,
			squareFeetHigh: squareFeetHigh
		}, function () {
			$('#loadingScreen').fadeOut('fast', function() { return $('#resultsContainer').fadeIn("slow"); });
			$('#returnText').html('<a href = "javascript:displaySearch()">Return to Search</a>');
		}
	);
		});
	});
}
function displaySearch() {
	$('#returnText').html('');
	$('#resultsContainer').fadeOut('fast', function () {
		$('#searchContainer').fadeIn('slow');
	});
}
function loadProperty(id, floor, text) {
	$('#resultsContainer').fadeOut("fast", function() {
		$('#detailsContainer1').empty();
		$('#loadingScreen').fadeIn('fast', function() {
	$('#detailsContainer1').load('http://www.penterraplaza.com/loadHomeDetails.php', {
			id: id,
			oldId: 1,
			newId: 2,
			floor: floor
		}, function () {
			$('#loadingScreen').fadeOut('fast', function() { return $('#detailsContainer1').fadeIn("slow"); });
			$('#returnText').html('<a href = "javascript:displayResults(1, '+floor+')">'+text+'</a>');
		}
	);
		});
	});
}
function loadAnotherProperty(id, oldProp, newProp, floor, text) {
	$('#detailsContainer'+oldProp).fadeOut("fast", function() {
		$('#detailsContainer'+newProp).empty();
		$('#loadingScreen').fadeIn('fast', function() {
	$('#detailsContainer'+newProp).load("http://www.penterraplaza.com/loadHomeDetails.php", {
			id: id,
			oldId: newProp,
			newId: oldProp,
			floor: floor
		}, function () {
			$('#loadingScreen').fadeOut('fast', function() { return $('#detailsContainer'+newProp).fadeIn("slow"); });
			$('#returnText').html('<a href = "javascript:displayResults(2, '+floor+')">'+text+'</a>');
		}
	);
		});
	});
}
function displayResults(num, floor) {
	$('#detailsContainer'+num).fadeOut('fast', function() {
		$('#resultsContainer').fadeIn('slow');
	});
	if(floor) {
		$('#returnText').html('<a href = "javascript:displayInteractiveBuilding();">Return to Interactive Building</a>');
		$('#headerImage').fadeOut('fast', function () {
			$('#headerImage').empty();
			$('#headerImage').html('<img src = "http://www.penterraplaza.com/images/textImage.php?height=22&width=280&fontSize=13&bgColor=333333&textColor=FFFCE1&text=Floor '+floor+'&align=left" width = "280" height = "22" />');
			$('#headerImage').fadeIn('fast');
		});
	} else {
		$('#returnText').html('<a href = "javascript:displaySearch()">Return to Search</a>');
		$('#headerImage').fadeOut('fast', function () {
			$('#headerImage').empty();
			$('#headerImage').html('<img src = "http://www.penterraplaza.com/images/textImage.php?height=22&width=280&fontSize=13&bgColor=333333&textColor=FFFCE1&text=Results&align=left" width = "280" height = "22" />');
			$('#headerImage').fadeIn('fast');
		});
	}
}
function displayFloorDetails (floorNum) {
	$('#floorTable').fadeIn('fast');
	$(".floor_"+floorNum).fadeIn('fast');
}
function hideFloorDetails (floorNum) {
	$('#floorTable').fadeOut('fast');
	$(".floor_"+floorNum).fadeOut('fast');
}
function displayInteractiveBuilding() {
	$('#resultsContainer').fadeOut('fast', function() {
		$('#buildingContainer').fadeIn('slow');
		$('#returnText').html('');
		$('#headerImage').fadeOut('fast', function () {
			$('#headerImage').empty();
			$('#headerImage').html('<img src = "http://www.penterraplaza.com/images/textImage.php?height=22&width=280&fontSize=13&bgColor=333333&textColor=FFFCE1&text=Floorplans&align=left" width = "280" height = "22" />');
			$('#headerImage').fadeIn('fast');
		});

	});
}
function mycarousel_itemLoadCallback0(carousel, state) {
	for (var i = carousel.first; i <= carousel.last; i++) {
	        if (carousel.has(i)) {
			continue;
		}
		if (i > mycarousel_itemList0.length) {
			break;
		}
		// Create an object from HTML
		var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList0[i-1])).get(0);
		// Apply thickbox
		tb_init(item);
		carousel.add(i, item);
	}
}
function mycarousel_itemLoadCallback1(carousel, state) {
	for (var i = carousel.first; i <= carousel.last; i++) {
	        if (carousel.has(i)) {
			continue;
		}
		if (i > mycarousel_itemList1.length) {
			break;
		}
		// Create an object from HTML
		var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList1[i-1])).get(0);
		// Apply thickbox
		tb_init(item);
		carousel.add(i, item);
	}
}
function mycarousel_itemLoadCallback2(carousel, state) {
	for (var i = carousel.first; i <= carousel.last; i++) {
	        if (carousel.has(i)) {
			continue;
		}
		if (i > mycarousel_itemList2.length) {
			break;
		}
		// Create an object from HTML
		var item = jQuery(mycarousel_getItemHTML(mycarousel_itemList2[i-1])).get(0);
		// Apply thickbox
		tb_init(item);
		carousel.add(i, item);
	}
}
