


$(document).ready(function(){
	
	$(document).pngFix();
	
	
	$("#home-slideshow").html(galleryHTML);
	
	// home animations
	$("div.anim").each(function(){	
		var indx = $(this).index();
		var speed_rdm = Math.floor(Math.random()*401);
		var delay_rdm = Math.floor(Math.random()*3001);
		var timeout_rdm = Math.floor(Math.random()*4001);
		$(this).fadeIn(speed_rdm);
		$(this).delay( 2000+delay_rdm ).cycle({
			speed: speed_rdm+200,
			timeout:2000+timeout_rdm
		});
	});

	// gallery fancybox
	if($("dl.gallery-item a").length) {
	$("dl.gallery-item a").attr('rel','gallery');
	$("dl.gallery-item a").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	}
	
	// floorplan fancybox
	if($("a.floorplan-link").length) {
	$("a.floorplan-link").attr('rel','floorplan');
	$("a.floorplan-link").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	}
	
	// load XML for availability/sitemap data
	if(true){
    $.ajax({
        type: "GET",
        url: "/data/rebuilddata.php",  // for the rebuilt style
        dataType: "xml",
        success: xmlParserFloorplans
    });
    }
    
    $('#fb').fbWall({
		id:'WoodbineLiving',
		accessToken:'206158599425293|b7931350f1a3b00914b7108e.1-1435643418|K5B4duXZkk5HtH9HDehdmxfpOkM',
		showGuestEntries:true,
		showComments:true,
		max:3,
		timeConversion:24
	});
	
});


galleryHTML = '<div id="slide01" class="anim">';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_A_01.jpg" width="335" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_B_01.jpg" width="335" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_C_01.jpg" width="335" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_D_01.jpg" width="335" height="239" />';
galleryHTML += '</div>';
galleryHTML += '<div id="slide02" class="anim">';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_A_03.jpg" width="333" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_B_03.jpg" width="333" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_C_03.jpg" width="333" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_D_03.jpg" width="333" height="239" />';
galleryHTML += '</div>';
galleryHTML += '<div id="slide03" class="anim">';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_A_05.jpg" width="336" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_B_05.jpg" width="336" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_C_05.jpg" width="336" height="239" />';
galleryHTML += '<img src="http://67.225.237.6/~woodbine/wp-content/themes/blankSlate3.0/images/slides/home_D_05.jpg" width="336" height="239" />';
galleryHTML += '</div>';


// needed for direct link to online leasing app
var siteID = "1093746";
var todaysDate=new Date();
dateNeeded = todaysDate.toLocaleDateString();

/*******************************
*
*	function xmlParserFloorplans(xml)
*		receives an XML object and creates objects in the DOM
*
*******************************/
function xmlParserFloorplans(xml) {

	var units = "";
	var unitsOnThisFloor = "";
	
	var unitLinks = "";
	
	var dateNeeded = Date.today().toString("MM/dd/yyyy");
    
    $(xml).find("Floorplan").each(function () {
    
    	floorplanName = $(this).attr("name");
    	floorplanID = $(this).attr("id");
    	
    	// show list of available units
    	units = "<form action='http://property.onesite.realpage.com/ol/default.aspx' target='_blank' method='GET'>";
    	units += "<input type='hidden' name='siteid' value='"+siteID+"' />";
  //  	units += "<input type='hidden' name='dateneeded' value='"+dateNeeded+"' />";
    	units += "<p>Select an available unit from the menu to lease it today!";
    	units += "<select name='unitid'>";
  			for(f=1;f<10;f++) {
	  			unitCount = 0;
  				unitsOnThisFloor = "<optgroup label='"+getOrdinal(f)+" Floor'>";
				$(xml).find("UnitGroup[floorplanID="+floorplanID+"] Unit").each(function () {
				
					// check to see if we're looking at the proper floor level
					if($(this).attr("floorLevel")==f) {
				
						thisUnitAvailable = false;
						
						// determine unit availability
						if($(this).attr("availability")=="no") {
							if($(this).attr("userOption")!="applied") {
								if($(this).attr("availableDate")!="") {
									thisUnitAvailable = true;
									availableDate = $(this).attr("availableDate");
								}
							}
						} else {
							thisUnitAvailable = true;
							availableDate = "Today";
						}
						
						// if it's available, figure what will be shown
						if(thisUnitAvailable) { 
						
							unitCount++;
							dateNeeded = Date.today().toString("MM/dd/yyyy");
							thisUnit = "" + getOrdinal($(this).attr("floorLevel"))+" Floor, Apt #"+$(this).attr("suite")+" &bull; $"+$(this).attr("rentPrice") + "/mo.";
							if ($(this).attr("availableDate")) {
								thisUnit += " (Available "+$(this).attr("availableDate")+")";
							}
							unitLinks += "<br /><a href='http://property.onesite.realpage.com/ol/default.aspx?siteID="+siteID+"&unitId="+$(this).attr("unitID")+"&dateneeded="+encodeURI(dateNeeded)+"'>"+thisUnit+"</a>";
							thisUnit = "<option value='"+$(this).attr("unitID")+"'>"+thisUnit+"</option>";
						
							unitsOnThisFloor += thisUnit + "\n";
						}
					
					}
				});
    			unitsOnThisFloor += "</optgroup>";
    			if(unitCount>0) {
    				units += unitsOnThisFloor;
    			}
    		}
    	units += "</select>";
	   	units += "</p>";
	   	units += "Desired Move-in Date <input type='text' value='"+dateNeeded+"' name='dateneeded' style='width:100px;' /> ";
	   	units += "<input type='submit' value='Lease Today' />";
	   	units += "</form>";
    	
    	// add list to each unit
    	$("#floorplan-"+floorplanName).append(units);
    	
//    	$("#floorplan-C1").append(unitLinks);
    	
    	//alert(floorplanName);
    	
    });
    
}


