var dynLoaded = false; // function to load jQuery... load = function() { load.getScript("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"); load.tryReady(0); // This function waits until jQuery loads before using it. } // dynamically load a javascript file. load.getScript = function(filename) { var script = document.createElement('script') script.setAttribute("type","text/javascript") script.setAttribute("src", filename) if (typeof script!="undefined") document.getElementsByTagName("head")[ 0 ].appendChild(script) } load.tryReady = function(time_elapsed) { // Continually polls to see if jQuery is loaded. if (typeof jQuery == "undefined") { // if jQuery isn't loaded yet... if (time_elapsed <= 10000) { // and we havn't given up trying... setTimeout("load.tryReady(" + (time_elapsed + 200) + ")", 200); // set a timer to check again in 200 ms. } else { // alert("Timed out while loading jQuery.") } } else { // Any code to run after jQuery loads goes here! // for example: dynLoaded = true; groupon_init(); } } if (typeof(jQuery) == 'undefined') { // jQuery isn't loaded, so we need to load it... load(); } else { groupon_init(); } var DateDiff = function(d1, d2) { var t2 = d2.getTime(); var t1 = d1.getTime(); var wholeDays = 0; var wholeHours = 0; var wholeMinutes = 0; var wholeSeconds = 0; var totalSeconds = parseInt((t2-t1) / 1000); // 86400 seconds in 1 day (totalSeconds > 86400) ? wholeDays = Math.abs(parseInt(totalSeconds / (86400))) : wholeDays = 0; var leftAfterDays = totalSeconds - (wholeDays * 86400); // 3600 seconds in 1 hour var wholeHours = Math.abs(parseInt(leftAfterDays / 3600)); var leftAfterHours = leftAfterDays - (wholeHours * 3600); // 60 seconds in 1 minute var wholeMinutes = Math.abs(parseInt(leftAfterHours / 60)); var leftAfterMinutes = leftAfterHours - (wholeMinutes * 60); var breakDown = new Object(); breakDown[ 'days' ] = wholeDays; if (wholeDays > 0) { wholeHours = wholeHours + (24*wholeDays); } breakDown[ 'hours' ] = wholeHours; breakDown[ 'minutes' ] = wholeMinutes; breakDown[ 'seconds' ] = leftAfterMinutes; return breakDown; } var niceDateDiff = ''; var gInterval=new Array(); function startCountdown(endDate, i) { gInterval[ i ]=setInterval(function() { d1 = new Date(); niceDateDiff = DateDiff(d1, endDate); // $('#grouponDays' + i).text(niceDateDiff[ 'days' ]); jQuery('#grouponHours' + i).text(niceDateDiff[ 'hours' ]); jQuery('#grouponMinutes' + i).text(niceDateDiff[ 'minutes' ]); jQuery('#grouponSeconds' + i).text(niceDateDiff[ 'seconds' ]); }, 1000); } function displayGrouponAd(APIKEY, size, location, color1, showpreloader, pid, aid, title) { ASSETDOMAIN = 'http://www.groupon.com'; //CSSURL = new String(); //CSSURL = 'http://www.coolsavings.com/' + size + '.css'; //console.log(CSSURL); //jQuery('HEAD').append(''); IMGURL = ASSETDOMAIN + '/images/groupon/widget/'; APIURL = 'http://api.groupon.com/v2/deals.json?client_id='+APIKEY+'&callback=?'; if (location.length) { var latLon = location.split(','); APIURL += '&lat=' + latLon[ 0 ]; APIURL += '&lng=' + latLon[ 1 ]; } jQuery('
').insertAfter('#grouponAd'); sizeSplit = size.split('.'); if (showpreloader) { jQuery('#grouponAdContainer').html('

