var CPU= {'slow': false}
var FrameRate= 20; //20 ms
var Nfr=60;				// 60 Number of Frames for Dynamic Execution on images LIMIT
var xUA=navigator.userAgent.toLowerCase()
var Catfile="fc.html"


//if (document.all && xUA.indexOf('msie')!=-1) 
//{ // IE takes too long to perform filter operation so set it as slow
//  Catfile="fc.html"; 
//  CPU.slow=true; 
//  FrameRate=20;
//}

var rad= 0.0174532952 ; 	// number of rad per degree
var Fade_sine= new Array()
for (i=0;i< Nfr/2;i++) {Fade_sine[i]= 0}
for (i=Nfr/2;i< Nfr;i++) 
	{ 
	var mangle= (i-Nfr/2)*3;
	Fade_sine[i]= Math.sin( mangle*rad ) ;
	}
Fade_sine[0]=0;			// force values
Fade_sine[Nfr]=1;			// force values
var fr= new Array();  		// Array of Frames to create and show
var FN=0;				// frame number initialy 0
var FN_max=800;			// = 25 fr times Number of Animated Tiles
var timen=null;
sitegfx=		"homegfx/";			// Backslash
var elapsems=0;			// actual elapsed time for a 100ms delay
var firstdatems=0;
var Nbrowser= {type:'none'}	// values='w3c','moz','khtml','none'
//	PAGE LOGIC
page_onload=		true;
page_images_loaded=	false;
page_load_timedout=	false;
//page_status=		"loading";

//if (document.all) {d=document.all}
//else d=document;						

//--------------------------------------


function popUp(url)
{
sealWin=window.open(url,"win",'toolbar=0,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,WIDTH=500,height=450')
self.name = "mainWin"
}

function opencat() 
{
var args=""
if (opencat.arguments.length==1) {args="?Query=a"+opencat.arguments[0];}
jcat=window.open('http://'+SiteLocation+'/'+Catfile+ args,"NTTBCAT","toolbar=false,status=yes,scrollbars=yes,resizable,top=8,left=8,height=704,width=1000")
jcat.focus()
}

function opensafebuy()
{
safebuy=window.open('http://www.safebuy.org.uk/certificate/b86c19d1-0a05-4b3e-ba76-b5c4d854e0a0.html',"SafeBuy","")
safebuy.focus()
}

function ShowInfoWindow()
{
InfoWin = window.open("","Information","toolbar=false,scrollbars=yes,resizable")
InfoWin.document.location.href = 'http://'+SiteLocation+'/info0.html'
InfoWin.focus()
}
function BookmarkSite() 
{
tmp=window.external.AddFavorite('http://'+SiteLocation,"NoTimeToBrowse (Jewellery Catalogue)")
}
//--------------------------

// TIMING Detection of CPU.slow == true.

function actualhundredms()
{
var firstdate=	new Date(); 
firstdatems=	firstdate.getTime();	// time in milliseconds since computer time
var delay=		setTimeout("time_this()",150);
}

function time_this() 
{
var seconddate=	new Date(); 
seconddatems=	seconddate.getTime();	// time in milliseconds since computer time
var elapsems=seconddatems-firstdatems;
if (elapsems>200) { CPU.slow=true; (window.status="Image load"); }
else (window.status="Image load and fade")
}

