/* ----- common ----- */ function getInternetExplorerVersion() { var rv = -1; if (window.navigator) { if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat(RegExp.$1); } } return rv; } if (window.DD_roundies) { DD_roundies.addRule('.cornerround', '0 15px 15px 15px', true); DD_roundies.addRule('.cornerround-ur', '0 15px 0 0', true); DD_roundies.addRule('.toprounded', '15px 15px 0 0', true); DD_roundies.addRule('.bottomrounded', '0 0 15px 15px', true); DD_roundies.addRule('.rounded', 15, true); DD_roundies.addRule('.roundedsmall', 8, true); DD_roundies.addRule('.roundedsmall-corner', '8px 0 8px 8px', true); DD_roundies.addRule('.roundedrealsmall', 5, true); DD_roundies.addRule('.accordion', 15, true); DD_roundies.addRule('.accordion.selected', '15px 15px 0 0', true); if (getInternetExplorerVersion() == -1) { DD_roundies.addRule('input.text', 5, true); DD_roundies.addRule('textarea', 5, true); DD_roundies.addRule('a.button', 5, true); DD_roundies.addRule('.rounded-iecond', 15, true); DD_roundies.addRule('.roundedrealsmall-iecond', 5, true); DD_roundies.addRule('#auth .inside', 8, true); DD_roundies.addRule('.button-auth-inside', 8, true); } } if (window.Cufon) { Cufon.replace('h3', { fontFamily: 'TitleFontBold' }); Cufon.replace('h4', { fontFamily: 'TitleFont' }); Cufon.replace('h5', { fontFamily: 'TitleFontLight' }); } function errorAlert(text) { if ($.prompt) { $.prompt(text, { buttons: { Close: true } } ); } else { alert(text); } } // Fix ClearType rendering in IE7 (function($) { $.fn.realFadeIn = $.fn.fadeIn; $.fn.fadeIn = function(speed, callback) { $(this).realFadeIn(speed, function() { if(jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter'); if(callback != undefined) callback(); }); }; $.fn.realFadeOut = $.fn.fadeOut; $.fn.fadeOut = function(speed, callback) { $(this).realFadeOut(speed, function() { if(jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter'); if(callback != undefined) callback(); }); }; })(jQuery); $(document).ready(function() { $.watermark.attachAll(); $('form#search-form .watermark label').click(function() { // iphone/ipad mobile trap }); $('.dim-dialog').each(function() { $(this).insertAfter('#footer').center(); }); $.fn.qtip.styles.rec = { tip: 'leftMiddle', border: { width: 0, radius: 5, color: '#198690' }, background: '#198690', color: '#FFFFFF' }; $('a.tip.to-left').qtip({ style: { name: 'rec', tip: true }, position: { corner: { target: 'leftTop', tooltip: 'rightBottom' } } }); $('a.tip:not(a.tip.to-left)').qtip({ style: { name: 'rec', tip: true }, position: { corner: { target: 'rightTop', tooltip: 'leftBottom' } } }); $('a.tip:not(a.clickable)').click(function() { $(this).blur(); return false; }); $('a').mousedown(function() { this.hideFocus = true; this.blur(); }); $('a').mouseup(function() { this.hideFocus = false; this.blur(); }); $('div.shrinkable').expander({ slicePoint: 200, expandText: 'read more', userCollapseText: 'less' }); $('div.shrinkable').height('auto'); $('#feedback-tab').click(function() { dim('#feedback-dialog'); return false; }); $('#feedback-send').click(function() { if ($('#feedback-text').val().length) { $('#feedback-send').addClass('waiting'); $('#feedback-text').attr('disabled', true); $.post('/ajax/sendfeedback', { text: $('#feedback-text').val(), auth: getAuth() }, function() { undimSuccess(); setTimeout(function() { location.reload(true); }, 2000); }); } return false; }); $('#search-activate').click(function() { if ($('#header > #search').is(':hidden')) { $('#header > #search').fadeIn('fast', function() { $('#search-text').focus(); }); } else { $('#header > #search').fadeOut('normal'); } return false; }) $('#search-deactivate').click(function() { return $('#search-activate').click(); }); $('#search-submit').click(function() { $('#search-form').submit(); return false; }); $('#search-form').submit(function() { if ($('#search-text').val().length) { return true; } return false; }); $('#inpage-search-submit').click(function() { $('#inpage-search-form').submit(); return false; }); $('#inpage-search-form').submit(function() { if ($('#inpage-search-text').val().length) { return true; } return false; }); $('#login-activate').click(function() { if ($('#header-login').is(':visible')) { if (getInternetExplorerVersion() == -1) { $('#header-login').hide('fast'); } else { $('#header-login').hide(); } } else { if (isFbLoad || isTwLoad) return false; if (getInternetExplorerVersion() == -1) { $('#header-login').show('fast', function() { $('#login-username').focus(); }); } else { $('#header-login').show(); $('#login-username').focus(); } } return false; }); $('#login-deactivate').click(function() { return $('#login-activate').click(); }); $('#login-submit').click(function() { $('#login-form').submit(); return false; }); $("#login-username").keydown(function(e) { if (e.which == 27) { $('#login-username').val(''); $('#login-password').val(''); $('#login-deactivate').click(); } else if (e.which == 13) { $('#login-password').focus(); } }); $("#login-password").keydown(function(e) { if (e.which == 27) { $('#login-username').val(''); $('#login-password').val(''); $('#login-deactivate').click(); } else if (e.which == 13) { $('#login-submit').click(); } }); $('#login-form').submit(function() { if ($('#login-username').val().length && $('#login-password').val().length) { return true; } return false; }); sortTabs(); var isFbLoad = false; var isTwLoad = false; $('.head-facebook-auth').click(function() { if (isFbLoad || isTwLoad) return false; isFbLoad = true; if (window.pageTracker && window.event_channel) pageTracker._trackEvent(event_channel, 'FacebookAuth', 'Facebook Auth Click'); $('.head-facebook-auth').addClass('waiting'); fbStartAuth(function() { $('.head-facebook-auth').removeClass('waiting'); isFbLoad = false; updateCrumb(); }, function(errorMsg) { $('.head-facebook-auth').removeClass('waiting'); isFbLoad = false; errorAlert('It appears there is a problem with Facebook Connect at the moment. Please try again in a moment. (Remember, if you\'ve set a password, you can still log in through the log in link at the top.)'); }); return false; }); $('.head-twitter-auth').click(function() { if (isTwLoad || isFbLoad) return false; isTwLoad = true; if (window.pageTracker && window.event_channel) pageTracker._trackEvent(event_channel, 'TwitterAuth', 'Twitter Auth Click'); $('.head-twitter-auth').addClass('waiting'); twStartAuth(function() { $('.head-twitter-auth').removeClass('waiting'); isTwLoad = false; updateCrumb(); }, function(errorMsg) { $('.head-twitter-auth').removeClass('waiting'); isTwLoad = false; errorAlert('It appears there is a problem with Twitter at the moment. Please try again in a moment. (Remember, if you\'ve set a password, you can still log in through the log in link at the top.)'); }); return false; }); $('#dim').css('height', $(document).height()); $(window).bind("resize", function() { $("#dim").css("height", $(window).height()); }); $('.dim-closer').click(function() { undim(); return false; }); }); var authed = '0'; var wasAuthed = authed; var crumbUpdating = 0; var refreshAfterAuth = false; function updateCrumb() { if (refreshAfterAuth && authed != wasAuthed) { window.location.reload(true); return; } setTimeout(function() { var wasAuthed = $('#auth > .outside.authed').is(':visible'); if (authed != wasAuthed && crumbUpdating == 0) { crumbUpdating = 1; $('#auth > .outside.' + (authed ? 'not-' : '') + 'authed').fadeOut('fast'); var insideName = '#auth > .inside.' + (authed ? 'not-' : '') + 'authed'; var insideStuff = '#head-' + (authed ? 'not-' : '') + 'authed-contents'; $(insideName).width('auto'); var oldWidth = $(insideName).width(); $(insideStuff).hide(); var newWidth = $(insideName).width(); $(insideStuff).show(); $(insideName).width(oldWidth + 'px'); $(insideStuff).fadeOut('fast', function() { $(insideStuff).hide(); $(insideName).animate({ width: newWidth + 'px' }, 250, 'swing', function() { $(insideName).width('auto'); $(insideStuff).show(); $(insideName).hide(); var insideNameNext = '#auth > .inside.' + (authed ? '' : 'not-') + 'authed'; var insideStuffNext = '#head-' + (authed ? '' : 'not-') + 'authed-contents'; $(insideStuffNext).hide(); $(insideNameNext).show(); $(insideStuffNext).show(); var finalWidth = $(insideNameNext).width(); $(insideStuffNext).hide(); $(insideNameNext).width(newWidth + 'px'); $(insideNameNext).animate({ width: finalWidth + 'px' }, 250, 'swing', function() { $(insideNameNext).width('auto'); $(insideStuffNext).fadeIn('fast'); $('#auth > .outside.' + (authed ? '' : 'not-') + 'authed').fadeIn('fast', function() { crumbUpdating = 0; }); }); }); }); } }, 600); } function dim(element, cb) { if (!element) { element = '.dim-dialog'; } $('#dim').height($(document).height() + 'px'); $('#dim').fadeIn('fast', function() { $(element).fadeIn('fast', function() { $(element + ' > .darker > .focus-this').focus(); if (cb) cb(); }) }); } function undim(element, cb) { if (!element) { element = '.dim-dialog'; } $(element).fadeOut('fast', function() { $('#dim').fadeOut('fast', function() { if (cb) cb(); }); }); } function undimSuccess(element, cb) { if (!element) { element = '.dim-dialog'; } $(element + ' > .main-input').fadeOut('slow', function() { $(element + ' > .success').fadeIn('slow', function() { setTimeout(function() { undim(element, cb); }, 4000); }); }); } function parseJSON(data) { try { return eval('(' + data + ')'); } catch (e) { return null; } } function sortTabs() { if (window.noSortTabs) return; $('.tabset > .tabs, .tabset > .tabs-static').each(function() { var row = 0; var pos = 1; var lx = 0; var t; $(this).children('li').each(function() { t = $(this).offset(); if (t.top > lx) { lx = t.top; row++; pos = 1; } else { pos++; } $(this).addClass('r' + row); $(this).addClass('p' + pos); }); $(this).children('li:last').css('margin-right', '20px'); $(this).css('height', 38 * row); }); $('.tabs > li > a').click(function(event) { if ($(this).parent().hasClass('selected')) return false; $(this).parent().siblings('li').removeClass('selected'); $(this).parent().addClass('selected'); if (window.Cufon) { Cufon.refresh('h3'); } $('.ac_results').hide(); var myHref = '#' + $(this).attr('href').split('#').pop(); var topID = $(this).parent().parent().parent().attr('id'); var oldHeight = $('#' + topID + ' > .wrapper').height(); var oldTabID = $('#' + topID + ' > .wrapper > .content:visible').attr('id'); var oldSel = '#' + topID + ' > .wrapper > #' + oldTabID; var newSel = '#' + topID + ' > .wrapper > ' + myHref; var wrapSel = '#' + topID + ' > .wrapper'; if (getInternetExplorerVersion() == -1) { $(oldSel).hide(); $(newSel).show(); var newHeight = $(wrapSel).height(); $(newSel).hide(); $(oldSel).show(); $(wrapSel).height(oldHeight + 'px'); $(oldSel).fadeOut('normal', function() { $(wrapSel).animate({ height: newHeight + 'px' }, 250, 'swing', function() { $(newSel).fadeIn('normal', function() { $(wrapSel).height('auto'); eval('if (typeof window.' + myHref.substring(1).replace(/-/g, '') + 'TabCallback == "function") ' + myHref.substring(1).replace(/-/g, '') + 'TabCallback("' + myHref.substring(1) + '");'); }); }); }); } else { try { $(oldSel).hide(); $(newSel).show(); $(wrapSel).height('auto'); eval('if (typeof window.' + myHref.substring(1).replace(/-/g, '') + 'TabCallback == "function") ' + myHref.substring(1).replace(/-/g, '') + 'TabCallback("' + myHref.substring(1) + '");'); } catch (e) {} } if (event.stopImmediatePropagation) event.stopImmediatePropagation(); if (event.preventDefault) event.preventDefault(); event.returnValue = false; }); } function loadImage(element, asAlt, url, width, height, cb) { $.post('/ajax/loadimage', { load_auth: getAuth(), image_url: url, width: width, height: height }, function(data) { var item = parseJSON(data); if (!item.error) { if (asAlt) { $(element).attr('alt', item.url); } else { $(element).attr('src', item.url); } if (cb) { cb(); } } }); } function loadBetterImages(terms, index_name, extra_name, cb) { $.post('/ajax/loadbetterimages', { load_auth: getAuth(), terms: terms, index_name: index_name, extra_name: extra_name }, function(data) { var item = parseJSON(data); if (!item.error) { cb(item); } }); } function checkAuth(callIsAuthed, callIsNotAuthed) { $.post('/ajax/checkauth', { check_auth: getAuth() }, function(data) { var item = parseJSON(data); if (item.isAuthed) { authed = true; if (callIsAuthed) callIsAuthed(); } else { authed = false; if (callIsNotAuthed) callIsNotAuthed(); } updateCrumb(); }); } function checkAuthForService(service, callIsAuthed, callIsNotAuthed, callIsError) { $.post('/ajax/checkauthforservice', { check_auth: getAuth(), service: service }, function(data) { var item = parseJSON(data); if (item.isAuthed) { if (callIsAuthed) callIsAuthed(); } else { if (item.authError) { if (callIsError) callIsError(item.authError); } else { if (callIsNotAuthed) callIsNotAuthed(); } } updateCrumb(); }); } function tryCheckAuth(service, callIsAuthed, callIsNotAuthed) { $.post('/ajax/trycheckauth', { check_auth: getAuth(), service: service }, function(data) { var item = parseJSON(data); if (item.isAuthed) { authed = true; if (callIsAuthed) callIsAuthed(); } else { if (callIsNotAuthed) callIsNotAuthed(); } updateCrumb(); }); } function getAuthedServices(cb) { $.post('/ajax/getauthedservices', { check_auth: getAuth() }, function(data) { var item = parseJSON(data); cb(item.services); }); } function fbStartAuth(finalCb, errorCb) { var s = false; FB.getLoginStatus(function(r) { if (r.status === 'connected' || r.status === 'not_authorized') { return fbDoLogin(r.authResponse.accessToken, finalCb, errorCb); } }); FB.login(function(r) { if (r.authResponse) { return fbDoLogin(r.authResponse.accessToken, finalCb, errorCb); } }, { perms: '' }); } function fbDoLogin(token, finalCb, errorCb) { $.post('/ajax/authendpoint', { service: 'facebook', token: token, con_auth: getAuth() }, function(data) { var item = parseJSON(data); if (item.success) { authed = true; updateCrumb(); finalCb(); } else { errorCb(item.error); } }); } var twTimer; var twExpire; var twWindow; var twFirst; var twDispTimer; function twStartAuth(finalCb, errorCb, noOpenWindow, returnMeTo, returnExtra) { if (window.BrowserDetect && BrowserDetect.browser == 'Firefox') { if (twDispTimer) clearTimeout(twDispTimer); if (returnMeTo) { $.post('/ajax/setlogin1dest', { url: returnMeTo, extra: returnExtra, auth: getAuth() }, function(data) { window.location.href = '/auth/login1/twitter'; }); } else { window.location.href = '/auth/login1/twitter'; } return; } if (twTimer && !twFirst) clearTimeout(twTimer); if (!noOpenWindow) { twWindow = window.open('/auth/login/twitter', 'twitterAuth4fbab22885f50', 'status=no,toolbar=no,location=no,menubar=no,directories=no,resizable=yes,scrollbars=yes,height=420,width=820'); } tryCheckAuth('twitter', function() { authed = true; updateCrumb(); finalCb(); }, function() { twFirst = true; twExpire = setTimeout(function() { if (twTimer) clearTimeout(twTimer); errorCb('Time ran out - Twitter may be slow today. Please try again.'); }, 60000); twRunListener(finalCb, errorCb); }); } function twRunListener(finalCb, errorCb) { twTimer = setTimeout(function() { twFirst = false; checkAuthForService('twitter', function() { if (twExpire) clearTimeout(twExpire); finalCb(); }, function() { twRunListener(finalCb, errorCb); }, function(errorMessage) { if (twExpire) clearTimeout(twExpire); errorCb(errorMessage); }); }, 1000); } function postToFb(rec_id, productName, url, msg, imageUrl, finalCb, errorCb) { $.post('/ajax/servicepost', { service: 'fb', productName: productName, rec_id: rec_id, url: url, msg: msg, imageUrl: imageUrl, post_auth: getAuth() }, function(data) { var item = parseJSON(data); if (item.success) { if (finalCb) finalCb(); } else { if (errorCb) errorCb(); } }); } function postToTw(rec_id, msg, finalCb, errorCb) { $.post('/ajax/servicepost', { service: 'tw', rec_id: rec_id, msg: msg, post_auth: getAuth() }, function(data) { var item = parseJSON(data); if (item.success) { undimSuccess(null, finalCb); } else { if (errorCb) errorCb(); } }); } function loadLinkToElement(element, link, restoreFrame) { $(element).load(link, '', function() { $(element).removeClass('temp-loader'); if (window.Cufon) { Cufon.refresh(); } $(element + ' .star').rating(); if (getInternetExplorerVersion() == -1) { if (restoreFrame) { $(element + ' .result-container').show(); var height = $(element + ' .result-container').height(); $(element + ' .result-container').hide(); $(element).animate({ height: height + 'px' }, 250, 'swing', function() { $(element + ' .result-loader').fadeOut('fast', function() { $(element + ' .result-container').fadeIn('fast'); $(element).height('auto'); }); }); } $(element + ' .rs-nav').each(function(i) { $(this).click(function() { var height = $(element + ' .result-container').height(); $(element).height(height + 'px'); $(element + ' .result-loader').hide(); var hreff = $(this).attr('href'); $(element + ' .result-container').fadeOut('fast', function() { $(element + ' .result-loader').height(height + 'px'); $(element + ' .result-loader').fadeIn('fast', function() { loadLinkToElement(element, hreff, 1); }); }); return false; }); }); } else { $(element + ' .rs-nav').each(function(i) { $(this).click(function() { var hreff = $(this).attr('href'); loadLinkToElement(element, hreff); return false; }); }); } }); } function handleRatingSave(element, value) { if (!element.name) return; $.post('/ajax/saverating', { save_auth: getAuth(), element: element.name, value: value }, function(data) { var item = parseJSON(data); if (item.success) { $('#' + element.name + '_text').fadeOut('normal', function() { $('#' + element.name + '_text').text(item.count_text); $('#' + element.name + '_text').fadeIn('normal'); }); } }); } function numberFormat(number, decimals, dec_point, thousands_sep) { var n = number, prec = decimals; var toFixedFix = function (n,prec) { var k = Math.pow(10,prec); return (Math.round(n*k)/k).toString(); }; n = !isFinite(+n) ? 0 : +n; prec = !isFinite(+prec) ? 0 : Math.abs(prec); var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep; var dec = (typeof dec_point === 'undefined') ? '.' : dec_point; var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); var abs = toFixedFix(Math.abs(n), prec); var _, i; if (abs >= 1000) { _ = abs.split(/\D/); i = _[0].length % 3 || 3; _[0] = s.slice(0,i + (n < 0)) + _[0].slice(i).replace(/(\d{3})/g, sep+'$1'); s = _.join(dec); } else { s = s.replace('.', dec); } var decPos = s.indexOf(dec); if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) { s += new Array(prec-(s.length-decPos-1)).join(0)+'0'; } else if (prec >= 1 && decPos === -1) { s += dec+new Array(prec).join(0)+'0'; } return s; } (function ($) { $.fn.verticaAlign = function(container) { return this.each(function(i) { var myHeight = $(this).height(); var parentHeight = $(this).parent().height(); var topMargin = Math.floor((parentHeight / 2) - (myHeight / 2)); $(this).css('margin-top', topMargin); }); }; })(jQuery); (function ($) { $.fn.center = function () { this.css("position", "fixed"); this.css("top", Math.round(($(window).height() / 2) - (this.height() / 2)) + "px"); this.css("left", Math.round(($(window).width() / 2) - (this.width() / 2)) + "px"); return this; }; })(jQuery);