window.defaultStatus = ' ';

var FlashTrackingIsEnabled = true; // enable Google Analytics to track Flash and other non-page events

var _dBug = 0;
var _dBugKeyBuffer = 0;

var showMessage = false;  // indicates whether an initial greeting message will be displayed before any other content

var motto = 'Let The Tiger Make Your Meal!';
var telephoneNumber = '(937) 878-2583';
var ohioSalesTax = 6.5; // Greene county; see https://thefinder.tax.ohio.gov/StreamlineSalesTaxWeb/ZipLookup/LookupByZip.aspx?taxType=Sales

var MenuHelpIsActive = false;

var cssTextLeft   = "'text-align: left;   width: 650px; margin: auto;'";     // 650
var cssTextCenter = "'text-align: center; width: 650px; margin: auto;'";
var cssTextRight  = "'text-align: right;  width: 650px; margin: auto;'";
var cssTextJustify  = "'text-align: justify;  width: 650px; margin: auto;'";

var pTextLeft   =  '<p style=' + cssTextLeft   + '>';
var pTextRight  =  '<p style=' + cssTextRight  + '>';
var pTextCenter =  '<p style=' + cssTextCenter + '>';
var pTextDefault = pTextCenter;
var pClose = '</p>'; 


var dTextLeft   =  '<div style=' + cssTextLeft   + '>';
var dTextRight  =  '<div style=' + cssTextRight  + '>';
var dTextCenter =  '<div style=' + cssTextCenter + '>';
var dTextJustify =  '<div style=' + cssTextJustify + '>';
var dTextDefault = dTextCenter;
var dClose = '</div>';

var deltaSharpness = deltaGamma = deltaColor = 1;

var rangeSharpness = rangeGamma = 'ae';
var rangeColor = 5;
var colorIndex = 1;

var menuSelectedColor = '#FF3300';
var activeLayer = '';
var prevItem = '';	

var _meal = 'lunch';

var menuPHPfile = 'menu4.php';  // increment w/changes to prevent caching

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1; //alert( InternetExplorer );

//alert( 'MSIE6: ' + MSIE6 );

/////////////////////////////////////////////////////////////
// used to detect keystrokes
/////////////////////////////////
var blnDOM = false, blnIE4 = false, blnNN4 = false; 

if (document.layers) blnNN4 = true;
else if (document.all) blnIE4 = true;
else if (document.getElementById) blnDOM = true;

function getKeycode(e) {
  if (blnNN4) {
    var NN4key = e.which
    //document.frmMain.txtShowKey.value = "Keycode = " + NN4key;
	//alert( NN4key );
	_dBugKeyBuffer = NN4key;
  }
  if (blnDOM) {	// FireFox
    var blnkey = e.which
    //document.frmMain.txtShowKey.value = "Keycode = " + blnkey;
	//alert( blnkey );
	_dBugKeyBuffer += blnkey; //alert( _dBugKeyBuffer );
  }
  if (blnIE4) {		// MSIE 6
    var IE4key = event.keyCode
	// document.frmMain.txtShowKey.value = "Keycode = " + IE4key
	//alert( IE4key );
	_dBugKeyBuffer += IE4key;
	}
}

document.onkeydown = getKeycode
if (blnNN4) document.captureEvents(Event.KEYDOWN)

/////////////////////////////////////////////////////////////


function Flying_Tiger_Chinese_DoFSCommand(command, args) {
	var Flying_Tiger_ChineseObj = InternetExplorer ? Flying_Tiger_Chinese : document.Flying_Tiger_Chinese;
	if( command == 'setStatus') { updateWinStatus( args ); }
	if( command == 'hidePanel') { hidePanel( args ); }
	if( command == 'showPanel') { showPanel( args ); }
}

function hidePanel( _panel ) { 
	if( activeLayer ) {
		$(activeLayer).hide();
		// $('guiButtonLayer').hide();
		if( prevItem == 'menuLayer' ) { $('menuOptionsLayer').hide(); }
		$('statusLayer').hide();
		if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUhidePanel"); }
	}
}