//								TILE DEFINITIONS
//								TILE TO image.src alt text and action to be performed
// Below are tiles that have an image text and an action
// You can have more that one image with different text and action
var P1= {'src':	'tile_product1.png',		'action':	'',	'alt':	'Gold chains'			}
var P2= {'src':	'tile_prod_106-06.jpg',		'action':	'',	'alt':	'Gold heart t-bar necklace'	}
var P3= {'src':	'tile_product3.png',		'action':	'',	'alt':	'Gold double dog tags'		}
var P4= {'src':	'tile_prod_001-42.png',		'action':	'',	'alt':	'Split bar silver bangle'	}
var P5= {'src':	'tile_prod_010-32.jpg',		'action':	'',	'alt':	'Gold plate segments silver cufflinks'	}
var P6= {'src':	'tile_prod_003-19.jpg',		'action':	'',	'alt':	'Silver dragonfly brooch'	}
// above are preloaded in static HTML
var P9= {'src':	'tile_product9.png',		'action':	'fade_in',	'alt':	'Gold teardrop earrings'	}
var P10= {'src':	'tile_prod_001-60.png',		'action':	'fade_in',	'alt':	'Mens silver bangle'			}
var P11= {'src':	'tile_prod_001-96.png',		'action':	'fade_in',	'alt':	'Silver bangle mother of pearl'			}
var P12= {'src':	'tile_prod_007-73.png',		'action':	'fade_in',	'alt':	'Amber heart silver pendant'		}
var P13= {'src':	'tile_prod_106-44.png',		'action':	'fade_in',	'alt':	'Gold tbar heart necklace'			}
var P14= {'src':	'tile_prod_113-15-4.jpg',	'action':	'fade_in',	'alt':	'Gold hoop earrings'		}
var P15= {'src':	'tile_prod_107-98.jpg',		'action':	'fade_in',	'alt':	'Gold heart pendant'		}
var P16= {'src':	'tile_prod_001-56.jpg',		'action':	'fade_in',	'alt':	'Silver bangle'			}
var P17= {'src':	'tile_prod_006-04.png',		'action':	'fade_in',	'alt':	'Silver ball necklace Tbar'		}
// ALL new Image() are loaded now as Javascript is interpreted. 
var DLV = new Image()
var DLV = {'src':	'tile_delivery.png',		'action':	'fade_in',	'alt':	'Free delivery 2-4 working days'		}
//var DLV = {'src':	'tile_reopen_4thjan.png',	'action':	'fade_in',	'alt':	'Sorry but we are closed for christmas. We will process your orders on the 4th January when we reopen'		}
//var DLV = {'src':	'tile_xmas_delivery.png',	'action':	'fade_in',	'alt':	'Order by Saturday morning 19th December for Christmas Delivery'		}
//var DLV = {'src':	'tile_late_xmas_delivery.png',	'action':	'fade_in',	'alt':	'Order by 1:30pm Tuesday 22nd December for Christmas Delivery'		}
//var DLV = {'src':	'tile_xmas_last_orders.png',	'action':	'fade_in',	'alt':	'Order by Thursday morning 18th December for Christmas Delivery? Ring us with product code 01202 518805. £5 Special delivery on orders under £100'		}

var CU1 = new Image()
var CU1 = {'src':	'tile_cust_jenny.png',		'action':	'fade_in',	'alt':	'Thanks really pleased ...recommended Jenny'}
var CU2 = new Image()
var CU2 = {'src':	'tile_cust_jacky.png',		'action':	'fade_in',	'alt':	'Jacky'				}
var CU3 = new Image()
var CU3 = {'src':	'tile_cust_sally.png',		'action':	'fade_in',	'alt':	'Sally'				}


var M1 = {'src':	'tile_9ctSSilver.png',		'action':	'fade_in',	'alt':	'9ct Gold and Sterling Silver'		}
var M2 = {'src':	'tile_fast_secure_easy.png',	'action':	'fade_in',	'alt':	'Fast, secure and easy to use'		}
var M4 = {'src':'tile_SALE25.png',			'action':	'fade_in',	'alt':	'SALE up to 25% off'		}
//var M2 = {'src':'tile_delivery.png',		'action':	'fade_in',	'alt':	'Free delivery 2-4 working days'		}
//var M4 = {'src':'tile_xmas_returns.png',	'action':	'fade_in',	'alt':	'Christmas Returns accepted to 14th January'		}
//var M4 = {'src':'tile_reopen2ndJan.png',		'action':	'fade_in',	'alt':	'Merry Christmas & a Happy New Year We Re-Open 2nd January'		}

var E2 = new Image()
var E2 = {'src':	'tile_enter2.png',		'action':	'fade_in',	'alt':	'Click to Enter'			}
var E4 = {'src':	'enter_ani.gif',			'action':	'load',	'alt':	'Click to Enter'			}

var BL = {'src':	'tile_template.png',		'action':	'fade_in',	'alt':	'1px'					}
var BB = {'src':	'tile_blank.png',			'action':	'load',	'alt':	'blank'				}
var BLF = {'src':	'tile_template.png',		'action':	'fade_out',	'alt':	'1px'					}

