
$.noConflict(true)(function($)
{var styleConfig=$('input[name^="code["]:visible'),ftd=$(document),stylePreview=$('span[name=previewusername]'),previewUsername=$('span[name=previewusername]:first').text();ftd.on('click','input[name=shoploader]',function()
{var shopid=$(this).attr('data-shopid');if(vBShop.shopid!=shopid)
{animateBox(vbphrase['dbtech_vbshop_switching_shop'],vbphrase['dbtech_vbshop_switching_shop_descr'],true);refreshShop(shopid);}});ftd.on('click','a[name=default]',itemSort);ftd.on('click','a[name=title]',itemSort);ftd.on('click','a[name=popularity]',itemSort);ftd.on('click','a[name=price]',itemSort);ftd.on('change','select[name=perpage]',function()
{animateBox(vbphrase['dbtech_vbshop_sorting_items'],vbphrase['dbtech_vbshop_sorting_items_descr'],true);vBShop.perpage=$(this).val();refreshShop(vBShop.shopid,true,true);});ftd.on('click','input[name=purchase]',function()
{animateBox(vbphrase['dbtech_vbshop_buying_item'],vbphrase['dbtech_vbshop_buying_item_descr'],true);var extraParams={'securitytoken':SECURITYTOKEN,'do':'ajax','action':'addtocart','isajax':'1','shopid':vBShop.shopid,'itemid':$(this).attr('data-itemid')};var type='POST';var jqxhr=$.ajax({type:type,url:'vbshop.php',data:(SESSIONURL?SESSIONURL+'&':'')+$.param(extraParams),dataType:'json'}).done(function(data)
{if(typeof data=='string')
{try
{data=$.parseJSON(data);}
catch(e)
{var errmsg=data;data={'error':errmsg+"\n\n"+data};}}
if(data.success)
{refreshShop(vBShop.shopid,true,true);}});});ftd.on('click','a[name="shoptab"]',function(e)
{e.preventDefault();var thisTab=$(this),tabList=thisTab.parent().parent().children('dd'),currentTab;tabList.each(function(index,element)
{if($(element).hasClass('selected'))
{currentTab=$(element).children('a').attr('data-tabid');return true;}});if(thisTab.attr('data-tabid')==currentTab)
{return true;}
$('a[name="shoptab"][data-tabid="'+currentTab+'"]').parent().removeClass('selected');$('div[name="shopview"][data-tabid="'+currentTab+'"]').fadeOut('fast')
currentTab=thisTab.attr('data-tabid');thisTab.parent().addClass('selected');$('div[name="shopview"][data-tabid="'+currentTab+'"]').fadeIn('fast');});ftd.on('mouseenter','span[name="itemloader"]',function(e)
{$('div[name="itempopup"][data-itemid="'+$(this).attr('data-itemid')+'"]').show();}).on('mouseleave','span[name="itemloader"]',function(e)
{$('div[name="itempopup"][data-itemid="'+$(this).attr('data-itemid')+'"]').hide();}).on('mousemove','span[name="itemloader"]',function(e)
{$('div[name="itempopup"][data-itemid="'+$(this).attr('data-itemid')+'"]').css({'top':e.pageY+10,'left':e.pageX-150});});ftd.on('mouseenter','span[name="shoploader"]',function(e)
{$('div[name="shoppopup"][data-shopid="'+$(this).attr('data-shopid')+'"]').show();}).on('mouseleave','span[name="shoploader"]',function(e)
{$('div[name="shoppopup"][data-shopid="'+$(this).attr('data-shopid')+'"]').hide();}).on('mousemove','span[name="shoploader"]',function(e)
{$('div[name="shoppopup"][data-shopid="'+$(this).attr('data-shopid')+'"]').css({'top':e.pageY+10,'left':e.pageX-150});});ftd.on('keyup','input[name^="cart["]',cleanCartInput);ftd.on('click','[name=removeitem]',removeItem);styleConfig.on('keyup keydown change',updatePreview);$('input[name^="cart["]').keypress(function(e)
{if(e.which==13)
{updateCart();e.preventDefault();}});updatePreview();function cleanCartInput()
{var thisInput=$(this);switch(thisInput.attr('data-inputtype'))
{case'quantity':case'discountpoints':thisInput.val(thisInput.val().replace(/[^\d.]/g,''));break;case'couponcode':thisInput.val(thisInput.val().replace(/[^\w.]/g,''));break;}};function removeItem(e)
{var button=$(this),itemid=button.attr('data-itemid'),shopid=button.attr('data-shopid'),cartObj=$('input[name="cart['+shopid+']['+itemid+'][quantity]"]');if(!cartObj)
{return false;}
cartObj.val('0');updateCart();};function updateCart()
{var button=$('#updatecart'),inputElems=$("input[name^='cart[']");if(!inputElems)
{return false;}
cleanCartInput();animateBox(vbphrase['dbtech_vbshop_updating_cart'],vbphrase['dbtech_vbshop_updating_cart_descr'],true);var extraParams={'securitytoken':SECURITYTOKEN,'do':'ajax','action':'updatecart',};var type='POST';var jqxhr=$.ajax({type:type,url:'vbshop.php',data:(SESSIONURL?SESSIONURL+'&':'')+$.param(extraParams)+'&'+inputElems.serialize()}).done(function(data)
{data=$(data);if(data.find('error').length)
{animateBox(vbphrase['error'],data.find('error').text(),true);}
else
{animateBox(false,false,false);}
if(parseInt(data.find('redirect').text()))
{window.location='vbshop.php?'+SESSIONURL+'do=shop';}
$('#cartcontents').html(data.find('cartcontents').text());});};function itemSort(e)
{animateBox(vbphrase['dbtech_vbshop_sorting_items'],vbphrase['dbtech_vbshop_sorting_items_descr'],true);var clickedLink=$(this);if(vBShop.sorttype==clickedLink.attr('name'))
{vBShop.sortorder=(vBShop.sortorder=='asc'?'desc':'asc');}
else
{vBShop.sorttype=clickedLink.attr('name');vBShop.sortorder='asc';}
refreshShop(vBShop.shopid,true);}
function refreshShop(shopid,refreshSame,noPage)
{var extraParams={};extraParams['do']='shop';extraParams['action']='shop';extraParams['isajax']='1';extraParams['shopid']=shopid;extraParams['perpage']=vBShop.perpage;extraParams['sorttype']=vBShop.sorttype;extraParams['sortorder']=vBShop.sortorder;if(refreshSame)
{extraParams['tab']=vBShop.tab;if(!noPage)
{extraParams['pagenumber']=vBShop.pagenumber;}}
var type='GET';var jqxhr=$.ajax({type:type,url:'vbshop.php',data:(SESSIONURL?SESSIONURL+'&':'')+$.param(extraParams)}).done(function(data)
{var arr=['shopname'];for(var i in arr)
{$('#'+arr[i]).text($(data).find(arr[i]).text());}
var arr=['shopcontent','cartitems','totalprice'];for(var i in arr)
{$('#'+arr[i]).html($(data).find(arr[i]).text());}
vBShop.shopid=shopid;animateBox(false,false,false);});}
function animateBox(title,description,onoff)
{var box=$('#ajaxprogress');if(onoff)
{box.css('display','inline-block');box.css('opacity',0);}
if(title)
{$('#progresstitle').html(title);}
if(description)
{$('#progresscontent').html(description);}
box.animate({opacity:(onoff?0.8:0)},{duration:700,complete:function()
{if(!onoff)
{$(this).fadeOut('fast');}}});}
function updatePreview(e)
{var openTag='';var closeTag='';var configOptions=new Array();styleConfig.each(function(index)
{var self=$(this),cb=self.is(':checkbox'),chk=self.is(':checked'),val=self.val(),inputName=self.attr('name').replace('code[','').replace(']','');if(cb)
{configOptions[inputName]=chk;}
else
{if(inputName!='url'&&inputName!='smilieurl')
{val=val.replace(/[^A-Za-z0-9 #():,]/g,'');self.val(val);}
configOptions[inputName]=val;}});if(configOptions['bold'])
{openTag+='font-weight:bold; ';}
if(configOptions['italic'])
{openTag+='font-style:italic; ';}
if(configOptions['underline'])
{openTag+='text-decoration:underline; ';}
if(configOptions['color'])
{openTag+='color:'+configOptions['color']+'; ';}
if(configOptions['glow_onoff'])
{openTag+='text-shadow: 0px 0px 0.2em '+configOptions['glow']+', 0px 0px 0.2em '+configOptions['glow']+', 0px 0px 0.2em '+configOptions['glow']+'; ';}
if(configOptions['shadow_onoff'])
{openTag+='text-shadow:2px 2px 4px '+configOptions['shadow']+'; ';}
if(openTag)
{openTag='<span style="'+openTag+'">';closeTag='</span>';}
stylePreview.html(openTag+previewUsername+closeTag);}});YAHOO.util.Event.onDOMReady(function()
{if(YAHOO.util.Dom.get('sidebar'))
{var scroll_offset=YAHOO.util.Dom.get('sidebar').offsetTop;YAHOO.util.Dom.setStyle('sidebar','width',YAHOO.util.Dom.getStyle('sidebar_container','width'));YAHOO.util.Event.addListener(window,'scroll',function()
{var scroll_top=YAHOO.util.Dom.getDocumentScrollTop();if(scroll_top+YAHOO.util.Dom.get('sidebar').offsetHeight<YAHOO.util.Dom.get('content').offsetHeight&&scroll_top>scroll_offset)
{YAHOO.util.Dom.setStyle('sidebar','position','fixed');YAHOO.util.Dom.setStyle('sidebar','marginTop','-'+scroll_offset+'px');}
else if(scroll_top>scroll_offset)
{YAHOO.util.Dom.setStyle('sidebar','position','');YAHOO.util.Dom.setStyle('sidebar','marginTop',((YAHOO.util.Dom.get('content').offsetHeight-YAHOO.util.Dom.get('sidebar').offsetHeight)>0?(YAHOO.util.Dom.get('content').offsetHeight-YAHOO.util.Dom.get('sidebar').offsetHeight):0)+'px');}
else if(scroll_top<scroll_offset)
{YAHOO.util.Dom.setStyle('sidebar','position','');YAHOO.util.Dom.setStyle('sidebar','marginTop','0px');}});}});