function showPanel( _panel ) {
	if( activeLayer ) {
		$(activeLayer).show();
		$('guiButtonLayer').show();
		if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowPanel"); }
		
		if( prevItem == 'menuLayer' ) {
			$('menuOptionsLayer').show();
			statusLayer();
		}
	}
}



function updateWinStatus( _text ) {
	switch( _text ) {
		case 'menu':
			return winStatus(' Browse our mouth-watering menu ');
			break;

		case 'hours':
			return winStatus(' Dine with us 7 days a week ');
			break;

		case 'phone':
			return winStatus(' Reserve your table or call-in a takeout order ');
			break;
		
		case 'map':
			return winStatus(' Find us fast with our interactive map ');
			break;
		
		case 'tour':
			return winStatus(' Come see the restaurant ');
			break;

		case 'welcome':
			return winStatus(' Greetings from the manager ');
			break;
		
		case '(next menu)':
			return winStatus(' [more options...] ');
			break;
			
		case '(main menu)':
			return winStatus(' [return to the main menu] ');
			break;
	}
}

function winStatus( _msg ) {
	window.status = _msg;
	return true;
}


function doMenu( _item ) {
	messageControl(); // if there's a greeting message, handle it
	
	activeLayer = _item + 'Layer';

	if( activeLayer != prevItem ) {
	
		if( prevItem ) {
			$(prevItem).hide();
			if( prevItem == 'menuLayer' ) { $('menuOptionsLayer').hide(); }
			if( prevItem == 'menuLayer' ) { $('statusLayer').hide(); }
		}

		switch( activeLayer ) {
			case 'welcomeLayer':
				$('welcomeLayer').update('<iframe id="welcomeIFrame" name="welcomeIFrame" src="./welcomeLayer.html" scrolling="yes" frameborder="0" width="705" height="244"  type="text/html"></iframe>');	

				$('welcomeLayer').show();
				
				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowWelcome"); }
				break;
			
			case 'menuLayer':
											
				if( MenuHelpIsActive ) {
					selectMenu();
				} else {
					refreshMenu();
				}
				
				$('menuLayer').show();
				$('menuOptionsLayer').show();
				statusLayer();

				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowMenu"); }
				break;
			
			case 'hoursLayer':
				$('hoursLayer').show();

				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowHours"); }
				break;
			
			case 'phoneLayer':
				$('phoneLayer').show();

				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowPhone"); }
				break;
			
			case 'mapLayer':
				$('mapLayer').update('<iframe id="mapIFrame" name="mapIFrame" src="./googlemap.html" scrolling="no" frameborder="0" width="705" height="330" type="text/html"></iframe>');
				
				$('mapLayer').show();

				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowMap"); }
				break;
			
			case 'tourLayer':
				$('tourLayer').show();

				if( FlashTrackingIsEnabled ) { pageTracker._trackPageview("/MENUshowTour"); }
				break;
		}
		prevItem = activeLayer;

	}
}

function messageControl() {
	if( showMessage ) {
			$('messageLayer').hide();
			//mainLayerIMG. src="./pix/frame1ScIcMa.jpg"; 
			$('guiButtonLayer').show();

			cycleMenuBackground( "gSaturationBTN" );
	}
}

