//alert('can see script');
//start flash sound scripts//

var movieName = "flashsounds";
var isFlashInstalled=false;
noautoinstall = "";
if(navigator.appName == "Microsoft Internet Explorer" && 
                (navigator.appVersion.indexOf("Mac") != -1 || 
                 navigator.appVersion.indexOf("3.1") != -1)){
                        noautoinstall = "true";
        }

if (navigator.appName == "Microsoft Internet Explorer" && noautoinstall != "true")
        {
                isFlashInstalled=true;
        }
else if(navigator.plugins)
        {
                if(navigator.plugins["Shockwave Flash"] || navigator.plugins["Shockwave Flash 2.0"])
                {
                       isFlashInstalled=true;
                }
          }
if(isFlashInstalled){
        if(document.getElementById){
        //alert('hiding image for flash replacement');
        document.writeln('<style type="text/css">div#flashcontent {        background-image: none!important;}</style>');
        }
}
 function is_iemac(){
        var SniffVer=navigator.appVersion;
        SniffVer=SniffVer.substring(0,4);
        var SniffClient=navigator.appName;
        var SniffOS=navigator.platform;
        if(SniffOS=='MacPPC' && SniffClient=='Microsoft Internet Explorer'){
                        return true;
                        }
                        else{return false;}
}
                   
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {    return window[movieName]  }        else {    return document[movieName]  }
}
// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {    return theMovie.PercentLoaded() == 100;  } else {    return false;
  }
}
function playmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {    thisMovie(movieName).Play();  }
}
function stopmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {    thisMovie(movieName).StopPlay();  }
}
function go(theFrame) {
        //alert('running go');
  if (movieIsLoaded(thisMovie(movieName))) {    thisMovie(movieName).GotoFrame(theFrame);  }
}
function golabel() {  if (movieIsLoaded(thisMovie(movieName))) {   thisMovie(movieName).TGotoLabel("_level0/","redframe");  }
}
function ReDraw(){
//needs attention
        var CurrentWidth=document.body.clientWidth;
        //alert(CurrentWidth);
        var NewWidth=CurrentWidth+1;
        //alert(NewWidth);
        document.body.style.width=NewWidth;
        document.body.style.width=CurrentWidth;
}
function setActiveStyleSheet(title){ 
if (is_iemac()){
        return false;
}
 var i, a, main;
  if (title) {
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') ) {
       if(a.getAttribute('title')!='printstyle'){
                  // alert(a.getAttribute('title'));
                           a.disabled = true;
                   }
        if(a.getAttribute('title') == title && a.getAttribute('title')!='printstyle' ) a.disabled = false;
      }
    }
  }
  hideDiv('loadingcontent');
ReDraw();
}

function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled ) return a.getAttribute('title');
    }
    return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
    if(a.getAttribute('rel').indexOf('style') != -1
       && a.getAttribute('rel').indexOf('alt') == -1
       && a.getAttribute('title')
       )
       return a.getAttribute('title');
  }
  return null;
ReDraw();
}

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;
}

function eraseCookie(name) {
        createCookie(name,'',-1);
}
//comment in to activate
        //window.onload = function(e) {
        //var cookie = readCookie('second-themeName');
          //var title = cookie ? cookie : getPreferredStyleSheet();
          //setActiveStyleSheet(title);
//}

window.onunload = function(e) {
        var title = getActiveStyleSheet();
          createCookie('second-themeName', title, 365);
}

function changeTxtSize(direction){
                //alert('calling function correctly');
                var textIncrement=10;//percentage by which font size is increased
                if(document.body.style.fontSize==''){document.body.style.fontSize='100%';}
                if(direction=='dec'){textIncrement=-textIncrement;}
                //alert(textIncrement);
                  newFs=parseInt(document.body.style.fontSize)+textIncrement;
                createCookie('preferedFontSize', newFs,365);
                document.body.style.fontSize=newFs+'%';
                //alert(document.body.style.fontSize);
                
}


function swapTextTool(){
        
if(document.getElementById && !is_iemac()){
        var TC = document.getElementById('txtcontrols');
        //a.innerHTML="<a href=\"textsize.htm\">increase text size</a> | <a href=\"textsize.htm\">decrease text size</a>";
		
		var swappedtext='<h3>Textcontrols</h3>';
		if(document.location.pathname=="/view.aspx"){
	 	swappedtext=swappedtext+' <img src="nav_images/pyramid/txt_tool.gif" width="147" height="39" border="0" usemap="#Map" />';
		}else{
				 	swappedtext=swappedtext+' <img src="../../../../nav_images/pyramid/txt_tool.gif" width="147" height="39" border="0" usemap="#Map" />';
		}
      	swappedtext=swappedtext+'<map name="Map" id="Map">';
        swappedtext=swappedtext+'<area shape="rect" coords="1,4,30,33" href="javascript:changeTxtSize(\'inc\');" alt="click here to make the text larger" />';
        swappedtext=swappedtext+'<area shape="rect" coords="36,4,66,35" href="javascript:changeTxtSize(\'dec\');" alt="click here to make the text smaller" />';
        swappedtext=swappedtext+'<area shape="rect" coords="82,5,114,36" href="javascript:setActiveStyleSheet(\'high contrast\');"alt="click here to use the inverted high contrast style sheet" />';
        swappedtext=swappedtext+'<area shape="rect" coords="118,2,147,34" href="javascript:setActiveStyleSheet(\'high contrast inverted\');" alt="click here to use the high contrast style sheet" />';
      	swappedtext=swappedtext+'</map>';
	  	swappedtext=swappedtext+'<p><a href="javascript:setActiveStyleSheet(\'standard stylesheet\');setDefaultFontSize();" title="user normal text size and colours" >use normal text</a></p>';


        TC.innerHTML=swappedtext;
        }
}
 