Loading Groupon
'); } jQuery.getJSON(APIURL, function(data) { var i; var d1 = new Date(); var theDate = data.deals[ 0 ].endAt; var safeDateTime = theDate.split('T'); var safeDate = safeDateTime[ 0 ].replace(/-/g,"/"); var safeTime = safeDateTime[ 1 ].replace(/Z/g,""); var d2 = new Date(safeDate + ' ' + safeTime); for (i = 0; i < data.deals.length; i++) { data.deals[ i ].price = data.deals[ i ].options[ 0 ].price.formattedAmount.replace(/\.\d+/, ''); data.deals[ i ].value = data.deals[ i ].options[ 0 ].value.formattedAmount.replace(/\.\d+/, ''); data.deals[ i ].discountAmount = data.deals[ i ].options[ 0 ].discount.formattedAmount.replace(/\.\d+/, ''); data.deals[ i ].discountPercent = data.deals[ i ].options[ 0 ].discountPercent; } jQuery('#grouponAdContainer').html(''); //adding code to not loop through to side-deal if there isnt one if(data.deals[ 1 ]==undefined){var lE=1;}else{var lE=2;} //and if the color doesnt have hashtag, we'll add one if(color1.indexOf("#")<0){color1="#"+color1;} //prepend CJ information to the clickthru var cjprepend='http://www.anrdoezrs.net/click-'+pid+'-'+aid+'?url='; switch (size) { case 'groupon-deals': for (i=0; i'; jQuery('#grouponAdContainer').append(grouponAd); var cityDiv = '
Daily Deal: ' + data.deals[ i ].division.name + '
'; jQuery(thisDeal).append(cityDiv); var titleDiv = '
' + data.deals[ i ].title.replace("&","and") + '
'; jQuery(thisDeal).append(titleDiv); var imgDiv = '
'; jQuery(thisDeal).append(imgDiv); if(lE==2){ if (i == 0) { thisButtonID = 'grouponShowSide' var otherDealDiv = '
'; } else { thisButtonID = 'grouponShowDaily'; var otherDealDiv = '
'; } jQuery(thisDeal).append(otherDealDiv); } var tableDiv = '
'; jQuery(thisDeal).append(tableDiv); jQuery(thisDeal+' .grouponTableLeft').html('Discount:
You Save:'); jQuery(thisDeal+' .grouponTableRight').html(data.deals[ i ].discountPercent + '%
' + data.deals[ i ].discountAmount); var boughtDiv = '
' + data.deals[ i ].soldQuantity + ' Bought
'; jQuery(thisDeal).append(boughtDiv); var getDiv = '
'; jQuery(thisDeal).append(getDiv); var countdown = '
Time left to buy 0:H 0:M 0:S
'; jQuery(thisDeal).append(countdown); if(typeof(gInterval)!='undefined'){ clearInterval(gInterval[ i ]); } startCountdown(d2, i); var poweredByDiv = '
'; jQuery(thisDeal).append(poweredByDiv); // change color of text... if (typeof(color1) != 'undefined') { jQuery(thisDeal).css('border-color', color1); jQuery('.grouponCity').css('color', color1); jQuery('.grouponGet').css('color', color1); } } jQuery('#grouponShowSide').click(function(e) { e.preventDefault(); jQuery('#grouponAdContents0, #grouponAdContents1').animate({ left: '-=593'}, 1000, function() { // animation complete... jQuery('#grouponAdContainer').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 1 ].dealUrl); }); }); return false; }); jQuery('#grouponShowDaily').click(function(e) { e.preventDefault(); jQuery('#grouponAdContents0, #grouponAdContents1').animate({ left: '+=593'}, 1000, function() { // animation complete... jQuery('#grouponAdContainer').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 0 ].dealUrl); }); }); return false; }); autoEl = setInterval(function() { if (typeof(jQuery().autoEllipsis) == 'function') { jQuery('.grouponTitle').autoEllipsis(); clearInterval(autoEl); } }, 200); break; case 'groupon-home': for (i=0; i
'; jQuery('#grouponAdContainer').append(grouponAd); var titleDiv = '
' + data.deals[ i ].title.replace("&","and") + '
'; jQuery(thisDeal).append(titleDiv); var imgDiv = '
'; jQuery(thisDeal).append(imgDiv); if(lE==2){ if (i == 0) { thisButtonID = 'grouponShowSide' var otherDealDiv = '
'; } else { thisButtonID = 'grouponShowDaily'; var otherDealDiv = '
'; } jQuery(thisDeal).append(otherDealDiv); } var tableDiv = '
'; jQuery(thisDeal).append(tableDiv); jQuery(thisDeal+' .grouponTableLeft').html('Discount:
You Save:'); jQuery(thisDeal+' .grouponTableRight').html(data.deals[ i ].discountPercent + '%
' + data.deals[ i ].discountAmount); var getDiv = '
'; jQuery(thisDeal).append(getDiv); var poweredByDiv = '
'; jQuery(thisDeal).append(poweredByDiv); // change color of text... if (typeof(color1) != 'undefined') { jQuery(thisDeal).css('border-color', color1); jQuery('.grouponCity').css('color', color1); jQuery('.grouponGet').css('color', color1); } } /*jQuery('#grouponShowSide').click(function(e) { e.preventDefault(); jQuery('#grouponAdContents0, #grouponAdContents1').animate({ left: '-=280'}, 1000, function() { // animation complete... jQuery('#grouponAdContainer').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 1 ].dealUrl); }); }); return false; }); jQuery('#grouponShowDaily').click(function(e) { e.preventDefault(); jQuery('#grouponAdContents0, #grouponAdContents1').animate({ left: '+=280'}, 1000, function() { // animation complete... jQuery('#grouponAdContainer').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 0 ].dealUrl); }); }); return false; });*/ autoEl = setInterval(function() { if (typeof(jQuery().autoEllipsis) == 'function') { jQuery('.grouponTitle').autoEllipsis(); clearInterval(autoEl); } }, 200); break; } //jQuery('#grouponAdContainer').css('cursor','pointer').unbind('click').click(function() { // window.open(cjprepend+data.deals[ 0 ].dealUrl); //}); jQuery('#grouponAdContents0').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 0 ].dealUrl); }); jQuery('#grouponAdContents1').css('cursor','pointer').unbind('click').click(function() { window.open(cjprepend+data.deals[ 1 ].dealUrl); }); }); } function groupon_init() { // ellipsis plugin // /* by Homam Hosseini http://abstractform.wordpress.com bluesnowball@gmail.com */ jQuery.fn.autoEllipsis = function(options) { var get_AutoEllipsisScroller = function(id) { var aeScrollerId = "WingooliAutoEllipsisScroller_" + id if (!document.getElementById(aeScrollerId)) { var div = document.createElement("div"); div.id = aeScrollerId + "_Container"; div.innerHTML = ""; document.body.appendChild(div); } return document.getElementById(aeScrollerId); }; var StringEllipsesByMaxLetters = function(element, originalText, maxLettersAllowed) { element.title = ""; var text = originalText; if (text == null || text == "") text = element.innerHTML; var maxAllowedLatterIndex = text.length - maxLettersAllowed; if (maxAllowedLatterIndex > 0) { element.title = text; if (originalText == null) originalText = text; element.innerHTML = text.substr(0, maxLettersAllowed - 2) + "…"; } else { element.innerHTML = text; } }; var _this = this; var settings = jQuery.extend({}, options); this.each(function(i) { var aeScroller = get_AutoEllipsisScroller(i); saeScroller = jQuery(aeScroller); sthis = jQuery(this); saeScroller.text(sthis.text()); var origText = sthis.html(); var element = this; var elementBounds = { width: element.offsetWidth, height: element.offsetHeight }; var jAeScroller = jQuery(aeScroller); var jElement = jQuery(element); var props = [ "font-size", "font-weight", "font-family", "font-style", "padding" ]; for (var i = 0; i < props.length; i++) { try { jAeScroller.css(props[ i ], jElement.css(props[ i ])); } catch (ex) { } } jElement.css("overflow", "visible"); jAeScroller.width(jElement.innerWidth()); var isIe = (document.all != undefined); var scrollerWidth = jAeScroller.innerWidth(); var scrollerHeight = jAeScroller.innerHeight(); var fitText = saeScroller.text(); while (scrollerHeight > elementBounds.height && fitText != "") { fitText = fitText.substr(0, fitText.length - 2); var autoScrollerInnerHTML = fitText + "…"; saeScroller.html(autoScrollerInnerHTML); scrollerHeight = jAeScroller.innerHeight(); } if (fitText == "") { fitText = origText; saeScroller.html(fitText); jElement.css("whiteSpace", "nowrap"); jAeScroller.width(""); var scrollerWidth = jAeScroller.width(); } while (scrollerWidth > elementBounds.width && fitText != "") { fitText = fitText.substr(0, fitText.length - 2); var autoScrollerInnerHTML = fitText + "…"; saeScroller.html(autoScrollerInnerHTML); scrollerWidth = jAeScroller.innerWidth(); } var scrollerHeight = aeScroller.offsetHeight; var r = (Math.ceil(elementBounds.height / scrollerHeight) - 1); r += (r == 0) ? 1 : 0; var maxLettersAllowed = fitText.length * r; StringEllipsesByMaxLetters(element, origText, maxLettersAllowed + (r + 1)); }); } // initialize with options... if ((typeof(_gwparam) != 'undefined') && (typeof(_gwparam[ 'size' ]) != 'undefined')) { displayGrouponAd(_gwparam[ 'APIKEY' ] ,_gwparam[ 'size' ], _gwparam[ 'location' ], _gwparam[ 'bgcolor' ], true, _gwparam[ 'PID' ], _gwparam[ 'AID' ], _gwparam[ 'title' ] ); } }