var Sharis=new function()
{this.init=function()
{var self=Sharis;self.initForms();var page=$('body').attr('id');switch(page)
{case'home':self.initFeaturedSlider();self.initPieSlider();self.initColorbox();break;case'menu':self.initColorbox();self.initSubmenu();break;case'litestyles':self.initSubmenu();break;case'honored':case'giftcards':self.initBalanceCheckForm();break;case'takeout':case'feedback':self.initLocationSelectForm();break;case'company':case'pressrelease':case'press':self.initSubmenu();break;case'piegram':self.initDatepicker();break;}}
this.initForms=function()
{var ZIPCODE_DEFAULT_TEXT='enter zipcode...';var DIRECTIONS_DEFAULT_TEXT='start address or zipcode...';var _zipcode=$('#address');var _directions=$('#startaddress');_zipcode.focus(function()
{if(_zipcode.val()==ZIPCODE_DEFAULT_TEXT)
{_zipcode.val('');}});_zipcode.blur(function()
{if(_zipcode[0].value.replace(/\s+/,'')=='')
{_zipcode.val(ZIPCODE_DEFAULT_TEXT)}});if(_directions.size())
{_directions.focus(function()
{if(_directions.val()==DIRECTIONS_DEFAULT_TEXT)
{_directions.val('');}});_directions.blur(function()
{if(_directions[0].value.replace(/\s+/,'')=='')
{_directions.val(DIRECTIONS_DEFAULT_TEXT)}});}}
this.initFeaturedSlider=function()
{var options={effect:'random',slices:15,animSpeed:500,pauseTime:6000,startSlide:0,directionNav:true,directionNavHide:true,keyboardNav:true,pauseOnHover:true,controlNav:true};$('#slider').nivoSlider(options);}
this.initPieSlider=function()
{$('#slider-prev').click(function()
{var pieList=$('#pieslider ul');if(pieList.is(':animated')){return false;}
var scrollAmount=pieList.parent().width()+5;var maxScrollPos=pieList.width()-scrollAmount;var curScrollPos=Math.abs(pieList.position().left-30);if(scrollAmount<maxScrollPos-curScrollPos)
{pieList.animate({'left':'-='+scrollAmount},'slow');}
else if(maxScrollPos-curScrollPos!=0)
{pieList.animate({'left':'-='+(maxScrollPos-curScrollPos)},'slow');}
else
{pieList.animate({'left':0},'slow');}
return false;});$('#slider-next').click(function()
{var pieList=$('#pieslider ul');if(pieList.is(':animated')){return false;}
var scrollAmount=pieList.parent().width()+5;var curScrollPos=Math.abs(pieList.position().left-30);if(curScrollPos>=scrollAmount)
{pieList.animate({'left':'+='+scrollAmount},'slow');}
else if(curScrollPos<scrollAmount)
{pieList.animate({'left':'+='+curScrollPos},'slow');}
return false;});$('#pieslider li').hover(function()
{var tooltip=$(this).find('img').attr('alt');var parentPos=$(this).parent().position().left;var parentOffset=parseInt($('#pieslider div').css('margin-left'));var tooltipStart=$(this).position().left-Math.abs(parentPos-parentOffset)+parentOffset;$('#pieslider').append('<span>'+tooltip+'</span>').find('span').addClass('tooltip');var tooltipWidth=$('#pieslider .tooltip').outerWidth();var leftOffset=Math.floor((tooltipWidth-$(this).width())/2);$('#pieslider .tooltip').css({'left':tooltipStart-leftOffset});},function()
{$('#pieslider .tooltip').remove();});}
this.initColorbox=function()
{$('a[rel="pieslider"], a[rel="nutrition-label"]').colorbox({speed:350,opacity:0.75,preloading:true,initialWidth:150,initialHeight:250,transition:'elastic'});}
this.initSubmenu=function()
{$('#submenu').lavaLamp({fx:"backout",speed:700,click:function(event,menuItem)
{}});}
this.initBalanceCheckForm=function()
{$('#balanceCheckForm').submit(function(e)
{e.preventDefault();$.ajax({type:'POST',cache:false,timeout:5000,url:$(this).attr('action'),data:{'token':$('#token').val(),'cardnumber':$('#cardnumber').val()},beforeSend:function(request)
{$('#message').removeClass().addClass('loading').text('Accessing card details...');},error:function(request,statusTxt,exceptionObj)
{if(statusTxt=='timeout')
{$('#message').removeClass().addClass('error').text('Your request has taken longer than expected and was stopped. Please try again.');}},success:function(json)
{$('#token').val(json.token);for(var j in json.message)
{$('#message').removeClass().addClass(j).text(json.message[j]);}}});});$('#cardnumber').focus();}
this.initDatepicker=function()
{var self=Sharis;if($('#calendar').size())
{$('#calendar').click(function(e)
{e.preventDefault();});$('#calendar').datepick({'minDate':0,'maxDate':'+12m','onSelect':function(dates)
{if(dates.length)
{self.updateDateControls(dates[0]);}}});$('#month, #day, #year').change(function()
{$('#calendar').datepick('setDate',new Date($('#year').val(),$('#month').val()-1,$('#day').val()));});}}
this.updateDateControls=function(date)
{$('#month').val(date.getMonth()+1);$('#day').val(date.getDate());$('#year').val(date.getFullYear());}
this.initLocationSelectForm=function()
{$('#state').change(function(e)
{if($(this).val()!='')
{$('#message').fadeOut('slow');$.ajax({type:'POST',cache:true,timeout:5000,url:$(this).parents('form').attr('action'),data:{'token':$('.token').val(),'state':$(this).val()},success:function(json)
{$('.token').val(json.token);$('#store').children().not(':first').remove();for(var j in json.stores)
{$('#store option:first').clone().val(j).text(json.stores[j]).appendTo('#store');}},error:function(request,statusTxt,exObj)
{if(statusTxt=='timeout')
{$('#message').removeClass().addClass('error').text('Error loading locations for selected state. Please try again.');}}});}
else
{$('#store').children().not(':first').remove();}});$('#locationSelectForm').submit(function(e)
{if($('#store').val()!='')
{return true;}
$('#message').addClass('error').text('Please select your state and/or restaurant location.').show();return false;});}}
$(window).load(function(){Sharis.init();});
