/* ----------------------------------- vn_group_class.js (class def for vn_group -- deck & shuffle) used on "deal" or "selection" pages (c) 2001, visionary networks any questions? ask jewel mlnarik (jewel@tarot.com) --------------------------------------- */ ///////////////////////////////////// // vn_group // //////////////////////////////////// //show layer function sk102803 function show(layer_ref) { var state = 'visible'; if (document.all) { //IS IE 4 or 5 (or 6 beta) eval( "document.all." + layer_ref + ".style.visibility = state"); } if (document.layers) { //IS NETSCAPE 4 or below document.layers[layer_ref].visibility = state; } if (document.getElementById && !document.all) { obj = document.getElementById(layer_ref); obj.style.visibility = state; } } //member function for GROUP called by shuffle() function group_shuffleCut() { var max = 10; var temp = Math.random()%max; var number = Math.round(10*temp); number += 35; this.left_hand = number; this.right_hand = number +1; } //member function for GROUP called by shuffle() function group_shuffleCardFall() { var max = 3; var temp = Math.random()%max; var number = Math.round(10*(Math.random()%max)); return number; } //member function for GROUP function group_shuffle() { //will need a temp deck for shuffled cards shuffled_group = new Array(); //always cut cards before shuffling this.cut(); var done = 0; var count = 0; var lcount = 0; var rcount = this.right_hand -1; while (done == 0) { if ((lcount >= this.left_hand) && (rcount >= this.total_pieces)) done = 1; left_fall = this.card_fall(); //no cards that fell if ((lcount + left_fall) > this.left_hand) { left_fall = this.left_hand - lcount; } lmax = lcount + left_fall; for (lcount; lcount == (lmax -1); lcount++) { shuffled_group[count] = this.group_array[lcount]; count++; } right_fall = this.card_fall(); if ((rcount + right_fall) > this.total_pieces) { right_fall = this.total_pieces - rcount; } rmax = rcount + right_fall; for (rcount; rcount ==(rmax -1); rcount++) { shuffled_group[count] = this.group_array[rcount]; count++; } } this.group_array = shuffled_group; fisherYates(this.group_array); //DebugArray(this.group_array, 'Shuffled Deck'); // DEBUG } function fisherYates ( myArray ) { var i = myArray.length; while ( i-- ) { var j = Math.floor( Math.random() * ( i + 1 ) ); var tempi = myArray[i]; var tempj = myArray[j]; myArray[i] = tempj; myArray[j] = tempi; } return myArray; } function DebugArray(jsThisArray, jsHeader) { jsOutput = ''; for (x = 0; x < jsThisArray.length; x++) { jsOutput += jsThisArray[x]; if (x < jsThisArray.length - 1) jsOutput += ','; } //alert(jsHeader + ': ' + jsOutput); } function group_shuffleStart() { this.time = new Date(); // reset the date to now this.startTime = this.time.getTime(); } // stopTime is a date object function group_shuffleStop(stopTime) { this.stopTime = stopTime.getTime(); // every 3 seconds, we shuffle once more var shuffleTimes = Math.floor ( ((( this.stopTime - this.startTime )/1000)/60)/3 ); for (var i=0; i<=shuffleTimes; i++ ) { this.shuffle(); } } function group_clear() { for (var i=0; i< this.total_pieces; i++) { //sk071204 this.group_array[i] = i; // this.group_array[i] = -1; } //DebugArray(this.group_array, 'Cleared Deck'); // DEBUG } function group_find( refNum ) { // return the index where refNum is located in the deck var found = -1; for (var i=0; i selectedObj.total_pieces ) { //double check final card was set if (!selectedObj.picked_pieces[selectedObj.total_pieces] || (selectedObj.picked_pieces[selectedObj.total_pieces].picked <0) ) { selectedObj.pick_no -= 1; } } if ( selectedObj.pick_no > selectedObj.total_pieces ) { alert("You have already selected your " + selectedObj.total_pieces +" cards. \n Click on one of them to continue or clear your cards and select new ones. \n To Clear your cards: \n\t Expert Readings: Press the 'Clear the Cards' link below your spread. \n\t Sample Readings: Refresh your screen."); } else { if ( selectedObj.pick_no == selectedObj.total_pieces ) { show('pop_text'); } for (var i = objSelected.pick_no; i <= objSelected.total_pieces; i++) { pickPiece( i, objSelected, objGroup); } } } function pickPiece( pnum, selectedObj, groupObj){ // pnum is an integer from 0 thru this.total_pieces - 1 (e.g. 77 for tarot cards) //alert( "pnum: "+pnum+ "\nselectedObj: " + selectedObj + "\ngrp_arr: "+ //groupObj.group_array[pnum] + "\nstrUpsellImagePrefix: " + strUpsellImagePrefix + "\n"); //pnum -- where in the fanned deck the user has clicked //refnum = groupObj.group_array[pnum] -- value of card where user clicked. -1 = already chosen //selectedObj.pick_no -- position number, 1 to total pieces //alert( "PRE\n\npnum: "+ pnum + "\ngroup_arr: "+ groupObj.group_array[pnum] + "\npick_no: "+ selectedObj.pick_no + "\n"); var refNum; var numInsertedPosition; //sk071304 //good place to do a final check to make sure the last card //was selected if ( selectedObj.pick_no > selectedObj.total_pieces ) { //double check final card was set if (!selectedObj.picked_pieces[selectedObj.total_pieces] || (selectedObj.picked_pieces[selectedObj.total_pieces].picked <0) ) { selectedObj.pick_no -= 1; } } // if all cards already picked if ( selectedObj.pick_no > selectedObj.total_pieces ) { alert("You have already selected your " + selectedObj.total_pieces +" cards. \n Click on one of them to continue."); // else if this card position hasn't been picked before } else if ( groupObj.group_array[pnum] > -1 ) { if ( selectedObj.pick_no == selectedObj.total_pieces ) { show('pop_text'); } // get the number of the card refNum = groupObj.group_array[pnum]; // erase the card so it can't be picked again groupObj.group_array[pnum] = -1; //this is where the picked card gets stored. Make sure this happens! // insert picked item into selectedObj // numInsertedPosition = selectedObj.insert( refNum, selectedObj.pick_no ); // alert("numInsertPos: "+numInsertedPosition+"\npick_no: "+selectedObj.pick_no); numInsertedPosition = selectedObj.insert( refNum ); // and then of course "turn the card over" (display the images) turnOver( numInsertedPosition, selectedObj ); // else get the next card in the deck } else { if ( selectedObj.pick_no == selectedObj.total_pieces ) { show('pop_text'); } pnum++; //alert("total pieces: " + selectedObj.total_pieces ); if ( pnum > selectedObj.total_pieces - 1 ){ pnum = 0; } pickPiece(pnum, selectedObj, groupObj); } } function AnimateUpsellPromo( numPromo, strImagePrefix ) { document.upsell_promo.src = 'images/upsell_promo/' + strImagePrefix + '_' + numPromo + '.gif'; } //turns over card[imgNum]...pickNum...and sets name img src for rollover function turnOver(posNo, selectedObj) { var imgName = "cardimg" + posNo; var nameImg = "name" + posNo; //card image document[imgName].src = selectedObj.picked_pieces[posNo].image.piece_img.src; //name image if (document[nameImg]) { var imgStr = selectedObj.picked_pieces[posNo].image.name_img.src; // flash reading card names have a "_f" suffix to connotate purple bgcolor // so doctor the string if ((flashReading) && (flashReading != 0)) { var flashEnd = "_f.gif"; var replaceMe = ".gif"; imgStr = imgStr.replace( replaceMe, flashEnd); } //document[nameImg].src = selectedObj.picked_pieces[posNo].image.name_img.src; document[nameImg].src = imgStr //alert(selectedObj.picked_pieces[posNo].image.name_img.src); } }