﻿$.featuredProperties = { slideWidth: 225, slides: null, time: 5000, timer: null, imgSource: null, relIndex: null, clicked: "off", borderProperties: null, activeAjaxRequest: null, pageNumber: 0, firstTimeDataCall: true, properties: new Array(), totalProperties: null, totalDownloadedProperties: null, currentPropertyNo: null, slideInner: null, controlActive: false, waitingPanel: null, moreInfoPanel: null, propertyImagesPath: null }; $.featuredProperties.isLastDownloadedProperty = function () { return ($.featuredProperties.currentPropertyNo == $.featuredProperties.totalDownloadedProperties - 1) ? true : false; }; $.featuredProperties.hasMoreRemoteProperties = function () { return ($.featuredProperties.totalDownloadedProperties == $.featuredProperties.totalProperties) ? false : true; }; $.featuredProperties.currentSlideNo = function () { return ($.featuredProperties.currentPropertyNo == null) ? 0 : Math.floor($.featuredProperties.currentPropertyNo / 6); }; $.featuredProperties.totalSlides = function () { return Math.ceil($.featuredProperties.totalDownloadedProperties / 6); }; $.featuredProperties.hasMoreSlides = function () { return ($.featuredProperties.totalSlides() < Math.floor($.featuredProperties.totalProperties / 6)); }; $.featuredProperties.isLastSlide = function () { return ($.featuredProperties.currentSlideNo() == $.featuredProperties.totalSlides()); }; $.featuredProperties.isFirstSlide = function () { return ($.featuredProperties.currentSlideNo() == 0); }; $.featuredProperties.startTimer = function () { $.featuredProperties.stopTimer(); if (!$.featuredProperties.controlActive) { $.featuredProperties.timer = setInterval($.featuredProperties.onTimerEvent, $.featuredProperties.time); } }; $.featuredProperties.stopTimer = function () { clearInterval($.featuredProperties.timer); }; $.featuredProperties.toggleWaiting = function (showWaiting) { if (showWaiting) { $.featuredProperties.waitingPanel.show(); $.featuredProperties.moreInfoPanel.hide(); } else { $.featuredProperties.waitingPanel.hide(); $.featuredProperties.moreInfoPanel.show(); } }; $.featuredProperties.init = function (imagesPath) { $.featuredProperties.propertyImagesPath = imagesPath; $.featuredProperties.waitingPanel = $(".featureWaiting"); $.featuredProperties.moreInfoPanel = $("#slidesContainer .moreInfo"); if ($.featuredProperties.firstTimeDataCall) { $.featuredProperties.pageNext($.featuredProperties.init, $.featuredProperties.propertyImagesPath); return; } if ($.featuredProperties.properties != null && $.featuredProperties.properties.length > 0) { $("#featPropertiesControl").show(200); } else { return; } $.featuredProperties.setupSlides(); $.featuredProperties.setupNavButtons(); $.featuredProperties.attachEventHandlers(); $.featuredProperties.moveFirst(); $.featuredProperties.startTimer(); }; $.featuredProperties.setupSlides = function () { $("#slidesContainer").css("overflow", "hidden"); $.featuredProperties.slideInner = $("#slideInner"); $("#slideInner").css("width", $.featuredProperties.slideWidth * $.featuredProperties.numberOfSlides).css("float", "left"); }; $.featuredProperties.setupNavButtons = function () { $("#featPropertiesControl").prepend('<span class="control" id="leftControl">Prev</span>').prepend('<span id="buttonPipe">|</span>').append('<span class="control" id="rightControl">Next</span>'); $.featuredProperties.toggleNavButtons(); }; $.featuredProperties.resetImageNames = function () { $(".thumbnails li a img").each(function (index) { $(this).addClass("imgSelection" + index); $(this).attr("rel", index); }); }; $.featuredProperties.attachEventHandlers = function () { $(".control").bind("click", function () { var oldPropertyNo = $.featuredProperties.currentPropertyNo; if ($(this).attr("id") == "rightControl") { if (!$.featuredProperties.isLastSlide()) { $.featuredProperties.currentPropertyNo = ((($.featuredProperties.currentSlideNo() + 2) * 6) - 6); } else { $.featuredProperties.currentPropertyNo = 0; } } if ($(this).attr("id") == "leftControl") { if (!$.featuredProperties.isFirstSlide()) { $.featuredProperties.currentPropertyNo = ((($.featuredProperties.currentSlideNo()) * 6) - 6); } } $.featuredProperties.toggleActiveProperty($.featuredProperties.currentPropertyNo, oldPropertyNo); $.featuredProperties.slide(); $.featuredProperties.toggleNavButtons(); }); $("#featPropertiesControl").hover(function () { $.featuredProperties.controlActive = true; $.featuredProperties.stopTimer(); }, function () { $.featuredProperties.controlActive = false; $.featuredProperties.startTimer(); }); }; $.featuredProperties.toggleNavButtons = function () { if ($.featuredProperties.currentSlideNo() < $.featuredProperties.totalSlides() - 1) { $("#rightControl").fadeIn(200); } else { $("#rightControl").fadeOut(200); $("#buttonPipe").fadeOut(200); } if ($.featuredProperties.currentSlideNo() > 0) { $("#leftControl").fadeIn(200); } else { $("#leftControl").fadeOut(200); } }; $.featuredProperties.toggleActiveProperty = function (newPropertyNo, oldPropertyNo) { $(".imgSelection" + newPropertyNo).removeClass("featuredPropertyOff"); $(".imgSelection" + newPropertyNo).addClass("featuredPropertyOn"); $(".featuredPropTitle b").text($(".imgSelection" + newPropertyNo).attr("name")); $(".featuredPropTitle h2").text($(".imgSelection" + newPropertyNo).attr("title")); $(".mainContent img").hide(); $(".mainContent img").attr("src", $(".imgSelection" + newPropertyNo).attr("src")); $(".mainContent img").css("border", "1px solid #cccccc"); $(".mainContent img").fadeIn(600); $(".imgSelection" + (oldPropertyNo)).removeClass("featuredPropertyOn"); $(".imgSelection" + (oldPropertyNo)).removeClass("featuredPropertyOff"); $(".featuredPropTitle span b").html($.featuredProperties.properties[newPropertyNo].Suburb + ", " + $.featuredProperties.properties[newPropertyNo].City); $(".featuredPropTitle em h2").html($.featuredProperties.properties[newPropertyNo].PriceText); var hlink = "/property/" + $.featuredProperties.properties[newPropertyNo].Id; $(".featuredPropTitle a").attr("href", hlink); }; $.featuredProperties.pageNext = function (delegateFunctionToCall, delegateParameter) { $.featuredProperties.stopTimer(); $.featuredProperties.pageNumber += 1; if ($.featuredProperties.activeAjaxRequest != null) { $.featuredProperties.activeAjaxRequest.abort(); } $.featuredProperties.toggleWaiting(true); $.featuredProperties.activeAjaxRequest = $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "/extensions/Properties.asmx/GetFeaturedProperties", data: "{ 'pageNumber': '" + ($.featuredProperties.pageNumber - 1) + "'}", dataType: "json", success: function (result) { $.featuredProperties.firstTimeDataCall = false; if (result.d.Properties != null) { $.featuredProperties.properties = $.merge($.featuredProperties.properties, result.d.Properties); $.featuredProperties.totalDownloadedProperties = $.featuredProperties.properties.length; } $.featuredProperties.totalProperties = result.d.TotalCount; $.featuredProperties.populateResults(); $.featuredProperties.toggleWaiting(false); if (delegateFunctionToCall != null) { delegateFunctionToCall(delegateParameter); } } }); }; $.featuredProperties.moveFirst = function () { $.featuredProperties.toggleActiveProperty(0, $.featuredProperties.currentPropertyNo); $.featuredProperties.currentPropertyNo = 0; $.featuredProperties.slide(); $.featuredProperties.toggleNavButtons(); }; $.featuredProperties.moveNext = function () { if (!$.featuredProperties.isLastDownloadedProperty()) { $.featuredProperties.toggleActiveProperty($.featuredProperties.currentPropertyNo + 1, $.featuredProperties.currentPropertyNo); $.featuredProperties.currentPropertyNo++; $.featuredProperties.toggleNavButtons(); $.featuredProperties.slide(); } else { if ($.featuredProperties.hasMoreRemoteProperties()) { $.featuredProperties.pageNext($.featuredProperties.moveNext); } else { $.featuredProperties.moveFirst(); } } }; $.featuredProperties.getNextPage = function () { $.featuredProperties.pageNumber += 1; $.featuredProperties.activeAjaxRequest = $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "/extensions/Properties.asmx/GetFeaturedProperties", data: "{ 'pageNumber': '" + ($.featuredProperties.pageNumber - 1) + "'}", dataType: "json", success: function (result) { $.featuredProperties.populateResults(result, false); $(".searchWaiting").hide(); } }); }; $.featuredProperties.onTimerEvent = function () { $.featuredProperties.moveNext(); }; $.featuredProperties.populateResults = function () { $slidesContainer = $("#featPropertiesControl #slideInner"); $.each($.featuredProperties.properties, function (index, property) { if (!$slidesContainer.find(".imgSelection" + index).length) { var $workingSlide = $slidesContainer.find("div.slide:last"); if ($workingSlide.find("li img").length == 6) { $workingSlide = $workingSlide.clone(); $workingSlide.find("ul.thumbnails").empty(); $workingSlide.appendTo($slidesContainer); } $("<li></li>").html($("<a></a>").attr("href", "javascript:void(0)").attr("title", "").html($("<img></img>").attr("src", $.featuredProperties.propertyImagesPath + property.PriorityImage).bind("click", function () { var newPropertyNo = parseInt($(this).attr("rel")); $.featuredProperties.toggleActiveProperty(newPropertyNo, $.featuredProperties.currentPropertyNo); $.featuredProperties.currentPropertyNo = newPropertyNo; }))).appendTo($workingSlide.find("ul.thumbnails")); } }); $.featuredProperties.slides = $(".slide"); $.featuredProperties.resetImageNames(); }; $.featuredProperties.slide = function () { var currentLeftMargin = parseInt($.featuredProperties.slideInner.css("margin-left")); var newLeftMargin = $.featuredProperties.slideWidth * (-Math.floor($.featuredProperties.currentPropertyNo / 6)); if (currentLeftMargin != newLeftMargin) { $.featuredProperties.stopTimer(); $.featuredProperties.slideInner.animate({ marginLeft: $.featuredProperties.slideWidth * (-Math.floor($.featuredProperties.currentPropertyNo / 6)) }, function () { $.featuredProperties.startTimer(); }); } }; $(document).ready(function () { var maskTemplate = '<div class="imageMask"><p class="maskText">Click <a href="">here</a> to view this property\'s details</p></div>'; var maskTitle; var maskLink; var propertyLink; $(".mainContent img").after(maskTemplate); $(".mainContent img").bind("mouseenter", function () { $(".imageMask").fadeTo(150, 0.85); propertyLink = $(".featuredPropTitle a").attr("href"); $(".imageMask a").attr("href", propertyLink); }); $(".mainContent").bind("mouseleave", function () { $(".imageMask").fadeOut(150); }); });
