var tempHtml;
var tempStr1;
var tempStr2;
if (section == null)	var section = 0;
if (level1 == null)	var level1 = "";
if (level2 == null)	var level2 = "";
if (level3 == null)	var level3 = "";
if (selectArray == null)	var selectArray = null;
var id1 = null;
var id2 = null;
var id3 = null;
var groupButton1_array = new Array();
var groupButton_current = null;

/*
if (location.search != '')
{
	if (GetParam('level1'))	level1 = GetParam('level1');
	if (GetParam('level2'))	level2 = GetParam('level2');
	if (GetParam('level3'))	level3 = GetParam('level3');
}*/


//getLevel();
genId();


function getLevel() {
	var link = location.href.toString();
	var obj = sectionArray[section];

	if (level1 == "") {
		for (var i=0; i<obj.length; i++) {
			if (link.indexOf(("/" + obj[i].id + "/")) > -1) {
				level1 = obj[i].id;

				if (level2 == "" && obj[i].subSection) {
					var obj1 = obj[i].subSection;

					for (var j=0; j<obj1.length; j++) {
						if (link.indexOf((obj1[j].id)) > -1) {
							level2 = obj1[j].id;

							if (level3 == "" && obj1[j].subSection) {
								var obj2 = obj1[j].subSection;

								for (var k=0; k<obj2.length; k++) {
									if (link.indexOf((obj2[k].id)) > -1) {
										level3 = obj2[k].id;

										break;
									}
								}
							} else {
								break;
							}
						}
					}
				} else {
					break;
				}
			}
		}
	}

//	alert("level2: "+level2);
}


function genId() {
	var obj = sectionArray[section];

	if (level1 != "") {
		for (var i=0; i<obj.length; i++) {
			//alert(obj[i].id + "  " + level1);
			if (obj[i].id == level1) {
				id1 = i;

				if (level2 != "") {
					var obj1 = obj[i].subSection;
					for (var j=0; j<obj1.length; j++) {
						//alert(obj[i].id + "  " + level1);
						if (obj1[j].id == level2) {
							id2 = j;

							if (level3 != "") {
								var obj2 = obj1[j].subSection;
								for (var k=0; k<obj2.length; k++) {
									//alert(obj[i].id + "  " + level1);
									if (obj2[k].id == level3) {
										id3 = k;
										break;
									}
								}
							} else {
								break;
							}
						}
					}
				} else {
					break;
				}
			}
		}
	}
//alert("id1: "+id1+"   id2: "+id2+"   id3: "+id3);
}

function genTop(section) {
	tempHtml = '';

	tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '	<tr>';
	tempHtml += '		<td valign="top" align="center" style="background:url('+path+'images/common/bg.gif) no-repeat center top;">';
	tempHtml += '			<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '				<tr valign="center">';
	tempHtml += '					<td>';
	tempHtml += '						<div style="position:absolute;"  id="menu">';

	innerFlash(''+path+'images/swf/nav/nav.swf', '1100', '216', 'nav', ('path='+path+'&id1='+id1));

	tempHtml += '						</div>';

	document.write(tempHtml);
}

function genFooter(pad) {
	tempHtml = '';

	if (pad) {
		var str = pad;
	} else {
		var str = 0;
	}

	tempHtml += '						<table width="1100" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '							<tr>';
	tempHtml += '								<td class="footer" style="padding:10px 40px 0px 0px;" align="right">Copyright 2008-2012 &copy; Anahata Yoga. All rights reserved.</td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
	tempHtml += '					</td>';
	tempHtml += '				</tr>';
	tempHtml += '			</table>';
	tempHtml += '		</td>';
	tempHtml += '	</tr>';
	tempHtml += '</table>';

	document.write(tempHtml);
}

