document.write("'<style>.noscript {display:none;}</style>");
$(document).ready(function($) {
	$('div.navigation').css({'width':'177px','float':'right'});
	$('div.content').css('display','block');
	var onMouseOutOpacity = 0.67;
	$('#thumbs ul.thumbs li').opacityrollover({
		mouseOutOpacity: onMouseOutOpacity,
		mouseOverOpacity: 1.0,
		fadeSpeed: 'fast',
		exemptionSelector: '.selected'
	});
	var gallery = $('#thumbs').galleriffic({
		delay: 100,
		numThumbs: 10,
		preloadAhead: 16,
		enableTopPager: false,
		enableBottomPager: true,
		maxPagesToShow: 2,
		imageContainerSel: '#slideshow',
		controlsContainerSel: '#controls',
		captionContainerSel: '#caption',
		loadingContainerSel: '#loading',
		renderSSControls: false,
		renderNavControls: false,
		playLinkText: 'Play Slideshow',
		pauseLinkText: 'Pause Slideshow',
		prevLinkText: '&laquo; Previous Photo',
		nextLinkText: 'Next Photo &rdaquo;',
		nextPageLinkText: 'Next &raquo;', 
		prevPageLinkText: '&lsaquo; Prev',
		enableHistory: true,
		enableKeyboardNavigation: true,
		autoStart: false,
		syncTransitions: true,
		defaultTransitionDuration: 600,
		onTransitionIn: function() {
			$('#slideshow').children().fadeTo('normal', 1.0);
			$('#caption').children().fadeTo('normal', 1.0);
			$("div.download a").lightBox();
		},
		onSlideChange: function(prevIndex, nextIndex) {
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
		},
		onPageTransitionOut: function(callback) {this.fadeTo('fast',0.0,callback);},
		onPageTransitionIn: function() {this.fadeTo('fast',1.0);}
	});
	function pageload(hash) {
		if(hash) {$.galleriffic.gotoImage(hash);}
		else {gallery.gotoIndex(0);}
	}
	$.historyInit(pageload, "advanced.html");
	$("a[rel='history']").live('click', function(e) {
		if (e.button != 0) return true;
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});
	$("#searchcriteriatt").css({
		display:"inline",
		cursor:"pointer",
		width:"16px",
		height:"16px"
	}).removeClass("hide").html('<img src="/images/info.png" width="16" height="16" />').click(function(){
		$("<div>").attr("id","scdialog").css("height","75px").html('<p class="sm10">Includes your most recent search (if any) to allow the agent to select more homes that match your criteria.</p>').dialog({
			autoOpen: false,
			height: "auto",
			modal: false,
			resizable:true,
			title:"Include Search Criteria"
		});
		$("#scdialog").dialog('open');
	});
	$("#SaveListingLink").click(function(){
		var rel = $(this).attr("rel");
		var dash = rel.indexOf("-");
		var id = rel.substring(0,dash)
		var table = rel.substring(dash+1)
		$.get("/inc/ajax/SaveListing.asp",{LID:id,t:table},function(data){
			$("<div>").attr("id","savelistingdialog").html(data).dialog({
				autoOpen: false,
				height: "auto",
				modal: false,
				resizable:true,
				title:"Save Listing"
			});
			$("#savelistingdialog").dialog('open');
		});
		return false;
	});
	$("#MapListingLink").click(function(){
		$("<div>").html('<iframe style="padding:0;margin:0;" src="'+$(this).attr("href")+'" width="505" height="505" frameborder="0" scrolling="no"></iframe>').dialog({
			autoOpen: true,
			height: 545,
			width: 525,
			modal: false,
			resizable:false,
			title:"Google Map"
		});
		return false;
	});
	$("#emailformcontainer").dialog({
		autoOpen: false,
		height: "auto",
		width: "auto",
		modal: true,
		resizable:true,
		title:"Send To A Friend"
	});
	/*
	$("#SendFriendLink").click(function(){
		$("#emailformcontainer").dialog('open');
		return false;
	});
	*/
	$("#emailform").submit(function(){
		$.post("/inc/ajax/SendFriend.asp",$(this).serialize(),function(data){
			$("#emailformcontainer").dialog('close');
			$("<div>").html(data).dialog({
				autoOpen: true,
				height: "auto",
				width: "auto",
				modal: true,
				resizable:true,
				title:"Send To A Friend"
			});
		});
		return false;
	});
	$("#CalcMortgageLink").click(function(){
		var url = $(this).attr("href").replace("Calculate-Mortgage.asp","/inc/ajax/Calculate-Mortgage.asp")
		$("<div>").attr("id","CalcMortModal").html('<iframe style="padding:0;margin:0;" src="'+url+'" width="345" height="375" frameborder="0" scrolling="no"></iframe>').dialog({
			autoOpen: true,
			height: 420,
			width: 380,
			modal: true,
			resizable:false,
			title:"Calculate Mortgage"
		});
		return false;
	});
	$("#ScheduleShowingLink").click(function(){
		var url = $(this).attr("href").replace("Schedule-Showing.asp","/inc/ajax/Schedule-Showing.asp")
		$("<div>").attr("id","SchedShowingModal").html('<iframe style="padding:0;margin:0;" src="'+url+'" width="600" height="400" frameborder="0" scrolling="no"></iframe>').dialog({
			autoOpen: true,
			height: 455,
			width: 655,
			modal: true,
			resizable:false,
			title:"Schedule A Showing"
		});
		return false;
	});
	$("#ContactRealtorForm").submit(function(event){
		event.preventDefault();
		$.post("/inc/ajax/ContactRealtor.asp",$(this).serialize(),function(data){
			$("<div>").html(data).dialog({
				autoOpen: true,
				height: "auto",
				width: "auto",
				modal: true,
				resizable:true,
				title:"Request More Information"
			});
			$("#crComments").val("I am interested in this property. Please contact me with more information, or to schedule a showing.");
			$("#crFirstName").val("").triggerHandler("blur");
			$("#crLastName").val("").triggerHandler("blur");
			$("#crEmail").val("").triggerHandler("blur");
			$("#crPhone").val("").triggerHandler("blur");
			$("#crSearchCriteria").attr("checked",false);
		});
	});
	$.get("/inc/token.asp",function(txt) {
		$("#ContactRealtorForm").append('<input type="hidden" name="timestamp" value="'+txt+'" />');
	});
});
