(function(a){Code.registerNamespace("Website");Website.Core=Code.Class.extend({init:function(){},setCookie:function(c,d,b){var e=new Date();e.setDate(e.getDate()+b);document.cookie=c+"="+escape(d)+((b==null)?"":";expires="+e.toGMTString())},getCookie:function(b){if(document.cookie.length>0){c_start=document.cookie.indexOf(b+"=");if(c_start!=-1){c_start=c_start+b.length+1;c_end=document.cookie.indexOf(";",c_start);if(c_end==-1){c_end=document.cookie.length}return unescape(document.cookie.substring(c_start,c_end))}}return""}});Website.Core=new Website.Core()})(jQuery);(function(a){Code.registerNamespace("Website.Pages");Website.Pages.Index=Code.Class.extend({init:function(c,d){var b=this;b._dataXMLUrl=c;b._resultsUrl=d},onReady:function(){var b=this;a.get(b._dataXMLUrl,function(c){b._dataXML=c;b.initFromXML(c)});a(".frow-giftfinder-search-type .frow-radio").click(function(){a("input",this).attr("checked","checked");Website.Pages.Index.loadWhoDropDown();Website.Pages.Index.loadInterestsDropDown()});a("#giftfinder-form").submit(function(){b.onSearchSubmit();return false})},onSearchSubmit:function(){var i=this;var j;var f;var d;var k;d=a("#GiftFinderWho").val();f=a("#GiftFinderCost").val();k=a("#GiftFinderInterests").val();j=a("input[name=GiftFinderType]:checked").val();var e=a(".giftfinder-results-header");if((d==0)||(f==0)||(k==0)||(j==0)){e.html("");if(d==0){e.append("<strong>You need to select who the gift is for.</strong><br />")}if(f==0){e.append("<strong>You need to select how much you would like to spend.</strong><br />")}if(k==0){e.append("<strong>You need to select their interests.</strong><br />")}if(a(".frow-giftfinder-search-type input:checked").length<=0){e.append("<strong>You need to select the type of present they would like.</strong><br />")}return false}Website.Core.setCookie("giftfinder-who",d,1);Website.Core.setCookie("giftfinder-cost",f,1);Website.Core.setCookie("giftfinder-interest",k,1);Website.Core.setCookie("giftfinder-type",j,1);if(i._dataXML!=null){var h=a("selection > cr[ct='"+j+"'][in='"+k+"'][rp='"+d+"'][bg='"+f+"']",i._dataXML);var g=a(h).length;if(g<=0){e.html("");e.append("<strong>No results could be found. Please select another criteria.</strong>");return false}var c=a("rs",h);var b=c.attr("c1");var m=c.attr("c2");var l=c.attr("c3");e.html('<img alt="" src="graphics/giftfinder/ajax-loader.gif" /> Loading results for your <strong>'+a("#GiftFinderWho option:selected").html()+"</strong> from <strong>"+a("#GiftFinderCost option:selected").html()+"</strong>.");if(!a.browser.safari){a("div.giftfinder-results-container").html("").hide()}a.get(i._resultsUrl,{c1:b,c2:m,c3:l},function(n){i.loadResults(n)})}else{e.append("<strong>The page encountered a problem returning your results. Please refresh the page and try again.</strong>");return false}return false},loadResults:function(b){a("div.giftfinder-results-container").hide().html(b);a(".giftfinder-results-carousel").addClass("js-giftfinder-results-carousel");a(".giftfinder-results-header").animate({opacity:1},1000,function(){a("div.giftfinder-results-container").show();a(".giftfinder-results-header").animate({opacity:1},1000,function(){a(".giftfinder-results-header").html("This is what we found for your <strong>"+a("#GiftFinderWho option:selected").html()+"</strong> from <strong>"+a("#GiftFinderCost option:selected").html()+"</strong>.");if(a.browser.safari){var c=function(d){d.setup();d.prev()};a(".js-giftfinder-results-carousel").jcarousel({scroll:1,initCallback:c})}else{a(".js-giftfinder-results-carousel").jcarousel({scroll:1})}})})},initFromXML:function(c){var b=this;b.loadCategory(c,"GiftFinderType1",0);b.loadCategory(c,"GiftFinderType2",1);b.loadCategory(c,"GiftFinderType3",2);var e=Website.Core.getCookie("giftfinder-type");if(e==""){a("#GiftFinderType1").attr("checked","checked");e="1"}if(e==1){a("#GiftFinderType1").attr("checked","checked")}if(e==2){a("#GiftFinderType2").attr("checked","checked")}if(e==3){a("#GiftFinderType3").attr("checked","checked")}b.loadWhoDropDown();b.loadInterestsDropDown();b.loadBudgetDropDown();a("input[name=GiftFinderType]").each(function(){a(this).bind("click",function(){Website.Pages.Index.loadWhoDropDown();Website.Pages.Index.loadInterestsDropDown()})});a("#GiftFinderWho").bind("change",function(){Website.Pages.Index.loadInterestsDropDown()});var d=Website.Core.getCookie("giftfinder-who");var f=Website.Core.getCookie("giftfinder-interest");var g=Website.Core.getCookie("giftfinder-cost");if((d!="")&&(f!="")&&(g!="")){b.onSearchSubmit()}},loadWhoDropDown:function(){var b=this;var h=a("input[name=GiftFinderType]:checked").val();var g=Website.Core.getCookie("giftfinder-who");a("#GiftFinderWho").empty();var c=a("categories > ct[vl='"+h+"'] > recipients > *",b._dataXML);var e="";for(var f=0;f<c.length;f++){var d=a(c[f]).attr("nm");var j=a(c[f]).attr("vl");e+='<option value="'+j+'"';if(j==g){e+=' selected="selected"'}e+=">"+d+"</option>"}a("#GiftFinderWho").append(e)},loadInterestsDropDown:function(){var j=this;var d=a("input[name=GiftFinderType]:checked").val();var b=a("#GiftFinderWho").val();var g=Website.Core.getCookie("giftfinder-interest");var k=a("categories > ct[vl='"+d+"'] > recipients > rp[vl='"+b+"']",j._dataXML);a("#GiftFinderInterests").empty();var l="";if(a("input[name=GiftFinderType]:checked").val()==3){l+='<option value="1" selected="selected">Not applicable</option>'}else{if(k.length>0&&k.attr("in")==1){var h=a("interests > *",j._dataXML);for(var f=0;f<h.length;f++){var c=a(h[f]).attr("nm");var e=a(h[f]).attr("vl");l+='<option value="'+e+'"';if(e==g){l+=' selected="selected"'}l+=">"+c+"</option>"}}else{l+='<option value="1" selected="selected">Not applicable</option>'}}a("#GiftFinderInterests").append(l)},loadBudgetDropDown:function(){var b=this;var h=Website.Core.getCookie("giftfinder-cost");var c=a("budgets > *",b._dataXML);var e="";for(var f=0;f<c.length;f++){var d=a(c[f]).attr("nm");var g=a(c[f]).attr("vl");e+='<option value="'+g+'"';if(g==h){e+=' selected="selected"'}e+=">"+d+"</option>"}a("#GiftFinderCost").append(e)},loadCategory:function(e,d,c){var b=a("categories > ct:eq("+c+")",e);a("#"+d).attr("value",b.attr("vl"))},_dataXMLUrl:null,_dataXML:null,_resultsUrl:null});Website.Pages.Index=new Website.Pages.Index("giftfinder.xml","giftFinderResults.do");a().ready(function(){Website.Pages.Index.onReady()})})(jQuery);
