
var isNN6=false;
if (navigator.userAgent.indexOf('Netscape6') > -1) isNN6=true;
if (navigator.userAgent.indexOf('Mozilla/5') > -1) isNN6=true;

if (!document.getElementById){
alert('Sorry old Timer!\nThe Game needs IE5+ or NN6+ to play');
};

if (isNN6){
document.addEventListener('draggesture' ,killMe  , true);
document.addEventListener('dragover' ,killMe  , true);
document.addEventListener('dragdrop' ,killMe  , true);
};

function killMe (evt){
evt.preventDefault();
evt.cancelBubble=true;
return true;
}
function b7(elemId){
return document.getElementById(elemId);
};

function g3(a,b){
return (a>b?a:b);
};

function g4(a,b){
return (a<b?a:b);
};

function e2(evt){
return (isNN6?evt.clientX:window.event.clientX);
};
function e3(evt){
return (isNN6?evt.clientY:window.event.clientY);
};

var f2, f3,e9,f1;
function i5(evt){
if (!isNN6) return document.getElementsByTagName('body')[0].scrollLeft;
else return evt.pageX-evt.clientX;
};
function i5(evt){
if (!isNN6) return document.getElementsByTagName('body')[0].scrollTop;
else  return evt.pageY-evt.clientY;
};
function c5(evt){
f2=e2(evt);
f3=e3(evt);
e9=window.screenX+window.innerWidth;
f1=window.screenY+window.innerHeight;
};
function i8(el){
if (!el || el.tagName=='BODY' || el.tagName=='HTML') return 0;
if (isNN6){
var x=parseInt(el.offsetLeft);
return x+i8(el.offsetParent);
}
else{
var x=parseInt(el.offsetLeft);
return x+i8(el.offsetParent);
};
};
function i9(el){
if (!el || el.tagName=='BODY' || el.tagName=='HTML') return 0;

if (isNN6){
var x=parseInt(el.offsetTop);
return x+i9(el.offsetParent);
}
else{
var x=parseInt(el.offsetTop);
return x+i9(el.offsetParent);
}
};
function c1(evt, d0){

var i6=i5(evt);
var i7=i5(evt);
var gOL=i8(d0);
var gOT=i9(d0);
if ((e2(evt)+i6)<gOL) return false;
if ((e3(evt)+i7)<gOT) return false;
if ((e2(evt)+i6)>gOL+parseInt(d0.offsetWidth)) return false;
if ((e3(evt)+i7)>gOT+parseInt(d0.offsetHeight)) return false;

return true;
};

var e1=['h9','h0','g5','h1','h2','i1','g6','g7','h3','i2','h4','g8','h5'];
var d7=['g9','e8','f7','f8'];

var b4=new Array();
var a7;

function a1(){
for (var i=1;i<=52;i++) b4[i]=i;
a7=52;
};

function a8(){
var f9=1+Math.round(Math.random()*(a7-1));
var f0=b4[f9];
b4[f9]=b4[a7];
a7--;
return f0;
};

function a3( e5 ){
var f9=Math.round(Math.random()*(a7-1));
var f0=e5[f9];
e5[f9]=e5[a7-1];
a7--;
return f0;
};

var b8=null;

var f6=new Array();
var f4=new Array();
var e0=new Array();

function d9(d4,x, y){
this.d4=d4;
this.x=x;
this.y=y;
this.name='x'+x+'y'+y;
this.b0=null;
};

d9.prototype={
a4 : function(){
var g1="<DIV ID="+this.name+" CLASS='d9'>";
g1+="<IMG  SRC='images/53.gif'>";
g1+="</DIV>";
document.write(g1);

this.myTS=b7(this.name);
},
a0 : function(){
this.myTS.style.left=(this.x*72);
this.myTS.style.top=(150+this.y*100);
},
b5 : function(f0){

var myX=this.x-1;
var myY=this.y;

if (myX<0) return false;
if (f4[myY][myX].b0==null) return false;
if (f6[f0.id].h6 !=f4[myY][myX].b0.h6) return false;
if (f6[f0.id].h7 -  f4[myY][myX].b0.h7 !=1 )  return false;
return true;
},
d6 : function(f0){

if (this.x !=0) return false;
if (f6[f0.id].h7 !=0) return false;
return true;
},
e7 : function(){
return this.b0;
},
c2 : function(g0){

g0.d5(this.x,this.y);
this.b0=g0;
}
};

function h8(d4, g2, row, col, c7){
if (c7<=0 || c7>52) alert(c7);
this.d4=d4;
this.f0="";
this.f5=c7;
this.c3='f0'+this.f5;

this.h6=Math.floor((c7-1)/13);
this.h7=(c7-1) - this.h6*13;
this.c8=e1[this.h7]+' of '+d7[this.h6];
this.y=row;
this.x=col;
};