function getFontSize(){
           var pFS = readCookie('preferedFontSize');
                if(pFS)        {document.body.style.fontSize=pFS +'%';        }
 }
 function setDefaultFontSize(){
                 createCookie('preferedFontSize','',-365);
                {document.body.style.fontSize='100%';        }
 }
 function getstyle(){
         var pSS = readCookie('second-themeName');
         setActiveStyleSheet(pSS);
 }
 function swapflash(movieName,container,width,height,flashid){
		var newCode='';
        var flashCode='';
        var flashContainer='';
        var activestyle=getActiveStyleSheet();
        //if(isFlashInstalled&&activestyle=="regular"){
        if(isFlashInstalled){
			if(document.location.pathname=="/view.aspx"){movieName="flash/"+movieName;}
			   else{movieName="../../../../flash/"+movieName;}
                        flashContainer=document.getElementById(container);
                        //customisation
                        flashContainer.style.position="relative";        
                        flashContainer.style.backgroundImage="";
                        ///////////////
                        flashCode= "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " ;
                        flashCode=flashCode + "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" ";
                        flashCode=flashCode + "width=\"" + width + "\" height=\""+height+"\" >\n ";
                        flashCode=flashCode + "  <param name=\"movie\" value=\" " + movieName + " \">\n";
                        flashCode=flashCode + "        <PARAM NAME=\"wmode\" VALUE=\"transparent\" >\n";
                        flashCode=flashCode + "  <embed src=\""+ movieName + "\" quality=\"high\" wmode=transparent pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\">\n ";
                        flashCode=flashCode + "  </embed>\n";
                        flashCode=flashCode + "</object>\n";
                        newCode=flashCode+flashContainer.innerHTML;
                       	flashContainer.innerHTML=newCode;
						//alert(flashContainer.innerHTML);
                        }
}
function trans(frame,theUrl){
        if(qPress!=0){return;}
        qPress++;
        //var theUrl=this.getAttribute('href');
        //alert(theUrl);
       
        go(frame);
                //hide flash
                document.getElementById('flashcontent').style.visibility='hidden';
                
				//alert(getActiveStyleSheet());
			if(getActiveStyleSheet()=='standard stylesheet'){
				divshow('loadingcontent');
				//alert('running timeout');
           		setTimeout('msgpopup("'+theUrl+'")',2000);
		  }else{
			  //alert('straight there');
			  document.location=theUrl;}
}

var qPress=0;
 
 function preparelinks(){
         if(!document.getElementById)return false;
         //array for sounds//
         var snds = new Array (5);
         snds['arts']                =10;
         snds['about']                =20;
         snds['takingpart']        =30;
         snds['training']        =40;
         snds['news']                =50;
         snds['support']        =60;
         //
         
        //a=document.getElementById(theParent);
        var aLinks=document.getElementsByTagName('a');
         
        for (var i=0;i<aLinks.length;i++) {
                aLinks[i].onclick = function ()
                                {
                                theclass=this.parentNode.getAttribute('class');
                                                                if(!theclass){theclass=this.parentNode.getAttribute('className');}
                                                                thedestination=this.getAttribute('href');  
                                                                //alert(theclass + thedestination);
                                                                //alert(snds[theclass]);
                                                                if(snds[theclass]&&this.parentNode.nodeName=='LI')
                                                                {
                                                                        //alert('flashlink');
                                                                        trans(snds[theclass],thedestination);
                                                                }
                                                                else
                                                                {
                                                                        //alert('no flash');

																			if(getActiveStyleSheet()=='standard stylesheet'){
																				divshow('loadingcontent');				
																				setTimeout('msgpopup("'+thedestination+'")',2000);}
																			else{document.location=thedestination;}
																		
                                                                }
                                return false;
                                                                }
                }
 }
function msgpopup(destination){
//document.location=document.location;
document.location=destination;
qPress=0;
}
function divshow(theDiv){
        var b=document.getElementById(theDiv);
		if(b){
        b.style.display='block';
		}
}
function hideDiv(theDiv){
//alert('hiding: '+theDiv);
        var a=document.getElementById(theDiv);
		if(a){
        a.style.display='none';
		}
        
}
function makeloadalert(){
        if(!document.getElementById)return false;
        var newdiv="<div id=\"loadingcontent\"><h1>Going to page</h1><p><!--Please Wait--></p></div>";
		var switchDiv=document.getElementById('footer');
        switchDiv.innerHTML=switchDiv.innerHTML+newdiv;
        if(isFlashInstalled){
                //alert('writing flash code');
                var flashcode="<embed src=\"flash/pyramidsound.swf\" quality=high bgcolor=#FFFFFF  width=\"1\" height=\"1\" name=\"flashsounds\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed>";
                switchDiv.innerHTML=switchDiv.innerHTML+flashcode;
        }//alert(newdiv);
}

function loadfunctions(){
	//alert('running job load scripts');
        if(!document.getElementById('bblitebar'))
        {//functions not run in edit mode}
       	getFontSize();
       	swapTextTool();
        //popupLinks();
        getstyle();
        swapflash('pyramidbanner.swf','flashcontent',390,120,'headergraphic');
        makeloadalert();
		preparelinks();
		hideDiv('loadingcontent');
	}
}
window.onload=loadfunctions;