function Prep() {
	////////////////////////////////////////
	// logic to center image on page HORZ & VERT
	////////////////////////////////////////
	obj = $( 'mainLayerIMG' );
	obj.anchorCenter();

	obj2 = $( 'mainLayer' );

	obj2.style.position = obj.style.position; // "absolute";
	//obj2.style.zIndex = obj.style.zIndex;
	
	obj2.style.top = obj.style.top // "50%";
	 obj2.style.marginTop = obj.style.marginTop;
	  obj2.style.height = obj.style.height;

	obj2.style.left = obj.style.left // "50%";
	 obj2.style.marginLeft = obj.style.marginLeft;
	  obj2.style.width = obj.style.width;

	
	
	/*
	alert( 'position = ' + obj2.style.position );
	alert( 'top = ' + obj2.style.top );
	alert( 'marginTop = ' + obj2.style.marginTop );
	alert( 'height = ' + obj2.style.height );
	alert( 'left = ' + obj2.style.left );
	alert( 'marginLeft = ' + obj2.style.marginLeft );
	alert( 'width = ' + obj2.style.width );
	*/

	obj2.setStyle( {
		marginTop: '-10em'
	});

	
	obj.show();

	adjustGUI();
	$( 'guiButtonLayer' ).show();
	statusLayer();

	$( 'menuBarLayer' ).show();

	////////////////////////////////////////
	// logic to display greeting messages
	////////////////////////////////////////
	if( showMessage ) { 
		$( 'messageLayer' ).show();
		mainLayerIMG. src="./pix/frame1SaIbMa.jpg";				// for Chinese New Year:  "./pix/frame1SaIbMa-red.jpg"; 
		$( 'guiButtonLayer' ).hide();
	}

	$( 'shadowLayer' ).show();

	////////////////////////////////////////
	// misc logic to correct Ms. IE 6+ box model display errors
	////////////////////////////////////////
	//if( MSIE6 ) {}


	
	////////////////////////////////////////
	// enable dragging of display window
	////////////////////////////////////////
	
	//if( !MSIE6 ) { Drag.init(document.getElementById("mainLayer")); }

	setBackground();

}

function statusLayer() {
	var _totqty = parseInt( $('total_qty').innerHTML );
	
	$('statusLayerText').update( ' selection costs $' );
	if( _totqty != 0 ) {
		if( _totqty > 1 ) { $('statusLayerText').update( ' selections cost $' ); }
		$('statusLayer').show();
	
	} else {
		$('statusLayer').hide();
	}
}

function setMenuDish( _arg ) {
	//alert( _arg.checked );
}

function clearMenu() { // Clear button
// clears all selections
	$('total_qty').innerHTML = 0;
	$('total_cost').innerHTML = 0.00;
	$('id_list').innerHTML = '';
	
	statusLayer();
	refreshMenu();
}

function zPrint( _target ) { // Print button
// prints the menu (iframe) window contents
	_target.focus();
	_target.print();
}

function refreshButtonControl() {
	MenuHelpIsActive=false;
	adjustGUI();
	refreshMenu();
}


function refreshMenu() { // Update Menu button
// updates the menu display to show checkbox categories,
// along with any selected menu items

	var menuSort = '/id'; //menuSort = '/name-cost';
	menuSort = '/cost';


	// ** headlines are set by default in the menu.php file **
	
	if( _meal == 'lunch' ) { var _headline = '/lunch'; }

	if( _meal == 'dinner' ) { var _headline = '/dinner'; }

	var parms = '/_meal' + '/' + _meal + '/_headline' + _headline + getSelections();
	
	parms += "/_showBeef/" +				( ( $('_showBeef').checked == true )			? '1' : '0' );
	 parms += "/_showChicken/" +		( ( $('_showChicken').checked == true )	? '1' : '0' );
	  parms += "/_showPork/" +			( ( $('_showPork').checked == true )		? '1' : '0' );
	   parms += "/_showSeafood/" +		( ( $('_showSeafood').checked == true )	? '1' : '0' );
		parms += "/_showVeggies/" +	( ( $('_showVeggies').checked == true )	? '1' : '0' );

	parms += "/menuSort" + menuSort;
					
	if ( _dBug ) { parms = "/debug/1" + parms; alert( parms ); }  
	
	///////////////////////////////////////////////////////////////////////

	writeDynamicIframe( parms );
}

