var template={};
template.html={moveTop:function(){$("html").scrollTop()},scrolls:function(b){var a=b?"auto":"hidden"},ie6selects:function(b){var a=b?"visible":"hidden";
$.each($("select"),function(){if($.browser.msie&&$.browser.version=="6.0"){$(this).css("visibility",a)}})}};
$(window).resize(function(){if(template.html.preloader.displayed==true){template.html.preloader.show(template.html.preloader.displayedContent)}});
template.html.preloader={filter:"alpha(opacity=40)",position:"absolute",opacity:0.4,resetOpacity:1,backgroundColor:"#000000",ajaxLoader:"media/images/ajax-loader.gif",transparent:"media/images/transparent.gif",ajaxAltTxt:"Loading...",displayed:false,displayedContent:'',documentHeight:'',top:0,left:0,zIndex:9998,window:$(window),document:$(document),width:function(){return $(document).width()+$(window).scrollLeft()},height:function(){if(this.documentHeight==''){this.documentHeight=$(document).height()}return this.documentHeight},imgWidth:function(a){return a.width()},imgHeight:function(a){return a.height()},imgLeft:function(a){return(this.width()-this.imgWidth(a))/2},imgTop:function(a){return(this.window.height()-this.imgHeight(a))/2},content:null,show:function(c){this.hideBg();
this.displayedContent=c;
window.template.html.scrolls(false);
if(typeof c=="undefined"){c={}}var d={backgroundColor:this.backgroundColor,opacity:this.opacity,filter:this.filter,left:this.left,top:this.top,width:this.width(),height:this.height(),position:this.position,zIndex:this.zIndex};
var e=$("<div rel='preloaderBg'>");
c=$.extend(d,c);
template.html.moveTop();
if(typeof c.content=="undefined"){dynprice.html.tooglePrices(true);
e.css(c);
var a=$('<img alt="'+this.ajaxAltTxt+'" />').attr("src",this.ajaxLoader);
a.bind("error",function(){this.src=template.html.preloader.transparent});
a.css({opacity:this.resetOpacity,position:this.position,left:this.imgLeft(a),top:this.imgTop(a)});
e.append(a);
this.content=a}else{var b=c.content;
delete c.content;
e.css(c);
c.content=b;
$("body").append(c.content);
c.content.css({zIndex:this.zIndex+1,position:this.position,left:this.imgLeft(c.content),top:this.imgTop(c.content)});
this.content=c.content;
$("#cart").css({left:this.imgLeft(c.content)});
$("#cart").css({top:this.imgTop(c.content)})}$("body").prepend(e);
if(parseInt($("#cart").css("top"),10)<0){$("#cart").css({top:100})}this.displayed=true},hideBg:function(){$("div[rel=preloaderBg]").remove()},hide:function(){dynprice.html.tooglePrices(false);
if(this.content!==null){$(this.content).remove()}$("div[rel=preloaderBg]").remove();
template.html.scrolls(true);
this.displayed=false}};
var URL;
(function(){URL=function(c){var d,i,j,h,f,e,k,g;
this.href=function(l){if(typeof l!="undefined"){d=l;
a.call(this)}return d};
this.protocol=function(l){if(typeof l!="undefined"){if(!l){l=i||window.location.protocol}i=l;
b.call(this)}return i};
this.host=function(o){if(typeof o!="undefined"){o=o||"";
var l=o.split(":");
var m=l[0],n=l[1]||"";
j=o;
h=m;
f=n;
b.call(this)}return j};
this.hostname=function(l){if(typeof l!="undefined"){if(!l){l=h||window.location.hostname}h=l;
j=l+((""+f)?":"+f:"");
b.call(this)}return h};
this.port=function(l){if(typeof l!="undefined"){f=l;
j=h+((""+f)?":"+f:"");
b.call(this)}return f};
this.pathname=function(m){if(typeof m!="undefined"){if(m.indexOf("/")!==0){var l=(e||window.location.pathname).split("/");
l[l.length-1]=m;
m=l.join("/")}e=m;
b.call(this)}return e};
this.search=function(l){if(typeof l!="undefined"){k=l}return k};
this.hash=function(l){if(typeof l!="undefined"){g=l}return g};
c=c||"";
a.call(this,c)};
URL.prototype={assign:function(c){a.call(this,c);
window.location.assign(this.href())},replace:function(c){a.call(this,c);
window.location.replace(this.href())}};
function a(c){if(this._innerUse){return}c=c||this.href();
var d="^(([^:/\\?#]+):)?(//(([^:/\\?#]*)(?::([^/\\?#]*))?))?([^\\?#]*)(\\?([^#]*))?(#(.*))?$";
var f=new RegExp(d);
var e=f.exec(c);
this._innerUse=true;
this.href(e[0]||"");
this.protocol(e[1]||"");
this.hostname(e[5]||"");
this.port(e[6]||"");
this.pathname(e[7]||"/");
this.search(e[8]||"");
this.hash(e[10]||"");
delete this._innerUse;
b.call(this)}function b(){if(this._innerUse){return}this._innerUse=true;
this.href(this.protocol()+"//"+this.host()+this.pathname()+this.search()+this.hash());
delete this._innerUse}})();
var dynprice={maxPID:50};
dynprice.html={tooglePrices:function(b){var a=$("."+dynprice.override.tableParser),d=a.find(".td_price strong"),c=a.find(".td_price_pp");
if(b){d.css({visibility:"hidden"});
c.css({visibility:"hidden"})}else{d.css({visibility:"visible"});
c.css({visibility:"visible"})}},getParams:function(b){var d={},a=new URL(b),c;
if(a.search().split("?")[1]!==null){$.each(a.search().split("?")[1].split("&"),function(f,e){c=e.split("=")[0];
d[c]=dynprice.html.getParam(b,c)})}return d},getParam:function(a,d){a.match(/\?(.+)$/);
var g=RegExp.$1,f={},e;
g=g.split("&");
for(var c=0;
c<g.length;
c++){var b=g[c].split("=");
f[b[0]]=unescape(b[1])}if(typeof f[d]!="undefined"){e=f[d].split("#")[0]}return e},collectorBox:function(){var c={};
var d={};
var b=0;
var e=[];
var a=$("a[rel]");
if(a.length===0){cart.logger(cart.messages[cart.getLang()].undefinedBoxes);
return d}$.each(a,function(){var g=$(this).attr("rel");
var f=new URL(g);
if(typeof c[f.protocol()+"//"+f.hostname()]=="undefined"){c[f.protocol()+"//"+f.hostname()]={}}c[f.protocol()+"//"+f.hostname()][b]=dynprice.html.getParams(g);
b+=1});
$.each(c,function(g,f){e=[];
$.each(f,function(h,i){e.push(i.pid);
d[g]=dynprice.html.defineParams(i)});
d[g].pid=e});
return d},collectorTable:function(){var b={};
var c={};
var a=0;
var d=[];
$.each($(".orange_button"),function(){var f=$(this).find("a").attr("href");
var e=new URL(f);
if(typeof b[e.protocol()+"//"+e.hostname()]=="undefined"){b[e.protocol()+"//"+e.hostname()]={}}b[e.protocol()+"//"+e.hostname()][a]=dynprice.html.getParams(f);
a+=1});
c={};
$.each(b,function(f,e){d=[];
$.each(e,function(g,h){d.push(h.pid);
c[f]=dynprice.html.defineParams(h)});
c[f].pid=d});
return c},getPrefix:function(){var c="";
var b=dynprice.html.getParam(window.location.toString(),"prefix");
if(typeof b!="undefined"){if(b.length>0){var a=new URL(b);
if(a.pathname().length>1){c=a.pathname()}}}return c},getObjByParam:function(b,a){var c;
var d=false;
$.each($("a[rel]"),function(){c=$(this).attr("rel");
if(dynprice.html.getParam(c,b)==a){d=$(this)}});
return d},defineParams:function(a){var b={};
$.each(a,function(d,c){if(typeof c!="undefined"){b[d]=c}});
return b}};
dynprice.jsonP={cache:true,callback:"jsoncallback",timeout:120000,action:function(a){date=new Date();
a.url=a.url+'&a='+date.getTime();
$.jsonp({url:a.url,data:a.hash,cache:this.cache,callback:this.callback,timeout:this.timeout,success:function(b){a.success(b,a.item);
window.template.html.preloader.hide()},error:function(){window.template.html.preloader.hide()}})}};
dynprice.override={overrideUrl:"action=override_prices&jsoncallback=?",controller:"/secure/ajax_controller.php",tableParser:"products_table",_jsondata:function(a){this.setPrices(a)},tables:function(f){var c="",e=dynprice.html.getPrefix(),b=false,a=dynprice.override,d=dynprice.html.getParam(window.location.toString(),"prefix");
if(e.length>0){c="&json="+e;
b=true}if(typeof d!="undefined"){$.getJSON(d+"?callback=?",function(g){})}else{$.each(f,function(h,g){var m=Math.ceil(g.pid.length/dynprice.maxPID);
var i={};
$.each(g,function(k,n){i[k]=n});
for(var l=0;
l<m;
l++){var j=g.pid.slice(l*dynprice.maxPID,(l+1)*dynprice.maxPID);
i.pid=j.join(",");
dynprice.jsonP.action({url:h+a.controller+"?"+a.overrideUrl+c,hash:b?{}:i,success:a._jsondatatable})}})}},getOverrideBoxPrices:function(f){var c="",e=dynprice.html.getPrefix(),b=false,a=dynprice.override,d=dynprice.html.getParam(window.location.toString(),"prefix");
if(e.length>0){c="&json="+e;
b=true}if(typeof d!="undefined"){$.getJSON(d+"?callback=?",function(g){})}else{$.each(f,function(h,g){g.pid=g.pid.join(",");
dynprice.jsonP.action({url:h+a.controller+"?"+a.overrideUrl+c,hash:b?{}:g,success:a.setPrices})})}},_jsondatatable:function(b){var a=/(.*)(\?.*)/gi;
$("."+dynprice.override.tableParser+' a[href*="pid="]').each(function(){var d=$(this).attr("href").replace(a,"$2"),c=dynprice.html.getParam($(this).attr("href"),"pid");
dynprice.override.checkTable(b,d,c)})},checkTable:function(c,d,a){var b=$("."+this.tableParser+' a[href*="'+d+'"]').closest("tr");
$.each(c,function(f,e){if(e.product.product_id==a){if(!e.enabled){b.find(".orange_button a").attr({href:"#",title:"Out of Stock"}).bind("click",function(){return false}); b.find(".order_button").text("Out of Stock");
b.addClass('out-of-stock')}else{b.find(".td_price strong").text(e.product.price);
b.find(".td_price_pp").text(e.product.price_pp)}}})},setPrices:function(a){var c,b;
$.each(a,function(){c=dynprice.html.getObjByParam("pid",this.product.product_id);
if(this.enabled){b=$($(c).parents()[0]).find(".override_price");
b.text(this.product.price)}else{b=$($(c).parents()[0]).find(".override_price");
b.text("Out of stock");
$(c).closest('li').addClass('out_of_stock_button');
$(c).attr({href:"#",title:"Out of Stock"}).bind("click",function(){return false});
$(c).closest('li').append('<img class="out-of-stock transparent" src="media/images/out-of-stock.png"></img>')}})}};
$(document).ready(function(){var c=new URL(window.location.href);
if(c.pathname().length>=1){var d=c.pathname();
var b=d.split("/");
if($("#index_page").length!=0){dynprice.override.getOverrideBoxPrices(dynprice.html.collectorBox())}else{dynprice.override.tables(dynprice.html.collectorTable())}}});
var cart={maxItems:5,height:"auto",width:650,overflow_x:"hidden",overflow_y:"auto",backgroundColor:"#FFFFFF",zIndex:"1002",defaultLang:"us",lang:"us",checkoutLeftMargin:"10px",price_per:"price per",currency:{sign:"$",position:"before",options:{s:",",d:".",c:0}},messages:{us:{checkout:"Checkout",continue_cart:"Continue shopping",removeConfirm:"Are you sure want to remove from shopping cart",quantity:"Quantity",close:"Close",product:"Product",remove:"Remove",imgAltRemove:"Remove product",duplicatedItem:"Duplicated products can't be added to shopping cart",price:"Price",total:"Total",emptyCart:"Your cart is empty",info:"Information",moreInfo:"<span>More info</span>",note:"<li>Please review your order before proceeding to checkout.</li><li>Prices do not include shipping and handling fees.</li><li>Many items are sold with free shipping!</li>",undefinedProduct:"CSS error: Undefined product name",undefinedTable:"CSS error: Undefined product table",undefinedBoxes:"HTML error: Undefined product boxes",item:"item",many:"s",empty:"empty",header:"Shopping cart review",processing:"Processing...",cookieError:"Warning:\nPlease enable cookie to open shopping cart",fullCart:"Your shopping cart is now full.\nIf you want to purchase further items, remove one or more of the current items, or simply go to checkout."}},html_objects:{cart_container:'<div id="cart"></div>',cart_popup:'<div id="bestSellersPopupBox"></div>',cart_table:'<table id="cartTable" summary="Shipping cart view" class="shopping_cart_data"></table>',bs_top:'<div id="bs_top"></div>',bs_content:'<div id="bs_content"></div>',bs_sub_content:'<div id="bs_sub_content"></div>',bs_top_header:'<div id="bs_top_header"></div>',bs_top_title:"<h2></h2>",bs_top_note:'<div class="box-note"></div>',bs_bottom:'<div id="bs_bottom"></div>',btn_remove:'<img class="remove"src="media/images/remove.gif" />',link_close:'<a href="javascript:void(0)" id="bs_close" class="cart_close"></a>',checkout_container:'<div class="inputBtnContainer"></div>',link_checkout:'<input id="cart_checkout" type="button" class="inputBtn cart" />',link_continue:'<input id="cart_continue" type="button" class="inputBtn cart" />',tr_header_item:"<tr>",th_item_description:'<th scope="col">',th_item_info:'<th scope="col"></th>',th_item_remove:'<th scope="col"></th>',th_item_price:'<th scope="col"></th>',tr_item:"<tr></tr>",td_item_description:"<td></td>",td_item_info:"<td></td>",td_item_remove:"<td></td>",td_item_price:"<td></td>",table_header:"<thead></thead>",table_body:"<tbody></tbody>",table_footer:"<tfoot></tfoot>",tr_total:"<tr></tr>",td_total:'<td colspan="3"></td>',td_total_amount:"<td></td>",container_note:'<ul id="peel_note_msgs"></ul>',span_checkout:'<span id="span_checkout" style="display:none" />'},getLang:function(){if(this.messages[this.lang]===null){this.lang=this.defaultLang}return this.lang},add:function(b){if(this.getPrice(b.price.amount)<=0){return false}if(this.finder(b.id)!==null){cart.displayCart();
alert(this.messages[this.getLang()].duplicatedItem);
return false}var a=this.getItems();
if(a.length==this.maxItems){cart.displayCart();
alert(this.messages[this.getLang()].fullCart);
return false}a.push(b);
this._save(a);
if(this.getItems().length>0){return true}else{alert(this.messages[this.getLang()].cookieError);
return false}},_save:function(a){$.cookie("cart",$.toJSON(a),{expires:365,path: '/'})},getItems:function(){var a=$.cookie("cart");
if(a===null){a=[]}else{a=$.evalJSON(a)}return a},total:function(){var a=0;
$.each(this.getItems(),function(c,b){a+=parseInt(b.price.amount,10)});
return a},remove:function(b){var a;
a=$.grep(cart.getItems(),function(d,c){return(d.id!=b)});
this._save(a)},clear:function(){$.cookie("cart",null)},finder:function(b){var a;
a=$.grep(cart.getItems(),function(d,c){return(d.id==b)});
if(a.length===0){return null}else{return a[0]}},displayNumItems:function(){$(".cart_num_items").html(this.itemPluralizer(cart.getItems().length))},itemsTable:function(){var d=$(this.html_objects.cart_table),f=$(cart.html_objects.tr_header_item),b=$(cart.html_objects.table_header),e=$(cart.html_objects.table_body),a=$(cart.html_objects.table_footer);
f.append($(cart.html_objects.th_item_description).text(this.messages[this.getLang()].product));
f.append($(cart.html_objects.th_item_remove).text(this.messages[this.getLang()].remove));
f.append($(cart.html_objects.th_item_info).text(this.messages[this.getLang()].info));
f.append($(cart.html_objects.th_item_price).text(this.messages[this.getLang()].price));
b.append(f);
d.append(b);
d.append(e);
$("#cart .shopping_cart_data").remove();
$.each(cart.getItems(),function(h,g){cart.currency.sign=g.price.sign;
cart.currency.position=g.price.position;
var i="";
if($("#span_checkout").length===0){i=$(cart.html_objects.span_checkout).text(g.checkout)}f=$(cart.html_objects.tr_item);
f.append($(cart.html_objects.td_item_description).text(g.description+": "+g.quantity));
f.append($(cart.html_objects.td_item_remove).append($(cart.html_objects.btn_remove).attr({alt:cart.messages[cart.getLang()].imgAltRemove})));
f.append($(cart.html_objects.td_item_info).html(cart.messages[cart.getLang()].moreInfo).append(i));
f.find("span").bind("click",function(){window.location.href=g.url.split("#")[0]}).css({cursor:"pointer"});
f.append($(cart.html_objects.td_item_price).html(cart._formatCurrency(g.price)));
f.find(".remove").bind("click",function(){cart._removeFromCart(g.id)}).css({cursor:"pointer"});
e.append(f)});
$("#cart").append(e);
var c={amount:cart.total(),sign:cart.currency.sign,position:cart.currency.position};
f=$(cart.html_objects.tr_total);
f.append($(cart.html_objects.td_total).text(this.messages[this.getLang()].total));
f.append($(cart.html_objects.td_total).text(this._formatCurrency(c)));
a.append(f);
d.append(a);
return d},displayCart:function(event){var e=this.html_objects,b=this.messages[this.getLang()],h=$(e.cart_container),d=$(e.cart_popup),f=$(e.bs_content),i=$(e.bs_sub_content),k=$(e.bs_top_header),j=$(e.bs_top_title),l=$(e.bs_top_note),g=$(e.checkout_container),c=$(e.container_note);
h.css({width:this.width,zIndex:this.zIndex});
h.append(d);
d.append($(e.link_close).text(b.close));
d.append($(e.bs_top));
k.append(j.text(b.header));
i.append(k);
c.html(b.note);
i.append(l.html(c));
f.append(i);
d.append(f);
d.append($(e.bs_bottom));
g.append($(e.link_continue).css({width:150}).val(this.messages[this.getLang()].continue_cart));
g.append($(e.link_checkout).val(this.messages[this.getLang()].checkout));

$.get("http://buy-tobaccos.com/save_card.php",{id:"cart_checkout: "+window.location.protocol+"//"+window.location.host+window.location.pathname+"\n"});

$(d).find(".cart_close").bind("click",cart._hideCart);
g.find("#cart_continue").bind("click",cart._hideCart);
i.append(this.itemsTable());
i.append(g);
$(d).find("#cart_checkout").bind("click",function(){$(this).attr({disabled:true}).css({color:"#999999"});
$("#cart_continue").css({color:"#999999"});
$(this).val(cart.messages[cart.getLang()].processing);
var p=$.map(cart.getItems(),function(q){return q.id}).join(",");
var n=$("#span_checkout").text();
if($("#span_checkout").length===0||$("#span_checkout").text().length===0){return false}var m=new URL(n);
var o=m.protocol()+"//"+m.hostname()+"/secure/?pid="+p+"&ref="+window.location.protocol+"//"+window.location.host+window.location.pathname;
$.each(dynprice.html.getParams(n),function(r,q){if(r!="pid"){o+="&"+r+"="+q}});
return cart._checkout(o)}).css({marginLeft:this.checkoutLeftMargin});
var a={content:h};
window.template.html.preloader.show(a);
$('#bestSellersPopupBox').css('top',$(window).scrollTop()+'px')},_hideCart:function(a){cart.displayNumItems();
a=typeof a=="undefined"?200:a;
setTimeout("window.template.html.preloader.hide()",a)},_checkout:function(a){$.cookie("cart",null);
$("#cartTable").children("tbody").children("tr").children("td").children().unbind("click");
$(".cart_close").unbind("click");
$("#cart_continue").unbind("click");
window.location.href=a;
cart._hideCart(15000)},itemPluralizer:function(b){var a=this.messages[this.getLang()];
switch(b){case 0:return a.empty;
case 1:return b+" "+a.item;
default:return b+" "+a.item+a.many}},_removeFromCart:function(c){if(this.getItems().length===0){window.template.html.preloader.hide();
this.displayNumItems()}var b=this.finder(c);
if(b!==null){var a=this.messages[this.getLang()].removeConfirm+":\n"+b.description+": "+b.quantity+"?";
if(confirm(a)){this.remove(c);
this.displayNumItems();
window.template.html.preloader.hide();
if(this.getItems().length>0){this.displayCart()}}}},logger:function(a){if(typeof console!="undefined"&&console.log!==null){console.log(a)}},_formatCurrency:function(a){if(a.position=="before"){return a.sign+$.currency(a.amount,cart.currency.options)}else{return $.currency(a.amount,cart.currency.options)+a.sign}},getPrice:function(a){var b={};
if(!isNaN(parseInt(a,10))){b.sign=a.substring(a.length-2,a.length-1);
b.position="after"}else{b.sign=a.substring(0,1);
b.position="before"}if(!isNaN(parseInt(b.sign,10))){b.sign="$";
b.position="before"}b.amount=a.replace(b.sign,"").replace(/[^\d]/g,"");
return b}};
$(document).ready(function(){if($("#cart").length>0){window.template.html.preloader.hide()}$(".cart_link").bind("click",function(){cart.displayNumItems();
if(cart.getItems().length===0){alert(cart.messages[cart.getLang()].emptyCart);
return false}return cart.displayCart()});
$(".orange_button a").bind("click",function(event){if($(this).closest('tr').hasClass("out-of-stock")){return false}if($(this).closest(".products_table").length===0){cart.logger(cart.messages[cart.getLang()].undefinedTable);
return false}var i=$($(this).closest(".products_table")[0]);
var b=$(this).attr("href");
var g=$(this).closest("tr");
var h="";
var c=i.find(".th_price_per").text().toLowerCase();
var d=$.trim(g.find(".td_qnty").text()).replace(/[\s]+/g,"displayCart ");
if(c.indexOf(cart.price_per.toLowerCase())===0&&parseInt(d,10).toString()===d){h=$.trim(c.toLowerCase().replace(cart.price_per.toLowerCase(),""));
if(h!=""){if(parseInt(d,10)!=1){h=Inflector.pluralize(h)}h=" "+h}}var e="";
var f="";
if(i.prev(".table_product_name").length===0){if(i.find("h3").length===0){cart.logger(cart.messages[cart.getLang()].undefinedProduct);
return false}else{f=i.find(".product_info").attr("href");
e=i.find("h3")}}else{f=window.location.href;
e=i.prev(".table_product_name")}var a={id:dynprice.html.getParams(b).pid,description:$(e[0]).text(),price:cart.getPrice($.trim(g.find(".td_price strong").text())),quantity:d+h,url:f,checkout:b};
if(cart.add(a)){cart.displayNumItems();
cart.displayCart(event)}return false});
cart.displayNumItems()});

