
/* 
	Landon Homes Javascript Library 

*/

/* Extend jQuery with Disable Selection Function */
jQuery.fn.extend({ 
        disableSelection : function() { 
                return this.each(function() { 
                        this.onselectstart = function() { return false; }; 
                        this.unselectable = "on"; 
                        jQuery(this).css('user-select', 'none'); 
                        jQuery(this).css('-o-user-select', 'none'); 
                        jQuery(this).css('-moz-user-select', 'none'); 
                        jQuery(this).css('-khtml-user-select', 'none'); 
                        jQuery(this).css('-webkit-user-select', 'none'); 
                }); 
        } 
});

jQuery(document).ready(function() {

// Disabled Jump on Click + Community Page Hashtags as valid bookmarks
	var hash = window.location.hash; // would be "#div1" or something
	if (hash != "") {
		var id = hash.substr(1); // get rid of #
		contentSwap(id);
	}

// Turn off image dragging in Firefox
	jQuery(document).bind("dragstart", function() {
		return false;
	});

/* Initialize Ask Tanya Pull-Down */	
	jQuery('.askTanyaSlide').tabSlideOut({
		tabHandle: '.tanyaTab',
		tabLocation: 'top',
		leftPos: '0px',
		imageWidth: '124px',
		imageHeight: '24px'
	});
	jQuery(".askTanyaSlide").css("display","block");
	jQuery(".tanyaTab").css("left", (jQuery(window).width() - 960) / 2 + 960 - 124);
	jQuery(window).resize(function() {
		jQuery(".tanyaTab").css("left", (jQuery(window).width() - 960) / 2 + 960 - 124);
	});

// Secret Search by Street Address Option
	jQuery('#reset').swipe({
		swipeLeft: function() { jQuery('#addressSearch').show(); },
		swipeRight: function(){ jQuery('#addressSearch').show(); },
		threshold: 10
	});

	jQuery(".touchcarousel").touchCarousel({
		pagingNav: false,
		snapToItems: false,
		itemsPerMove: 1,
		scrollToLast: false,
		loopItems: false,
		scrollbar: true,
		scrollbarAutoHide: true
	});

	var sliderRotator = jQuery('#rotator').royalSlider({
		slideshowEnabled: true, 
		slideTransitionType: "fade",		
		slideshowDelay: 3000,
		imageScaleMode: "fit",
		imageAlignCenter: true,
		slideTransitionSpeed: 800, 	
		directionNavEnabled: false,
		directionNavAutoHide: true,
		welcomeScreenEnabled:false
	});

	var sliderGallery = jQuery('#galleryrotator').royalSlider({
		imageScaleMode: "fit",
		imageAlignCenter: true,
		slideshowEnabled: true, 
		slideshowDelay: 3000,
		slideTransitionType: "fade",
		slideTransitionSpeed: 800, 	
		directionNavEnabled: true,
		controlNavThumbs: true,
		directionNavAutoHide: true,
		welcomeScreenEnabled:false,
		autoScaleSlider: true,
		autoScaleSliderWidth: 700,
		autoScaleSliderHeight: 468 		
	});

	/* Column Search Reset */
	jQuery('#reset').click(function() {
		jQuery('#qMSearch :checkbox').removeAttr("checked");	
		jQuery('#qMSearch select').val(0);
	});
/* Connect Sort <select> with column search */
	jQuery("#pageSortBy").change(function () {
		jQuery("#sidebarSortBy").val(jQuery("#pageSortBy").val());
	});
	jQuery("#sortSubmit").click(function() {
		jQuery("#qMSearch").submit();
	});
		
/* Initialize Google Maps */
	if (jQuery('#map_canvas').length > 0) {
		initialize();
	}
});

/* LivePerson Chat */

function letsChat() {
  window.open('http://server.iad.liveperson.net/hc/83280955/?cmd=file&file=visitorWantsToChat&site=83280955&referrer='+escape(document.location),
              'chat83280955',
              'width=472,height=320,resizable=yes');
 }

/* Community Page */

function contentSwap(e) {
	jQuery('#commNav li').removeClass();
	jQuery('.section').hide();
	jQuery('#'+e+'-section').show();
	jQuery('#'+e+'-link').addClass('selected');
	if (e == 'model-home-tour' || e =='virtual-tour') {
		jQuery('#lazyTour').attr('src', function() {
			return jQuery(this).data('src');
		});		
	}
	else {
		jQuery('#lazyTour').attr('src', function() {
			return '';
		});		
	
	}
	if (e == 'overview') {
		initialize();
		//google.maps.event.trigger(map, 'resize');
		//jQuery('#map_canvas').setZoom(jQuery('#map_canvas').getZoom() );
	}
}

function eSwap(e) {
    if (e != jQuery('img#elevation').attr('src')) {
        jQuery('img#elevation').stop().animate({opacity:'0'},function(){
			jQuery('img#elevation').attr('src',e);
		}).load(function(){
			jQuery('img#elevation').stop().animate({opacity:'1'});
        });
    }
    return false;
}

/* Floorplans Page */

function pSwap(e) {
	jQuery('#fpMask img').hide();
	jQuery('#'+e).show();
}
