text: var GAME={
  decks:5,
  cash:0,
  clearing:false,
  dealing:false,
  playing:false,
  hitting:false,
  turns:0,
  maxturns:1}
  var SUITS=[]
  SUITS[0]='Spades'
  SUITS[1]='Diamonds'
  SUITS[2]='Hearts'
  SUITS[3]='Spades'
  var VALUES=[]
  VALUES[0]='Ace'
  VALUES[1]='Two'
  VALUES[2]='Three'
  VALUES[3]='Four'
  VALUES[4]='Five'
  VALUES[5]='Six'
  VALUES[6]='Seven'
  VALUES[7]='Eight'
  VALUES[8]='Nine'
  VALUES[9]='Ten'
  VALUES[10]='Jack'
  VALUES[11]='Queen'
  VALUES[12]='King'
  var DECK
  var DISCARD
  var HANDS=[]
  var DEBUG=true
  $(document).ready(function(){
  init()
  function log(s){
  if(DEBUG){
  if(typeof(console)!='undefined'){
  if(console){
  if(navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1){
  console.log(s)
  }else{
  console.log.apply(this,arguments)}}}}}
  function init(){
  $('#Discard').rotate(-25)
  $('#Shoe').rotate(385)
  $('#Dealer').rotate(0)
  $('#Player').rotate(0)
  $('.Payout').fadeOut(0)
  setcash(1000)
  hud()
  deck()
  setTimeout(function(){
  shuffle()
  },250)
  setTimeout(function(){
  $('#Deal').fadeIn(250)
  },1500)}
  function message(str){
  $('#Message').html(str).fadeIn(250,function(){
  setTimeout(function(){
  $('#Message').fadeOut(250)
  },1000)
  })}
  function hud(){
  var ns=0.85
  var os=1
  $('#Shoe').click(function(e){
  if(GAME.playing){
  $('#Hit').trigger('click')
  }else{
  $('#Deal').trigger('click')}
  }).hover(function(){$(this).stop().animate({scale:os+0.15},250);},function(){$(this).stop().animate({scale:ns+0.15},125);})
  $('#Player .Wager').click(function(e){
  $('#CancelWager').trigger('click')
  }).hover(function(){$(this).stop().animate({scale:os},250);},function(){$(this).stop().animate({scale:ns},125);})
  $('a.Chip').animate({scale:ns},0).click(function(e){
  if(GAME.clearing==false&&!GAME.playing&&!GAME.dealing&&!GAME.hitting){
  if(!$(this).hasClass('Locked')){
  bet($('#Player'),$(this).attr('id'))}}
  return false
  }).hover(function(){if(parseInt($(this).css('opacity'))>=1){$(this).stop().animate({scale:os},250);}},function(){if(parseInt($(this).css('opacity'))>=1){$(this).stop().animate({scale:ns},125);}})
  $('a.Action').animate({scale:ns},0).click(function(e){
  if(GAME.clearing==false&&GAME.playing&&!GAME.dealing&&!GAME.hitting){
  if(!$(this).hasClass('Locked')){
  action($('#Player'),$(this).attr('id'))}}
  return false
  }).hover(function(){$(this).stop().animate({scale:os},250);},function(){$(this).stop().animate({scale:ns},125);})
  $('#CancelWager').click(function(e){
  $('#CancelWager').fadeOut(250)
  if(GAME.clearing==false&&GAME.playing==false){
  GAME.clearing=true
  var l=$('#Player .Wager .ChipSm').length
  cancelwager()
  setTimeout(function(){
  $('#CancelWager').fadeIn(250)
  GAME.clearing=false
  },l*250)}
  })
  $('#Options #Deal').animate({scale:ns},0).click(function(e){
  if(GAME.playing==false){
  deal()
  GAME.playing=true}
  }).hover(function(){if($(this).css('opacity')>=1){
  $(this).stop().animate({scale:os},250);}},function(){if($(this).css('opacity')>=1){
  $(this).stop().animate({scale:ns},125);}})}
  function bet(entity,b){
  switch(b){
  default:
  var amt=b.split('Bet')[1]
  setcash(-amt)
  var w=$(entity).find('.Wager')
  w.append('<span class="ChipSm '+b+'"></span>')
  var chip=$('.ChipSm.'+b,w).last()
  chip.css({top:$(window).height()+100})
  chip.scale(3)
  chip.rotate(360)
  chip.stop().animate({rotate:0,scale:1,top:-($('.ChipSm',w).length-1)*2},500)
  break}
  checkchips()}
  function action(entity,a){
  switch(a){
  case('Hit'):
  hit(entity)
  break
  case('Stand'):
  stand(entity)
  break
  case('Split'):
  splithand(entity)
  break
  case('DoubleDown'):
  doubledown(entity)
  break
  case('Surrender'):
  surrender(entity)
  break
  default:
  break}}
  function deck(){
  var n=0
  var newDeck=[]
  for(var d=0;d<GAME.decks;d++){
  for(var s=0;s<SUITS.length;s++){
  for(var v=0;v<VALUES.length;v++){
  newDeck.push([SUITS[s],VALUES[v]])
  n+=1}}}
  n/=VALUES.length
  $('#Shoe').prepend('<div id="Deck" style="margin-top:'+(-n)+'px; padding-top:'+(n)+'px"><div class="Card"><div class="Flip"><div class="Front"><div></div></div></div>')
  var c=$('#Shoe .Card')
  if(Modernizr.csstransforms){
  c.scale(0.515)
  c.css({width:c.width()*2,height:c.height()*2,marginLeft:-c.width()*0.5,marginTop:-c.height()*0.5})}
  DECK=newDeck}
  function shuffle(){
  var newDeck=DECK
  var card1
  var card2
  var temp
  for(var i=0;i<1000;i++){
  card1=Math.floor(DECK.length*Math.random())
  card2=Math.floor(DECK.length*Math.random())
  temp=DECK[card2]
  DECK[card2]=DECK[card1]
  DECK[card1]=temp}
  DECK=newDeck}
  function card(){
  var n=DECK.length/VALUES.length
  var d=DECK.pop()
  $('#Deck').css({marginTop:(-n),paddingTop:(n)})
  $('#Cards').append('<div id="Card_'+parseInt(DECK.length)+'" class="Card"><div class="Flip"><div class="Back '+d[0]+' '+d[1]+'"></div><div class="Front"></div></div></div')
  var c=$($('#Cards .Card').last())
  c.css({left:$('#Shoe').offset().left,top:$('#Shoe').offset().top,zIndex:15})
  if(Modernizr.csstransforms){
  c.rotate(parseInt($('#Shoe').rotate()))
  c.scale(0.5)
  c.css({width:c.width()*2,height:c.height()*2,marginLeft:-c.width()*0.5,marginTop:-c.height()*0.5})
  c.hover(function(e){
  if(GAME.playing&&!GAME.clearing&&!GAME.dealing&&!GAME.hitting&&!$(this).hasClass('Back')){
  $('.Card').css('z-index',14)
  $(this).stop().animate({scale:0.75},250).css('z-index',15)}
  },function(e){
  if(GAME.playing&&!GAME.clearing&&!GAME.dealing&&!GAME.hitting&&!$(this).hasClass('Back')){
  $('.Card').css('z-index',15)
  $(this).stop().animate({scale:0.5},125)}
  })}
  return c}
  function deal(){
  var h=0
  if(GAME.dealing==false){
  GAME.dealing=true
  GAME.playing=true
  checkplaying()
  for(var i=0;i<$('#Hands div').length*2;i++){
  setTimeout(function(){
  if(h>=$('#Hands div').length){
  h=0}
  hit($($('#Hands div').get(h)))
  h++
  },i*650)}
  setTimeout(function(){
  if($('#Cards .Card').length !=$('#Hands div').length*2){
  discard()
  deal()
  }else{
  GAME.dealing=false
  nextturn($('#Player'))}
  },$('#Hands div').length*2*650)}}
  function nextturn(entity){
  if(entity.attr('id')=='Dealer'){
  var h=HANDS[entity.attr('id').toString()]
  for(var i=1;i<h.length;i++){
  doflip($('#'+h[i]))}
  var score=checkscore(entity).toString()
  $(entity.find('.Score')).html(score)
  if(score.indexOf('/')!=-1){
  score=score.split('/')[1]}
  if(score>21){
  bust(entity)}
  else if(score<17){
  hit(entity)
  setTimeout(function(){
  nextturn(entity)
  },500)
  }else{
  var e=getnext(entity)
  if(e){
  nextturn(e)}
  end(entity)}}
  if(GAME.turns>=GAME.maxturns){
  end()
  }else{
  checkactions(entity)}}
  function cancelwager(){
  var n=0
  var l=$('#Player .Wager .ChipSm').length
  if(!l){
  l=1}
  $('#Player .Wager .ChipSm').each(function(){
  var t=$(this)
  setTimeout(function(){
  t.stop().animate({scale:3,rotate:360,top:$(window).height()+100},250,function(){
  var amt=t.attr('class').split('Bet')[1]
  setcash(amt)
  t.remove()
  })
  },(l-n)*125)
  n++
  })
  checkchips()}
  function cashin(){
  var n=0
  var l=$('#Player .Payout .ChipSm').length
  if(!l){
  l=1}
  $('#Player .Payout .ChipSm').each(function(){
  var t=$(this)
  setTimeout(function(){
  t.stop().animate({scale:3,rotate:360,top:$(window).height()+100},250,function(){
  var amt=t.attr('class').split('Bet')[1]
  setcash(amt)
  t.remove()
  })
  },(l-n)*125)
  n++
  })
  setTimeout(function(){
  $('#Player .Payout').fadeOut(250)
  },((l-n)*125)+250)
  checkchips()}
  function payout(entity,amount){
  var p=$(entity).find('.Payout')
  p.fadeIn(250,function(){
  var chips=[]
  while(amount>0){
  if(amount>=500){
  amount-=500
  chips.push('Bet500')}
  else if(amount>=100){
  amount-=100
  chips.push('Bet100')}
  else if(amount>=50){
  amount-=50
  chips.push('Bet50')}
  else if(amount>=25){
  amount-=25
  chips.push('Bet25')}
  else if(amount>=5){
  amount-=5
  chips.push('Bet5')}
  if(amount<5){
  amount=0}}
  for(var c=0;c<chips.length;c++){
  var chip=chips[c]
  p.append('<span class="ChipSm '+chip+'"></span>')
  $('.ChipSm.'+chip,p).last().css({top:-$(window).height()}).animate({top:-($('.ChipSm',p).length-1)*2},500)}
  setTimeout(function(){
  cashin()
  },1500)
  })}
  function getwager(){
  var n=0
  var l=$('#Player .Wager .ChipSm').length
  var amt=0
  $('#Player .Wager .ChipSm').each(function(){
  var t=$(this)
  amt+=parseInt(t.attr('class').split('Bet')[1])
  })
  return amt}
  function hit(entity){
  if(GAME.hitting==false){
  GAME.hitting=true
  var h=HANDS[entity.attr('id').toString()]
  if(!h){
  h=HANDS[entity.attr('id').toString()]=[]}
  var c=card()
  var lo=h.length*(15)
  h.push(c.attr('id').toString())
  c.animate({rotate:parseInt(entity.rotate()),left:entity.offset().left+lo,top:entity.offset().top},300,function(){
  GAME.hitting=false
  var score=checkscore(entity).toString()
  if(score.indexOf('/')!=-1){
  var ns=score.split('/')
  if(ns[1]<=21&&ns[0]>17){
  score=ns[1]}}
  var sc=parseInt(score)
  if(sc>21){
  bust(entity)}
  if(entity.attr('id')!='Dealer' ||
  h.length<2){
  doflip(c)
  $(entity.find('.Score')).html(score).fadeIn(250)
  }else{}
  })}
  checkactions(entity)}
  function doflip(entity){
  if(Modernizr.csstransforms){
  var f=$('.Flip',entity)
  f.css({width:$(entity).width(),height:$(entity).height()})
  f.rotate3Di('flip',300,{direction: 'counterclockwise',sideChange: flipCard})
  }else{
  entity.find('.Back').show()
  entity.find('.Front').hide()}}
  function unflip(entity){
  if(Modernizr.csstransforms){
  var f=$('.Flip',entity)
  f.css({width:$(entity).width(),height:$(entity).height()})
  f.rotate3Di('unflip',300,{direction: 'clockwise',sideChange: flipCard})
  }else{
  entity.find('.Back').hide()
  entity.find('.Front').show()}}
  function stand(entity){
  nextturn(getnext(entity))}
  function splithand(entity){
  message('Coming Soon...')}
  function surrender(entity){
  end(entity,'surrender')}
  function doubledown(entity){
  $('#Player').find('.Wager .ChipSm').each(function(){
  bet($('#Player'),$(this).attr('class').split(' ')[1])
  })
  setTimeout(function(){
  if(GAME.hitting==false){
  hit(entity)
  stand(entity)}
  },500)}
  function bust(entity){
  end(entity,'bust')}
  function blackjack(entity){
  end(entity,'blackjack')}
  function end(entity,special){
  if(GAME.playing){
  GAME.playing=false
  if(typeof(entity)=='undefined'){
  entity=null}
  if(typeof(special)=='undefined'){
  special=null}
  var winner=null
  var best=0
  var ispush=false
  var wager=getwager()
  var mult=1
  if(special){
  switch(special){
  case 'blackjack':
  winner=entity
  message('Blackjack!')
  mult=1.5
  break
  case 'bust':
  if(entity.attr('id')=='Player'){
  winner=$('#Dealer')
  }else{
  winner=$('#Player')}
  message(entity.attr('id')+' Busts!')
  mult=1
  break
  case 'surrender':
  if(entity.attr('id')=='Player'){
  winner=$('#Dealer')
  }else{
  winner=$('#Player')}
  message('Surrendered.')
  mult=0.5
  $('#Player').find('.Wager .ChipSm').animate({top:-600},500,function(){
  $(this).remove()
  })
  payout($('#Player'),wager*mult)
  break
  case 'push':
  ispush=true
  message('Push!')
  mult=1
  break
  default:
  winner=entity
  break}
  var sc=checkscore(winner).toString()
  if(sc.indexOf('/')!=-1){
  sc=sc.split('/')[1]}
  best=parseInt(sc)
  }else{
  $('#Hands div').each(function(){
  var sc=checkscore($(this)).toString()
  if(sc.indexOf('/')!=-1){
  sc=sc.split('/')[1]}
  sc=parseInt(sc)
  if(sc==best){
  ispush=true}
  if(sc>best){
  best=sc
  winner=$(this)
  mult=1}
  })}
  if(!ispush){
  if(winner.attr('id')!='Player'){
  $('#Player').find('.Wager .ChipSm').animate({top:-600},500,function(){$(this).remove()})
  }else{
  payout($('#Player'),wager*mult)
  setTimeout(function(){cancelwager();},1000)}
  if(!special){
  message(winner.attr('id')+' Wins!')}
  }else{
  message('Push!')}
  setTimeout(function(){
  discard()
  },1000)}}
  function discard(){
  $('#Hands div').each(function(){
  var t=$(this)
  if(HANDS[t.attr('id').toString()]){
  var h=HANDS[t.attr('id').toString()]
  var d=$('#Discard')
  var score=t.find('.Score')
  setTimeout(function(){
  score.fadeOut(250,function(){$(this).html('0')})
  for(var c=h.length;c>=0;c--){
  var ol=0
  var ot=0
  if(navigator.userAgent.toLowerCase().indexOf("applewebkit")!=-1){
  ol=d.width()*0.25
  ot=d.height()*0.125}
  $('#'+h[c]).stop().animate({left:d.offset().left+ol,top:d.offset().top+ot,rotate:d.rotate()},250,function(){
  HANDS[t.attr('id').toString()]=h.slice(c)
  $(this).fadeOut(250,function(){$(this).remove()})
  })
  }},1000)}
  })
  setTimeout(function(){
  checkplaying()
  HANDS=[]
  },1500)}
  function setcash(c){
  c=parseInt(c)
  var a='+'
  if(c<0){
  a=' '}
  if(c !=0){
  var cc=GAME.cash
  $('#Cash').append('<span class="PlusMinus">'+a+c+'</span>')
  GAME.cash=(cc+c)
  $('#Cash .PlusMinus').first().fadeOut(0).fadeIn(75,function(){
  var t=$(this)
  setTimeout(function(){
  t.fadeOut(75,function(){
  t.remove()
  $('#Cash').html('$ '+(GAME.cash))
  })
  },150)
  })}
  checkchips()}
  function checkchips(){
  $('#Chips .Chip').removeClass('Locked')
  if(GAME.cash<500){
  $('#Chips #Bet500').addClass('Locked')}
  if(GAME.cash<100){
  $('#Chips #Bet100').addClass('Locked')}
  if(GAME.cash<50){
  $('#Chips #Bet50').addClass('Locked')}
  if(GAME.cash<25){
  $('#Chips #Bet25').addClass('Locked')}
  if(GAME.cash<5){
  $('#Chips #Bet5').addClass('Locked')}}
  function checkactions(entity){
  var h=HANDS[entity.attr('id')]
  var hard=0
  var soft=0
  var c1
  var c2
  var score=checkscore(entity).toString()
  var wager=getwager()
  if(score.indexOf('/')!=-1){
  soft=score.split('/')[0]
  hard=score.split('/')[1]
  }else{
  soft=hard=score}
  if(soft>21 || hard>21){
  bust(entity)}
  if(h){
  if(h.length==2){
  var c1=$('#'+h[0]).find('.Back').attr('class').split(' ')[2]
  var c2=$('#'+h[1]).find('.Back').attr('class').split(' ')[2]
  if(c1=='King' || c1=='Queen' || c1=='Jack' || c1=='Ten'){
  c1='Face'}
  if(c2=='King' || c2=='Queen' || c2=='Jack' || c2=='Ten'){
  c2='Face'}
  if(c2=='Face'&&c1=='Ace'){
  blackjack(entity)}
  if(c1=='Face'&&c2=='Ace'){
  blackjack(entity)}}
  if(soft>21&&hard>21){
  bust(entity)}
  else{
  if(entity.attr('id')=='Player'){
  $('#Stand').removeClass('Locked')
  $('#Hit').removeClass('Locked')
  $('#Surrender').removeClass('Locked')
  if(c1&&c2&&h.length<3){
  if(c1==c2){
  $('#Split').removeClass('Locked')}}
  if(h.length<3&&wager<=GAME.cash){
  $('#DoubleDown').removeClass('Locked')
  }else{
  $('#DoubleDown').addClass('Locked')}}
  else{}}}}
  function getnext(entity){
  var n=null
  if(entity.next()){
  n=$(entity.next())}
  else if(!entity.next()){
  n=$(entity.last())
  GAME.turns++}
  if(!n.attr('id')){
  n=null}
  return n}
  function checkplaying(){
  if(GAME.playing){
  $('#Deal').fadeOut(250)
  $('#Chips a.Chip').fadeOut(250)
  $('#CancelWager').fadeOut(250)
  }else{
  $('#Deal').fadeIn(125)
  $('#Chips a.Chip').fadeIn(125)
  $('#CancelWager').fadeIn(125)
  $('#Stand').addClass('Locked')
  $('#Hit').addClass('Locked')
  $('#Surrender').addClass('Locked')
  $('#DoubleDown').addClass('Locked')
  $('#Split').addClass('Locked')}}
  function checkscore(entity){
  var hard=0
  var soft=0
  var h=HANDS[entity.attr('id')]
  if(!h){
  h=HANDS[entity.attr('id')]=[]}
  for(var i=0;i<h.length;i++){
  var c=$('#'+HANDS[entity.attr('id')][i])
  var b=c.find('.Back')
  if(b.css('display')!='none'){
  if(b.hasClass('Ace')&&hard<=10){
  hard+=11
  soft+=1
  }else if(b.hasClass('Ace')&&hard>10){
  hard+=1
  soft+=1}
  else if(b.hasClass('Two')){
  hard+=2
  soft+=2}
  else if(b.hasClass('Three')){
  hard+=3
  soft+=3}
  else if(b.hasClass('Four')){
  hard+=4
  soft+=4}
  else if(b.hasClass('Five')){
  hard+=5
  soft+=5}
  else if(b.hasClass('Six')){
  hard+=6
  soft+=6}
  else if(b.hasClass('Seven')){
  hard+=7
  soft+=7}
  else if(b.hasClass('Eight')){
  hard+=8
  soft+=8}
  else if(b.hasClass('Nine')){
  hard+=9
  soft+=9}
  else if(b.hasClass('Ten')||
  b.hasClass('Jack')||
  b.hasClass('Queen')||
  b.hasClass('King')){
  hard+=10
  soft+=10}}}
  var ht=hard
  if(hard>0){
  if(soft&&hard !=soft){
  if(hard !=21){
  if(hard<=21){
  ht=soft+'/'+hard
  }else{
  ht=soft}}}}
  return ht}
  function flipCard(front){
  if(front){
  $(this).parent().find('div.Front').show()
  $(this).parent().find('div.Back').hide()
  }else{
  $(this).parent().find('div.Front').hide()
  $(this).parent().find('div.Back').show()}}
  })
  