if (document.images) {
	var imageNames = new Array("next", "previous", "nav_30day", "nav_7dayplanner", "nav_dietrecipes", "nav_faq", "nav_aboutCCNW");
	var imagePath = "images-nav/";
	var imageExtension = ".gif";
	var allMyImages = new Array(imageNames.length);
	var curName = "";
	var gWhichGlowing = "";

	for (var i=0; i<imageNames.length; i++) {
		curName = imageNames[i];
		allMyImages[curName] = new Array("over", "out", "off");
		allMyImages[curName]["out"] = new Image();
		allMyImages[curName]["out"].src = imagePath+curName+"-out"+imageExtension;
		allMyImages[curName]["over"] = new Image();
		allMyImages[curName]["over"].src = imagePath+curName+"-over"+imageExtension;
		allMyImages[curName]["off"] = new Image();
		allMyImages[curName]["off"].src = imagePath+curName+"-off"+imageExtension;
		}
}

function aGlow(whichImage) {
	if (document.images) {
		document[whichImage].src = allMyImages[whichImage]["over"].src;
		gWhichGlowing = whichImage;
	}
}

function aDeGlow(){
	if (document.images) {
		document[gWhichGlowing].src = allMyImages[gWhichGlowing]["out"].src;
		gWhichGlowing = "";
	}
}

function PopUp(a,features){
	if (!features) features='channelmode=0,directories=0,fullscreen=0,width=600,height=400,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0';
	if (!/resizable/.test(features)) features+=',resizable=1';
	if (!/scrollbars/.test(features)) features+=',scrollbars=1';
	var w = window.open(a.href,a.target,features);
	try{ w.focus() }catch(e){}
	try{
		AttachEvent(w,'load',function(){
			try{
				var bh = w.document.body.offsetHeight;
				var html = w.document.getElementsByTagName('html');
				if (html && html.length>0){
					var hh = html[0].offsetHeight;
					var sh = screen.availHeight;
					//alert('hh=' + hh + '\n' + 'sh=' + sh + '\n' + 'bh=' + bh + '\n' + 'screen.availHeight=' + screen.availHeight + '\n');
					var y_delta = (hh + 50 > sh) ? (sh - hh - 50) : 0;
					w.resizeBy(0,y_delta);
				}
			}catch(e_inner){}
		},false);
	}catch(e){}
	return PreventDefault();
}

var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

if (document.images){
	var imgCache=[];
	(imgCache[0] = new Image()).src = "images/tab_1200-sel.gif";
	(imgCache[1] = new Image()).src = "images/tab_1600-sel.gif";
	(imgCache[2] = new Image()).src = "images/tab_2000-sel.gif";
}

var calorieCount = 1200;
var day = 1;
//var day_id = [];
var dayPlanner = [];
var currentMenu;
var minDayNum=1,maxDayNum=5;

function SetTab(calories) {
	var selTab = document.getElementById('calorietab_'+calorieCount);
	if (selTab) selTab.src = selTab.src.replace(/-sel.gif/i,'.gif');

	var newTab = document.getElementById('calorietab_'+calories);
	if (newTab) newTab.src = newTab.src.replace(/(-sel)?.gif/i,'-sel.gif');

	calorieCount = calories;
	ShowCurrentMenu();
}


function NextDay() {
	if ((day+=1)>maxDayNum) day=maxDayNum;
	ShowCurrentMenu();
}

function PreviousDay() {
	if ((day-=1)<minDayNum) day=minDayNum;
	ShowCurrentMenu();
}

function ShowCurrentMenu(){
	//if (currentMenu) currentMenu.style.display='none';
	//currentMenu = document.getElementById('day'+day+'_'+calorieCount);
	//if (currentMenu) currentMenu.style.display='block';
	//else return alert("Can't find current menu for day "+day+" and calorieCount"+calorieCount+"!");

	document.getElementById('selectedMenuContainer').innerHTML = document.getElementById('day'+day+'_'+calorieCount).innerHTML;

	UpdateSampleMenuFooter();
}


function UpdateSampleMenuFooter(){
	var img = document.getElementById('prevDayButton');
	if (!img) return alert("Can't find prevDayButton.");
	var link = (day>minDayNum);
	img.src = img.src.replace(/(-[a-z]+)?.gif/i, link?'-out.gif':'-off.gif' );
	img.onclick     = link ? PreviousDay : null;
	img.onmouseout  = link ? aDeGlow : null;
	img.onmouseover = link ? function(){ aGlow('previous') } : null;
	img.className   = link ? 'jslink' : '';

	var img = document.getElementById('nextDayButton');
	if (!img) return alert("Can't find nextDayButton.");
	var link = (day<maxDayNum);
	img.src = img.src.replace(/(-[a-z]+)?.gif/i, link?'-out.gif':'-off.gif' );
	img.onclick     = link ? NextDay : null;
	img.onmouseout  = link ? aDeGlow : null;
	img.onmouseover = link ? function(){ aGlow('next') } : null;
	img.className   = link ? 'jslink' : '';
}
