// JavaScript Document

/*window.onload = function() { 
	$("#outerContainer").animate({ opacity: 1.0 }, 200);
	$("#centerContainer").animate({ opacity: 1.0 }, 200);
}*/

$(document).ready( function() {
			
			tp.general.init();
			
			tp.addthisUtils.init();
			
			/*$('body').vCenter();
			$(window).resize(function() { $('body').vCenter(); });*/
			
			$("[rel='external']").addClass("externalLink").click(
			function() { 
				window.open($(this).attr("href")); return false;  // make rel="external" links open in new windows
			});
			
			$("#circle .jqmClose").click( circleCloseClick );
			$("button").focus( function() { $(this).blur() } ); // remove dotted indicators in FF at expense of accessibility
});

function openFloorplansPopup() {
	var paramStr = "status=0,toolbar=0,location=0,menubar=0,fullscreen=0,resizable=0,height=700,width=899";
											window.open("floorplans.html", "_blank", paramStr);
											return false;
}

function openApartmentFloorplansPopup() {
	var paramStr = "status=0,toolbar=0,location=0,menubar=0,fullscreen=0,resizable=0,height=700,width=899";
											window.open("apartmentFloorplans.html", "_blank", paramStr);
											return false;
}

function openFurniturePopup() {
	var paramStr = "status=0,toolbar=0,location=0,menubar=0,fullscreen=0,resizable=0,height=700,width=899";
											window.open("furniture.html", "_blank", paramStr);
											return false;
}

function openFlashNeighborhoodMapPopup() {
	var paramStr = "status=0,toolbar=0,location=0,menubar=0,fullscreen=0,resizable=0,height=700,width=900";
											window.open("flashNeighborhoodMap.html", "_blank", paramStr);
											return false;
}

function openFlashCommunityMapPopup() {
	var paramStr = "status=0,toolbar=0,location=0,menubar=0,fullscreen=0,resizable=0,height=700,width=900";
											window.open("flashCommunityMap.html", "_blank", paramStr);
											return false;
}

function fadeInCenterContainer() {
	$items = $("#centerContainer").children();
	if(jQuery.browser.msie) {
			// workaround for IE 6 & 7 ClearType bug:
				if(parseInt(jQuery.browser.version) < 8) {
					  $items.hide().fadeIn("slow", function() {
								  this.style.removeAttribute('filter');
							  });
				}
				else { /* IE 8 doesn't like the filter fix */ }
			}
	else { // not IE
			$items.hide().fadeIn("slow");
	}
	
}

function showCircleVideo( bgImagePath, youtubeEmbedCode, externalURL ) {
	var appendHTML = '<div class="youtubeContainer">' + youtubeEmbedCode + '</object><a href="' + externalURL + '" target="_blank" class="externalYouTubeLink">Watch in HD</a></div>';
	var circleImg = $("#circleImg");
	window.clearTimeout(circleTimeout);
	circleImg.attr("src", bgImagePath);	
	circleImg.animate({ width: "313px",
									height: "313px",
									right: "0px",
									bottom: "0px",
									opacity: "100%" }, "slow", function() {
										if( $(".youtubeContainer").length == 0) {
												$("#circle").append( appendHTML );
										}
										$("#circle .jqmClose").fadeIn("slow").removeClass("inactive");
										$(".externalYouTubeLink").click( circleCloseClick );
									});
	
}

function circleCloseClick() {
	$(".youtubeContainer").remove();
	$(this).addClass("inactive");
	shrinkCircle();
	$("#mainRight button").fadeIn("slow"); // show the carousel control buttons
}

function shrinkCircle() {
	$("#circle .jqmClose").hide();
	 $("#circleImg").animate({ width: "30px",
								height: "30px",
								right: "51px",
								bottom: "-18px" }, "slow", function() {
																$(this).fadeOut("fast");
														});
}

// Slideshow functions: 
var curIdx = 0;

function bindSlideshowButtonClicks() {
			$("#prev").click( prevClick );
			$("#next").click( nextClick );
}