function create_fr()
{//Tiles
// NOTE THAT ERRORS MADE HERE CAUSE PAGE TO FREEZE (i.e. do nothing)
var centerblank= 		{	'cell':	xGetElementById('c79') ,	'tile':	BB	} // blank

var frame_delivery = 	{	'cell':	xGetElementById('c14') ,	'tile':	DLV	}

var framec1 = 		{	'cell':	xGetElementById('c1') ,	'tile':	P11	}
var frame_enterin = 	{	'cell':	xGetElementById('c79') ,	'tile':	E2	}
var frame_enter_ani = 	{	'cell':	xGetElementById('c79') ,	'tile':	E4	}


var frame_jenny = 	{	'cell':	xGetElementById('c2') ,	'tile':	CU1	}
var frame_sally = 	{	'cell':	xGetElementById('c4') ,	'tile':	CU3	}
var frame_jacky = 	{	'cell':	xGetElementById('c2') ,	'tile':	CU2	}

var frame_BQ = 		{	'cell':	xGetElementById('c12') ,	'tile':	M1	}
var frame_FSE = 		{	'cell':	xGetElementById('c14') ,	'tile':	M2	}
var frame_FDR = 		{	'cell':	xGetElementById('c12') ,	'tile':	M4	}

var frame_BL1 = 		{	'cell':	xGetElementById('c1') ,	'tile':	BLF	}
var frame_BL2 = 		{	'cell':	xGetElementById('c2') ,	'tile':	BLF	}
var frame_BL3 = 		{	'cell':	xGetElementById('c3') ,	'tile':	BLF	}
var frame_BL4 = 		{	'cell':	xGetElementById('c4') ,	'tile':	BLF	}
var frame_BL5 = 		{	'cell':	xGetElementById('c5') ,	'tile':	BLF	}
var frame_BL6 = 		{	'cell':	xGetElementById('c6') ,	'tile':	BLF	}
var frame_BL79 = 		{	'cell':	xGetElementById('c79') ,	'tile':	BLF	}
var frame_BL10 = 		{	'cell':	xGetElementById('c10') ,	'tile':	BLF	}
var frame_BL11 = 		{	'cell':	xGetElementById('c11') ,	'tile':	BLF	}
var frame_BL12 = 		{	'cell':	xGetElementById('c12') ,	'tile':	BLF	}
var frame_BL13 = 		{	'cell':	xGetElementById('c13') ,	'tile':	BLF	}
var frame_BL14 = 		{	'cell':	xGetElementById('c14') ,	'tile':	BLF	}
var frame_BL15 = 		{	'cell':	xGetElementById('c15') ,	'tile':	BLF	}

var frame_P10 = 		{	'cell':	xGetElementById('c11') ,	'tile':	P10	}
var frame_P12 = 		{	'cell':	xGetElementById('c13') ,	'tile':	P12	}
var frame_P9 = 		{	'cell':	xGetElementById('c10') ,	'tile':	P9	}

var frame_P11 = 		{	'cell':	xGetElementById('c11') ,	'tile':	P11	}
var frame_P13 = 		{	'cell':	xGetElementById('c3') ,	'tile':	P13	}
var frame_P14 = 		{	'cell':	xGetElementById('c5') ,	'tile':	P14	}
var frame_P15 = 		{	'cell':	xGetElementById('c1') ,	'tile':	P15	}
var frame_P17 = 		{	'cell':	xGetElementById('c13') ,	'tile':	P17	}

//							Framenames TO CREATE FRAMES
// create a number (Nfr) of aniframes (fr) using framename 
i=0
i=ani(i,frame_jenny)
i=ani(i,frame_sally)
i=ani(i,frame_BQ)
i=ani(i,frame_FSE)
i=ani(i,frame_jacky)
i=ani(i,frame_enterin)
i=ani(i,frame_FDR)
i=ani(i,frame_delivery)
i=ani(i,frame_BL11)
i=ani(i,frame_P10)
i=ani(i,frame_BL13)
i=ani(i,frame_P12)
i=ani(i,frame_BL3)
i=ani(i,frame_P13)
i=ani(i,frame_BL5)
i=ani(i,frame_P14)
i=ani(i,frame_BL11)
i=ani(i,frame_P11)
i=ani(i,frame_BL13)
i=ani(i,frame_P17)
i=ani(i,frame_BL1)
i=ani(i,frame_P15)
fr[i]=frame_enter_ani
i+=60
FN_max=i

}
 
function ani(i,aframe)
{
if (CPU.slow==true) 	{ fr[i]= aframe; return i + Nfr }		
else for (j=0;j< Nfr;j++,i++) { fr[i]= aframe; }
return i;
}