h8.prototype={
c9 : function(){
var g1="<DIV ID="+this.c3+" CLASS='h8'>";
g1+="<IMG  ID='"+this.c3+"img' SRC='images/"+this.f5+".gif'>";
g1+="</DIV>";
document.write(g1);

this.f0=b7(this.c3);
this.f0Img=b7(this.c3+'img');

},
d3 : function(){

this.d5(this.x, this.y);
this.f0.onmousedown=this.c0;
this.f0.onmouseover=this.e7;

},
d5 : function(x,y){

this.x=x;
this.y=y;

this.f0.style.left=(this.x*72);
this.f0.style.top=(150+this.y*100);

},
e7 : function(){

},
c0 : function(evt){

b8=this;
b8.style.zIndex=100;

c5(evt);

e0[4]=f6[this.id].b3();

document.onmousemove=f6[this.id].e6;
document.onmouseup=f6[this.id].b2;

},
e6 : function(evt){
var xMove=(e2(evt)-f2);
var yMove=(e3(evt)-f3);

b8.style.left=g3(parseInt(b8.style.left) + xMove,0);
b8.style.top=g3(parseInt(b8.style.top) + yMove,0);
c5(evt);

return false;
},
b2 : function(evt){
c4();
document.onmousemove=null;
document.onmouseup=null;
if (b8){

b8.style.zIndex=2;

var i=0;
var d2=false;
while (i<4 & !d2){
if (c1(evt, e0[i].myTS)){
d2=true;
}
else i++;
}
if (d2){

if (e0[i].d6(b8) || e0[i].b5(b8)){

f6[b8.id].d5(e0[i].x, e0[i].y);

e0[i].b0=f6[b8.id];

e0[i]=e0[4];
e0[4].b0=null;
window.status="You have "+(4-b1)+" shuffles left";
}
else{

window.status='bad h6 sequence';
f6[b8.id].d5(f6[b8.id].x,f6[b8.id].y);
}
}
else{
window.status='not dropped on empty slot';

f6[b8.id].d5(f6[b8.id].x,f6[b8.id].y);
}
}
},
b3 : function(){
return f4[this.y][this.x];
}
};

var b1=1;
var d1=[0,0,0,0];

function c4(){

var c6=0;
var row,col;

for (row=0;row<4;row++){
d1[row]=0;
for (col=0;col<14;col++){
if (f4[row][col].e7()!=null){
if (f4[row][col].d6(f4[row][col].e7().f0) || f4[row][col].b5(f4[row][col].e7().f0)){
d1[row]++;
}
else{
col=30;
}
}
}
};
for (row=0;row<4;row++){
for (col=d1[row];col<14;col++){

if (f4[row][col].e7()!=null){
c6++;
}
}
};

if (c6 !=(52-d1[0]- d1[1]-d1[2]-d1[3]))
alert('g2ed h8s='+c6+'\n\nshould have '+(52-d1[0]- d1[1]-d1[2]-d1[3]));
};

function e4(){
if (b1>3){
alert('Sorry Buster \n\nYou\'ve had your lot !!');
return false;
}
else{
b1++;
window.status="You have "+(4-b1)+" shuffles left";

var a2=new Array();
var c6=0;

for (var row=0;row<4;row++){
d1[row]=0;
for (var col=0;col<14;col++){
if (f4[row][col].e7()!=null){
if (f4[row][col].d6(f4[row][col].e7().f0) || f4[row][col].b5(f4[row][col].e7().f0)){
d1[row]++;
}
else{
col=30;
}
}
}
};

for (var row=0;row<4;row++){
for (var col=d1[row];col<14;col++){

if (f4[row][col].e7()!=null){
a2[c6]=f4[row][col].e7();
c6++;
}
}
};

if (c6 !=(52-d1[0]- d1[1]-d1[2]-d1[3]))
alert('g2ed h8s='+c6+'\n\nshould have '+(52-d1[0]- d1[1]-d1[2]-d1[3]));

a7=c6;

var b9;
b9=0;

for (var row=0;row<4;row++){

e0[row]=f4[row][d1[row]];
e0[row].b0=null;

for (var col=d1[row]+1;col<14;col++){
f4[row][col].c2(a3(a2 ) );
b9++;
}
}
}
};

function a5(){

a1();
myBody=document;

for (var row=0;row<4;row++){
f4[row]=new Array();
for (var col=0;col<14;col++){
var g2=row*14+col+1;
f4[row][col]=new d9(myBody, col, row);
f4[row][col].a4();
f4[row][col].a0();
}
}
for (var i=0;i<4;i++) e0[i]=f4[i][0];

for (var row=0;row<4;row++){
for (var col=0;col<13;col++){
var g2=row*13+col+1;
var nrc=a8();

f6['f0'+nrc]=new h8(myBody, g2, row, col+1,nrc);
f6['f0'+nrc].c9();
f6['f0'+nrc].d3();

f4[row][col+1].b0=f6['f0'+nrc];
}
}
};

function i4(){
window.open("/therles.html","rles");
};

function i3(){
b1=0;

var a2=new Array();
var c6=0;

for (var row=0;row<4;row++){
d1[row]=0;
};

for (var row=0;row<4;row++){
for (var col=d1[row];col<14;col++){

if (f4[row][col].e7()!=null){
a2[c6]=f4[row][col].e7();
c6++;
}
}
};

if (c6 !=(52-d1[0]- d1[1]-d1[2]-d1[3]))
alert('g2ed h8s='+c6+'\n\nshould have '+(52-d1[0]- d1[1]-d1[2]-d1[3]));

a7=c6;

var b9;
b9=0;

for (var row=0;row<4;row++){

e0[row]=f4[row][d1[row]];
e0[row].b0=null;

for (var col=d1[row]+1;col<14;col++){
f4[row][col].c2(a3(a2 ) );
b9++;
}
}
window.status="You have "+(4-b1)+" shuffles left";

};
