var gv_url = 'http://grapevinereviews.com/api';
/*-----------------------------------------------------------------------------
 * Grapevine Reviews JS gv2.js
 * Copyright 2009-2011 Storemsiths.com
 * All Rights reserved
 * 
 * !!!IMPORTANT!!! 
 * Do not attempt to modify or reverse-engineer the functionality of this file, 
 * as this code can change without notice!!
 * !!!IMPORTANT!!! 
 *
 *-----------------------------------------------------------------------------
 */


function log(a){if(window.gv_debug)try{console.log(a)}catch(e){}}var gv;if(window.MooTools||window.Prototype)jQuery.noConflict();
(function(a){if(a.browser.msie)try{document.execCommand("BackgroundImageCache",false,true)}catch(e){}a.fn.rating=function(b){if(this.length==0)return this;if(typeof arguments[0]=="string"){if(this.length>1){var d=arguments;return this.each(function(){a.fn.rating.apply(a(this),d)})}a.fn.rating[arguments[0]].apply(this,a.makeArray(arguments).slice(1)||[]);return this}b=a.extend({},a.fn.rating.options,b||{});a.fn.rating.calls++;this.not(".star-rating-applied").addClass("star-rating-applied").each(function(){var c,
f=a(this),k=(this.name||"unnamed-rating").replace(/\[|\]/g,"_").replace(/^\_+|\_+$/g,""),h=a(this.form||document.body),j=h.data("rating");if(!j||j.call!=a.fn.rating.calls)j={count:0,call:a.fn.rating.calls};var i=j[k];if(i)c=i.data("rating");if(i&&c)c.count++;else{c=a.extend({},b||{},(a.metadata?f.metadata():a.meta?f.data():null)||{},{count:0,stars:[],inputs:[]});c.serial=j.count++;i=a('<span class="star-rating-control"/>');f.before(i);i.addClass("rating-to-be-drawn");if(f.attr("disabled"))c.readOnly=
true;i.append(c.cancel=a('<div class="rating-cancel"><a title="'+c.cancel+'">'+c.cancelValue+"</a></div>").mouseover(function(){a(this).rating("drain");a(this).addClass("star-rating-hover")}).mouseout(function(){a(this).rating("draw");a(this).removeClass("star-rating-hover")}).click(function(){a(this).rating("select")}).data("rating",c))}var g=a('<div class="star-rating rater-'+c.serial+'"><a title="'+(this.title||this.value)+'">'+this.value+"</a></div>");i.append(g);this.id&&g.attr("id",this.id);
this.className&&g.addClass(this.className);if(c.half)c.split=2;if(typeof c.split=="number"&&c.split>0){var l=(a.fn.width?g.width():0)||c.starWidth,m=c.count%c.split;l=Math.floor(l/c.split);g.width(l).find("a").css({"margin-left":"-"+m*l+"px"})}c.readOnly?g.addClass("star-rating-readonly"):g.addClass("star-rating-live").mouseover(function(){a(this).rating("fill");a(this).rating("focus")}).mouseout(function(){a(this).rating("draw");a(this).rating("blur")}).click(function(){a(this).rating("select")});
if(this.checked)c.current=g;f.hide();f.change(function(){a(this).rating("select")});g.data("rating.input",f.data("rating.star",g));c.stars[c.stars.length]=g[0];c.inputs[c.inputs.length]=f[0];c.rater=j[k]=i;c.context=h;f.data("rating",c);i.data("rating",c);g.data("rating",c);h.data("rating",j)});a(".rating-to-be-drawn").rating("draw").removeClass("rating-to-be-drawn");return this};a.extend(a.fn.rating,{calls:0,focus:function(){var b=this.data("rating");if(!b)return this;if(!b.focus)return this;var d=
a(this).data("rating.input")||a(this.tagName=="INPUT"?this:null);b.focus&&b.focus.apply(d[0],[d.val(),a("a",d.data("rating.star"))[0]])},blur:function(){var b=this.data("rating");if(!b)return this;if(!b.blur)return this;var d=a(this).data("rating.input")||a(this.tagName=="INPUT"?this:null);b.blur&&b.blur.apply(d[0],[d.val(),a("a",d.data("rating.star"))[0]])},fill:function(){var b=this.data("rating");if(!b)return this;if(!b.readOnly){this.rating("drain");this.prevAll().andSelf().filter(".rater-"+b.serial).addClass("star-rating-hover")}},
drain:function(){var b=this.data("rating");if(!b)return this;b.readOnly||b.rater.children().filter(".rater-"+b.serial).removeClass("star-rating-on").removeClass("star-rating-hover")},draw:function(){var b=this.data("rating");if(!b)return this;this.rating("drain");if(b.current){b.current.data("rating.input").attr("checked","checked");b.current.prevAll().andSelf().filter(".rater-"+b.serial).addClass("star-rating-on")}else a(b.inputs).removeAttr("checked");b.cancel[b.readOnly||b.required?"hide":"show"]();
this.siblings()[b.readOnly?"addClass":"removeClass"]("star-rating-readonly")},select:function(b){var d=this.data("rating");if(!d)return this;if(!d.readOnly){d.current=null;if(typeof b!="undefined"){if(typeof b=="number")return a(d.stars[b]).rating("select");typeof b=="string"&&a.each(d.stars,function(){a(this).data("rating.input").val()==b&&a(this).rating("select")})}else d.current=this[0].tagName=="INPUT"?this.data("rating.star"):this.is(".rater-"+d.serial)?this:null;this.data("rating",d);this.rating("draw");
var c=a(d.current?d.current.data("rating.input"):null);d.callback&&d.callback.apply(c[0],[c.val(),a("a",d.current)[0]])}},readOnly:function(b,d){var c=this.data("rating");if(!c)return this;c.readOnly=b||b==undefined?true:false;d?a(c.inputs).attr("disabled","disabled"):a(c.inputs).removeAttr("disabled");this.data("rating",c);this.rating("draw")},disable:function(){this.rating("readOnly",true,true)},enable:function(){this.rating("readOnly",false,false)}});a.fn.rating.options={cancel:"Cancel Rating",
cancelValue:"",split:0,starWidth:16}})(jQuery);
(function(a){gv={shop:null,remote_url:gv_url+"/products",reviews_id:"#gv_reviews",newreview_id:"#gv_review_new",form_id:"#gv_review_form",timeout:1E4,noop:function(){},registerCallbacks:function(){if(typeof gvcallbacks!=="undefined"){a(document).bind("gv:review:before_load",gvcallbacks.beforeReviewLoad||this.noop);a(document).bind("gv:review:after_load",gvcallbacks.afterReviewLoad||this.noop);a(document).bind("gv:review:before_submit",gvcallbacks.beforeReviewSubmit||this.noop);a(document).bind("gv:review:after_submit",
gvcallbacks.afterReviewSubmit||this.noop);a(document).bind("gv:badge:before_load",gvcallbacks.beforeBadgeLoad||this.noop);a(document).bind("gv:badge:after_load",gvcallbacks.afterBadgeLoad||this.noop)}},showReviews:function(){a(this.reviews_id).show();a(this.newreview_id).hide()},hideReviews:function(){a(this.reviews_id).hide()},showForm:function(){a(this.newreview_id).show();a(this.reviews_id).hide()},hideForm:function(){a(this.newreview_id).hide()},createReview:function(e){var b=this,d=a(this.form_id).serialize()+
"&"+a.param({shop:b.shop}),c=this.remote_url+"/"+e+"/reviews/create.json";a(document).trigger("gv:review:before_submit",{id:e});a.ajax({type:"GET",dataType:"jsonp",url:c,data:d,timeout:this.timeout,beforeSend:b.setShopHeader,success:function(f){f=f.html.replace(/\{\%\slayout\snone\s\%\}/g,"");a(b.newreview_id).html(f);b._initRatingHelper();a(document).trigger("gv:review:after_submit",{id:e,status:"success"})},error:function(){alert("Sorry, there was a problem submitting your review. Please try again later.");
a(document).trigger("gv:review:after_submit",{id:e,status:"error"})}});return false},reportReview:function(e,b){a(document).trigger("gv:review:before_report",{id:e});var d=this;a.ajax({type:"GET",dataType:"jsonp",timeout:this.timeout,url:this.remote_url+"/"+e+"/reviews/"+b+"/report.json",data:a.param({shop:d.shop}),beforeSend:d.setShopHeader,success:function(c){html=c.html.replace(/\{\%\slayout\snone\s\%\}/g,"");a("#report_review_"+b).replaceWith("<span>"+html+"</span>");a(document).trigger("gv:review:after_report",
{id:e,status:"success"})},error:function(){alert("Sorry, there was a problem with your request. Please try again later.");a(document).trigger("gv:review:after_report",{id:e,status:"error"})}})},getReviews:function(){var e=this;a("div.gvreviews").each(function(){var b=a(this).attr("id").split("_").slice(-1);if(b){a(document).trigger("gv:review:before_load",{id:b});var d=this;a.ajax({type:"GET",dataType:"jsonp",timeout:this.timeout,url:e.remote_url+"/"+b+"/reviews.json",data:a.param({shop:e.shop}),
beforeSend:e.setShopHeader,success:function(c){c=c.html.replace(/\{\%\slayout\snone\s\%\}/g,"");a(d).html(c);e._initRatingHelper();e._initPagination();e._initOverlay();a(document).trigger("gv:review:after_load",{id:b,status:"success"})},error:function(){a(d).html("Reviews currently unavailable");a(document).trigger("gv:review:after_load",{id:b,status:"error"})}})}})},getBadges:function(){var e=this,b=e.remote_url+"/reviews/badges.json",d=jQuery.makeArray(a("div.gvbadge").map(function(){return e._getId(this)}));
if(d.length!=0){var c=a.param({ids:d.join(","),shop:e.shop});jQuery.each(d,function(){a(document).trigger("gv:badge:before_load",{id:this})});a.ajax({type:"GET",dataType:"jsonp",timeout:e.timeout,url:b,data:c,beforeSend:e.setShopHeader,success:function(f){f=f.html.replace(/\{\%\slayout\snone\s\%\}/g,"");a("body").append(f);var k=jQuery.makeArray(a("#gv_all_badges .gv_badge_response").map(function(){var h=a(this).attr("id").split("_").slice(-1);return parseInt(h,10)}));a("#gv_all_badges .gv_badge_response").each(function(){var h=
a(this).attr("id").split("_").slice(-1),j=a(this).html();a("#gvbadge_"+h).html(j)});a("#gv_all_badges").remove();jQuery.each(d,function(){var h=parseInt(this,10);h=jQuery.inArray(h,k)==-1?"error":"success";a(document).trigger("gv:badge:after_load",{id:this,status:h})})},error:function(){jQuery.each(d,function(){a(document).trigger("gv:badge:after_load",{id:this,status:"error"})})}})}},setShopHeader:function(e){e.setRequestHeader("X-GVSHOP-DOMAIN",gv.shop)},_getId:function(e){if(e=a(e).attr("id").split("_").slice(-1))return parseInt(e,
10)},_initRatingHelper:function(){a("input[type=radio].star").rating()},_initPagination:function(){a("div.gvreviews").live("click",function(e){var b=e.target;if(jQuery.inArray(b,a(".pagination a"))>=0){a.ajax({type:"GET",dataType:"jsonp",timeout:this.timeout,url:b.href,beforeSend:gv.setShopHeader,success:function(d){d=d.html.replace(/\{\%\slayout\snone\s\%\}/g,"");a("#gv_reviews").html(d);a("#gv_reviews").trigger({type:"gv:review:after_paginate"})}});e.preventDefault()}})},_initOverlay:function(){a("#gvloading").bind("ajaxSend",
function(){a(this).show()}).bind("ajaxComplete",function(){a(this).hide()})}};jQuery(document).ready(function(){gv.shop=Shopify.shop;gv.registerCallbacks();gv.getReviews();gv.getBadges()})})(jQuery);