function selectMenu() {  // View Selections button

	var _test = $('total_qty').innerHTML;  // have any items been selected?
	
	if( _dBug ) { alert( '_test ( ' + _test + ' ) \n' + 'MenuHelpIsActive ( ' + MenuHelpIsActive + ' ) \n' + '_meal  ( ' + _meal + ' )\n Selections: ' + getSelections() ); }

	if ( _test != 0 ) {

		var menuSort = '/name'; //menuSort = '/name-cost';
		
		/////////////////////////////////////
		// prebuilt css styles exist in the menu.php rendered page,
		// useful for standard headings, i.e. H6, H5, H4, H3, H2, and H1
		// (H1 is the largest)
		// e.g., insert '<h2>' in the _headline string
		// g1 - g6 also available (they are non-bold versions of h1-h6)
		// s6 is a small (10 px) font size
		/////////////////////////////////////
		var _v1 = ( $('total_qty').innerHTML == 1 ) ? '1 item, $' : $('total_qty').innerHTML + ' items, $';
		var _v2 = $('total_cost').innerHTML;
		_v2 = dollarFormat( _v2 );
		var _v3 = addSalesTax( _v2 );
		_v3 = dollarFormat( _v3 );

		_headline = '/' + urlAutoEncode(	dTextDefault + '<br /><g5>' + motto.bold() + '</g5><br />' +
			'<g6>' + _v1 + _v2 + ' total ($' + _v3 + ' when dining in)<br />' +
			'Call us at ' + telephoneNumber + ' to place this order</g6><br />' +
			dClose );

		var parms = '/_meal' + '/' + _meal + '/_headline' + _headline + getSelections();

		parms += "/menuSort" + menuSort;   

		if ( _dBug ) { parms = "/debug/1" + parms; alert( parms ); }  

		///////////////////////////////////////////////////////////////////////

		writeDynamicIframe( parms );

	} else {

		if( !MenuHelpIsActive ) {

			MenuHelpIsActive = true; adjustGUI();
		
			//_meal = 'none'; //cannot be blank!!
		
			//var pStyle = pStyleDefault;  // default centered text for entire PARAGRAPH
			
			var _headline = '/' +
				urlAutoEncode( dTextCenter + 
				'<br /><h3>Nothing is selected!</h3>' + dClose + 
				dTextJustify + '<br /><span style=\'color: brown;\'><g5><b>You have not selected</b> any menu items yet, ' +
				'and we have over 100 dishes to choose from! Customize the display to show only your selections ' + 
				'by clicking on items in the menu. A selected item is shown <span style=\'background-color: yellow;\'>highlighted</span>. ' +
				'<br /><br /><b>When you&rsquo;re finished choosing</b>, click the <span style=\'color: black;\'><button class=\'helpBTN\'>View Selections</button></span> button to see the list you&rsquo;ve made. This group of personal ' +
				'selections is like having your own custom menu, and is useful for comparing individual dishes, figuring ' +
				'the cost of a group of meals, or for printing as a phone order. Now, click the <span style=\'color: black;\'><button class=\'helpBTN\' onClick=\'window.parent.refreshButtonControl();\'>Update Menu</button></span> button to get started.</g5></span>' + dClose );
		
			parms = '/_meal/' + _meal + '/_headline' + _headline;
		
			if ( _dBug ) { parms = "/debug/1" + parms; alert( parms ); }  

			writeDynamicIframe( parms );
		}
	}
}

function writeDynamicIframe( _parms ) {
	var newHTML = '<iframe id="menuIFrame" name="menuIFrame" src="./' + menuPHPfile +
		_parms + '" scrolling="vertical" frameborder="0" width="700" height="240" type="text/html"></iframe>';

	//var newHTML = '<object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="http://flyingtigerchinese.com/menu.php' + _parms + '" id="menuIFrame" //name="menuIFrame" width="700" height="240" type="text/html"></object>';

	var obj = $('menuLayer');
	obj.update( newHTML );
}

function getSelections() {
	var _obj = $('id_list');
	var _selections = _obj.innerHTML;    // values are stored in hidden container on the menu frame
	_selections = _selections.strip();   // remove whitespace for and aft
	_selections = ( _selections.length ) ? '/' + _selections.replace( / /g, '/2/' ) + '/2' : '';
	return _selections;
}


// this makes a string safe to pass in the url,
// so that we can pass HTML for example as a parm to the menu
//
// it also performs moderate string translation, so that we
// can insert custom tags like '<g1>' into our text, and it
// will change it to '<span class="g1">'
function urlAutoEncode( _arg ) {
	_arg = strTranslate( _arg );
					
	var _ret = '', _char = '', _tmp = '', _e = '';
	var encodeList = "<>/%&é";

	for( var x=0; x<_arg.length; x++ ) {
		_char = _arg.substr( x, 1 );
		
		_tmp = _char;
		for( var y=0; y<encodeList.length; y++ ) {
			_e = encodeList.substr( y, 1 );
			if( _char.indexOf( _e ) != -1 ) { _tmp = urlEncode( _char ); }
		}
		
		//alert( _char + ' -> ' + _tmp );
		_ret += _tmp;
	}
	return _ret;
}