function changeButtonStatus() {
	var idStr = arguments[0];
	var targetImg = document.getElementById(arguments[0]);
	if (!targetImg) return false;
	//status = {'link', 'hover','active','selected','visited'};
	var status = arguments[1];
	switch (status) {
		case 'link':
			if (groupButton_current != idStr) {
				targetImg.src = groupButton1_array[idStr].src;
			}
			break;
		case 'hover':
			if (groupButton_current != idStr) {
				targetImg.src = groupButton1_array[idStr].altsrc;
			}
			break;
		case 'selected':
			targetImg.src = groupButton1_array[idStr].altsrc;
			groupButton_current = idStr;
			changeButtonOthersExcept(idStr, groupButton1_array);
			break;
		case 'active':
			break;
		case 'visited':
			break;
		default:
			if (groupButton_current != idStr) {
				targetImg.src = groupButton1_array[idStr].src;
			}		
	}
}

function changeButtonOthersExcept(targetStr, buttonArray) {
	for (var item in buttonArray) {
			 
		if (item != targetStr) {
			var tempImg = document.getElementById(item);
			if (tempImg) {
				tempImg.src = groupButton1_array[item].src;
			}
		}
	}
}

function initGroupButton(groupButtonStr) {
	var groupButton = document.getElementById(groupButtonStr);
	var list = groupButton.getElementsByTagName('img');

	var counter = 0;
	//for (var item in list) {
	for (var item=0;item<list.length;item++) {
		var e = list[item];
		if (typeof(e)!="object") continue;
		counter++;
		var id = e.getAttribute('id');
		
		var temp = {altsrc:e.getAttribute('altsrc'), src:e.getAttribute('src')};
		groupButton1_array[id] = temp;
		// preLoad altsrc image of the button
		var dummyImage = new Image();
		dummyImage.src = e.getAttribute('altsrc');
	}
	changeButtonStatus('yogananth','selected') ;
}


function genInstructor() {
	var sect = 0;
	var obj = instructorArray[sect];

	tempHtml = '';

	tempHtml += '<table width="1100" border="0" cellspacing="0" cellpadding="0" align="center">';
	tempHtml += '	<tr>';
	tempHtml += '		<td><img src="'+path+'images/instructors/banner.jpg" width="1100" height="260"></td>';
	tempHtml += '	</tr>';
	tempHtml += '	<tr valign="top">';
	tempHtml += '		<td style="background:url('+path+'images/instructors/bg_title.gif) repeat-x top;" height="205">';
	tempHtml += '			<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">';
	tempHtml += '				<tr valign="top">';
	tempHtml += '					<td align="right" style="padding:0px 40px 0px 0px;"><img src="'+path+'images/instructors/title.gif" alt="Instructors"></td>';
	tempHtml += '				</tr>';
	tempHtml += '				<tr valign="bottom">';
	tempHtml += '					<td height="100%">';
	tempHtml += '						<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '							<tr>';
	tempHtml += '								<td width="70" align="center"><a href="javascript:;" onmousedown="scrollStop(); scrollStart(\'instructorsNav\', -3)" onmouseup="scrollStop();"><img src="'+path+'images/instructors/arrow_l.gif" width="29" height="31" border="0"></a></td>';
	tempHtml += '								<td align="center">';
	tempHtml += '									<div style="width:1010px; overflow:hidden;" id="instructorsNav">';
	tempHtml += '										<table id="groupButton1" width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '											<tr valign="bottom">';

	for (var i=0; i<obj.length; i++) {

			tempStr1 = '';
			var isSect = 0;

		tempHtml += '<td>';
		tempHtml += '<a href="javascript:changeButtonStatus(\''+obj[i].id+'\',\'selected\');genContent('+i+');"  onMouseOut="changeButtonStatus(\''+obj[i].id+'\',\'link\');" onMouseOver="changeButtonStatus(\''+obj[i].id+'\',\'hover\');">';
		tempHtml += '<img src="'+path+'images/instructors/'+obj[i].id+tempStr1+'.jpg" border="0" hspace="2" id="'+obj[i].id+'"  name="'+obj[i].id+'" alt="'+obj[i].name+'"  altsrc="'+path+'images/instructors/'+obj[i].id+tempStr1+'_on.jpg">';
		tempHtml += '</a>';
		tempHtml += '</td>';
		
		MM_preloadImages(path+'images/instructors/'+obj[i].id+'_lrg.jpg');
	}


	tempHtml += '											</tr>';
	tempHtml += '										</table>';
	tempHtml += '									</div>';
	tempHtml += '								</td>';
	tempHtml += '								<td width="70" align="center"><a href="javascript:;" onmousedown="scrollStop(); scrollStart(\'instructorsNav\', 3)" onmouseup="scrollStop();"><img src="'+path+'images/instructors/arrow_r.gif" width="29" height="31" border="0"></a></td>';
	tempHtml += '							</tr>';
	tempHtml += '						</table>';
	tempHtml += '					</td>';
	tempHtml += '				</tr>';
	tempHtml += '			</table>';
	tempHtml += '		</td>';
	tempHtml += '	</tr>';

	tempHtml += '	<tr>';
	tempHtml += '		<td style="padding:15px 0px 0px 0px;">';
	tempHtml += '<span id="inDetail"></span>';
	//genContent(obj[0]);
	tempHtml += '		</td>';
	tempHtml += '	</tr>';

	tempHtml += '</table>';
	document.write(tempHtml);
	genContent(0);
	initGroupButton("groupButton1");
}

