/* ----- 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();
$('.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) {
FB.login(function(response) {
if (response.session) {
if (response.perms) {
$.post('/ajax/authendpoint', {
service: 'facebook',
con_auth: getAuth()
}, function(data) {
var item = parseJSON(data);
if (item.success) {
authed = true;
updateCrumb();
finalCb();
} else {
errorCb(item.error);
}
});
} else {
errorCb('We were unable to authenticate you via Facebook. Please try again.');
}
} else {
errorCb('We were unable to authenticate you via Facebook. Please try again.');
}
}, { perms: 'email' });
}
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', 'twitterAuth4c896f2ab593b', '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);
/* ----- Index.index ----- */
if (window.DD_roundies) {
DD_roundies.addRule('#news-ticker-label', '0 0 0 15px', true);
DD_roundies.addRule('#news-ticker', '0 0 15px 0', true);
}
$(document).ready(function() {
$('#greatrecs-outer').serialScroll({
items: $('#greatrecs-container .panel'),
duration: 1000,
easing: 'swing'
});
$('#greatrecs-prev').click(function() {
clearTimeout(rotateTime);
$('#greatrecs-outer').trigger('prev');
moveSp(-1);
return false;
});
$('#greatrecs-next').click(function() {
clearTimeout(rotateTime);
$('#greatrecs-outer').trigger('next');
moveSp(1);
return false;
});
$('#news-ticker').load('/ajax/news');
var rotateTime;
var sp = 0;
function rotateGreat() {
$('#greatrecs-outer').trigger('next');
rotateTime = setTimeout(rotateGreat, 6000);
moveSp(1);
}
function moveSp(v) {
var max = 3;
sp += v;
if (sp == -1) sp = max;
if (sp > max) sp = 0;
if (sp == 1) {
$('#h-tab-normal').hide();
$('#h-tab-leaderboard').show();
} else {
$('#h-tab-leaderboard').hide();
$('#h-tab-normal').show();
}
}
rotateTime = setTimeout(rotateGreat, 10000);
});
function seefriendsTabCallback() {
loadLinkToElement('#seefriends', '/index/inlineseefriends', false, false);
}
/* ----- rec_create ----- */
var baseHeight;
var origHeight;
var minImageSize = 300;
var okToClickImg;
var postedRecId;
var answerForCode = '';
var recCreateDoneCB;
var fbPostCall;
var charityShort;
var thumbs;
var categoryId = 0;
var baseUrl = 'http://rec.fm/';
var sel_product_id = -1;
var sel_product_name;
var sel_image;
var sel_image_hash;
var rec_text;
var loaded_images;
var do_load_better_images = false; // ;
var persistType;
$(document).ready(function() {
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, '1_PageLoad', 'Page Load');
pageTracker._trackPageview('/tracking/' + event_channel + '/rec/1_PageLoad');
}
$('#post-twitter-text').textlimit('#post-dialog-twitter-counter', 140);
$('#product-show-description-link').click(function() {
if (!origHeight) {
origHeight = $('#stage1').height();
}
$('#product-description-shown').show();
var thisHeight = $('#product-description-shown').height();
$('#product-description-shown').hide();
$('#product-description-hidden').fadeOut();
$('#stage1').animate({ height: origHeight + thisHeight + 'px' }, 250, 'swing', function() {
$('#product-description-hidden').hide();
$('#product-description-shown').fadeIn('fast');
});
return false;
});
$('#product-hide-description-link').click(function() {
$('#product-description-shown').fadeOut('fast', function() {
$('#stage1').animate({ height: origHeight + 'px' }, 250, 'swing', function() {
$('#product-description-hidden').fadeIn('fast');
});
});
return false;
});
$('#product-search-box').autocomplete('/ajax/productsearch/', {
extraParams: { search_auth: getAuth() },
width: 320,
max: 20,
minChars: 3,
highlight: false,
scroll: true,
scrollHeight: 300,
onListEmpty: function() {
$('#large-thumbs').empty();
},
formatItem: function(data, i, n, value) {
var item = parseJSON(data);
if (item) {
var imageId = 'thumbimg' + item._id + '_row' + i + 'x';
$('.source-image-large').hide();
var code = '';
code = '

';
code += '' + item.formatted_name + '
';
code += '
' + (item.category ? item.category + ' — ' : '') + ' $' + item.price + '
';
code += '
' + item.shortened_description + '
';
if (getInternetExplorerVersion() == -1) {
$('#large-thumbs').append('');
}
return code;
} else {
return '';
}
},
formatResult: function(data, value) {
var item = parseJSON(data);
if (item) {
return item.name;
} else {
return '';
}
}
});
if (getInternetExplorerVersion() == -1) {
$('.source-image').live('mouseover', function() {
var id = $(this).attr('id');
var hoffset = $(this).offset();
$('#' + id + '-large').css('top', (hoffset.top - 45) + 'px');
$('#' + id + '-large').css('left', (hoffset.left - 45) + 'px');
$('#' + id + '-large').fadeIn('fast');
okToClickImg = false;
setTimeout(function() {
okToClickImg = true;
}, 750);
});
$('.source-image-large').live('click', function(e) {
if (okToClickImg == true) {
var rowId = $(this).attr('id').match(/row([0-9]*)x/)[1];
$('.ac_row_' + rowId).click();
$(this).fadeOut();
} else {
e.preventDefault();
e.stopPropagation();
}
return false;
});
$('.source-image-large').live('mouseout', function() {
$(this).fadeOut();
});
}
$('#product-search-box').result(function(event, data, formatted) {
var item = parseJSON(data);
activateItem(item);
});
$('#product-reset-link').click(function() {
deactivateItem();
return false;
});
$('#product-reset-link-after').click(function() {
step2To1();
return false;
});
$('#product-select-btn').click(function() {
if (sel_product_id > -1) {
step1To2();
}
return false;
});
$('#product-image').mouseover(function() {
$('#product-image-large').fadeIn();
okToClickImg = false;
setTimeout(function() {
okToClickImg = true;
}, 750);
});
$('#product-image-large').click(function() {
if (okToClickImg == true) {
$('#product-image-large').fadeOut();
}
return false;
});
$('#product-image-large').mouseout(function() {
$('#product-image-large').fadeOut();
});
$('#rec-text-box').textlimit('#rec-text-counter', 140);
$('#rec-text-box').keyup(function() {
if (this.value.length > 2) {
$('#rec-do-btn').removeClass('disabled');
} else {
$('#rec-do-btn').addClass('disabled');
}
});
$('#rec-do-btn').click(function() {
if ($('#rec-text-box').val().length > 2) {
step2To3();
}
return false;
});
$('#post-facebook-btn').click(function() {
$('#post-service-btns').addClass('waiting');
fbStartAuth(function() {
$('#post-service-btns').removeClass('waiting');
doRec();
}, function() {
$('#post-service-btns').removeClass('waiting');
// error
});
persistData(function() {});
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, 'Z_FacebookAuthButtonClick', 'Facebook Auth Button Clicked');
}
return false;
});
$('#post-twitter-btn').click(function() {
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, 'Z_TwitterAuthButtonClick', 'Twitter Auth Button Clicked');
}
$('#post-service-btns').addClass('waiting');
twDispTimer = setTimeout(function() {
$('#stage3').css('height', 'auto');
$('#stage3-content-twitterwait').show();
var newHeight = $('#stage3').height();
$('#stage3-content-twitterwait').hide();
$('#stage3').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#stage3-content-twitterwait').fadeIn('fast');
});
}, 1000);
persistData(function() {
twStartAuth(function() {
doRec();
}, function() {
restoreState3C();
$('#post-service-btns').removeClass('waiting');
});
});
return false;
});
$('#post-twitter-link').click(function() {
twStartAuth(function() {
doRec();
}, function() {
restoreState3C();
}, true);
});
$('#post-share-facebook-btn').click(function() {
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, 'Z_FacebookShareButtonClick', 'Facebook Share Button Clicked');
}
FB.ui({
method: 'stream.publish',
display: 'popup',
name: "I recommend " + sel_product_name + " for the benefit of " + thumbs.charity + ".",
message: $('#rec-text-box').val(),
attachment: {
name: "I recommend " + sel_product_name + " for the benefit of " + thumbs.charity + ".",
caption: '',
description: '',
href: $('#post-url-box').val(),
media: [
{ name: 'Product', type: 'image', src: thumbs.product_image, href: $('#post-url-box').val() },
{ name: 'Charity', type: 'image', src: thumbs.charity_image, href: $('#post-url-box').val() }
]
},
action_links: [
{ text: 'View the Rec', href: $('#post-url-box').val() },
{ text: 'Make a Rec', href: baseUrl }
],
user_prompt_message: "Share Your Rec"
});
return false;
});
$('#post-share-twitter-btn').click(function() {
dim('#post-twitter-dialog');
return false;
});
$('#category-select').click(function() {
dim('#category-select-dialog');
return false;
});
$('#post-twitter-dialog-btn').click(function() {
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, 'Z_TwitterShareButtonClick', 'Twitter Share Button Clicked');
}
if ($('#post-twitter-text').val().length) {
$('#post-twitter-dialog-btn').addClass('waiting');
$('#post-twitter-text').attr('disabled', true);
twStartAuth(
function() {
postToTw(
postedRecId,
$('#post-twitter-text').val(),
function() {
$('#post-twitter-dialog-btn').removeClass('waiting');
$('#post-twitter-text').attr('disabled', false);
}
);
},
function(error) {
errorAlert('There was an error while trying to authenticate you with Twitter: ' + error);
},
false,
('/rec/twpostsingle/' + postedRecId),
$('#post-twitter-text').val()
);
}
return false;
});
$('#post-signup-btn').click(function() {
persistData(function() {
window.location.href = '/signup/index/fromrec';
});
return false;
});
$('#post-login-btn').click(function() {
persistData(function() {
window.location.href = '/login/index/fromrec';
});
return false;
});
});
function activateItem(item) {
sel_product_id = item._id;
sel_product_name = item.name;
$('#product_title').html(sel_product_name);
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, '3_ItemSelect', 'Activate Item');
pageTracker._trackPageview('/tracking/' + event_channel + '/rec/3_ItemSelect');
}
baseHeight = $('#stage1').height();
/* $('#product-select-btn').fadeOut('fast', function() {
$('#product-select-btn').removeClass('disabled');
$('#product-select-btn').fadeIn('fast');
}); */
$('#product-name-label').html(item.name);
$('#product-search-hint').hide();
$('#product-reset').show();
if (item.full_description) {
$('#product-description-text').html(item.full_description);
$('#product-description').slideDown();
}
$('#product-search-box').addClass('with-image');
sel_image = null;
sel_image_hash = null;
loaded_images = null;
imageWaiting();
if (item.image_width < minImageSize && item.image_height < minImageSize && (do_load_better_images || item.source == 'Product_Source_iTunes')) {
loadBetterImages(item.name, 'MP3Downloads|Music', (item.extra_label ? item.extra_label : null), function(images) {
loaded_images = images;
populateImage(images, true, null, null, 0, item.image_url);
});
} else {
populateImage(item.image_url, false, item.image_width, item.image_height);
}
step1To2();
}
function deactivateItem(noAnimate) {
sel_product_id = -1;
sel_product_name = null;
sel_image = null;
sel_image_hash = null;
loaded_images = null;
$('#product-search-box').removeClass('with-image');
$('#product-select-btn').addClass('disabled');
$('#product-search-hint').show();
$('#product-reset').hide();
$('#product-image').hide();
$('#product-description-text').html('');
$('#product-description').hide();
$('#product-description-shown').hide();
$('#product-description-hidden').show();
$('#product-search-box').val('');
if (!noAnimate) {
$('#stage1').animate({ height: baseHeight + 'px' }, 250, 'swing', function() {
$('#product-search-box').focus();
});
}
}
function step2To1() {
$('#stage1-check').hide();
$('#rec-text-counter').hide();
$('#stage2-content').hide();
var s2TargetHeight = $('#stage2').height();
$('#stage2-content').show();
$('#stage2').height($('#stage2').height() + 'px');
$('#stage2-content').fadeOut('slow', function() {
$('#stage2').animate({
height: s2TargetHeight + 'px',
backgroundColor: '#d9df86'
}, 250, 'swing', function() {
$('#stage2').css('height', 'auto');
$('#stage1').css('height', 'auto');
var curHeight = $('#stage1').height();
$('#product-pick-hint').show();
$('#product-search-box').show();
$('#product-select-ctls').show();
$('#product-reset-after').hide();
$('#product-description').show();
$('#product-name-display').hide();
$('#product-image').removeClass('within-inactive');
deactivateItem(true);
$('#stage1').animate({ height: baseHeight + 'px' }, 250, 'swing', function() {
$('#product-search-box').focus();
});
$('#stage1').css('height', 'auto');
var newHeight = $('#stage1').height();
$('#stage1').css('height', curHeight + 'px');
$('#stage1').animate({
height: newHeight + 'px',
backgroundColor: '#b8c600'
}, 250, 'swing', function() {
deactivateItem();
});
});
});
$('#stage3').animate({
backgroundColor: '#e2e6aa'
}, 250, 'swing');
}
function step1To2() {
$('#stage1').css('height', 'auto');
var curHeight = $('#stage1').height();
$('#product-pick-hint').hide();
$('#product-search-box').hide();
$('#product-select-ctls').hide();
$('#product-reset').hide();
$('#product-reset-after').show();
$('#product-description-text').html('');
$('#product-description').hide();
$('#product-description-shown').hide();
$('#product-description-hidden').hide();
$('#product-name-display').show();
$('#product-image').addClass('within-inactive').show();
$('#stage1').css('height', 'auto');
var newHeight = $('#stage1').height();
$('#product-reset-after').hide();
$('#stage1').css('height', curHeight + 'px');
$('#stage1').animate({
height: newHeight + 'px',
backgroundColor: '#abd7da'
}, 250, 'swing', function() {
$('#stage2-content').show();
var s2TargetHeight = $('#stage2').height();
$('#stage2-content').hide();
$('#stage2').animate({
height: s2TargetHeight + 'px',
backgroundColor: '#b8c600'
}, 250, 'swing', function() {
$('#stage2-content').fadeIn('slow', function() {
$('#stage2').css('height', 'auto');
if (getInternetExplorerVersion() == -1) {
$('#stage1-check').fadeIn('slow');
}
$('#rec-text-box').focus();
var tb = $('#rec-text-box').get(0);
var ml = tb.value.length;
if (tb.setSelectionRange) {
tb.setSelectionRange(ml, ml);
} else if (tb.createTextRange) {
var range = tb.createTextRange();
range.collapse(true);
range.moveEnd('character', ml);
range.moveStart('character', ml);
range.select();
}
$('#rec-text-counter').fadeIn('fast');
$('#product-reset-after').fadeIn('fast');
});
});
});
$('#stage3').animate({
backgroundColor: '#d9df86'
}, 250, 'swing');
}
function step2To3() {
unPersistData();
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, '4_EnteredRecText', 'Entered Rec Text');
pageTracker._trackPageview('/tracking/' + event_channel + '/rec/4_EnteredRecText');
}
$('#stage2').css('height', 'auto');
var curHeight = $('#stage2').height();
$('#rec-text-display').text($('#rec-text-box').val());
$('#product-reset-after').hide();
$('#rec-text-counter').hide();
$('#rec-hint').hide();
$('#stage2-content3').hide();
$('#stage2-content2').hide();
$('#stage2-content').hide();
var newHeight = $('#stage2').height();
$('#stage2').css('height', curHeight + 'px');
$('#stage2').animate({
height: newHeight + 'px',
backgroundColor: '#abd7da'
}, 250, 'swing', function() {
$('#stage2').css('height', 'auto');
curHeight = $('#stage2').height();
$('#rec-text-display').show();
var newHeight = $('#stage2').height();
$('#rec-text-display').hide();
$('.post-services-img.rec').hide();
$('#stage2').css('height', curHeight + 'px');
$('#stage2').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#rec-text-display').fadeIn('fast', function() {
$('#stage2').css('height', 'auto');
if (getInternetExplorerVersion() == -1) {
$('#stage2-check').fadeIn('slow');
}
checkAuth(function() {
doRec();
}, function() {
$('#stage3-content').show();
var s3TargetHeight = $('#stage3').height();
$('#stage3-content').hide();
$('#stage3').animate({
height: s3TargetHeight + 'px',
backgroundColor: '#b8c600'
}, 250, 'swing');
$('#stage3-content').fadeIn('slow', function() {
$('#stage3').css('height', 'auto');
});
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, '5_PromptForAuth', 'Auth Prompt');
pageTracker._trackPageview('/tracking/' + event_channel + '/rec/5_PromptForAuth');
}
});
});
});
});
}
function restoreState3C() {
$('#stage3').css('height', 'auto');
$('#stage3-content-twitterwait').hide();
var newHeight = $('#stage3').height();
$('#stage3-content-twitterwait').show();
$('#stage3-content-twitterwait').fadeOut('fast', function() {
$('#stage3').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#stage3-content').fadeIn('fast');
});
});
}
function doRec() {
if ($('#stage3-content').is(':visible')) {
$('#stage3').css('height', 'auto');
$('#stage3-content').hide();
var newHeight = $('#stage3').height();
$('#stage3-content').show();
var curHeight = $('#stage3').height();
$('#stage3').css('height', curHeight + 'px');
$('#stage3-content').fadeOut('normal', function() {
$('#stage3').animate({
height: newHeight + 'px'
}, 500, 'swing', function() {
doRec2();
});
});
} else {
doRec2();
}
}
function doRec2() {
$('#stage3').css('height', 'auto');
$('#post-posting').show();
var newHeight = $('#stage3').height();
$('#post-posting').hide();
$('#stage3').animate({
height: newHeight + 'px',
backgroundColor: '#b8c600'
}, 250, 'swing', function() {
$('#post-posting').fadeIn('slow', function() {
postRec();
});
});
}
function postRec() {
setTimeout(function() {
$.post('/ajax/newrec', {
rec_product_id: sel_product_id,
rec_product_name: sel_product_name,
rec_text: $('#rec-text-box').val(),
rec_sel_image: sel_image,
rec_sel_image_hash: sel_image_hash,
answer_for: answerForCode,
rec_auth: getAuth()
}, function(data) {
var item = parseJSON(data);
if (item.rec_id) {
postedRecId = item.rec_id;
unPersistData();
donePostRec(item.url);
} else {
// error
errorAlert('Something bad happened: ' + item.error);
}
});
}, 500);
}
function persistData(cb) {
$.post('/ajax/persistrec', {
persistType: 'rec',
sel_product_id: sel_product_id,
sel_product_name: sel_product_name,
rec_text: $('#rec-text-box').val(),
sel_image: sel_image,
sel_image_hash: sel_image_hash,
uniqid: '4c896f2ab8045',
auth: getAuth()
}, function(data) {
cb();
});
}
function unPersistData() {
$.post('/ajax/unpersistrec', { auth: getAuth(), uniqid: '4c896f2aba758' });
}
function loadData(data) {
for (var i in data) {
eval(i + " = '" + data[i].toString().replace("'", "\\'") + "';");
}
setStep3();
}
function setStep3() {
$('#rec-text-box').val(rec_text);
populateImage(sel_image, false, null, null, false, null);
$('#product-select .watermark').remove();
$('#product-select-btn').hide();
$('#product-name-label').html(sel_product_name);
$('#product-pick-hint').hide();
$('#product-search-hint').hide();
$('#product-search-box').hide();
$('#product-select-ctls').hide();
$('#product-reset').hide();
$('#product-description-text').html('');
$('#product-description').hide();
$('#product-description-shown').hide();
$('#product-description-hidden').hide();
$('#product-name-display').show();
$('#product-image').addClass('within-inactive');
$('#stage1').css('height', 'auto');
$('#stage1').css('backgroundColor', '#abd7da');
$('#stage2-content').show();
$('#stage2').css('height', 'auto');
$('#stage2').css('backgroundColor', '#b8c600');
$('#rec-encourage-hint').hide();
$('#stage2-content2').show();
$('#stage2-content3').show();
$('#stage2').height('auto');
step2To3();
}
function donePostRec(url) {
$('#post-url-box').val(url);
$('#post-preview-link').attr('href', url);
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, '6_RecPosted', 'Rec Posted');
pageTracker._trackPageview('/tracking/' + event_channel + '/rec/6_RecPosted');
}
try {
FB.Insights.impression({
'id' : 6002506549288,
'h' : '51c5066cc3'
});
} catch (e) {}
$.post('/ajax/charityshort', { auth: getAuth() }, function(chShort) {
charityShort = chShort;
var twString1 = 'Just recommended ';
var twString2 = ' on rec.fm for the benefit of my followers and ' + charityShort + ' ';
var twString3 = url;
var totalLength = twString1.length + twString2.length + twString3.length;
if (sel_product_name.length > (140 - totalLength)) {
var twProduct = sel_product_name.substring(0, (140 - totalLength)).replace(/^\s+|\s+$/g, "");
} else {
var twProduct = sel_product_name;
}
$('#post-twitter-text').val(twString1 + twProduct + twString2 + twString3);
$('#post-twitter-text').trigger('keyup');
});
$.post('/ajax/getfbimages', {
auth: getAuth(),
id: postedRecId
}, function(data) {
thumbs = parseJSON(data);
});
$('#post-share-facebook-btn').show();
$('#post-share-twitter-btn').show();
$('#post-share-btn').click(function() {
if (window.pageTracker && window.event_channel) {
pageTracker._trackEvent(event_channel, 'Z_ShareButtonClick', 'Share Button Clicked');
}
iBeginShare.show(document.getElementById('post-share-btn'), {
link: url,
title: sel_product_name,
link_style: 'text'
});
return false;
});
$('#stage3').css('height', 'auto');
$('#post-posting').hide();
var newHeight = $('#stage3').height();
$('#post-posting').show();
var curHeight = $('#stage3').height();
$('#stage3').css('height', curHeight + 'px');
$('#post-posting').fadeOut('slow', function() {
$('#stage3').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#stage3').css('height', 'auto');
$('#post-created').show();
var newHeight = $('#stage3').height();
$('#post-created').hide();
$('#stage3').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#post-created').fadeIn('slow', function() {
if (recCreateDoneCB) recCreateDoneCB();
});
});
});
});
}
function imageWaiting() {
$('#product-image').attr('src', '/media/images/spinner.24.gif');
$('#product-image').fadeIn('fast');
}
function populateImage(image, isMulti, width, height, multiIndex, fallBack) {
$('#product-image').show();
$('#product-image').removeClass('spinner');
if (!isMulti) {
sel_image = image;
loadImage('#product-image-large', false, image, minImageSize, minImageSize);
loadImage('#product-image', false, image, 35, 35, function() {
$('#product-image').fadeIn('slow');
});
} else {
if (image[multiIndex]) {
sel_image = image[multiIndex].url;
sel_image_hash = image[multiIndex].hash;
} else {
sel_image = fallBack;
}
$('#product-image').fadeOut('fast', function() {
loadImage('#product-image-large', false, sel_image, minImageSize, minImageSize);
loadImage('#product-image', false, sel_image, 35, 35, function() {
$('#product-image').fadeIn('slow');
});
});
}
}
function getCategory() {
return categoryId;
}
function setCat(obj, id) {
categoryId = id;
if (id) {
n = 'category: ' + $(obj).children('span').html();
} else {
n = 'select a category?';
}
$('#category-select').html(n);
undim();
}
/* ----- ask_create ----- */
var askText;
var askString;
var postedAskId;
var persistType;
$(document).ready(function() {
$('#ask-twitter-text').textlimit('#ask-dialog-twitter-counter', 140);
askString = "I'm looking for ";
$('#ask-text-box').addClass('grey').val(askString);
$('#ask-text-box').textlimit('#ask-text-counter', 140);
$('#ask-text-box').focus(function() {
if ($('#ask-text-box').val() == askString) {
$('#ask-text-box').val(' ');
$('#ask-text-box').focus();
$('#ask-text-box').val(askString);
}
$(this).removeClass('grey');
});
if ($('#ask-text-box').is(':visible')) {
var vt = $('#ask-text-box').val();
$('#ask-text-box').val(' ');
$('#ask-text-box').focus();
$('#ask-text-box').val(vt);
}
$('#ask-text-box').keypress(function() {
if ($(this).val().length > 10) {
$('#ask-continue-btn').removeClass('disabled');
} else {
$('#ask-continue-btn').addClass('disabled');
}
});
$('#ask-continue-btn').click(function() {
if (!$(this).hasClass('disabled') && $('#ask-text-box').val().length > 10) {
askStep1To2();
}
return false;
});
$('#ask-facebook-btn').click(function() {
$('#ask-service-btns').addClass('waiting');
askPersistData(function() {
fbStartAuth(function() {
$('#ask-service-btns').removeClass('waiting');
doAsk();
}, function() {
$('#ask-service-btns').removeClass('waiting');
// error
});
});
return false;
});
$('#ask-twitter-btn').click(function() {
$('#ask-service-btns').addClass('waiting');
$('#ask-stage2').css('height', 'auto');
$('#ask-stage2-content-twitterwait').show();
var newHeight = $('#ask-stage2').height();
$('#ask-stage2-content-twitterwait').hide();
$('#ask-stage2').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#ask-stage2-content-twitterwait').fadeIn('fast');
});
askPersistData(function() {
twStartAuth(function() {
doAsk();
}, function() {
askRestoreState2C();
$('#ask-service-btns').removeClass('waiting');
});
});
return false;
});
$('#ask-twitter-link').click(function() {
twStartAuth(function() {
doAsk();
}, function() {
askRestoreState2C();
}, true);
});
$('#ask-signup-btn').click(function() {
askPersistData(function() {
window.location.href = '/signup/index/fromask';
});
return false;
});
$('#ask-login-btn').click(function() {
askPersistData(function() {
window.location.href = '/login/index/fromask';
});
return false;
});
});
function askStep1To2() {
askUnPersistData();
var curHeight = $('#ask-stage1').height();
$('#ask-stage1').height(curHeight + 'px');
if (!askText || $('#ask-text-box').val() != askString) {
askText = $('#ask-text-box').val();
}
$('#ask-text-box').hide();
$('#ask-text-counter').hide();
$('#ask-text-display').show();
$('#ask-text-display').text(askText);
$('#ask-continue-btn').hide();
$('#ask-stage1-content').hide();
$('#ask-stage2-content').hide();
$('#ask-stage1').height('auto');
var newHeight = $('#ask-stage1').height();
$('#ask-stage1').height(curHeight + 'px');
$('#ask-stage1').animate({
height: newHeight + 'px',
backgroundColor: '#abd7da'
}, 250, 'swing', function() {
$('.ask.post-services-img').hide();
$('#ask-stage1').height('auto');
if (getInternetExplorerVersion() == -1) {
$('#ask-stage1-check').fadeIn('slow');
}
$('#ask-stage2').animate({
backgroundColor: '#b8c600'
}, 250, 'swing', function() {
checkAuth(function() {
doAsk();
}, function() {
$('#ask-stage2-content').show();
var s2TargetHeight = $('#ask-stage2').height();
$('#ask-stage2-content').hide();
$('#ask-stage2').animate({
height: s2TargetHeight + 'px',
backgroundColor: '#b8c600'
}, 250, 'swing', function() {
$('#ask-stage2-content').fadeIn('slow', function() {
$('#ask-stage2').css('height', 'auto');
});
});
});
});
});
}
function askLoadData(data) {
for (var i in data) {
eval(i + " = '" + data[i].toString().replace("'", "\\'") + "';");
}
askStep1To2();
}
function askRestoreState2C() {
$('#ask-stage2').css('height', 'auto');
$('#ask-stage2-content-twitterwait').hide();
var newHeight = $('#ask-stage2').height();
$('#ask-stage2-content-twitterwait').show();
$('#ask-stage2-content-twitterwait').fadeOut('fast', function() {
$('#ask-stage2').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#ask-stage2-content').fadeIn('fast');
});
});
}
function doAsk() {
$('#ask-stage2').height('auto');
if ($('#ask-stage2-content').is(':visible')) {
$('#ask-stage2-content').hide();
var newHeight = $('#ask-stage2').height();
$('#ask-stage2-content').show();
$('#ask-stage2').height($('#ask-stage2').height() + 'px');
$('#ask-stage2-content').fadeOut('normal', function() {
$('#ask-stage2').animate({ height: newHeight + 'px' }, 250, 'swing', function() {
$('#ask-stage2').height('auto');
$('#ask-posting').show();
newHeight = $('#ask-stage2').height();
$('#ask-posting').hide();
$('#ask-stage2').animate({ height: newHeight + 'px' }, 250, 'swing', function() {
$('#ask-posting').fadeIn('normal', function() {
postAsk();
});
});
});
});
} else {
$('#ask-stage2').height('auto');
$('#ask-posting').show();
var newHeight = $('#ask-stage2').height();
$('#ask-posting').hide();
$('#ask-stage2').animate({ height: newHeight + 'px' }, 250, 'swing', function() {
$('#ask-posting').fadeIn('normal', function() {
postAsk();
});
});
}
}
function postAsk() {
setTimeout(function() {
$.post('/ajax/newask', {
ask_text: askText,
ask_auth: getAuth()
}, function(data) {
var item = parseJSON(data);
if (item.ask_id) {
postedAskId = item.ask_id;
unPersistData();
donePostAsk(item.url);
} else {
// error
errorAlert('Something bad happened: ' + item.error);
}
});
}, 500);
}
function donePostAsk(url) {
$('#ask-url-box').val(url);
$('#ask-preview-link').attr('href', url);
$.post('/ajax/charityshort', { auth: getAuth() }, function(chShort) {
var twString1 = askText + ' ';
var twString2 = '...please RT ';
var twString3 = url;
var totalLength = twString1.length + twString2.length + twString3.length;
if (totalLength > 140) {
var twString = twString1.substring(0, (140 - (twString2.length + twString3.length))) + twString2 + twString3;
} else {
var twString = twString1 + twString2 + twString3;
}
$('#ask-twitter-text').val(twString);
$('#ask-twitter-text').trigger('keyup');
});
$('#ask-share-facebook-btn').show();
$('#ask-share-twitter-btn').show();
$('#ask-share-btn').click(function() {
iBeginShare.show(document.getElementById('ask-share-btn'), {
link: url,
title: askText,
link_style: 'text'
});
return false;
});
$('#ask-share-facebook-btn').click(function() {
$.post('/ajax/charityshort', { auth: getAuth() }, function(sel_charity) {
FB.Bootstrap.requireFeatures(["Connect"], function() {
FB.Facebook.init('00a648fa5ff6b33c186a72f9cc79a351', 'http://rec.fm/js/xdreceiver');
FB.ensureInit(function() {
$.post('/ajax/getfbimages', {
auth: getAuth(),
id: postedAskId
}, function(data) {
var item = parseJSON(data);
if (item.product_image && item.charity_image) {
FB.Connect.showFeedDialog(202442275198, {
product: sel_product_name,
charity: sel_charity,
link: $('#ask-url-box').val(),
url: $('#ask-url-box').val(),
images: [
{
src: item.product_image,
href: $('#ask-url-box').val()
},
{
src: item.charity_image,
href: $('#ask-url-box').val()
}
]
}, null, '', null, FB.RequireConnect.promptConnect, function() {
// empty
}, null, askText);
} else {
FB.Connect.showFeedDialog(202442270198, {
product: sel_product_name,
charity: sel_charity,
link: $('#ask-url-box').val(),
url: $('#ask-url-box').val(),
images: [{
src: sel_image,
href: $('#ask-url-box').val()
}]
}, null, '', null, FB.RequireConnect.promptConnect, function() {
// empty
}, null, askText);
}
});
});
});
});
return false;
});
$('#ask-share-twitter-btn').click(function() {
dim('#ask-twitter-dialog');
return false;
});
$('#ask-twitter-dialog-btn').click(function() {
if ($('#ask-twitter-text').val().length) {
$('#ask-twitter-dialog-btn').addClass('waiting');
$('#ask-twitter-text').attr('disabled', true);
twStartAuth(function() {
postToTw(postedAskId,
$('#ask-twitter-text').val(), function() {
$('#ask-twitter-dialog-btn').removeClass('waiting');
$('#ask-twitter-text').attr('disabled', false);
});
});
}
return false;
});
$('#ask-stage2').css('height', 'auto');
$('#ask-posting').hide();
var newHeight = $('#ask-stage2').height();
$('#ask-posting').show();
var curHeight = $('#ask-stage2').height();
$('#ask-stage2').css('height', curHeight + 'px');
$('#ask-posting').fadeOut('slow', function() {
$('#ask-stage2').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#ask-stage2').css('height', 'auto');
$('#ask-created').show();
var newHeight = $('#ask-stage2').height();
$('#ask-created').hide();
$('#ask-stage2').animate({
height: newHeight + 'px'
}, 250, 'swing', function() {
$('#ask-created').fadeIn('slow');
});
});
});
}
function askPersistData(cb) {
$.post('/ajax/persistrec', {
persistType: 'ask',
askText: askText,
uniqid: '4c896f2abce68',
auth: getAuth()
}, function(data) {
cb();
});
}
function askUnPersistData() {
$.post('/ajax/unpersistrec', { auth: getAuth(), uniqid: '4c896f2abf56c' });
}