function urlEncode( _arg ) {
	var _ret = '', _char = '', _hex = '';
	
	for( var x=0; x<_arg.length; x++ ) {
		_char = _arg.substr( x, 1 );
		if( _char == '/' ) { _char = '`'; }
		if( _char == '%' ) { _char = '#'; }

		_hex = "%" + DecToHex( _char.charCodeAt(0) );
		_ret += _hex;
	}
	return _ret;			
}

function strTranslate( _arg ) {
	var  _out = '';
	_out = _arg.replace(      /<g1>/g, "<span class=\'g1\'>" );
	 _out = _out.replace(     /<g2>/g, "<span class=\'g2\'>" );
	  _out = _out.replace(    /<g3>/g, "<span class=\'g3\'>" );
	   _out = _out.replace(   /<g4>/g, "<span class=\'g4\'>" );
		_out = _out.replace(  /<g5>/g, "<span class=\'g5\'>" );
		 _out = _out.replace( /<g6>/g, "<span class=\'g6\'>" );

	_out = _out.replace(      /<\/g1>/g, "</span>" );       // </g1>
	 _out = _out.replace(     /<\/g2>/g, "</span>" );    
	  _out = _out.replace(    /<\/g3>/g, "</span>" );    
	   _out = _out.replace(   /<\/g4>/g, "</span>" );   
		_out = _out.replace(  /<\/g5>/g, "</span>" );    
		 _out = _out.replace( /<\/g6>/g, "</span>" );    
	
	return _out;
}


function DecToHex( _dec ) {
	var hD="0123456789ABCDEF";
	var h = hD.substr( _dec & 15, 1 );
	while( _dec > 15 ) { _dec >>= 4; h = hD.substr( _dec & 15, 1 ) + h; }
	return h;
}

function HexToDec( _hex ) { return parseInt( h,16 ); } 
			

var deltaSharpness = 1;
var deltaGamma = 1;
var deltaColor = 1;

var rangeSharpness = 'ae';
var rangeGamma = 'ae';
var rangeColor = 5, colorIndex = 1;

function cycleMenuBackground( _in ) {
	var _fnum = 0;
	var _sharp = _gamma = _color = '';
	var newSRC = '';

	_fnum = getRegExFromFilename( /.*(\d).*/ );
		
	_sharp = getRegExFromFilename( /.*S(\D).*/ );
	_gamma = getRegExFromFilename( /.*I(\D).*/ );
	_color = getRegExFromFilename( /.*M(\D).*/ );
				
	switch( _in ) {
		case 'gSharpnessBTN':
			_sharp = _sharp.charCodeAt(0) + deltaSharpness;  
			
			if( _sharp > rangeSharpness.charCodeAt(1) ) {
				_sharp -= 2;
				deltaSharpness *= -1;
			}
			if( _sharp < rangeSharpness.charCodeAt(0) ) {
				_sharp += 2;
				deltaSharpness *= -1;
			}
								
			_sharp = String.fromCharCode( _sharp ); 
			break;
			
		case 'gGammaBTN':
			_gamma = _gamma.charCodeAt(0) + deltaGamma;  
			
			if( _gamma > rangeGamma.charCodeAt(1) ) {
				_gamma -= 2;
				deltaGamma *= -1;
			}
			if( _gamma < rangeGamma.charCodeAt(0) ) {
				_gamma += 2;
				deltaGamma *= -1;
			}
								
			_gamma = String.fromCharCode( _gamma ); 
			break;

		case 'gSaturationBTN':
			 _dBugKeyBuffer = 0;
			if( _dBug == 1 ) {
				_dBug = 0;
				alert( 'debug mode: OFF' );
		}
		
			if( deltaColor == 1 ) {
				TimerIsRunning = true;
				fadeStart();
			} else {
				window.clearInterval( _timerID );
				TimerIsRunning = false;
			}
			
			deltaColor *= -1 ;
			
			adjustGUI();
			break;

		case 'gResetBTN':
			if( _dBugKeyBuffer == 449 ) { 
				_dBug = 1;
				alert( 'debug mode: ON' );
			}
			
			if( _dBugKeyBuffer == 401 ) { 
				if( !MSIE6 ) { 	Drag.init(document.getElementById("mainLayer")); }
			}

			if( _dBugKeyBuffer != 401 ) { 
				deltaSharpness = deltaGamma = deltaColor = 1;
				_sharp = _gamma = 'c';

				window.clearInterval( _timerID );
				TimerIsRunning = false;
				faderValue = 99;
				faderPlus  = 0;
				faderMinus = 1;
		
				fade_IE_filter( 99 ); 

				adjustGUI();
			}
			break;
	}

	if( _in != 'gSaturationBTN' ) {
		newSRC = 'frame' + _fnum + 'S' + _sharp + 'I' + _gamma + 'M' + _color  + '.jpg'; 
		mainLayerIMG.src = './pix/' + newSRC;
	}
}

