var FeaturedPropertyFormClass = Class.create(); FeaturedPropertyFormClass.prototype = { initialize: function(options) { }, getStartDate: function() { var dY = parseInt($('select[name="start_date[Y]"]').val()); var dM = parseInt($('select[name="start_date[M]"]').val()); var dD = parseInt($('select[name="start_date[d]"]').val()); if (isNaN(dY) || isNaN(dM) || isNaN(dD)) { return false; } return sprintf('%04d-%02d-%02d', dY, dM, dD); }, getEndDate: function() { var dY = parseInt($('select[name="end_date[Y]"]').val()); var dM = parseInt($('select[name="end_date[M]"]').val()); var dD = parseInt($('select[name="end_date[d]"]').val()); if (isNaN(dY) || isNaN(dM) || isNaN(dD)) { return false; } return sprintf('%04d-%02d-%02d', dY, dM, dD); }, getCurrentDate: function() { var d = new Date(); var y = d.getYear(); if (y < 1900) { y += 1900; } return sprintf('%04d-%02d-%02d', y, d.getMonth() + 1, d.getDate()); }, updateStatus: function() { var sd = this.getStartDate(); var ed = this.getEndDate(); var cd = this.getCurrentDate(); var status = 'Inactive'; if (sd && ed) { if (sd <= cd && ed >= cd) { status = 'Showing on homepage'; } else if (sd > cd) { status = 'Inactive - will be shown in future' } else if (ed < cd) { status = 'Inactive - was shown before'; } } $('#id_active').html(status); } }; var featuredPropertyForm = new FeaturedPropertyFormClass(); // --------------------------------------------------------------------------------------------------------------- var slideTimer = null; var slideWidth = 0; var slidesWidth = 0; var slideCurrentOffset = 0; var slideMaxOffset = 0; var frameSize = null; //5; var centerFrame = 3; var slidesData = null; var slidesMoving = false; var shortTimeout = 7000; var longTimeout = 20000; function slideTimeoutStart(timeout) { timeout = parseInt(timeout) || shortTimeout; slideTimer = setTimeout("prevSlides();", timeout); return true; } function slideTimeoutStop() { if (slideTimer != null) { clearTimeout(slideTimer); slideTimer = null; } return true; } function slideShowActive() { var slideId = $(".slide_list div:eq(2)").attr('id'); slideShowItem(slideId); } function nextSlides(timeout, step) { if (typeof step == 'undefined') { step = frameSize; } slideTimeoutStop(); if (slideMaxOffset > step && !slidesMoving) { var duration = 1000; if (step < frameSize) { duration = duration / (frameSize - step); } slidesMoving = true; var appendFrame = $('div.slide_list div[id^=property_slide_]:lt(' + step + ')'); $(appendFrame).each(function () { $('div.slide_list').append('
' + $(this).html() + '
'); }); $('div.slide_list').animate({marginLeft: '-=' + (slideWidth * step) + 'px'}, duration, 'linear', function () { $(appendFrame).remove(); $('div.slide_list').css('margin-left', 0); slideShowActive(); slidesMoving = false; }); sliderBindClick(); } slideTimeoutStart(timeout); } function prevSlides(timeout, step) { if (typeof step == 'undefined') { step = frameSize; } slideTimeoutStop(); if (slideMaxOffset > step && !slidesMoving) { var duration = 1000; if (step < frameSize) { duration = duration / (frameSize - step); } slidesMoving = true; var lastFrame = slideMaxOffset - step - 1; var prependFrame = $('div.slide_list div[id^=property_slide_]:gt(' + lastFrame + ')'); $('div.slide_list').css('margin-left', -(slideWidth * step)); var elements = []; $(prependFrame).each(function () { //elements.push($(this).clone(true)); elements.push('
' + $(this).html() + '
'); }); for (var i = elements.length - 1; i >= 0; i--) { //$(elements[i]).prependTo('div.slide_list'); $('div.slide_list').prepend(elements[i]); } $('div.slide_list').animate({marginLeft: '+=' + (slideWidth * step) + 'px'}, duration, 'linear', function () { $(prependFrame).remove(); slideShowActive(); slidesMoving = false; }); sliderBindClick(); } slideTimeoutStart(timeout); } function slideShowItem(id) { var idSlide = id.replace(/property_slide_/, ''); if (typeof slidesData[idSlide] != 'undefined') { var container = $('div.slide_details'); if ($(container).size()) { var html = '' + '' + ' ' + ' ' + '' + '
' + ' '; /*if (slidesData[idSlide].be_seen_url) { html += '
Be Seen Here
'; }*/ html += '
Be Seen Here
'; html += '
' + '
' + slidesData[idSlide].property_name + '
' + '
' + slidesData[idSlide].availability_title + '
' + '
' + slidesData[idSlide].property_address + '
' + slidesData[idSlide].property_city + ', ' + slidesData[idSlide].property_state + ' ' + slidesData[idSlide].property_zip + '
' + '
Type: ' + slidesData[idSlide].property_type + '
' + '
Contact: ' + slidesData[idSlide].contact_name + ', ' + slidesData[idSlide].company + '
' + ' VIEW DETAILS' + '
'; $(container).html(html).show(); } } } function sliderBindClick() { $('div.slide_list div.slide_item').each(function() { $(this).unbind('click'); $(this).click(function() { var id = $(this).attr('id'); var i = null; $(".slide_list div").each(function (index) { if ($(this).attr('id') == id) { i = index; return false; } }); var move = (centerFrame - 1) - i; if (move < 0) { nextSlides(longTimeout, Math.abs(move)); } else { prevSlides(longTimeout, move); } }); }); } $(document).ready(function() { slideMaxOffset = parseInt($('div.slide_list div.slide_item').size()); if (slideMaxOffset) { //$('div.slide_list').mouseover(function(){ slideTimeoutStop(); }).mouseout(function(){ slideTimeoutStart(); }); slideWidth = parseInt($('div.slide_list div.slide_item').css('width')) || 0; slidesWidth = slideWidth * slideMaxOffset; if (count(slidesData) > frameSize) { $('div.properties_slider div.slide_navi div.slide_back img').click(function() { nextSlides(longTimeout, 1); }); $('div.properties_slider div.slide_navi div.slide_next img').click(function() { prevSlides(longTimeout, 1); }); } else { $('div.properties_slider div.slide_navi div.slide_back img').css('visibility', 'hidden'); $('div.properties_slider div.slide_navi div.slide_next img').css('visibility', 'hidden'); } sliderBindClick(); slideShowActive(); slideTimeoutStart(); } });