/* /_ui/srawby/js/srawby_selector_.js - Last-Modified: Tue, 09 Jun 2009 21:46:04 GMT - Built [1258747730] */
/* _ui/srawby/js/srawby_selector_.js */
function srawby_selector_tabs(E,B){var G=$("#selector-tabs li").index($("#selector-tabs li.active")[0]);var A=E;var D=$("#productSelector_dontShow_val").val();if(E=="previous"){A=G-1}if(E=="next"){A=G+1}if(A<0||A>4){return }if(G>=0&&$(".checkboxes input:checkbox",$(".callout.step")[A]).length==0){srawby_thickbox_static_show("","height=90&width=300&modal=true&inlineId=productSelector_unavailableStep_warning");return }$("#productSelector div.step").hide().eq(A).show();$("#selector-tabs li").removeClass("active").eq(A).addClass("active");var C=$("#selector-tabs li").index($("#selector-tabs li.active")[0])+1;var F=$("#selector-tabs li").index($("#selector-tabs li.active")[0])-1;if(A<=0){$("#selector-tabs a.previous").addClass("prevDisabled")}else{$("#selector-tabs a.previous").removeClass("prevDisabled")}if(A>=4||$("#selector-tabs li").eq(C).is(".disabled")){$("#selector-tabs a.next").addClass("nextDisabled")}else{$("#selector-tabs a.next").removeClass("nextDisabled")}}var srawby_selector_table_currRequest=false;function srawby_selector_table(C,A,D){var B=$("#productSelector_gunType").val();if(A){C[A]=A}if(D){C[D]=D}$("#selectorTable").addClass("loading");$("#productSelector .compareFooter").hide();if(srawby_selector_table_currRequest){srawby_selector_table_currRequest.abort();srawby_selector_table_currRequest=false}C._requesttype="text/javascript";srawby_selector_table_currRequest=$.get("/product/selector/"+B+"/table",C,function(E,F){if(F=="success"){$("#selectorTable .table").html(E);srawby_jnice_links();$("#selectorTable .table input.wishlist.nobutton").each(function(){$(this).after('<a href="#" class="wishlist">'+$(this).val()+"</a>");$(this).remove()});$("#selectorTable .head .results span").empty().append($("#srawby_selector_resultCount").val());$("#selectorTable .head .pagination").remove();$("#selectorTable .table .pagination").clone(true).appendTo($("#selectorTable .head")).end().remove();srawby_selector_table_modify();$("#selectorTable").removeClass("loading");srawby_product_firearm_buynow("#selectorTable .table button.buynow");srawby_product_firearm_wishlist("#selectorTable .table a.wishlist");if($("#selectorTable table tr td").length>0){$("#productSelector .compareFooter").show()}}})}var srawby_selector_update_checkboxes_currRequest=false;var srawby_selector_update_checkboxes_currentWarnCheckbox;var srawby_selector_update_checkboxes_furthestCompleteTab=0;function srawby_selector_update_checkboxes(activeStep){if(typeof activeStep=="undefined"){activeStep=$("#selector-tabs li").index($("#selector-tabs li.active")[0])}$("#selector-tabs li:eq("+(activeStep)+")").removeClass("disabled");$("#selector-tabs li:gt("+(activeStep)+")").addClass("disabled");var nextStep=$("#selector-tabs li").index($("#selector-tabs li.active")[0])+1;if($("#selector-tabs li").eq(nextStep).is(".disabled")){$("#selector-tabs a.next").addClass("nextDisabled")}else{$("#selector-tabs a.next").removeClass("nextDisabled")}var gunType=$("#productSelector_gunType").val();var query=new Object();var section;var filter=new Array();if(gunType=="rifles"){switch(activeStep){case 4:filter[filter.length]="accuracy";section=section?section:"price";case 3:filter[filter.length]="finish";section=section?section:"accuracy";case 2:filter[filter.length]="stock";section=section?section:"finish";case 1:filter[filter.length]="caliber";section=section?section:"stock";case 0:section=section?section:"caliber";break;default:return }}else{switch(activeStep){case 4:filter[filter.length]="stock";section=section?section:"price";case 3:filter[filter.length]="gauge";section=section?section:"stock";case 2:filter[filter.length]="huntType";section=section?section:"gauge";case 1:filter[filter.length]="family";section=section?section:"huntType";case 0:section=section?section:"family";break;default:return }}var y=filter.length;for(var x=0;x<y;x++){var name=filter[x];var filters="";var els=document.getElementsByName(name);var c=els.length;for(var i=0;i<c;i++){if(els[i].checked){if(els[i].value=="all"){filters="";break}filters+=","+els[i].value}}if(filters!=""){query[name]=filters.substring(1)}}$(".checkboxes",$(".callout.step")[activeStep]).empty();var chkbx=$('<input id="'+section+'_all" type="checkbox" name="'+section+'" value="all" />');chkbx.click(function(){if(activeStep>srawby_selector_update_checkboxes_furthestCompleteTab){srawby_selector_update_checkboxes_furthestCompleteTab=activeStep}if(this.id==srawby_selector_update_checkboxes_currentWarnCheckbox){}else{var nextDone=false;if(activeStep<srawby_selector_update_checkboxes_furthestCompleteTab){nextDone=true}if(nextDone){srawby_thickbox_static_show("","height=110&width=350&modal=true&inlineId=productSelector_warning");var me=this;srawby_selector_update_checkboxes_currentWarnCheckbox=this.id;$(".productSelector_warning .button.ok").unbind("click").click(function(){tb_remove();srawby_selector_update_checkboxes_furthestCompleteTab=activeStep;$(me).click();return false});$(".productSelector_warning .button.cancel").unbind("click").click(function(){tb_remove();return false});if(this.checked){this.checked=false}else{this.checked=true}return }}if(this.checked){$(".checkboxes input:checkbox",$(".callout.step")[activeStep]).each(function(i,el){if(!el.disabled){$(el).attr("checked",true)}})}else{$(".checkboxes input:checkbox",$(".callout.step")[activeStep]).attr("checked",false)}srawby_selector_table_filter();srawby_selector_update_checkboxes(activeStep+1)});var lbl='<label for="'+section+'_all">No Preference</label>';var container=$('<span class="checkbox"></span>').append(chkbx).append(lbl);var preppedCheckboxes=new Array();preppedCheckboxes[0]=container;$(".checkboxes",$(".callout.step")[activeStep]).addClass("loading");if(srawby_selector_update_checkboxes_currRequest){srawby_selector_update_checkboxes_currRequest.abort();srawby_selector_update_checkboxes_currRequest=false}var selected=new Array();for(v in srawby_selector_table_selectedProducts){if(srawby_selector_table_selectedProducts[v]){selected[selected.length]=v}}if(selected.length>0){query["selectedProducts[]"]=selected}srawby_selector_update_checkboxes_currRequest=$.get("/product/selector/options/"+gunType+"/"+section,query,function(data,textStatus){if(textStatus=="success"){var availCount=0;var dat=eval(data);dat=dat[0];var c=dat.removeProducts.length;for(var i=0;i<c;i++){srawby_selector_table_selectedProducts[dat.removeProducts[i]]=false;$('#selectorTable table.product-placeholder input.nid[value="'+dat.removeProducts[i]+'"]').ancestors("tr:eq(0)").remove()}var checkboxes=dat.options;var c=checkboxes.length;for(var i=0;i<c;i++){var valStr=checkboxes[i][0];var lblStr=(typeof checkboxes[i][2]=="undefined")?checkboxes[i][0]:checkboxes[i][2];if(checkboxes[i][1]==0){var chkbx=$('<input id="'+section+"_"+i+'" type="checkbox" name="'+section+'" value="'+valStr+'" disabled="disabled" class="disabled" />');var lblClass=' class="disabled"'}else{var chkbx=$('<input id="'+section+"_"+i+'" type="checkbox" name="'+section+'" value="'+valStr+'" />');var lblClass=""}chkbx.click(function(){if(activeStep>srawby_selector_update_checkboxes_furthestCompleteTab){srawby_selector_update_checkboxes_furthestCompleteTab=activeStep}if(this.id==srawby_selector_update_checkboxes_currentWarnCheckbox||$("#productSelector_dontShow_val").val()=="true"){}else{var nextDone=false;if(activeStep<srawby_selector_update_checkboxes_furthestCompleteTab){nextDone=true}if(nextDone){srawby_thickbox_static_show("","height=110&width=350&modal=true&inlineId=productSelector_warning");var me=this;srawby_selector_update_checkboxes_currentWarnCheckbox=this.id;$(".productSelector_warning .button.ok").unbind("click").click(function(){tb_remove();srawby_selector_update_checkboxes_furthestCompleteTab=activeStep;$(me).click();return false});$(".productSelector_warning .button.cancel").unbind("click").click(function(){tb_remove();return false});if(this.checked){this.checked=false}else{this.checked=true}return }}$("#"+section+"_all").attr("checked",false);srawby_selector_table_filter();srawby_selector_update_checkboxes(activeStep+1)});if(checkboxes[i][1]==0){chkbx.disabled="disabled"}else{availCount++}var lbl='<label for="'+section+"_"+i+'"'+lblClass+">"+lblStr+"</label>";var container=$('<span class="checkbox"></span>').append(chkbx).append(lbl);preppedCheckboxes[preppedCheckboxes.length]=container}if(gunType=="rifles"&&(activeStep=="caliber"||activeStep=="0")){var numColumns=4;var cbxs=preppedCheckboxes.length;var max=Math.ceil(cbxs/numColumns);var iterator=0;var div=$('<div style="float: left; width: 160px;"></div>');for(var i=0;i<cbxs;i++){if(iterator==max-1){iterator=0;div.append(preppedCheckboxes[i]);$(".checkboxes",$(".callout.step")[activeStep]).append(div);div=$('<div style="float: left; width: 160px;"></div>')}else{iterator++;div.append(preppedCheckboxes[i])}}$(".checkboxes",$(".callout.step")[activeStep]).append(div)}else{var cbxs=preppedCheckboxes.length;for(var i=0;i<cbxs;i++){$(".checkboxes",$(".callout.step")[activeStep]).append(preppedCheckboxes[i])}}if(availCount==1){$(".checkboxes input:checkbox",$(".callout.step")[activeStep]).each(function(){if(!this.disabled&&this.value!="all"){$(this).attr("checked",true)}});srawby_selector_update_checkboxes(activeStep+1)}if(activeStep==0&&gunType=="rifles"){srawby_selector_caliber_dropdown()}$(".checkboxes",$(".callout.step")[activeStep]).removeClass("loading")}})}var srawby_selector_caliber_dropdown_map;function srawby_selector_caliber_dropdown(){var selected=$("#edit-caliber-sort").val();if(typeof srawby_selector_caliber_dropdown_map=="undefined"){$.get("/product/selector/options/rifles/caliber_categories",function(data,textStatus){if(textStatus=="success"){srawby_selector_caliber_dropdown_map=eval(data);srawby_selector_caliber_dropdown_map=srawby_selector_caliber_dropdown_map[0];srawby_selector_caliber_dropdown()}});return }var map=srawby_selector_caliber_dropdown_map;if(selected=="all"){$(".checkboxes input:checkbox",$(".callout.step")[0]).attr("disabled",false);$(".checkboxes label.disabled",$(".callout.step")[0]).removeClass("disabled")}else{$(".checkboxes input:checkbox",$(".callout.step")[0]).each(function(i,el){if(el.value=="all"){}else{if($.inArray(el.value,map[selected])!=-1){$(el).attr("disabled",false);$(el).next().removeClass("disabled")}else{$(el).attr("checked",false);$(el).attr("disabled",true);$(el).next().addClass("disabled")}}})}}function srawby_selector_table_filter(E,M){if(typeof (E)=="undefined"){var E="1"}if(typeof (M)=="undefined"){var M="sell_price"}var I=$("#selector-tabs li").index($("#selector-tabs li.active")[0]);var H=new Object();var B=$("#productSelector_gunType").val();var F=new Array();if(B=="rifles"){switch(I){case 4:F[F.length]="price";case 3:F[F.length]="accuracy";case 2:F[F.length]="finish";case 1:F[F.length]="stock";case 0:F[F.length]="caliber"}}else{switch(I){case 4:F[F.length]="price";case 3:F[F.length]="stock";case 2:F[F.length]="gauge";case 1:F[F.length]="huntType";case 0:F[F.length]="family"}}var K=F.length;for(var L=0;L<K;L++){var A=F[L];var J=document.getElementsByName(A);var G=J.length;var D="";for(var C=0;C<G;C++){if(J[C].checked){if(J[C].value=="all"){D="";break}D+=","+J[C].value}}if(D!=""){H[A]=D.substring(1)}}if(E!=""){H._pgId=E}if(M!=""){H.orderBy=M}srawby_selector_table(H)}var srawby_selector_table_rowMap=new Object();srawby_selector_table_rowMap.title=1;srawby_selector_table_rowMap.caliber=2;srawby_selector_table_rowMap.family=2;srawby_selector_table_rowMap.gauge=3;srawby_selector_table_rowMap.cost=6;var srawby_selector_table_selectedProducts=new Object();function srawby_selector_table_modify(){var A=srawby_selector_table_rowMap;$("#selectorTable .table table td.product a").each(function(){var F=$("td.product a",this.parentNode.parentNode);var D=F.text();F=F.html();var B=$("td.caliber",this.parentNode.parentNode).html();if(!B){var B=$("td.gauge",this.parentNode.parentNode).html()+" Gauge"}var H=$("td.price",this.parentNode.parentNode).html();var C=$("td.product input.image",$(this).parents("tr")).val();C=srawby_getImageTag(C,D);$(this).attr("title","Weatherby Product");$(this).Tooltip({track:true,showURL:false,extraClass:"weatherby-detail",opacity:1,bodyHandler:function(){var I='<div class="srawby_selector_product_hover"><div class="image">'+C+'</div><div class="title">'+F+'</div><div class="caliber">'+B+'</div><div class="cost">'+H+"</div></div>";return I}});var E=$('<input type="checkbox" class="product-checkbox" />').click(function(){var J=$("input.nid",$(this).parents("tr")).val();if(this.checked){srawby_selector_table_selectedProducts[J]=true;if(!$('#selectorTable table.product-placeholder input.nid[value="'+J+'"]').length){var I=$("<tr></tr>").append($(this).ancestors("tr:eq(0)").html());$("input:checkbox",I).attr("checked",true);$("#selectorTable table.product-placeholder").append(I)}}else{srawby_selector_table_selectedProducts[J]=false;$('#selectorTable table.product-placeholder input.nid[value="'+J+'"]').ancestors("tr:eq(0)").remove()}});var G=$("input.nid",$(this).parents("tr")).val();if(typeof srawby_selector_table_selectedProducts[G]!="undefined"&&srawby_selector_table_selectedProducts[G]){E.attr("checked",true)}$(this).parents("tr").children("td.checkbox").append(E)});$("#selectorTable th a").unbind("click").click(function(){var B="1";var C=$(this).attr("rel");srawby_selector_table_filter(B,C);return false});$("#selectorTable .pgPagination a").unbind("click").click(function(){var B=$(this).text();var D=$("#srawby_selector_orderBy").val();var C=$("#selectorTable .table div.pages .pgPagination .pgCurrent").text();if(B==">>"){B=(1*C)+1}else{if(B=="<<"){B=(1*C)-1}}srawby_selector_table_filter(B,D);return false})}function srawby_selector_compare(){var C=new Array();var A=$("#productSelector_gunType").val();var B=srawby_selector_table_rowMap;$("#selector-compare .selects .selects-left").empty().append($("<select></select>").width("430px").change(function(){srawby_selector_compare_refreshDetail(0,this)}));$("#selector-compare .selects .selects-right").empty().append($("<select></select>").width("430px").change(function(){srawby_selector_compare_refreshDetail(1,this)}));var D=0;$("#selectorTable table.product-placeholder td.product").each(function(){if($("td.checkbox input:checkbox",this.parentNode)[0].checked){var F=$("input.nid",this).val();if(A=="rifles"){var E=$("td:eq("+B.title+")",this.parentNode).text()+" "+$("td:eq("+B.caliber+")",this.parentNode).text()}else{var E=$("td:eq("+B.title+")",this.parentNode).text()+" "+$("td:eq("+B.family+")",this.parentNode).text()+" "+$("td:eq("+B.gauge+")",this.parentNode).text()+" Gauge"}$("#selector-compare select").append('<option value="'+F+'">'+E+"</option>");D++}$("#selector-compare select:eq(0) option:eq(0)").attr("selected",true);$("#selector-compare select:eq(1) option:eq(1)").attr("selected",true);if($("#selector-compare select:eq(0) option").length>0){$("#selector-compare .detail.first").addClass("loading");srawby_selector_compare_refreshDetail(0,$("#selector-compare select:eq(0)")[0])}if($("#selector-compare select:eq(1) option").length>0){$("#selector-compare .detail.second").addClass("loading");srawby_selector_compare_refreshDetail(1,$("#selector-compare select:eq(1)")[0])}});$("#selector-compare").jNice();if(D>=2){srawby_thickbox_static_show("","height=380&width=930&modal=true&inlineId=selector-compare");$("#TB_ajaxContent").css("padding","0")}else{srawby_thickbox_static_show("","height=110&width=350&modal=true&inlineId=productSelector_compare_warning")}}var srawby_selector_compare_currRequest=new Array(false,false);function srawby_selector_compare_refreshDetail(index,select){var gunType=$("#productSelector_gunType").val();var prodId=select.options[select.selectedIndex].value;if(index==0){$("#TB_window .detail.first").addClass("loading")}else{$("#TB_window .detail.second").addClass("loading")}if(srawby_selector_compare_currRequest[index]){srawby_selector_compare_currRequest[index].abort();srawby_selector_compare_currRequest[index]=false}srawby_selector_compare_currRequest[index]=$.get("/product/selector/options/"+gunType+"/comparison",{model:prodId},function(data,textStatus){if(textStatus=="success"){var description=eval(data);var rowMap=srawby_selector_table_rowMap;var prodId=select.options[select.selectedIndex].value;var tr=$('#selectorTable table.product-placeholder tr:has(input[value="'+prodId+'"])');var nid=$("input.nid",tr).val();if(description==null||description==""){description="Details about "+$("td:eq(0)",tr).text()+" Coming Soon!"}var detail;var detail2;var detailf;var detail2f;var detail3;if(index==0){detail=$("#selector-compare .body .detail.first");detail2=$("#TB_window .detail.body .detail.first");detailf=$("#selector-compare .footer .detail.first");detail2f=$("#TB_window .detail.footer .detail.first");detail3=$("#TB_window .detail.first")}else{detail=$("#selector-compare .body .detail.second");detail2=$("#TB_window .detail.body .detail.second");detailf=$("#selector-compare .footer .detail.second");detail2f=$("#TB_window .detail.footer .detail.second");detail3=$("#TB_window .detail.second")}var price=$("td.price",tr).text();var image=$("td.product input.image",tr).val();var node_url=$("td.product input.node_url",tr).val();image=srawby_getImageTag(image);$(".image",detail).empty().append(image);$(".description",detail).empty().append(description);$(".price span",detailf).empty().append(price);$(".details",detailf).attr("href",node_url);$(".image",detail2).empty().append(image);$(".description",detail2).empty().append(description);$(".price span",detail2f).empty().append(price);$(".details",detail2f).attr("href",node_url);detail3.removeClass("loading")}})}function srawby_selector_ready(){var A="";srawby_selector_tabs(0,true);$("form.products-selector-select").addClass("alt-form").jNice({selectOffset:"4"});$("#selector-tabs li a").click(function(){A=$("#selector-tabs li a").index(this);srawby_selector_tabs(A);return false});$("#selector-tabs a.next").click(function(){if(!$(this).is(".nextDisabled")){srawby_selector_tabs("next")}return false});$("#selector-tabs a.previous").click(function(){if(!$(this).is(".prevDisabled")){srawby_selector_tabs("previous")}return false});$(".productSelector_warning input:checkbox").change(function(){$("#productSelector_dontShow_val").val(this.checked)});$("#productSelector_unavailableStep_warning .productSelector_warning .button, #productSelector_compare_warning .productSelector_warning .button").unbind("click").click(function(){tb_remove();return false});srawby_selector_update_checkboxes();$("#edit-caliber-sort").change(srawby_selector_caliber_dropdown);$("#productSelector .compareFooter").hide();$("#productSelector_reset").unbind("click").click(function(){srawby_thickbox_static_show("","height=110&width=350&modal=true&inlineId=productSelector_reset_warning");return false});$("#productSelector_reset_warning .button.ok").unbind("click").click(function(){tb_remove();window.location.reload();return false});$("#productSelector_reset_warning .button.cancel").unbind("click").click(function(){tb_remove();return false});$("div.compareFooter .compareSelected").unbind("click").click(function(){srawby_selector_compare();return false});$("#selector-compare .close").unbind("click").click(function(){tb_remove();setTimeout("$('#TB_ajaxContent').css('padding', '')",500);return false})}$(document).ready(function(){srawby_selector_ready()});