function getRegExFromFilename( _regex ) {
	var match = _regex.exec( mainLayerIMG.src );
	return match[1];
}

function roundToPennies( _n ) {
	var pennies = Math.round( _n * 100 );
	var strPennies = '' + pennies;
	var len = strPennies.length;
	return parseFloat( strPennies.substring( 0, len - 2 ) + '.' + strPennies.substring( len - 2, len ));
}

function addSalesTax( _amt ) {
	_amt = parseFloat( _amt );
	_amt += ( _amt * ( ohioSalesTax * 0.01 ));
	return roundToPennies( _amt );
}

function dollarFormat( _amt ) {
	var sAmt = _amt + '';
	if( sAmt.indexOf('.') == -1 ) { sAmt += '.00'; }
	var aAmt = sAmt.split('.');
	if( aAmt[1].length == 1 ) { sAmt += '0'; }
	return sAmt;
}

function adjustGUI() {
	//if( InternetExplorer ) { $('menuOptionsLayer').style.width = '706px'; }
	// fix dumb IE 6.0 render issue where it's short a pixel, go figure...
	// IE 7.0 is fine
	//alert(_timerID);

	if( TimerIsRunning ) {
		$('gSaturationBTN').title = " Translucense: cycling "; 
		$('gSaturationBTN').statusText = " Fade starting from " + eval('100 - faderValue') + "% transparency ";
	} else {
		$('gSaturationBTN').title = " Translucense ";
		$('gSaturationBTN').statusText = " ";
	}				
	
	if( MenuHelpIsActive ) {
		$('selectMenuBTN').title = " There are no selected menu items to view ";
		$('selectMenuBTN').statusText = " You have no selections. Please choose something from the menu. "
		//return winStatus( $('selectMenuBTN').statusText );

	} else {
		$('selectMenuBTN').title = " View selections and total price ";
		$('selectMenuBTN').statusText = " View your custom menu showing selections, totals and price including sales tax. "
		//return winStatus( $('selectMenuBTN').statusText );
	}
}

function jsCSS( a, o, c1, c2 ) {
	switch (a) {
		case 'swap':
			o.className =! jscss( 'check', o, c1 ) ? o.className.replace( c2, c1 ) : o.className.replace( c1, c2 );
			break;
		case 'add':
			if( !jsCSS( 'check', o, c1 )) { o.className += o.className ? ' '+c1 : c1; }
			break;
		case 'remove':
			var rep = o.className.match( ' '+c1 ) ? ' '+c1 : c1;
			o.className = o.className.replace( rep, '' );
			break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
			break;
	}
}
/*
function jsCSS [use to manage CSS classes for elements]

This function takes four parameters:
a  -- defines the action you want the function to perform. 
o  -- the object in question. 
c1 -- the name of the first class 
c2 -- the name of the second class 

Possible actions are:
swap -- replaces class c1 with class c2 in object o. 
add  -- adds class c1 to the object o. 
remove -- removes class c1 from the object o. 
check  -- test if class c1 is already applied to object o and returns true or false. 

credit: ////////////////////////////////////////////////////////////////////////////////
Unobtrusive Javascript (Separation of CSS and Javascript)
http://onlinetools.org/articles/unobtrusivejavascript/index.html [cached in Google]
////////////////////////////////////////////////////////////////////////////////////////
*/