function genContent(id)
{
	var sect = 0;
	var obj = instructorArray[sect];

	var tempTxt = '';

	tempTxt += '			<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempTxt += '				<tr valign="top">';
	tempTxt += '					<td width="273"><img src="'+path+'images/instructors/'+obj[id].id+'_lrg.jpg" width="273" height="335" hspace="20"></td>';
	tempTxt += '					<td style="padding:18px 40px 0px 0px;">';
	tempTxt += '						<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempTxt += '							<tr valign="top">';
	tempTxt += '								<td class="content" style="padding:0px 0px 5px 0px;" height="23"><img src="'+path+'images/instructors/title_'+obj[id].id+'.jpg" alt="'+obj[id].name+'"></td>';
	tempTxt += '							</tr>';
	tempTxt += '							<tr>';
	tempTxt += '								<td class="content">'+obj[id].txt+'</td>';
	tempTxt += '							</tr>';
	if (obj[id].tag != '') {
		tempTxt += '							<tr>';
		tempTxt += '								<td class="content" style="padding:30px 0px 0px 0px;"><img src="'+path+'images/instructors/tag_'+obj[id].id+'.gif" alt="'+obj[id].tag+'"></td>';
		tempTxt += '							</tr>';
	}
	if (obj[id].link != '') {
		tempTxt += '							<tr>';
		tempTxt += '								<td class="content" style="padding:30px 0px 0px 0px;"><a href="javascript:NewWindow(\'profile_'+obj[id].link+'.htm\',\'profile\',\'415\',\'500\',\'yes\',\'no\');"><img src="'+path+'images/instructors/profile_'+obj[id].id+'.gif" alt="'+obj[id].name+'\'s profile" border="0"></a></td>';
		tempTxt += '							</tr>';
	}
	tempTxt += '						</table>';
	tempTxt += '					</td>';
	tempTxt += '				</tr>';
	tempTxt += '			</table>';

	document.getElementById("inDetail").innerHTML = tempTxt;
//	return tempTxt;
}

function genHome() {
	var sect = 0;
	var obj = homeArray[sect];
	var num = Math.round(Math.random() * 6 ) + 1;
	
	tempHtml = '';
	tempHtml += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	tempHtml += '	<tr valign="top">';
	tempHtml += '		<td width="74"><div style="border:#D2C3AC 1px solid;"><img src="images/home/img_'+num+'.jpg" width="74" height="74"></div></td>';
	tempHtml += '<td style="padding:0px 0px 0px 12px;" class="content"><strong class="title">'+obj[num-1].name+'</strong><br>'+obj[num-1].txt+'<br><div align="right" style="padding:5px 0px 0px 0px;"><img src="images/common/arrow.gif" width="5" height="5" align="middle" vspace="2"> <a href="'+path+'instructors/index.htm" class="content">more</a></div></td>';

	tempHtml += '</tr>';
	tempHtml += '</table>';
	
	document.write(tempHtml);
}