/*******************************
*
*	function xmlParserSitemap(xml)
*		receives an XML object and creates objects in the DOM
*
*******************************/
function xmlParserSitemap(xml) {

    $('#loading-sitemap-data').hide("fast");
    
    $(xml).find("UnitGroup").each(function () {
    
    	suiteNum = $(this).attr("suite");
    	
    	// set availability styles of imagemap areas
		if ($(this).children("Unit[availability=yes]").length) {
			availability = "yes";
			$("area[rel="+suiteNum+"]").addClass(highlightAvailabileYes);
		} else {
			availability = "no";
			$("area[rel="+suiteNum+"]").addClass(highlightAvailabileNo);
		}
    	
    	title = $(xml).find("Floorplan[id="+$(this).attr("floorplanID")+"]").attr("name");
    	desc = "<p>"+ $(xml).find("Floorplan[id="+$(this).attr("floorplanID")+"]").attr("bedrooms") +" Bed";
    	desc += ", "+ $(xml).find("Floorplan[id="+$(this).attr("floorplanID")+"]").attr("bathrooms") +" Bath";
    	desc += ", "+ $(xml).find("Floorplan[id="+$(this).attr("floorplanID")+"]").attr("sqft") +" Sq. Ft.</p>";
    	
    	// determine availability of each individual unit and report
    	$(this).find("Unit").each(function() {
    		desc += "<p>";
    		if($(this).siblings().length>0) {
				desc += "Room "+ $(this).attr("room") +": ";
    		}
    		if($(this).attr("availability")=="no") {
    			if($(this).attr("userOption")=="applied") {
	    			desc += "Application on File.";
	    		} else {
	    			desc += "Occupied";
					if($(this).attr("availableDate")!="") {
		    			desc += ", Available on: "+ $(this).attr("availableDate");
					}
	    			desc += ".";
	    		}
    		} else {
    			desc += "<strong class='available'>Available Today!</strong>";
//	 			desc += " <a href='http://property.onesite.realpage.com/ol/default.aspx?siteID="+siteID+"&unitId="+$(this).attr("unitID")+"&dateneeded="+encodeURI(dateNeeded)+"' target='_blank'>Lease Online</a>";
    		}
    		desc += "</p>";
    	});
    	
    	// add individual <div> node to DOM
        $("#sitemap-data").append('<div class="unit-data available-'+availability+'" id="unit-'+suiteNum+'"><h4>' + suiteNum + ' <em>(' + title + ')</em></h4><div class="description">' + desc + '</div><a href="#" class="close">Close</a></div>');
    	
    });
    
    // get the map's offset, so we can show the details on the map
    
    // define actions for imagemap areas
    // note that the "rel" attribute contains the suite number for that area
    $('area').each(function(i){
        $(this).click(function (e) {
		    mapOffset = $("#sitemap-data").offset();
        	newY = e.pageY-(mapOffset.top)+15;
        	newX = e.pageX-(mapOffset.left)+15;
	    	$(".unit-data").hide("fast");
	    	$("#unit-"+$(this).attr("rel")).show("fast").css({top:(newY)+"px",left:(newX)+"px"});
	    	return false;
        });
    });
    
    // activate close button for each unit-data box
	$(".unit-data a.close").click(function(){
		$(this).parent().hide("fast");
		return false;
	});
    
    // trigger map hilights for each level's sitemap
    $(".sitemap-image").maphilight(hilightDefaults);

}

/****
 *
 *	function getOrdinal(num)
 *
 ****/
function getOrdinal(num) {
	var temp = "";
	switch(num){
		case 1 :
		case '1' : temp = "1st";
				break;
		case 2 :
		case '2' : temp = "2nd";
				break;
		case 3 :
		case '3' : temp = "3rd";
				break;
		default : temp = num+"th";
				break;
	}
	return temp;
}
 
