/**
 * ListingDetails JQuery Plugin
 *	usage: used on the listing details page
 *	dependencies: jquery, flot (with pie charting)
 */
(function( $ ) {

	/**
	 *  Main function that interprets the first option as a string or object and processes it as necessary
	 */
	$.fn.csListingDetails = function( method, options ) {

		//var self = this;
		var listingDetailsAjaxRequest = null;
		var listingInfoAjaxRequest = null;
		var highlightedDetailsSummaryTab = null;
		var highlightedDetailsTab = null;
		var methodQueue = new Array();  //Queue of methods that have been called before this object had been initialized i.e. slideshow
		
		var pano = null;
		
		var defaults = {
			'ajaxTarget' : 'listings',
			'listingNumber' : '',
			'listingDetailsLink' : '',
			'modletId' : '0',
			'plugin' : false,
			'statsData' : null,
			'listingUrl' : '',
			'infoBox' : false
		}
		
		var methods = {
			/**
			 *  Initializes the plugin with required values: ajaxTarget, listingNumber, listingDetailsLink, and modletId.  Also sets the details link on the page
			 *  itself.
			 */
			init : function(options) {
				var self = this;
				return this.each(function(){
					var $this = $(this);
					var settings = {};
					
					//merge default settings with settings sent in
					if(options) $.extend(settings, defaults, options);
					
					//Set modletId
					settings.modletId = $this.attr("id").substring($this.attr("id").lastIndexOf("_") + 1);
	
					// get the total photos available
					settings.totalPhotos = $('.cs-listing-details-slideshow-thumbnails li', this).size();
	
					//Save settings into data object
					$this.data("settings", settings);
					
					//see if we can use streetview
					methods.validateStreetView.call(self);
	
					//Initialize tab highlighting
					$("div.cs-tabs-container li:not(.cs-tabs-tab-left, .cs-tabs-tab-right)", this).click(function(){
						if($('a', this).html() != "VR Tour" && $('a', this).html() != "Statistics") {
							$(this).parents("ul.cs-tabs-list").find("li.cs-tabs-tab-active").removeClass("cs-tabs-tab-active").addClass("cs-tabs-tab");
							$(this).removeClass("cs-tabs-tab").addClass("cs-tabs-tab-active");
						}
					});
	
					// Slideshow is not initialized here, rather it is done in the module itself with a queued call.
	
					//initialize the print view
					helpers["printViewUrl"].call(self);
	
					//set the link of the listing
					$this.find("#listingURL").html("http://" + document.location.host + settings.listingDetailsLink);
					
					$this.find("#listingURL").click(function(elm){
						// De-Select any current selection.
						if (document.selection) document.selection.empty(); 
						else if (window.getSelection) window.getSelection().removeAllRanges();
						
						// Select the text in the listingURL div.
						if (document.selection) {
							var range = document.body.createTextRange();
							//range.moveToElementText(document.getElementById("listingURL"));
							range.moveToElementText(elm.currentTarget);
							range.select();
						} else if (window.getSelection) {
							var range = document.createRange();
							//range.selectNode(document.getElementById("listingURL"));
							range.selectNode(elm.currentTarget);
							window.getSelection().addRange(range);
						}
						
						return false;
					});
				});
			},
			/**
			 *  Initializes various click events for the slideshow view.  Note that the method queue was made for this function as it is fired 
			 *  before the plugin is initialized
			 */
			initSlideshow : function(){
				var self = this;
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
	
					//set the height of the main image for Webkit/IE to properly size colorbox
					var mainPhoto = new Image();
					mainPhoto.src = $('img.cs-listing-details-photo-main', this).attr("src");
					$('img.cs-listing-details-photo-main', this).attr("height", mainPhoto.height);
					
					//set rollover event on main photo if we've got photos available
					if(settings.totalPhotos > 1){
						$(".cs-listing-details-photo-container", $this).mouseover(function(){
							$('.cs-photo-nav-right, .cs-photo-nav-left', this).show();
						}).mouseout(function(){
							$('.cs-photo-nav-right, .cs-photo-nav-left', this).hide();
						});
						
						$('.cs-photo-nav-right', this).click(function(){
							// advance the photo
							if($(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().next().size() == 1){
								// update the main photo
								var $mainPhoto = $(this).siblings("img.mainPhoto");
								var $thumbnailImg = $(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().next().find("img");
								helpers.updateMainPhoto.call(self, $mainPhoto, $thumbnailImg);

								// advance the thumbnail
								$(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').removeClass("cs-listing-details-slideshow-thumbnail-selected").parent().next().find("a").addClass("cs-listing-details-slideshow-thumbnail-selected");
							}else{
								// update the main photo
								var $mainPhoto = $(this).siblings("img.mainPhoto");
								var $thumbnailImg = $(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().prevAll().last().find("img");
								helpers.updateMainPhoto.call(self, $mainPhoto, $thumbnailImg);

								// advance the thumbnail
								$(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').removeClass("cs-listing-details-slideshow-thumbnail-selected").parent().prevAll().last().find("a").addClass("cs-listing-details-slideshow-thumbnail-selected");
							}
						});
						$('.cs-photo-nav-left', this).click(function(){
							// advance the photo
							if($(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().prev().size() == 1){
								// update the main photo
								var $mainPhoto = $(this).siblings("img.mainPhoto");
								var $thumbnailImg = $(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().prev().find("img");
								helpers.updateMainPhoto.call(self, $mainPhoto, $thumbnailImg);

								// advance the thumbnail
								$(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').removeClass("cs-listing-details-slideshow-thumbnail-selected").parent().prev().find("a").addClass("cs-listing-details-slideshow-thumbnail-selected");
							}else{
								// update the main photo
								var $mainPhoto = $(this).siblings("img.mainPhoto");
								var $thumbnailImg = $(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').parent().nextAll().last().find("img");
								helpers.updateMainPhoto.call(self, $mainPhoto, $thumbnailImg);

								// advance the thumbnail
								$(this).parent().siblings('ul.cs-listing-details-slideshow-thumbnails').find('.cs-listing-details-slideshow-thumbnail-selected').removeClass("cs-listing-details-slideshow-thumbnail-selected").parent().nextAll().last().find("a").addClass("cs-listing-details-slideshow-thumbnail-selected");
							}
							// resize infobox if view resides in an infobox
							if(settings.infoBox) $.clickSoldUtils('infoBoxResize');
						});
					}
					
					//Display listing status overlay image
					if(settings.othStatus != null){
						if(settings.othStatus == "1"){
							$this.find(".mainPhoto").before("<div class=\"listingStatus_overlayIncrease\"></div>");
						}else if(settings.othStatus == "2"){
							$this.find(".mainPhoto").before("<div class=\"listingStatus_overlayDecrease\"></div>");
						}else if(settings.othStatus == "3"){
							$this.find(".mainPhoto").before("<div class=\"listingStatus_overlayNew\"></div>");
						}
					}
					$this.find("ul.cs-listing-details-slideshow-thumbnails li a").each(function(){
						$(this).unbind("click").bind("click", function(){
							// update the main photo
							var $mainPhoto = $(this).parents("ul.cs-listing-details-slideshow-thumbnails").siblings("div.cs-listing-details-photo-container").find("img.mainPhoto");
							var $thumbnailImg = $(this).find("img");
							helpers.updateMainPhoto.call(self, $mainPhoto, $thumbnailImg);
							
							// highlight the selected thumbnail
							$(this).closest("ul").find(".cs-listing-details-slideshow-thumbnail-selected").removeClass("cs-listing-details-slideshow-thumbnail-selected");
							$(this).addClass("cs-listing-details-slideshow-thumbnail-selected");
						});
					});
				});
			},
			/**
			 *  Retrieves listing details slideshow view via ajax call
			 */
			displaySlideshow : function(){
				return this.each(function(){
					//Retrieve init settings
					var $this = $(this);
					var settings = $(this).data("settings");
										
					//Retrieve other settings
					$this.find("#listingTabsOverlay").block({message: "<b>Loading Slideshow...</b>"});
	
					// abort any pending requests
					if($this.listingDetailsAjaxRequest){
						$this.listingDetailsAjaxRequest.abort();
					}
					
					//Get Search Options here & construct query string
					$this.listingDetailsAjaxRequest = $.ajax({
						type: "GET",
						url: settings.ajaxTarget,
						data: "pathway=6&listingNumber="+settings.listingNumber+"&slideshow=true&modletId="+settings.modletId,
						dataType: "html",
						error: function(data, error){
							alert("Error: displayListingDetailsSlideshow(): " + error + " " + data);
						},
						success: function(data){
							$this.find("#listingTabsModule").html(data);
						},
						complete: function (XMLHttpRequest, textStatus) {
							setTimeout(function(){
								$this.find("#listingTabsOverlay").unblock();
							}, 500);
						}
					});
				});
			},
			/**
			 *  Displays location of property in Google Map view
			 */
			displayMap : function(lat, lng){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					
					//Show overlay loading messasge
					$this.find("#listingTabsOverlay").block({message: '<b>Loading Map...</b>'});
		
					// abort any pending requests
					if($this.listingDetailsAjaxRequest){
						$this.listingDetailsAjaxRequest.abort();
					}
	
					// empty the content panel
					$this.find("#listingTabsModule").empty();
	
					// add the maps DOM element
					$this.find("#listingTabsModule").html('<div class="cs-listing-details-gmap-container"><div id="listingDetailsMap" style="height: 485px;"></div></div>');
	
					// do the map magic
					var map = new google.maps.Map($this.find("#listingDetailsMap").get(0), {
						center : new google.maps.LatLng(lat, lng),
						mapTypeId : google.maps.MapTypeId.ROADMAP,
						zoom : 15,
						mapTypeControl : true,
						zoomControl : true
					});
					
					var point = new google.maps.Marker({
						clickable : false,
						map : map,
						position : new google.maps.LatLng(lat, lng)
					});
					
					//point.setMap(map);
									
					// Remove overlay loading message
					setTimeout(function(){
						$this.find("#listingTabsOverlay").unblock();
					}, 500);
				});
			},
			/**
			 *  Displays any available media (PDFs, etc.) associated with this listing
			 */
			displayMedia : function(lat, lng){
				return this.each(function(){
					//Retrieve init settings
					var $this = $(this);
					var settings = $(this).data("settings");
										
					//Retrieve other settings
					$this.find("#listingTabsOverlay").block({message: "<b>Loading Media...</b>"});
	
					// abort any pending requests
					if($this.listingDetailsAjaxRequest){
						$this.listingDetailsAjaxRequest.abort();
					}
					
					//Get Search Options here & construct query string
					$this.listingDetailsAjaxRequest = $.ajax({
						type: "GET",
						url: settings.ajaxTarget,
						data: "pathway=6&listingNumber="+settings.listingNumber+"&media=true&modletId="+settings.modletId,
						dataType: "html",
						error: function(data, error){
							alert("Error: displayListingDetailsSlideshow(): " + error + " " + data);
						},
						success: function(data){
							$this.find("#listingTabsModule").html(data);
						},
						complete: function (XMLHttpRequest, textStatus) {
							setTimeout(function(){
								$this.find("#listingTabsOverlay").unblock();
							}, 500);
						}
					});
				});
			},
			/**
			 *  Displays any available media (PDFs, etc.) associated with this listing
			 */
			displayWalkscore : function(lat, lng){
				return this.each(function(){
					//Retrieve init settings
					var $this = $(this);
					var settings = $(this).data("settings");
										
					//Retrieve other settings
					$this.find("#listingTabsOverlay").block({message: "<b>Loading WalkScore<sup>&reg;</sup>...</b>"});
	
					// abort any pending requests
					if($this.listingDetailsAjaxRequest){
						$this.listingDetailsAjaxRequest.abort();
					}

					// create the Walkscore container in the tabs panel
					$this.find("#listingTabsModule").html('<div class="cs-listing-details-walkscore-container"></div>');
					
					// get the height and width of the walkscore container
					var walkscoreWidth = $this.find(".cs-listing-details-walkscore-container").width();
					var walkscoreHeight = $this.find(".cs-listing-details-walkscore-container").height();
					
					//Get Search Options here & construct query string
					$this.listingDetailsAjaxRequest = $.ajax({
						type: "GET",
						url: settings.ajaxTarget,
						data: "pathway=6&walkscore=true&latitude="+lat+"&longitude="+lng+"&width="+walkscoreWidth+"&height="+walkscoreHeight+"&modletId="+settings.modletId,
						dataType: "html",
						error: function(data, error){
							alert("Error: displayWalkscore(): " + error + " " + data);
						},
						success: function(data){
							$this.find(".cs-listing-details-walkscore-container").html(data)
						},
						complete: function (XMLHttpRequest, textStatus) {
							setTimeout(function(){
								$this.find("#listingTabsOverlay").unblock();
							}, 500);
						}
					});
				});
			},
			/**
			 *  Checks validity of listing coordinates with Google Street View and shows tab if a location is viewable
			 */
			validateStreetView : function(){
				var self = this;
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					if(settings.latitude != '' && settings.longitude != ''){
						var latLng = new google.maps.LatLng(settings.latitude, settings.longitude);
						var sv = new google.maps.StreetViewService();
						sv.getPanoramaByLocation(latLng, 30, function(data, status){
							if(status == google.maps.StreetViewStatus.OK){
								$this.find("#streetView").parent().show();
								settings.dataLocationPano = data.location.pano;
								$this.data("settings", settings);
								//Create click event for street view tab
								/*
								$this.find("#streetView").parent("li").click(function(){
									helpers["displayStreetView"].call(self, data.location.pano);
								});
								*/
							}
						});
					}
				});
	
			},
			
			/**
			 *  Displays Google Street View for a listing with proper coordinates
			 */
			displayStreetView : function(){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
	
					if(settings.dataLocationPano != null){
						// Show overlay loading message
						$this.find("#listingTabsOverlay").block({message: '<b>Loading Street View...</b>'});
		
						// abort any pending requests
						if($this.listingDetailsAjaxRequest){
							$this.listingDetailsAjaxRequest.abort();
						}
		
						// empty the content panel
						$this.find("#listingTabsModule").empty();
		
						// add the street view DOM element
						$this.find("#listingTabsModule").html('<div class="cs-listing-details-gmap-container"><div id="listingDetailsStView" style="height: 485px"></div></div>');
		
						this.pano = new google.maps.StreetViewPanorama($this.find("#listingDetailsStView").get(0));
						this.pano.setPano(settings.dataLocationPano);
						this.pano.setPov({
							heading: 270,
							pitch : 0,
							zoom : 1
						});
						this.pano.setVisible(true);
		
						// Remove overlay loading message
						setTimeout(function(){
							$this.find("#listingTabsOverlay").unblock();
						}, 500);
					}
				});
			},
			
			/**
			 * Destroys Google Street View object & associated event 
			 * NEEDED???
			 */
			hideStreetView : function(){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					
					if($("#listingDetailsStView").length > 0){
						if(this.pano != null){
							this.pano.setVisible(false);
							this.pano = null;
						}
					}
					
				});
			},
			/**
			 *  Retrieves neighbourhood statistics for a specific listing.  Current implementation as of 2011-03-21 does not work properly as
			 *  the VIP options haven't been worked out yet for the plugin product - works with all others.
			 */
			displayStats : function(){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);  
					var settings = $this.data("settings");
					
					// stop AJAX request if necessary
					if($this.listingDetailsAjaxRequest) $this.listingDetailsAjaxRequest.abort();
					
					/*Warning: Stats in back office rely on the url to be "listings", not "backOffice"*/
					//Get Search Options here & construct query string
	
					var data = "pathway=6&statistics=true";
					if(settings.statsData != null) data = settings.statsData;
	
					$.csVOWPanel('csVOWAjax', {
						type: "GET",
						url: settings.ajaxTarget,
						data: data + "&listingNumber=" + settings.listingNumber + "&modletId=" + settings.modletId,
						dataType: "html",
						error: function(data, error){
							alert("Error: displayListingStatistics(): " + error + " " + data);
						},
						success: function(data){
							$.clickSoldUtils('infoBoxCreate', {
								html : data,
								top: "30px",
								fastIframe : false,
								overlayClose : true,
								returnFocus : false,
								onComplete : function(){
									if(daysOnMarket) $('#daysOnMarket').clickSoldUtils("renderDOMGraph", daysOnMarket.MLSStatsDOMs);
									if(listingPrices) $('#prices').clickSoldUtils("renderPricesGraph", listingPrices.MLSStatsPrices);
									if(listedVersusSold) $('#listedVersusSold').clickSoldUtils("renderListedVersusSoldGraph", listedVersusSold.MLSStatsListedVersusSold);
									$.clickSoldUtils('infoBoxResize');
								}
							});
						}
					}, function(){}, function(){}, true);
				});
			},
			/**
			 *  Displays the mortgage calculator view configured for a specific listing.
			 */
			displayMortCalc : function(listPrice, tax, cFees, listingNumber, tab){  //NOTE: listingNumber param not required
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					
					//stop any pending ajax requests
					if($this.listingInfoAjaxRequest){
						$this.listingInfoAjaxRequest.abort();
					}
					
					// insert an element into the dom for our mortgage calculator if it doesn't already exist
					if($("#rpmCalcDialog").length == 0){
						$("body").append("<div id=\"rpmCalcDialog\" title=\"Mortgage Center\" style=\"display:none;\"></div>");
					}
					
					// get the mortgage calculator view
					$.clickSoldUtils("infoBoxCreate", {
						href : settings.ajaxTarget,
						data: "pathway=6&calculator=true&selectedTabId=" + tab + "&listPrice=" + listPrice + "&propTax=" + tax + "&conFees=" + cFees + "&listingNumber=" + settings.listingNumber + "&modletId=" + settings.modletId,
						opacity : 0.25,
						innerWidth : "750px",
						innerHeight : "600px",
						returnFocus : false,
						onComplete : function(){
							$("#QualifierOutFormContainer").RPMQualifier({
								'outputContainerId' : 'QualifierOutFormContainer',
								'containerTabId' : 'widgetRpmqualiferTabs',
								'calcuVars' : calcuVars,	
								'qualifierVars' : qualifierVars,
								'selectedTab' : selectedTab,
								'ajaxTarget' : settings.ajaxTarget
							});	
							$.clickSoldUtils("infoBoxResize");
							$(".ui-widget-overlay").bind("click", function(){
								$(".ui-widget-overlay").unbind("click");
								$("#rpmCalcDialog").dialog("close");
							});
						},
						onClosed : function(){
							$(".mortDialog").remove();
						}
					}).parents(".ui-dialog:eq(0)").wrap("<div class=\"mortDialog\"></div>");
					return false;
				});
			},
			/**
			 * Binds the email form for this specific object
			 */
			displayEmailForm : function(listingNumber){
				var $this = $(this);
				var settings = $this.data("settings");
				alert('here1');
				$this.find("#listingEmailForm").clickSoldUtils("csBindToForm", {
					updateDivId: "listingEmailModule",
					loadingDivId: "listingEmailLoadingOverlay",
					message: "Sending Message...",
					context: $this
				});
				alert('here2');
				$.clickSoldUtils("infoBoxCreate", {
					href : settings.ajaxTarget,
					data : "pathway=6&listingNumber=" + listingNumber + "&loadListingEmail=true",
					opacity : 0.25,
					overlayClose : false,
					onComplete : function(){
						$('#listingEmailForm').clickSoldUtils("csBindToForm", {
							updateDivId: "listingEmailModule",
							loadingDivId: "listingEmailLoadingOverlay",
							message: "Please wait...",
							plugin: settings.plugin
						});
					}
				});
			},
			/**
			 * Utility function for slideshow view that modifies main image width or height to fit properly inside main photo placeholder
			 */
			toggleEnlargePhoto : function(imgSrc){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					
					var img = new Image();
					img.src = imgSrc;
					if(img.width > 640 || img.height > 480){
						$(".photoOptionsEnlarge").css("display", "inline");
						$("#mainPhoto_buttons").css("width", "132px");
					}else{
						$(".photoOptionsEnlarge").css("display", "none");
						$("#mainPhoto_buttons").css("width", "100px");
					}
					img = null;
				});
			}
		};
		
		var helpers = {
			/**
			 * Updates the main photo in the listing modlet
			 */
			updateMainPhoto : function($mainPhoto, $thumbnailImg){
				return $(this).each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");

					// get the current height of the main photo
					var oldMainPhotoHeight = $mainPhoto.height();
					
					$mainPhoto.attr("src", $thumbnailImg.attr("src"));
					$mainPhoto.attr("alt", $thumbnailImg.attr("alt"));
					$mainPhoto.attr("title", $thumbnailImg.attr("title"));
					$mainPhoto.parents("div.cs-listing-details-photo-container").find("div.cs-listing-details-photo-desc").html($thumbnailImg.attr("title"));
					
					// we need to set the height in order for the resize command to work properly in webkit/IE
					var thumbnailImg = new Image();
					thumbnailImg.src = $thumbnailImg.attr("src");
					$mainPhoto.attr("height", thumbnailImg.height);
					$mainPhoto.css("height", thumbnailImg.height);

					// resize infobox if view resides in an infobox, and if image height has changed
					if(settings.infoBox && oldMainPhotoHeight != thumbnailImg.height){ $.clickSoldUtils('infoBoxResize');}
				});
			},

			/**
			 * Sets the proper URL to be used for the print view of a specific listing
			 */
			printViewUrl : function(){
				return $(this).each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					$this.find("#printView").attr("href", settings.ajaxTarget + "?pathway=6&listingNumber=" + settings.listingNumber + "&printView=true");
				});
			},
			/**
			 *  Retrieves a single slideshow view
			 */
			displayTour : function(tourNum){
				return this.each(function(){
					//Retrieve settings
					var $this = $(this);
					var settings = $this.data("settings");
					
					$('.tourFrame').attr('src', settings.ajaxTarget + '?pathway=6&type=results&tourNum=' + tourNum + '&vrTour=true&modletId=' + settings.modletId);
					$.clickSoldUtils("infoBoxResize");
				});
			}
		};
		
		if( methods[method] ){  //Method call
			if(typeof this.data("settings") == 'undefined'){
				//not initialized yet, add to queue
				var methodQueue = new Array();
				if( typeof this.data("methodQueue") != "undefined" ) methodQueue = this.data("methodQueue");
				methodQueue.push([method, Array.prototype.slice.call( arguments, 0 )]);
				this.data("methodQueue", methodQueue);
				return false;
			}else{
				return methods[method].apply(this, Array.prototype.slice.call( arguments, 1 ));
			}
		}else if(typeof method === "object"){  //Initialization call - must have arguments
			if(typeof this.data("settings") != 'undefined'){
				$.clickSoldUtils('csConsole', 'Removing Stuff');
				this.data("settings", null); 
				this.unbind();
			}
		
			var init = methods.init.apply(this, arguments);
			
			//Run queued method calls
			if( typeof this.data("methodQueue") != "undefined" ) {
				var methodQueue = this.data("methodQueue");
				while(methodQueue.length > 0){
					var m = methodQueue.shift();
					methods[m[0]].apply(this, m[1]);
				}
			}
			
			return init;
		}else{  //ERROR
			$.error("Method " + method + " does not exist on jQuery.listingDetails");
		}
	}


})(jQuery);// close ListingDetails