function home_body_onload()
{
//actualhundredms(); 			// takes 100ms and sees if CPU.slow= true
browser_change();				// adjustments for browser type
cpuwait=setTimeout("tell_story()",150);	// tell story for browser and cpu speed
//cache_images();
}

function tell_story()
{
create_fr(); 
var timen=setInterval( "paint_fr()", FrameRate);
}

function browser_change() {			//	Browser adaptations here if poss
		// OPACITY by browser type
		// Opacity and methods browsers support
		// restrict max opacity to prevent a visual popping effect in firefox
		// store the supported form of opacity as Nbrowser.type
var testi= xGetElementById('c1');
if(typeof testi.style.opacity != 'undefined')	{Nbrowser.type = 'w3c';}
else if(typeof testi.style.MozOpacity != 'undefined')	{Nbrowser.type = 'moz';}
else if(typeof testi.style.KhtmlOpacity != 'undefined')	{Nbrowser.type = 'khtml';}
		//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
		//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
		//then the returned value type, which should be a number, but in mac/ie5 is an empty string
else if(typeof testi.filters == 'object')	
	{Nbrowser.type = (testi.filters.length > 0 && typeof testi.filters.alpha == 'object' && typeof testi.filters.alpha.opacity == 'number') ? 'ie' : 'none';}
else {Nbrowser.type = 'none';}
//alert(Nbrowser.type)
}

function paint_opacity(tile,Nopacity)
{ 
xOpacity(tile, Nopacity)
/*
switch(Nbrowser.type)
{
case 'ie' :		tile.filters.alpha.opacity = Nopacity * 100; 
case 'khtml':	tile.style.KhtmlOpacity = Nopacity; 
case 'moz' : 	tile.style.MozOpacity = (Nopacity== 1 ? 0.9999999 : Nopacity); 
default : 		tile.style.opacity = (Nopacity== 1 ? 0.9999999 : Nopacity);
}// end switch
*/
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}


function xOpacity(e, o)
{
  var set = xDef(o);
  //  if (set && o == 1) o = .9999; // FF1.0.2 but not needed in 1.5
  if(!(e=xGetElementById(e))) return 2; // error
  if (xStr(e.style.opacity)) { // CSS3
    if (set) e.style.opacity = o + '';
    else o = parseFloat(e.style.opacity);
  }
  else if (xStr(e.style.filter)) { // IE5.5+
    if (set) e.style.filter = 'alpha(opacity=' + (100 * o) + ')';
    else if (e.filters && e.filters.alpha) { o = e.filters.alpha.opacity / 100; }
  }
  else if (xStr(e.style.MozOpacity)) { // Gecko before CSS3 support
    if (set) e.style.MozOpacity = o + '';
    else o = parseFloat(e.style.MozOpacity);
  }
  else if (xStr(e.style.KhtmlOpacity)) { // Konquerer and Safari
    if (set) e.style.KhtmlOpacity = o + '';
    else o = parseFloat(e.style.KhtmlOpacity);
  }
  return isNaN(o) ? 1 : o; // if NaN, should this return an error instead of 1?
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}


function paint_fr() 
{
if ( FN<FN_max ) 	
  { 
  paint_frame(FN);
  FN+=1;
  }
else 			
  {  
  clearTimeout(timen); 
//  window.status="Click Enter!";
  }
}

function paint_frame(N) {
if (fr[N])
  {
	if (CPU.slow==true) Action='load' 
	else Action=fr[N].tile.action
	switch(Action)
	{
	case 'load':	
		fr[N].cell.src=sitegfx+fr[N].tile.src; break;
	case 'fade_in':
		// grab image from first frame on Nfr
		paint_opacity( fr[N].cell, Fade_sine[N%Nfr]); 
		if (N%Nfr==0) 
			{
			fr[N].cell.src=sitegfx+fr[N].tile.src;
			paint_opacity( fr[N].cell,0);
			} 
		break;
	case 'fade_out':
		paint_opacity( fr[N].cell, Fade_sine[Nfr-N%Nfr]);
		if (N==Nfr-1) { fr[N].cell.src= sitegfx+BL.src; paint_opacity( fr[N].cell, 1);}
		break; 
	default:		break;
	} // end switch
  }
else return;// end if fr[N]
}



