d=document;w=window;bg_no=null;cg=null;clr=null;dw=null;dh=null;
var IE = (d.getElementById && d.all); 
var NS = (d.getElementById && !d.all); 
var NDR=0;if(parent.document.title=='Native Drums 1.0'){NDR=1;}

function f1(){setTimeout('bgid=3;go_module(13,0);set_sheets(null,4);',200);}
function f2(){setTimeout('bgid=2;go_module(14,0);set_sheets(null,3);',200);} 
function f3(){setTimeout('bgid=1;go_module(0,0);set_sheets(null,1);',200);}
function fr1(){setTimeout('bgid=1;va_module(0,0);set_sheets(null,1);',200);}
function fr2(){setTimeout('bgid=2;va_module(7,0);set_sheets(null,3);',200);} 
function fr3(){setTimeout('bgid=3;va_module(8,0);set_sheets(null,4);',200);}
function f4(){size=3;set_sheets(3,null);}
function f5(){size=2;set_sheets(2,null);}
function f6(){size=1;set_sheets(1,null);}
function on (ob){if(IE){ob.style.filter='alpha(opacity=100)';}else{ob.style.MozOpacity=1;}}
function off(ob){if(IE){ob.style.filter='alpha(opacity=50)';}else{ob.style.MozOpacity=0.5;}}

function createCookie(name,value,days){if (days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=";expires="+date.toGMTString();}else expires="";document.cookie=name+"="+value+expires+";path=/";}
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}return null;}

//  bgid   = what ever was passed in or default set by php
//  cgid   = what ever was passed in or default set by php
var size   = 1;						// default values 
var colour = 1;						// used if nothing passed into set_sheets();
function set_sheets(sz,clr,bg){

	if((typeof( sz)=='undefined')||(sz ==null)){sz =size;}
	if((typeof(clr)=='undefined')||(clr==null)){clr=colour}
	if((typeof( bg)=='undefined')||(bg ==null)){bg =bgid;}
	
	var sizesheetname = 'size'+sz;
	var clrsheetname  =  'clr'+clr;
	var bgsheetname   =   'bg'+bg;
	var nolinks = document.getElementsByTagName("link");
	
	// turn off all alternate style sheets
	for(var i=0;i<nolinks.length;i++){
	//	confirm('i='+i);
		var sheet = document.getElementsByTagName("link")[i];
		if(sheet.getAttribute("rel").indexOf("style")!=-1&&sheet.getAttribute("title")){
			sheet.disabled=true;}}

	// turn on the desired sheets
	for(var i=0;i<nolinks.length;i++){
		var sheet = document.getElementsByTagName("link")[i];
		if(sheet.getAttribute("rel").indexOf("style")!=-1&&sheet.getAttribute("title")){
		if(sheet.getAttribute("title")==sizesheetname){sheet.disabled=false;}
		if(sheet.getAttribute("title")==clrsheetname) {sheet.disabled=false;}
		if(sheet.getAttribute("title")==bgsheetname)  {sheet.disabled=false;}
		}}
	
	// save the values to make them available to the next page load
	// bg is not saved in a cookie, it is propagated thru the query string
	createCookie("colour", clr,365);
	createCookie("size",sz,365);
	if(tempid=='i'){ 	// interactive mode
		// should be able to just snag the bg colour from the dom and assign it to the parent's background colour but this works
		parent.document.body.style.backgroundColor=bgclrin;}
}


function load_env(){
    
	var raven = document.getElementById("rav").style;		// hide the raven if gallery
	if(document.getElementById("tim")){raven.visibility="hidden";}else{raven.visibility="visible";}

	cookie = readCookie("cg");
	if(cookie==null){cg=1;}else{cg=cookie;}
	if(_acc){show_gallery_fn(cg);}

	cookie = readCookie("colour");
	if(cookie==null){colour=1;}else{colour=cookie;}

	cookie = readCookie("size");
	if(cookie==null){size=1;}else{size=cookie;}

    set_sheets(size,colour)		  				// should bgid be passed in here?
    if((bgid==0)||(bgid==1)){showgroup_fn(2);}	// else{showgroup_fn(3)}
}

// move this onto the server - how to julio?
// possibly use database fields as input to javascript that generates the proper links on load? document.write...
// embed php code into content
var chapname = new Array('home','Myths','Drumming','Music','Sound','Interviews','Showcase','Galleries','Stories','Video','Press','About','Card','Scholars','Teachers');
var topname	 = new Array();
topname[0] = new Array('');
topname[1] = new Array('','Oral_Traditions','About_Stories','Storytellers','The_Stories','What_It_Means','Importance','Bibliography');
topname[2] = new Array('','Culture','Construction','A_Cree_Drum','An_Inuit_Drum','Snared_Drums','Flutes','Qilautik','Strings','Rattles','Bibliography');
topname[3] = new Array('','Introduction','Structuring','Uniqueness','Singing','Context','Drum_Dance','Social_Dance','Powwow','Glossary','Bibliography','Links');
topname[4] = new Array('','Introduction','Physics','Waves','The_Ear','Perception','Entrainment','Instruments','Epilogue','Bibliography');
topname[5] = new Array('','Nadjiwan','Bressette','Akiwenzie','Robinson');
topname[6] = new Array('','Introduction','Jerry_Alfred','John_Kim_Bell','Barbara_Croall','Leela_Gilday','Jani_Lauzon','Natalie_Picard','Red_Blaze','Kendra_Tagoona','Tzo_Kam','Cris_Villebrun');
topname[7] = new Array('','','','','','','','');
topname[8] = new Array('','Context','Earth_World','Tailfeather','Crow_Water','Lord_of_The_Sky','Elderberry','Hiwatha','Epilogue','The_Creation');
topname[9] = new Array('','','','','','','','');
topname[10] = new Array('','','','','','','','');
topname[11] = new Array('','Board','Partners','Copyright','Statistics','Team','Technology','');
topname[12] = new Array('','Context','Field_Names','Abbreviations','Organization','Languages','Credits');
topname[13] = new Array('','Context','Dead_Eagles','Deheigan','Crossing_Over');
topname[14] = new Array('','Accessibility','Trks','Themes','Copyright');

