// -- LANG constant ----------------------------------------------------------------- var LANG = 'en'; var CURRENCY = 'HKD'; var CURRENCY_SYM = 'HK$'; var IMG_DIR = '/v2/lang/en/images'; var __ = {}; __['subscribe-em'] = 'Subscribe to e-Magazine'; __['adv-enquiry'] = 'Advertising Enquiry'; __['street-view'] = 'Street View'; __['map'] = 'Map'; __['satellite'] = 'Satellite'; __['share-with-fds'] = 'Share with Friends'; __['enquiry'] = 'Enquiry'; __['email-this-agent'] = 'Email this Agent'; __['refer-this-agent'] = 'Refer this Agent'; __['size'] = 'Size'; __['bed'] = 'Bed'; __['bath'] = 'Bath'; __['ensuite-abbr'] = 'En'; __['size-unit'] = 'sq.ft.'; __['rental'] = 'Rental'; __['price'] = 'Price'; __['ref#'] = 'Property#'; __['del'] = 'Delete'; __['min'] = 'Min'; __['max'] = 'Max'; __['save-this-prop-to-myhome'] = 'Save this Property to \'MyOffices\''; __['remove-this-prop-fr-myhome'] = 'Remove this Property from \'MyOffices\''; __['is-del-this-prop'] = 'Remove this Property from \'MyOffices\'?'; __['is-del-this-item'] = 'Remove this item from \'MyOffices\' ?'; __['is-del-all-props'] = 'Remove all Properties belong to this list from \'MyOffices\' ?'; __['is-del-all-items'] = 'Remove all items belong to this list from \'MyOffices\' ?'; __['pls-enter-email-addr'] = 'Please enter your email address.'; __['pls-enter-pwd'] = 'Please enter your password.'; // __['no-items-saved'] = 'No items saved yet.'; __['no-items-saved'] = ''; // __["timer-year"] = 'timer-year'; // __["timer-month"] = 'timer-month'; // __["timer-day"] = 'timer-day'; // __["timer-hr"] = 'timer-hr'; // __["timer-hour"] = 'timer-hour'; // __["timer-minute"] = 'timer-minute'; // __["timer-sec"] = 'timer-sec'; // ---------------------------------------------------------------------------------- var hkh = hkh || {}; hkh.obj = {}; function selectMenu(item) { $('#menu-'+item).addClass('selected'); } function isiPad() { return navigator.platform.indexOf("iPad") != -1 } function isiPhone() { return navigator.platform.indexOf("iPhone") != -1 || navigator.platform.indexOf("iPod") != -1 } function isiDevice() { return isiPad() || isiPhone(); } function getCookie(key) { var val = ''; var i, x, y; var cookies = document.cookie.split(";"); for (var i = 0; i < cookies.length; i++) { x = cookies[i].substr(0,cookies[i].indexOf("=")); y = cookies[i].substr(cookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == key) { val = decodeURIComponent(y); break; } } return val; } function setCookie(key, val, is_delete) { var expires = new Date(); expires.setTime(expires.getTime() + 1000 * 60 * 60 * 24 * 365 * 20); // expiry after 20 years if (is_delete) { expires.setTime(1000 * 60 * 60 * 24 * 365 * 20 * -1); } var domain = window.location.hostname.split('.'); var domain_str = ''; var idx = 0; if (domain[0] == 'www') idx = 1; for (var i=idx; i < domain.length; i++) domain_str += '.'+domain[i]; document.cookie = key + '=' + encodeURIComponent(val) + '; path=/; expires=' + expires.toGMTString() + "; domain="+domain_str; } function deleteCookie(key) { setCookie(key, '', true); } var email_pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; var multiEmailVaildation = { version :"0.0.1", separator :"\n", check : function( email_str ) { invaild = true; emails = email_str.split( this.separator ); for (var i = 0; i < emails.length; i++) { email = emails[i].replace(/\s+/,""); if( email.length > 0 ) { if (!this.validate(emails[i]) ) { alert('one or more email addresses entered is invalid.'); return false; } invaild = false; } } return ( invaild ) ? false:true; }, validate : function( email ){ email_pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return email_pattern.test(email); } } function openPopup(url, w, h, window_name) { if (typeof window_name == 'undefined') { window_name = ''; } if (typeof w == 'undefined') w = 700; if (typeof h == 'undefined') h = 750; window.open(url, window_name, "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, width=" + w + ", height=" + h + ", left=" + ((window.screen.availWidth - (w + 4)) / 2) + ", top=" + ((window.screen.availHeight - (h + 50)) / 2)); } function fbs_click() { u=location.href; t=document.title; window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436'); return false; } // -- customSelect ------------------------------------------------------------------------------------- function formatNum(g) { var h = parseInt(g, 10); if (isNaN(h)) { return g } if (h < 10000) { return h } return h >= 1000000 ? (h / 1000000).toFixed(2).replace(/(\.[1-9]*)0+$/, "$1").replace(/\.$/, "") + "M" : (h / 1000).toFixed(2).replace(/\.0+$/, "") + "K" } function formatLocationSelectorWindowText(dropdown) { var display_txts = ''; var group_ids = []; var selected_vals = []; $('input:checked', dropdown).each(function () { selected_vals.push(this.value); }); $.each(selected_vals, function (i, val) { if (val.indexOf(',') != -1) { group_ids.push(val); } }); if (group_ids.length > 0) { display_txts = []; var pvc_ids_regex = []; $.each(group_ids, function (i, val) { pvc_ids_regex.push(val.replace(/,/g, '|')); }); pvc_ids_regex = '^('+pvc_ids_regex.join('|')+')$'; pvc_ids_regex = new RegExp(pvc_ids_regex); $('input', dropdown) .filter(function () { var is_not_in_group = this.value.match(pvc_ids_regex) == null; var is_checked = $(this).is(':checked'); return is_not_in_group && is_checked; }) .each(function () { display_txts.push($(this).parent().find('label').html()); }); display_txts = display_txts.join(', '); } dropdown.parent().prev().customSelect('setWindowText', display_txts); } function formatLocationSelectorDropdownOptions(dropdown) { dropdown.width(250); $('input[value*=","]', dropdown).each(function () { var self = $(this); self.parent().addClass('group'); var pvc_ids_regex = self.val().replace(/,/g, '|'); pvc_ids_regex = '^('+pvc_ids_regex+')$'; pvc_ids_regex = new RegExp(pvc_ids_regex); self.change(function () { var is_checked = self.is(':checked'); self.parent().parent() .find('input') .filter(function () { return this.value.match(pvc_ids_regex); }) .each(function () { $(this).attr('checked', is_checked); }); formatLocationSelectorWindowText(dropdown); }); }); $('input', dropdown) .filter(function () { return this.value.match(/^\d+$/); }) .each(function () { var self = $(this); self.val(); self.parent().addClass('group-sub-item'); var this_group_ids = ''; self.change(function () { var is_checked = self.is(':checked'); self.parent().parent() .find('input[value*=","]') .filter(function () { var all_group_ids = ','+this.value+','; return all_group_ids.indexOf(','+self.val()+',') != -1 }) .each(function () { if (is_checked) { var is_all_checked = true; var pvc_ids_regex = $(this).val().replace(/,/g, '|'); pvc_ids_regex = '^('+pvc_ids_regex+')$'; pvc_ids_regex = new RegExp(pvc_ids_regex); $(this).parent().parent() .find('input') .filter(function () { return this.value.match(pvc_ids_regex); }) .each(function () { if (!$(this).is(':checked')) { is_all_checked = false; return false; } }); if (is_all_checked) $(this).attr('checked', true); } else $(this).attr('checked', false); }); formatLocationSelectorWindowText(dropdown); }); }); } var customSelect_opts = { customValue: false, placeholder: '', customValuePlaceholder: 'custom', change: function (h) { if (h.originalEvent) { $(this).trigger("customselectblur"); } }, windowFormatter: function (h) { if (h === this.placeholder) { return this.placeholder; } if (h.match(/\+$/)) { return h; } h = h.replace(/^\$/, "").replace(/,/, ""); if (!h.match(/(K|k|M|m)$/)) { h = formatNum(h) } return h; }, customValidator: function (h, j) { if (j !== "") { var k = 1, i = true; j = j.replace(/,/g, ""); switch (j.charAt(j.length - 1).toLowerCase()) { case "k": k = 1000; j = j.substr(0, j.length - 1); break; case "m": k = 1000000; j = j.substr(0, j.length - 1); break } if (j.indexOf(".") !== -1) { if (j.match(/\./g).length > 1) { i = false } } if (j.match(/[^\d.]/g)) { i = false } if (i) { return Math.round(parseFloat(j) * k) + "" } else { h.setCustomValueError('Invalid value'); return false; } } return "" } } // ------------------------------------------------------------------------------------------------------ $(window).load(function () { // -- select-location hook ---------------------------------------------------------------- $('#select-location_customSelect .ui-customSelect-dropdown').ready(function () { var dropdown = $('#select-location_customSelect .ui-customSelect-dropdown'); formatLocationSelectorDropdownOptions(dropdown); }); $('#select-rent-location_customSelect .ui-customSelect-dropdown').ready(function () { var dropdown = $('#select-rent-location_customSelect .ui-customSelect-dropdown'); formatLocationSelectorDropdownOptions(dropdown); }); $('#select-buy-location_customSelect .ui-customSelect-dropdown').ready(function () { var dropdown = $('#select-buy-location_customSelect .ui-customSelect-dropdown'); formatLocationSelectorDropdownOptions(dropdown); }); // -------------------------------------------------------------------------------- }); $(function () { // -- main menu ---------------------------------------- $('#menu .items .item').hover( function () { var item = $(this); item.addClass('mouseover'); $('.sub-items', item).show(); }, function () { var item = $(this); item.removeClass('mouseover'); $('.sub-items', item).hide(); } ); // set the margin-left for drop down for different fonts $('#menu-coml-office, #menu-ind, #menu-agents_blog, #menu-living_hk, #menu-about_us, #menu-our_services, #menu-myhomes').each(function () { var w = $(this).width() - 2; // - 2 for border width $('.top-spacer', this).css('margin-left', w); }); // ----------------------------------------------------- // -- on button mouse over ----------------------------- $('.button.gray-90').hover( function () { $(this).addClass('gray-90-over'); }, function () { $(this).removeClass('gray-90-over'); } ); $('.button.gray-43').hover( function () { $(this).addClass('gray-43-over'); }, function () { $(this).removeClass('gray-43-over'); } ); $('.button.gold-90').hover( function () { $(this).addClass('gold-90-over'); }, function () { $(this).removeClass('gold-90-over'); } ); $('.button.gold-138').hover( function () { $(this).addClass('gold-138-over'); }, function () { $(this).removeClass('gold-138-over'); } ); $('.button.gold-165').hover( function () { $(this).addClass('gold-165-over'); }, function () { $(this).removeClass('gold-165-over'); } ); $('.icon-button.edit').hover( function () { $(this).addClass('edit-over'); }, function () { $(this).removeClass('edit-over'); } ); $('.icon-button.save').hover( function () { $(this).addClass('save-over'); }, function () { $(this).removeClass('save-over'); } ); $('.icon-button.remove-saved').hover( function () { $(this).addClass('remove-saved-over'); }, function () { $(this).removeClass('remove-saved-over'); } ); $('.icon-button.enquiry').hover( function () { $(this).addClass('enquiry-over'); }, function () { $(this).removeClass('enquiry-over'); } ); $('.icon-button.print').hover( function () { $(this).addClass('print-over'); }, function () { $(this).removeClass('print-over'); } ); $('.icon-button.pdf').hover( function () { $(this).addClass('pdf-over'); }, function () { $(this).removeClass('pdf-over'); } ); $('.icon-button.detail-pro-desc').hover( function () { $(this).addClass('detail-pro-desc-over'); }, function () { $(this).removeClass('detail-pro-desc-over'); } ); // ----------------------------------------------------- // -- myhomes box -------------------------------------- $('.myhomes-box .item').each(function () { var item = $(this); var sub_items = item.parent().children('.sub-items'); var sub_items_len = sub_items.length; if (sub_items_len > 0) { item.click(function (event) { event.preventDefault(); $(this).parent().children('.sub-items').toggle(); }); } }); // ----------------------------------------------------- // -- search-main-box -------------------------------------- $('.search-main-box .item').each(function () { var item = $(this); var sub_items = item.parent().children('.sub-items'); var sub_items_len = sub_items.length; if (sub_items_len > 0) { item.click(function (event) { event.preventDefault(); $(this).parent().children('.sub-items').toggle(); }); } }); // ----------------------------------------------------- // -- customSelect ------------------------------------------------------------------------ $('.refine-search-box').each(function () { customSelect_opts_min = $.extend(true, {}, customSelect_opts); customSelect_opts_min.customValue = true; customSelect_opts_min.placeholder = 'Min'; customSelect_opts_max = $.extend(true, {}, customSelect_opts); customSelect_opts_max.customValue = true; customSelect_opts_max.placeholder = 'Max'; var customSelect_opts_for_money_type = $.extend(true, {}, customSelect_opts); customSelect_opts_for_money_type.change = function (h) { if (h.originalEvent) { $(this).trigger("customselectblur"); var money_type = $(this).val(); var per_unit_sel_boxes = $('.money-per-unit-sel-boxes'); var total_sel_boxes = $('.money-total-sel-boxes'); if (money_type == 'per_unit') { per_unit_sel_boxes.show().find('select').attr('disabled', false); total_sel_boxes.hide().find('select').attr('disabled', true); } else { per_unit_sel_boxes.hide().find('select').attr('disabled', true); total_sel_boxes.show().find('select').attr('disabled', false); } } }; $('.money-type').customSelect(customSelect_opts_for_money_type); $('#select-sale-avail').customSelect(customSelect_opts); var val_fr = parseInt($('#select-unit-money-fr').parent().find('.arg-val').val()); var val_to = parseInt($('#select-unit-money-to').parent().find('.arg-val').val()); customSelect_opts_min.customValue = val_fr > 0 ? val_fr : true; customSelect_opts_max.customValue = val_to > 0 ? val_to : true; $('#select-unit-money-fr').customSelect(customSelect_opts_min); $('#select-unit-money-to').customSelect(customSelect_opts_max); var val_fr = parseInt($('#select-money-fr').parent().find('.arg-val').val()); var val_to = parseInt($('#select-money-to').parent().find('.arg-val').val()); customSelect_opts_min.customValue = val_fr > 0 ? val_fr : true; customSelect_opts_max.customValue = val_to > 0 ? val_to : true; $('#select-money-fr').customSelect(customSelect_opts_min); $('#select-money-to').customSelect(customSelect_opts_max); var val_fr = parseInt($('#select-size-fr').parent().find('.arg-val').val()); var val_to = parseInt($('#select-size-to').parent().find('.arg-val').val()); customSelect_opts_min.customValue = val_fr > 0 ? val_fr : true; customSelect_opts_max.customValue = val_to > 0 ? val_to : true; $('#select-size-fr').customSelect(customSelect_opts_min); $('#select-size-to').customSelect(customSelect_opts_max); customSelect_opts_min.customValue = false; customSelect_opts_max.customValue = false; $('#select-bed-fr').customSelect(customSelect_opts_min); $('#select-bed-to').customSelect(customSelect_opts_max); $('#select-bath-fr').customSelect(customSelect_opts_min); $('#select-bath-to').customSelect(customSelect_opts_max); customSelect_opts = { placeholder: 'Please select', isDelegateSetWindowTextFunction: 1 } $('#select-location').customSelect(customSelect_opts); var dropdown = $('#select-location_customSelect .ui-customSelect-dropdown'); formatLocationSelectorWindowText(dropdown); activatePlaceholders(); }); // ---------------------------------------------------------------------------------------- // -- refine search - multi-select-box ---------------------------------------------------------------- // $(document).click(function (e) { // if ($('.refine-search-box .multi-select-box')[0]) // { // if (!$.contains($('.refine-search-box .multi-select-box')[0], e.target)) // { // $('select[name="rental_fr"], select[name="rental_to"], select[name="size_fr"], select[name="size_to"], select[name="bed_fr"], select[name="bed_to"], select[name="bath_fr"], select[name="bath_to"]', $('.refine-search-box .row')).css('visibility', 'visible'); // $('.refine-search-box .multi-select-box .box-opts').hide(); // } // } // }); // $('.refine-search-box .multi-select-box .box-heading').click(function () { // $('select[name="rental_fr"], select[name="rental_to"], select[name="size_fr"], select[name="size_to"], select[name="bed_fr"], select[name="bed_to"], select[name="bath_fr"], select[name="bath_to"]', $('.refine-search-box .row')).css('visibility', 'hidden'); // $('.refine-search-box .multi-select-box .box-opts').show(); // }); // $('.refine-search-box .multi-select-box .box-opts input').change(function () { // var desc = $('.refine-search-box .multi-select-box .box-heading .box-heading-desc'); // var len = $('.refine-search-box .multi-select-box .box-opts input:checked').length; // if (len == 0) // { // desc.html('Please select'); // } // else // { // desc.html(len + ' selected'); // } // }); // // count selection after form submit to other page // $('.refine-search-box .multi-select-box .box-opts').each(function () { // var desc = $('.refine-search-box .multi-select-box .box-heading .box-heading-desc'); // var len = $('.refine-search-box .multi-select-box .box-opts input:checked').length; // if (len == 0) // { // desc.html('Please select'); // } // else // { // desc.html(len + ' selected'); // } // }); // // ----------------------------------------------------------------------------------------------- // if (isiDevice()) // { // $('.multi-select-box .box-opts').css('height', 'auto'); // } $('.refine-search-box .body .row .sub-section').click(function () { $(this).parent().siblings('.chk-opts').toggle(); }); // -- form search -------------------------------------- $('.btn-refine-search').click(function () { $('#form-refine-search').submit(); }); // ----------------------------------------------------- // -- form search - login_box -------------------------------------- $('.login-box form#form-login .btn-login').click(function () { var ele_val = null; var email = $('input[name="email"]'); ele_val = $.trim(email.val()); if (!ele_val) { alert(__['pls-enter-email-addr']); return false; } ele_val = $.trim($('input[name="pw"]').val()); if (!ele_val) { alert(__['pls-enter-pwd']); return false; } if (!email_pattern.test(email.val())) { alert('Invalid Email'); return false; } $('form#form-login').submit(); }); // ----------------------------------------------------- // -- result page change order ------------------------------------------------ $('#result_order').change(changeResultOrder); $('#result_rec_per_page').change(changeResultRecPerPage); // ---------------------------------------------------------------------------- $('.recently-viewed-props').each(function () { RecentlyViewedProperties.init(); }); $('.agent-card .email span').click(function () { var url = $('input.email-link:hidden', this).val(); var is_enquiry_link = $('input.is-enquiry-link:hidden', this).val() == '1'; if (is_enquiry_link) openEnquiryBox(url); else openEmailAgentBox(url); }); var h_lease = $('.popular-districts .lease .content').height(); var h_sale = $('.popular-districts .sale .content').height(); if (h_lease != h_sale) { if (h_lease < h_sale) { alert($('.popular-districts .lease .content')); $('.popular-districts .lease .content').height(h_sale); } else if (h_sale < h_lease) { alert($('.popular-districts .lease .content')); $('.popular-districts .sale .content').height(h_lease); } } // IE6 png fix if (navigator.userAgent.indexOf('MSIE') != -1) { $(document).pngFix(); } // change currency $('.currency-selector').each(function () { $('.change-currency a').simpletip({ content: $('.currency-selector').html(), baseClass: 'currency-selector', persistent: true, focus: true, position:[-15, 15], onShow: function () { if (navigator.userAgent.indexOf('MSIE') != -1) $('.change-currency').pngFix(); } }); }); // MyHomesKeeper hkh.obj.myhomes = {}; var config = { 'container': 'myhomes-keeper' }; hkh.obj.myhomes.keeper = new hkh.MyHomesKeeper.instance(config); $('#myhomes-keeper-activator').click(function () { hkh.obj.myhomes.keeper.ui.toggle(); }); config = { img_dir: IMG_DIR, myhomes_keeper: hkh.obj.myhomes.keeper, is_hide: true }; hkh.obj.actionbar = new hkh.ActionBar(config); }); function activatePlaceholders() { if ($.browser.msie) { var inputs = document.getElementsByTagName('input'); for (var i = 0; i < inputs.length; i++) { if (inputs[i].getAttribute('type') == 'text') { if (inputs[i].getAttribute('placeholder') && inputs[i].getAttribute('placeholder').length > 0) { inputs[i].value = inputs[i].getAttribute('placeholder'); inputs[i].onclick = function () { if (this.value == this.getAttribute('placeholder')) { this.value = ''; } return false; } inputs[i].onblur = function () { if (this.value.length < 1) { this.value = this.getAttribute('placeholder'); } } } } } } } function updateCaptcha() { var t = Math.random(); $('#captcha')[0].innerHTML = ''; var img = new Image(1,1); img.src = '/v2/captcha/img.php?t='+t; img.onload = function() { $('#captcha')[0].innerHTML = ''; } $('#sec_code')[0].value = ''; } function changeResultOrder() { var arg_val = $(this).val(); changeResultLink('order', arg_val); } function changeResultRecPerPage() { var arg_val = $(this).val(); changeResultLink('rec_per_page', arg_val); } function changeResultLink(arg_type, arg_val) { var ln = window.location.href; var ln_parts = ln.split('?'); var url = ln_parts[0]; var arg_parts = []; if (typeof(ln_parts[1]) != 'undefined') arg_parts = ln_parts[1].split('&'); // remove the order & page_no in GET URL for (var i=0; i < arg_parts.length; i++) { var arg = arg_parts[i]; if (arg.indexOf(arg_type+'=') == 0 || arg.indexOf('page_no=') == 0) { delete arg_parts[i]; } } // add args arg_parts.push(arg_type+'='+arg_val); arg_parts.push('page_no=1'); var new_arg_parts = []; for (var i=0; i < arg_parts.length; i++) { if (arg_parts[i]) new_arg_parts.push(arg_parts[i]); } window.location.href = url+'?'+new_arg_parts.join('&'); } function setGridHeight(ele, items_per_row) { var rows = []; var rows_max_h = []; var cols = []; var max_h = 0; ele.each(function (idx) { cols.push(this); var h = $(this).height(); if (h > max_h) { max_h = h; } if (cols.length == items_per_row || idx == (ele.length - 1)) { rows.push(cols); rows_max_h.push(max_h); cols = []; max_h = 0; } }); $.each(rows, function (i, a_row) { $.each(a_row, function (j, item) { $(item).height(rows_max_h[i]); }) }); } function htmlspecialchars(string) { string = string.replace(/&/g, '&'); string = string.replace(//g, '>'); string = string.replace(/"/g, '"'); string = string.replace(/\'/g, '''); return string; } function nl2br(str) { return str.replace(/\r\n|\r|\n/g, '
') } // -- xx minutes ago ------------------------------------------------------------------- function initUpdateTimeCounter() { startUpdateTimeCounter(); setInterval( startUpdateTimeCounter, 60000 ); } function startUpdateTimeCounter() { // var isie6 = (navigator.userAgent.match(/MSIE\s6/i) != null); var abbr = document.getElementsByTagName("span"); for( i=0; i< abbr.length; i++ ) { e = abbr[i]; if( e.className=='exp-time' ) { $(e).html(check_datetime_exp( e.title )); // if (isie6) // e.outerHTML = check_datetime_exp( e.title ); // else // e.innerHTML = check_datetime_exp( e.title ); } } } function check_datetime_exp( the_dt ) { var n = new Date(); var t = new Date( the_dt ); var diff = n.valueOf() - t.valueOf(); if( diff < 0 ) return 'NaN'; var r = new Date( diff ); var ret = ''; var Y = r.getYear(); var M = r.getMonth(); var D = r.getDate()-1; var h = r.getHours()-8; var m = r.getMinutes(); var s = r.getSeconds(); var dyn = false; if (LANG == 'zh-hk' || LANG == 'zh-cn') { if( Y!=70 ){ ret = ( Y-70 ) + '年前'; } else { if( M!=0 ) { ret = M + '個月前'; } else { dyn = true; if( D!=0 ) { ret = D + '日前'; } else { if( h!=0 ) { if( m!= 0 ) { ret = h + '小時' + m + '分鐘前'; } else { ret = h + '小時前'; } } else { if( m!= 0 ) { ret = m + '分鐘前'; } else { ret = s + '秒前'; } } } } } } else { if( Y!=70 ){ ret = ( Y-70 ) + plural_handling( ( Y-70 ) ," year__S__ ago", "s"); } else { if( M!=0 ) { ret = M + plural_handling( M ," month__S__ ago", "s"); } else { dyn = true; if( D!=0 ) { ret = D + plural_handling( D , " day__S__ ago", "s"); } else { if( h!=0 ) { if( m!= 0 ) { ret = h + plural_handling( h , " hr__S__ ", "s") + m + plural_handling( m , " minute__S__ ago", "s"); } else { ret = h + plural_handling( h , " hour__S__ ago", "s"); } } else { if( m!= 0 ) { ret = m + plural_handling( m , " minute__S__ ago", "s"); } else { ret = s + plural_handling( s , " sec__S__. ago", "s"); } } } } } } return ret; } function plural_handling(num, word, s) { var ret = ''; if( num > 1 ) { if( s == 'ies' ) { ret = word.replace("y__S__", s ); } else if( s == 'IES' ) { ret = word.replace("Y__S__", s ); } else { ret = word.replace("__S__", s ); } } else { ret = word.replace("__S__", "" ); } return ret; } // ----------------------------------------------------------------------------- // -- RecentlyViewedProperties ------------------------------------------------- RecentlyViewedProperties = { viewer: {}, curr_page: 1, ttl_pages: 1, ttl_props: 0, is_next_handler_binded: false, is_prev_handler_binded: false, props_per_slot: 6, slot_width: 786, // from: 775 + 11 init: function () { $('.recently-viewed-props ul').jcarousel({scroll: 6}); return; // var viewer = $('.recently-viewed-props'); // this.viewer.prev = $('.slide-prev', viewer); // this.viewer.next = $('.slide-next', viewer); // this.viewer.bar = $('.props-bar', viewer); // this.ttl_props = this.viewer.bar.children('.a-prop').length; // this.ttl_pages = Math.ceil(this.ttl_props / this.props_per_slot); // this.viewer.prev.css('cursor', 'default'); // if (this.isNextExists()) // { // this.viewer.next.css('cursor', 'pointer'); // this.viewer.next.addClass('vert-90-right'); // this.viewer.next.click($.proxy(this.nextPage, this)); // this.is_next_handler_binded = true; // } }, isNextExists: function () { return this.ttl_pages > this.curr_page; }, isPrevExists: function () { return this.curr_page > 1; }, nextPage: function () { var left = this.viewer.bar.css('left').split('px')[0]; left = parseInt(left); left = left - this.slot_width; this.viewer.bar.css('left', left+'px'); this.curr_page++; if (!this.isNextExists()) { this.viewer.next.css('cursor', 'default'); this.viewer.next.removeClass('vert-90-right'); this.viewer.next.unbind('click'); this.is_next_handler_binded = false; } if (!this.is_prev_handler_binded) { this.viewer.prev.css('cursor', 'pointer'); this.viewer.prev.addClass('vert-90-left'); this.viewer.prev.click($.proxy(this.prevPage, this)); this.is_prev_handler_binded = true; } }, prevPage: function () { var left = this.viewer.bar.css('left').split('px')[0]; left = parseInt(left); left = left + this.slot_width; this.viewer.bar.css('left', left+'px'); this.curr_page--; if (!this.isPrevExists()) { this.viewer.prev.css('cursor', 'default'); this.viewer.prev.removeClass('vert-90-left'); this.viewer.prev.unbind('click'); this.is_prev_handler_binded = false; } if (!this.is_next_handler_binded) { this.viewer.next.css('cursor', 'pointer'); this.viewer.next.addClass('vert-90-right'); this.viewer.next.click($.proxy(this.nextPage, this)); this.is_next_handler_binded = true; } } } // ----------------------------------------------------------------------------- // -- Google Maps -------------------------------------------------------------- var gmaps = { }; gmaps = {}; gmaps.addStreetViewButton = function (map, sv_loc) { var div = document.createElement('DIV'); var css = { 'overflow': 'hidden', 'text-align': 'center', 'color': 'black', 'font-size': '12px', 'background-color': '#FFFFFF', 'line-height': '160%', 'padding': '0 6px', 'border': '1px solid rgb(169, 187, 223)', 'font-weight': 'normal', 'min-width': '47px', 'margin-top': '5px', 'cursor': 'pointer' }; $(div) .css(css) .attr('title', 'Show Street View'); div.innerHTML = 'Street View'; google.maps.event.addDomListener(div, 'click', function() { var sv = map.getStreetView(); sv.setPano(sv_loc.pano); sv.setPov({ heading: 270, pitch: 0, zoom: 0 }); sv.setVisible(true); }); map.controls[google.maps.ControlPosition.TOP_RIGHT].push(div); } // -----------------------------------------------------------------------------