function galleryClick( idx ) {
	if(curIdx != idx) {
		curIdx = idx;
		$(".slideshow li.current").fadeOut("slow", function() { $(this).removeClass("current") });
		  //$(".slideshow li").removeClass("current");
		  var selStr = ".slideshow li:eq(" + curIdx + ")";
		  $(selStr).fadeIn("slow", function() { $(this).addClass("current") });	
	}
}

function nextClick() {
	galleryClick(checkImgIdx((curIdx + 1)));
}

function prevClick() {
	galleryClick(checkImgIdx((curIdx - 1)));
}

function checkImgIdx( nextIdx ) {
	var maxIdx = $(".slideshow li").length - 1;
	if(nextIdx < 0) { nextIdx = maxIdx; }
	if(nextIdx > maxIdx) { nextIdx = 0; }
	return nextIdx;
}

function checkCarouselButtonVisibility() {
		$("#mainRight button").each( function() {
										if($(this).hasClass("disabled")) {
											$(this).fadeOut("fast");	
										}
										else {
											$(this).fadeIn("fast");	
										}
								});
}

/* -------------------------------------------------------------------------------- */
window.tp = window.tp || {};

var addthis_pub="thorntonplace";
var addthis_offset_top = 0;
var addthis_offset_left = 0;
var addthis_brand = "Thornton Place";
//var addthis_header_color = "transparent";
var addthis_header_background = "#544a42";
var addthis_options = "email, facebook, myspace, twitter, linkedin, delicious, digg, stumbleupon";

(function() {
		  
	  this.general = {
		  	init : function() {
				this.initPrivacyPolicyPopup();
				this.hideJSWarning();
			},
		  
			initPrivacyPolicyPopup : function() {
					 $('#privacyDialog').jqm({
									overlay: 70,
									modal: true,
									trigger: '#privacyPolicyLink',
									popupIdx: 0,
									targetId: "#privacyDialog",
									target: '#privacyDialog .jqmContent',
									onHide: closeModal,
									onShow: openInFrame });	
					 var h = $(window).height() - 80;
					 var jqmStr = "disclaimer.html?q=jqmodal&height=" + (h+30) + "&width=627&jqmRefresh=false";
					 $("#privacyPolicyLink").attr("href", jqmStr).addClass("thickbox");
					$("#privacyDialog").css({ height: (h+30)+"px", width: "632px"});
					$("#privacyDialog iframe").css({ height: h, width: "612px" });
			}, // end initPrivacyPolicyPopup
			
			hideJSWarning : function() {
					$("#JSWarning").hide();
			}
	  };
		  
	  this.addthisUtils = {
				init : function() {
						// set up the Share This! link:
						$("#addthisShareLink").attr("href","http://www.addthis.com/bookmark.php?v=20").mouseover( 
													function() {
															return addthis_open(this, '', '[URL]', '[TITLE]'); 
														}).mouseout( function() {
															addthis_close(); 
															}).click( 
																function() {
																	tp.addthisUtils.addOverlay(); 
																	return addthis_sendto();
																});
						// close button onclick() handler:
						$("#at16pt a").click( function() {
								$("#overlay").fadeOut("fast");
						});
						// overlay hide:
						$(document).click( function() {
									if($("#at16p").is(":hidden")) {
										$("#overlay").fadeOut("fast");
									}
						});
				},
				
				addOverlay : function() {
						var curWidth = $(window).width();
						var curHeight = $(window).height();
						$("#overlay").css({
										  width: curWidth,
										  height: curHeight,
										  opacity: "0.5"
						}).show();
						$("#at16pt h4").html("Bookmark &amp; Share This Page"); // update the title shown in popup
						$("#at16pt a").html(""); // hide X in closebox
						// only show a subset of the networking options: 
						/*var linksToShow = ".at15t_email, .at15t_facebook, .at15t_myspace, .at15t_google, .at15t_linkedin, .at15t_delicious"; 
						$(".at15t").parent().css({ display: "none" });
						$(linksToShow).parent().css({ display: "block" });*/
				}
	  };
}).call(window.tp); // Initialize