var chapinom = new Array('Accueil','Tambours','Masques','Histoires','Entrevues','Videos','Presse','Enseignants','Universitaires','Apropos');
var matinom	 = new Array();
matinom[0] = new Array('');
matinom[1] = new Array('');
matinom[2] = new Array('');
matinom[3] = new Array('','Apropos','La_Creation','Monde_Terrestre','Queue_De_Plumes','L\'eau_Crow','Seigneur_Du_Ciel','Sureau','Petit_Hiwatha','L\'epilogue');
matinom[4] = new Array('','Nadjiwan','Bressette','Akiwenzie','Robinson');
matinom[5] = new Array('');
matinom[6] = new Array('');
matinom[7] = new Array('','Accessibilite','Droits','Themes','Trks');
matinom[8] = new Array('','Contexte','Deheigan');
matinom[9] = new Array('','Statistiques','Associes','Droits','Equipe','Technologie');

function go_module(chapter,topic){
	var target = 'index.php/'+chapname[chapter]+'/'+topname[chapter][topic]+'?tp=a'+'&bg='+bgid+'&ln=e'; 
	// confirm('target='+target);
	document.location=target;}
	
function va_module(chapter,topic){
	var target = 'index.php/'+chapinom[chapter]+'/'+matinom[chapter][topic]+'?tp=f'+'&bg='+bgid+'&ln=f'; 
	// confirm('le target='+target);
	document.location=target;}

var nobs = new Array(null,12,8,2,6,5,4,1,4,11,13,10);
var px	 = 'px';	
function show_gallery_fn(gallery_vr){    //confirm('cg='+cg);
	// hide all groups before displaying this gallery
	hidegroup_fn(1);hidegroup_fn(10);hidegroup_fn(11); 
	showgroup_fn(gallery_vr);
	createCookie("cg", gallery_vr,365);}

function hidegroup_fn(gn){
	for(var i=1;i<=nobs[gn];i++){
		var cid_vr = 'c'+gn+'z'+i;
		var ob = document.getElementById(cid_vr);
		if(ob){ob.style.visibility = 'hidden';}}}

function showgroup_fn(gn){
	for(var i=1;i<=nobs[gn];i++){
		var cid_vr = 'c'+gn+'z'+i;
		var ob = document.getElementById(cid_vr);
		if(ob){ob.style.visibility = 'visible';}}}

function scalegroup_fn(gn){
	for(var i=1;i<=nobs[gn];i++){
		var cid_vr = 'c'+gn+'z'+i;
		var im = document.getElementById(cid_vr).childNodes[0].childNodes[0];
		im.width = im.width*0.75;}} // this is valuable knowledge: no need to explicity scale height, forces scale in other dimension, 
	
function setClass(a,o,c1,c2){
	switch (a){
		case 'swap':
			o.className=!setClass('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);break;
		case 'add':
			for(var i=0; i<o.childNodes.length; i++){
				var node = o.childNodes[i];//o.parentNode.childNodes[i];//
				var len = o.childNodes.length-1;//-2;//o.parentNode.childNodes.length-2;//
				if(node.nodeType !=3){//nodeType 3 is text node
					if(i>0 && i<len){					
						if(!setClass('check',node,c1)){node.className+=node.className?' '+c1:c1;}}}}break;			
		case 'remove':
			for(var i=0; i<o.childNodes.length; i++){
				var node = o.childNodes[i];//o.parentNode.childNodes[i];//
				var len = o.childNodes.length-1;//-2;//o.parentNode.childNodes.length-2;//
				if(node.nodeType !=3 && node.className != 'undefinedhover'){//nodeType 3 is text node						
					if(i>0 && i<len){						
						var rep=node.className.match(' '+c1)?' '+c1:c1;
						node.className=node.className.replace(rep,'');}}}break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className);            break;}}

function popup(winloc,type){
	var dx=750;var dy=600;var winname="cardwin";
	if(type=='g'){if(IE){dx=1020;dy=740;}else{dx=990;dy=540;}winname="gamewin";}
	if(IE){var yy=self.screenTop+70;var xx=self.screenLeft+200;}
	else{var yy=self.screenY+70;var xx=self.screenX+200;}
	var popup_features="left="+xx+",top="+yy+",width="+dx+",height="+dy+",fullscreen=0,alwaysRaised=1,titlebar=1,toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1";
	nv_handle=window.open(winloc,winname,popup_features);
	nv_handle.focus();}
            
