
$(document).ready(function() {
	
	$(function() {
		$("#news-wrapper div.news-content").jScrollPane({showArrows:true});
	});
	
	/* Sub Page Navigation */
	$("#page #submenu ul li a").live("click", function () {
		
		var id = $(this).attr("id");
		var xml = $("#page #submenu ul").attr("id");
		
		// highlight link
		$("#page #submenu ul li a").removeClass("selected");
		$(this).addClass("selected");
		
		// stop animation if new animation starts before previous finished
		$(".img-container img.view").stop(true, true);
		
		if(xml == "news"){ /* News Sub Page Navigation */
			$.ajax({
	 			type: "POST",
 				url: xml+".ajax.php",
 				data: "action=navigate&index="+id,
 				dataType: "json",
 				success: function(json){
 					$("#news-wrapper div.loader").show();
 					$("#news-wrapper div.news-title, #news-wrapper div.news-content").css({'display' : 'none'}); // hide image
					$("#news-wrapper div.loader").fadeOut("slow"); //fade out loader
					$("#news-wrapper div.news-header").html(json.header).fadeIn("slow"); // change image and fade in
					$("#news-wrapper div.news-content").html(json.content).fadeIn("slow"); // change caption	
					$(function() {
						$("#news-wrapper div.news-content").jScrollPane({showArrows:true});
					});
 				},
 			});
		} else if(xml == "580"){ /* Floorplan Sub Page Navigation */
			$.ajax({
	 			type: "POST",
 				url: xml+".ajax.php",
 				data: "action=navigate&index="+id,
 				dataType: "json",
 				success: function(json){
 					$("#floorplan div.loader").show();
 					$("#floorplan img.view").css({'display' : 'none'}); // hide image
					$("#floorplan div.loader").fadeOut("slow"); //fade out loader
					$("#floorplan img.view").attr({'src' : json.image}).fadeIn("slow"); // change image and fade in
					$("#floorplan #dots").html(json.dots); // change caption		
 				},
 			});
		} else if(xml == "1812video"){
			$.ajax({
 				type: "POST",
 				url: xml+".ajax.php",
 				data: "action=navigate&index="+id,
 				dataType: "json",
 				success: function(json){
 					$("#video-wrapper div.loader").show(); // show loader
					$("#video-wrapper div.loader").delay(300).fadeOut("slow"); // fade out loader
					$("#video-wrapper").html(json.video);
 				},
 			});
		} else if(xml == "developer"){
			$("#image-wrapper img.view").css({'display' : 'none'}).delay(200); // hide image
			$.ajax({
 				type: "POST",
 				url: xml+".ajax.php",
 				data: "action=navigate&index="+id,
 				dataType: "json",
 				success: function(json){
 					$("#image-wrapper div.loader").show(); // show loader
					$("#image-wrapper div.loader").delay(300).fadeOut("slow"); // fade out loader
					$("#image-wrapper img.view").attr({'src' : json.image}).css({'display' : 'none', 'right' : '0px'}).delay(200).fadeIn("slow"); // change image
					$("#caption").html(json.caption); // change caption		
 				},
 			});
		} else {
			$("#image-wrapper img.view").css({'display' : 'none'}).delay(200); // hide image
			$.ajax({
 				type: "POST",
 				url: xml+".ajax.php",
 				data: "action=navigate&index="+id,
 				dataType: "json",
 				success: function(json){
 					$("#image-wrapper div.loader").show(); // show loader
					$("#image-wrapper div.loader").delay(300).fadeOut("slow"); // fade out loader
					$("#image-wrapper img.view").attr({'src' : json.image}).css({'display' : 'none', 'right' : '0px'}); // change image
					$("#image-wrapper img.view").attr({'width' : json.width}).delay(200).fadeIn("slow"); // fade in image
					$("#caption").html(json.caption); // change caption		
		
					/* Stunning Views Animation */
					var moveWidth = (parseInt($(".img-container img.view").width())-550);
					$(".img-container img.view").delay(1000).animate({right: '-='+moveWidth}, 5000, 'linear');
 				},
 			});
 		}
	});
	
	/* Floor Spacing */
	$("#page #floorplan #dot img").live('mouseover mouseout', function(event) {
  	if (event.type == 'mouseover') {
    	var selected = $(this).parent();
    	
    	if($(selected).next().children(".dot-image").html() != ""){
    		$(selected).next().children(".dot-image").css({'margin' : '5px 0'});
    	}
    	
			$(selected).next().show("fast").delay(1000);
  	} else {
   	 	var selected = $(this).parent();
  		$(selected).next().hide("slow");
  	}
	});
	
	/* Leed Platinum Sub Page Navigation */
	$("#page #submenu table tr td a").live("click", function () {
		var id = $(this).attr("id");
		var xml = $("#page #submenu table").attr("id");
		
		$.ajax({
 			type: "POST",
 			url: xml+".ajax.php",
 			data: "action=navigate&index="+id,
 			success: function(content){
 				$("#page-content").html(content);	
 			},
 		});
	});
});
