$(document).ready(function(){
	$.ga.load('UA-11347170-1');
	var fpDialog1;
	var fpDialog2;
	$('.detailsMenu a').address(function(){
		return $(this).attr('href').replace('/details', '');
	});	
	 $.address.change(function(event){
	 	var pNames = event.pathNames;
	 	//var category = new Array();
	 	//var category = pNames.split(',');
	 	if ($("li#" + pNames[0]).attr("class") != "active") {
	 		$(".detailsMenu ul li").removeClass("active");
	 		$(".detailsMenu ul.sub").slideUp("fast");
	 		$("li#" + pNames[0]).addClass("active").children("ul.sub").slideDown("fast");
	 	}
	 	$(".detailsMenu a").each(function(){
	 		var href = $(this).attr("href");
	 		var title = $(this).attr("title");
	 		if (href === '/details' + event.value) {
				$(this).addClass("current");
				var newTitle = $.address.title().split(':');
				$.address.title(title + ": " + newTitle[1]);
				GetDetails(this);
			}
			else {
				$(this).removeClass("current");
			}
			});
		});	
});
function GetDetails(e){
	var detailUrl = $(e).attr('href');
	 $.ga.trackPageview(detailUrl)
	detailUrl = detailUrl.replace(new RegExp(/\/$/), "");
	detailUrl = "/htmlTemplates" + detailUrl + ".html";
	$.ajax({
		url: detailUrl,
		cache: false,
		success: function(html){
			$("#divDetails").html(html);
			$("a.viewPhoto").click(function(){
				GetPhoto(this);
				return false;
			});
			$("a.floorPlan1").click(function(){
				GetFloorPlan1(this);
				return false;
			});
			$("a.floorPlan2").click(function(){
				GetFloorPlan2(this);
				return false;
			});
		}
	});
}
function GetPhoto(e){
	var photoHtml = "<img src='" + $(e).attr('href') + "' />"
	var photoDialog = new Boxy(photoHtml, {
		title: $(e).attr('title'),
		modal: true,
		unloadOnHide: true		
	});
}
function GetFloorPlan1(e){
	var dialogTitle = $(e).attr('title');
	if ((typeof(fpDialog1)).toLowerCase() == "undefined") {
		fpDialog1 = new Boxy($("#<div class='vpFloorPlan'><div id='divCFloorPlan1' class='cFloorPlan'>" +
		"<img id='imgFloorPlan1' src='/htmlTemplates/details/images/1stFloorPlan.jpg' /></div></div>"), {
			title: dialogTitle,
			modal: true,
			unloadOnHide: false,
			show: true
		});
			$("#imgFloorPlan1").draggable({
		containment: '#divCFloorPlan1'
	}).css({
		cursor: 'all-scroll'
	});
	}
	else {
		fpDialog1.show();
	}
	var coords = $(e).attr('coords');
	var xy = new Array();
	xy = coords.split(',');
	var coordsX = xy[0] + "px";
	var coordsY = xy[1] + "px";
	$("#imgFloorPlan1").css({
		'left': coordsX,
		'top': coordsY
	});
}
function GetFloorPlan2(e){
	var dialogTitle = $(e).attr('title');
	if ((typeof(fpDialog2)).toLowerCase() == "undefined") {
		fpDialog2 = new Boxy($("#<div class='vpFloorPlan'><div id='divCFloorPlan2' class='cFloorPlan'>" +
		"<img id='imgFloorPlan2' src='/htmlTemplates/details/images/2ndFloorPlan.jpg' /></div></div>"), {
			title: dialogTitle,
			modal: true,
			unloadOnHide: false,
			show: true
		});
			$("#imgFloorPlan2").draggable({
		containment: '#divCFloorPlan2'
	}).css({
		cursor: 'all-scroll'
	});
	}
	else {
		fpDialog2.show();
	}
	var coords = $(e).attr('coords');
	var xy = new Array();
	xy = coords.split(',');
	var coordsX = xy[0] + "px";
	var coordsY = xy[1] + "px";
	$("#imgFloorPlan2").css({
		'left': coordsX,
		'top': coordsY
	});
}