/*
 * JavaScript Component - Custom Thermometer v1.3.1 - Artez Addon 
 * http://www.fourandahalflines.com
 *
 * Copyright (c) 2009 Nick Lloyd
 * 
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
	ERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
	LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
	OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	
	The above copyright notice and this permission notice shall be
	included in all copies or substantial portions of the Software.
	
 * Date: 2009-01-27 (Tuesday, 27 Jan 2009)
 * 
 */


var EventThermometer=function(settings){therm=this;this.settings=settings;this.totals={"eventVerifiedTotalCollected":0,"eventVerifiedTotalSponsors":0,"eventVerifiedFundraisingGoal":0,"eventUnVerifiedFundraisingGoal":0,"eventUnVerifiedTotalCollected":0,"eventUnVerifiedTotalSponsors":0,"displayPercent":0,"displayCollected":0,"displaySponsors":0,"displayGoal":0};this.run();};EventThermometer.prototype={"run":function(){this.getEvents();},"getEvents":function(){var len=therm.settings.eventArray.length-1;for(var i=len;i>-1;i--){var eventID=therm.settings.eventArray[i];therm.getEventData(eventID);}},"getEventData":function(eventID){var cacheKiller=new Date().getTime();$.ajax({dataType:'jsonp',data:"_render=json&cacheKiller="+cacheKiller+"&domain="+therm.settings.artezDomain+"&eventID="+eventID+"&loginOrgID="+therm.settings.orgID+"&locationExportID="+therm.settings.locationExportID+"&Source=",cache:false,jsonp:'_callback',url:'http://pipes.yahoo.com/artez/global_geteventfundraisingtotals',success:function(data){therm.sumEventData(data);}});},"sumEventData":function(data){var collection=data.value.items[0];var evt=therm.convertCurrency(collection.eventVerifiedTotalCollected);var euvt=therm.convertCurrency(collection.eventUnVerifiedTotalCollected);var evfg=therm.convertCurrency(collection.eventVerifiedFundraisingGoal);var euvfg=therm.convertCurrency(collection.eventUnVerifiedFundraisingGoal);var evts=therm.convertTotal(collection.eventVerifiedTotalSponsors);var euvts=therm.convertTotal(collection.eventUnVerifiedTotalSponsors);therm.aggregateTotal(evt,evts,evfg,euvfg,euvt,euvts);},"aggregateTotal":function(evt,evts,evfg,euvfg,euvt,euvts){therm.totals.eventVerifiedTotalCollected+=evt;therm.totals.eventVerifiedTotalSponsors+=evts;therm.totals.eventVerifiedFundraisingGoal+=evfg;therm.totals.eventUnVerifiedFundraisingGoal+=euvfg;therm.totals.eventUnVerifiedTotalCollected+=euvt;therm.totals.eventUnVerifiedTotalSponsors+=euvts;if(therm.settings.includeOffline){therm.totals.displayCollected+=(evt+euvt);therm.totals.displaySponsors+=(evts+euvts);therm.totals.displayGoal+=(evfg+euvfg);}else{therm.totals.displayCollected+=evt;therm.totals.displaySponsors+=evts;therm.totals.displayGoal+=evfg;}therm.settings.iCount=therm.settings.iCount+1;if(therm.settings.iCount==therm.settings.eventArray.length){if(therm.totals.displayGoal>0){therm.totals.displayPercent=Math.round(therm.totals.displayCollected/therm.totals.displayGoal*100);therm.displayTherm();}else{therm.displayCounter();}}},"convertCurrency":function(amount){return parseFloat(amount);},"convertTotal":function(total){return parseInt(total);},"formatNumbers":function(data){therm.totals.displayCollected=therm.addCommasCurrency((therm.totals.displayCollected).toFixed(0));therm.totals.displayGoal=therm.addCommasCurrency((therm.totals.displayGoal).toFixed(0));therm.totals.displaySponsors=therm.addCommasNumber(therm.totals.displaySponsors);},"addCommasCurrency":function(nStr){nStr+="";var cM=therm.settings.currencyMarker;var x=nStr.split(".");var x1=x[0];var x2=x.length>1?"."+x[1]:"";var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,"$1"+","+"$2");}return cM+x1+x2;},"addCommasNumber":function(nStr){nStr+="";var x=nStr.split(".");var x1=x[0];var x2=x.length>1?"."+x[1]:"";var rgx=/(\d+)(\d{3})/;while(rgx.test(x1)){x1=x1.replace(rgx,"$1"+","+"$2");}return x1+x2;},"displayTherm":function(){therm.thermMarkup();therm.thermLabels();therm.formatNumbers();therm.thermNumbers();therm.thermStyle();},"displayCounter":function(){var target=$(therm.settings.domTarget);target.append("<div id='counterWrapper'></div");$("#counterWrapper").append("<div id='stats_holder'></div>");$("#stats_holder").append("<div id='raisedLabel' class='label_text'></div><div id='myRaised_holder'></div>");if(therm.totals.displaySponsors>0){$("#stats_holder").append("<div id='sponsorsLabel' class='label_text'></div><span id='sponsors_holder'></span>");}therm.formatNumbers();therm.thermLabels();therm.thermNumbers();therm.counterStyle();},"thermMarkup":function(){var target=$(therm.settings.domTarget);target.append("<div id='thermWrapper'></div");$("#thermWrapper").append("<div id='therm_holder'><div id='merc'></div></div>");$("#thermWrapper").after("<div id='stats_holder'></div>");$("#stats_holder").append("<div id='statWrapper'></div>");$("#statWrapper").append("<div id='goalLabel' class='label_text'></div><div id='myGoal_holder'></div><div class='clear'></div>");$("#statWrapper").append("<div id='raisedLabel' class='label_text'></div><div id='myRaised_holder'></div>");$("#stats_holder").append("<div id='percentWrapper></div>");$("#percentWrapper").append("<div id='myPercent_holder'></div><div id='percentLabel'></div>");$("#stats_holder").append("<div class='clear'></div>");if(therm.totals.displaySponsors>0){$("#statWrapper").append("<div id='sponsorsLabel' class='label_text'></div><span id='sponsors_holder'></span>");}$("#statWrapper").after("<div class='clear' id='thermometerClear'></div>");},"thermLabels":function(){$("#goalLabel").html(therm.settings.goalLabel);$("#raisedLabel").html(therm.settings.raisedLabel);$("#percentLabel").html(therm.settings.percentLabel);$("#sponsorsLabel").html(therm.settings.sponsorsLabel);},"thermNumbers":function(){$("#myPercent_holder").html(therm.totals.displayPercent+"%");$("#myGoal_holder").html(therm.totals.displayGoal);$("#myRaised_holder").html(therm.totals.displayCollected);$("#sponsors_holder").html(therm.totals.displaySponsors);},"thermStyle":function(){var mercHeight=therm.settings.baseHeight+((therm.totals.displayPercent/100)*therm.settings.mercHeight);$("#merc").height(mercHeight).width(therm.settings.thermWidth);$("#thermWrapper").height(therm.settings.thermHeight).width(therm.settings.thermWidth);var thermHeight=therm.settings.thermHeight;var thermResult=therm.settings.thermHeight-mercHeight;var offset={"top":thermResult};$("#merc").css("top",offset.top);$("#thermWrapper").css("background-image","url("+therm.settings.thermBG+")");$("#merc").css("background-image","url("+therm.settings.thermFG+")");$("#stats_holder").css({"top":-47,"color":therm.settings.textColor});$("#stats_holder").width(therm.settings.thermWidth);$("#percentWrapper").width((therm.settings.thermWidth/2)-6).css('float','right');$("#statWrapper").width((therm.settings.thermWidth/2)+6).css('float','left');$("#myPercent_holder, #myRaised_holder").css('color',therm.settings.highlightColor);},"counterStyle":function(){$("#myRaised_holder").css('color',therm.settings.highlightColor);$("#stats_holder").css({"color":therm.settings.textColor});}};
