var solitaireAnimations = {};
solitaireAnimations.randomAnimation = function (e) {
var oRand = Math.random();
if( oRand < ( 1 / 12 ) ) {
solitaireAnimations.moveCircles(e);
return;
}
var oFade, oShrink, oMove;
while( !oFade && !oShrink && !oMove ) {
oFade = ( Math.random() > 0.5 );
oShrink = ( Math.random() > 0.5 );
oMove = Math.floor( Math.random() * 2.9999 );
}
solitaireAnimations.doCardByCardHandling(e,oFade,oShrink,oMove);
};
solitaireAnimations.moveCircles = function (e) {
var oCounter = 0;
var theGame = e.target;
var oIncrement = ( Math.PI * 2 ) / 52;
var theInterval = setInterval(function () {
oCounter++;
var xFactor = theGame.usingCards.width * 3.5;
var yFactor = theGame.usingCards.height * 1.55;
for( var i = 0, oX, oY, oTmp, oTmpCounter; i < 52; i++ ) {
oTmp = theGame.cards.playingCards[i].number * 10;
if( oTmp < oCounter ) { continue; }
if( oTmp == oCounter ) {
theGame.cards.playingCards[i].autoPositionSolitaire();
continue;
}
oTmpCounter = oCounter / 10;
oX = Math.sin(oTmpCounter+(i*oIncrement)) + 1;
oY = Math.cos(oTmpCounter+(i*oIncrement)) + 1;
theGame.cards.playingCards[i].representation.style.left = Math.round(oX*xFactor) + 'px';
theGame.cards.playingCards[i].representation.style.top = Math.round(oY*yFactor) + 'px';
}
if( oCounter > 140 ) {
theGame.ondeal();
if( confirm(theGame.strings.youWin) ) {
theGame.startGame();
}
}
},75);
var oldDeal = theGame.ondeal, oldClick = theGame.workspace.onclick;
theGame.ondeal = function () {
clearInterval( theInterval );
theGame.ondeal = oldDeal;
theGame.workspace.onclick = oldClick;
return true;
};
theGame.workspace.onclick = function () {
theGame.ondeal();
for( var i = 0; i < 52; i++ ) {
theGame.cards.playingCards[i].autoPositionSolitaire();
}
if( confirm(theGame.strings.youWin) ) {
theGame.startGame();
}
};
return false;
};
solitaireAnimations.fadeShrinkMove = function (oFade,oShrink,oMove) {
if( !( oFade || oShrink || oMove ) ) { return null; }
return function (e) {
return solitaireAnimations.doCardByCardHandling(e,oFade,oShrink,oMove);
};
};
solitaireAnimations.doCardByCardHandling = function (e,oFade,oShrink,oMove) {
if( e.type != 'gamewon' ) { return true; }
var theGame = e.target;
if( !( oFade || oShrink || oMove ) ) { return confirm(theGame.strings.youWin); }
var cardStacks = e.target.cardStacks;
var onStack = 2, onCard = 12, curVal = 0;
var theInterval = setInterval(function () {
if( curVal == 4 ) {
cardStacks[onStack].cardsInStack[onCard].representation.style.display = 'none';
curVal = 0;
onStack++;
if( onStack > 5 ) {
onStack = 2;
onCard--;
if( onCard < 0 ) {
clearInterval(theInterval);
theGame.workspace.onclick = oldClick;
if( confirm(theGame.strings.youWin) ) {
theGame.ondeal();
theGame.startGame();
}
return;
}
}
}
var tmpCard = cardStacks[onStack].cardsInStack[onCard];
if( oFade ) {
var tmpVal = ( ( 4 - curVal ) * 0.25 );
tmpCard.representation.style.opacity = ''+tmpVal+'';
tmpCard.representation.style.MozOpacity = ''+tmpVal+'';
tmpCard.representation.style.filter = 'alpha(opacity='+(tmpVal*100)+')';
if( tmpCard.representation.style.setProperty ) {
try { tmpCard.representation.style.setProperty('-khtml-opacity',''+tmpVal+''); } catch(e) {}
}
}
if( oShrink ) {
var newHeight = Math.round( ( ( 4 - curVal ) / 4 ) * theGame.usingCards.height );
var newWidth = Math.round( ( ( 4 - curVal ) / 4 ) * theGame.usingCards.width );
tmpCard.representation.style.height = newHeight + 'px';
tmpCard.representation.style.width = newWidth + 'px';
tmpCard.cardImage.style.height = newHeight + 'px';
tmpCard.cardImage.style.width = newWidth + 'px';
tmpCard.representation.style.left = ( tmpCard.cardStack.leftPos + ( ( theGame.usingCards.width - newWidth ) / 2 ) ) + 'px';
}
if( oMove == 1 ) {
if( oShrink ) {
tmpCard.representation.style.top = Math.round( ( theGame.usingCards.height * ( curVal + 1 ) * 0.3 ) + ( ( theGame.usingCards.height - newHeight ) / 2 ) ) + 'px';
tmpCard.representation.style.left = Math.round( tmpCard.cardStack.leftPos + ( ( theGame.usingCards.width - newWidth ) / 2 ) ) + 'px';
} else {
tmpCard.representation.style.top = Math.round( theGame.usingCards.height * ( curVal + 1 ) * 0.3 ) + 'px';
}
} else if( oShrink ) {
tmpCard.representation.style.top = Math.round( ( theGame.usingCards.height / 10 ) + ( ( theGame.usingCards.height - newHeight ) / 2 ) ) + 'px';
}
if( oMove == 2 ) {
tmpCard.representation.style.left = Math.round( tmpCard.cardStack.leftPos * ( ( 3 - curVal ) / 4 ) ) + 'px';
}
curVal++;
},75);
var oldDeal = theGame.ondeal, oldClick = theGame.workspace.onclick;
theGame.ondeal = function () {
clearInterval( theInterval );
for( var i = 0, tmpCard; i < 52; i++ ) {
theGame.cards.playingCards[i].representation.style.display = 'block';
}
theGame.ondeal = oldDeal;
theGame.workspace.onclick = oldClick;
return true;
};
theGame.workspace.onclick = function () {
theGame.ondeal();
for( var i = 0; i < 52; i++ ) {
theGame.cards.playingCards[i].autoPositionSolitaire();
theGame.cards.setCardSize(theGame.usingCards.width+'px',theGame.usingCards.height+'px');
}
if( confirm(theGame.strings.youWin) ) {
theGame.startGame();
}
};
return false;
};