function applyFilter( _o, _filter ) {
	jsCSS( 'add', _o, _filter );
}


var faderValue = 99; // can't do '100' because of a FF bug
var faderPlus = 0;
var faderMinus = 1;

var faderHiBound = 99;
var faderLoBound = 40;

var _timerID = 0; TimerIsRunning = false;

function fade_IE() {
	if( faderValue < faderHiBound && faderPlus ) {
		faderValue += 1;
	} else {
		faderPlus  = 0;
		faderMinus = 1;
	}

	if( faderValue > faderLoBound && faderMinus ) {
		faderValue -= 1;
	} else {
		faderPlus  = 1;
		faderMinus = 0;
	} 

	fade_IE_filter( faderValue );
}

function fade_IE_filter( _val ) {
	if( InternetExplorer ) {
		$( 'mainLayerIMG' ).filters[0].opacity = _val;
	} else {
		$( 'mainLayerIMG' ).style.opacity = _val/100;
	}
}

function fadeStart() {
	_timerID = setInterval( "fade_IE()",  400 ); 
	//if( window.sidebar ) { setInterval( "fade_MOZ()", 400 );  }
	//if( document.all )   { }
}


var myDays = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
today = new Date();
thisDay = today.getDay();
thisDay = myDays[thisDay]; 


function rand ( n ) {
	return ( Math.floor( Math.random() * n + 1 ));
}

function getRandomNumber( loBound, hiBound ) {
	var _lob, _hib;

	_loB = loBound;
	_hiB = hiBound - loBound + 1;
	
	if( loBound > hiBound ) { 
		_loB = hiBound;
		_hiB = loBound - hiBound + 1;
	}

	var random_num = Math.floor( Math.random( initRNG( 1 ) ) * _hiB ) + _loB;
	return random_num;
}

// Use actual time to initialize (seed) the random function
function initRNG( _konstant ) {
	var rngS1 = new Date().getMilliseconds();
	var rngS2 = new Date().getMilliseconds();
	var rngS3 = new Date().getSeconds();
	var rngSeed = (( rngS1 * _konstant ) - rngS2 ) + rngS3; //alert( rngSeed );
	return rngSeed;
}

function percent( _percentage ) {
	var _pnum;
	_pnum = getRandomNumber( 1, 100 ); 

	if( _pnum > _percentage ) {
		return false;
	} else {
		return true;
	}
}

function setBackground() {
	var _postFix = 'a_1';
	var _newBackgroundImg = './pix/bg14' + _postFix + '.jpg';

	adjustMainLayer( 999 );
		
	if( rand( 100 ) < 31 ) {
		var _newBackgroundImg = getRandomNumber( 15, 17 );
		adjustMainLayer( _newBackgroundImg );
		_newBackgroundImg = './pix/bg' + _newBackgroundImg + _postFix + '.jpg';
	}
	document.body.style.background = "url('" + _newBackgroundImg + "') white fixed no-repeat center center";
}

function adjustMainLayer( _val ) {
	if( !showMessage ) {
	
		switch( _val ) {
			case 15:
				$('vistaLayer').hide();
				$( 'mainLayerIMG' ).src = "./pix/frame1SaIdMa.jpg";
				fade_IE_filter( 80 );
				break;

			case 16:
				$('vistaLayer').hide();
				$( 'mainLayerIMG' ).src = "./pix/frame1SbIbMa.jpg";
				fade_IE_filter( 60 );
				break;

			case 17:
				$('vistaLayer').hide();
				$( 'mainLayerIMG' ).src = "./pix/frame1SeIcMa.jpg";
				fade_IE_filter( 80 );
				break;
		
			case 999:		// Windows VISTA-ish look 
				$('vistaLayer').show();  // normally hidden
				$( 'mainLayerIMG' ).src = "./pix/frame1SdIeMa.jpg";  
				fade_IE_filter( 40 );
				break;
		}
	}
}


////////////////////////////////////////////
// globals
// var gtotal_qty = 0;


////////////////////////////////////////////