var movieName = "soundfx";
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 goframe(theFrame) {
       //alert(theFrame);
  		if (movieIsLoaded(thisMovie(movieName))) {  thisMovie(movieName).GotoFrame(theFrame);  }
}
function golabel() {  if (movieIsLoaded(thisMovie(movieName))) {   thisMovie(movieName).TGotoLabel("_level0/","redframe");  }
}


function imgPopup(url,alt){
        var openIpix='';
        var closeIpix='';
        var isIpix=false;
        urlExtension=url.split(".");
        if(urlExtension[urlExtension.length-1]=='ipx'){isIpix=true;}
        //else{alert('not an ipix, must be an image');}
                                        var imgPopup=window.open('','imgPopup','height=50,width=50,toolbar=no,scrollbars=no,resizable=yes,menubar=no,status=no,directories=no,location=no,50,50');
                                        imgPopup.document.open();
                                        imgPopup.document.writeln('<html><head><title>image</title> \n <style type="text/css"> \n a{color:#3f3479;} p#caption{background-color:#eeeeee;text-align: left;padding-left: 10px;padding-right: 10px;}  \n body {font-family: Tahoma, Arial, Helvetica, sans-serif;text-align: center;} \n p {font-size: 70%;margin-top: 0px;padding-top: 0.5em;padding-bottom: 1em;} \n img {display: block; margin-right: auto; margin-left: auto;} \n  p.close {text-align: center; margin-bottom: 0px;        width: 9em;        float: right;        color: #FFFFFF;           padding: 3px;        font-weight: normal;}  \n </style> \n </head> \n <body>');
                                                                               imgPopup.document.writeln('<img src="' + url + '" alt="' + alt + '" id="lrgimage" />');
                                                                               imgPopup.document.writeln(' \n<p class="close"><a href="javascript:window.close();">Close Window</a></p> \n </body> \n </html>');
                                                                               imgPopup.document.title=alt;
                                                                               var bigImage=imgPopup.document.getElementById('lrgimage');
                                        var captiontxt=imgPopup.document.getElementById('caption');
                                                                                //alert(bigImage.width);
                                        //captiontxt.style.color='#333333';
                                        //captiontxt.style.fontsize='70%';
                                        //1st resize for shitty explorer
                                                var newwidth=bigImage.width+60;
                                                if(!newwidth){newwidth=490;}
                                                var newheight=imgPopup.document.body.scrollHeight+40;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                                
                                        bigImage.onload = function ()
                                        //for firefox
                                        {
                                                newwidth=bigImage.width+40;
                                                newheight=imgPopup.document.body.scrollHeight+60;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                        }
                                                                                window.onload = function ()
                                        //for firefox
                                        {
                                                newwidth=bigImage.width+40;
                                                newheight=imgPopup.document.body.scrollHeight+60;
                                                imgPopup.resizeTo(newwidth,newheight);
                                                imgPopup.window.focus;
                                        }
                                                                                imgPopup.onblur=imgPopup.window.focus;
}

function docPopup(url){
                                                window.open(url,'popup');
}

function popupLinks(){
if(!document.getElementById)return false;
var aLinks=document.getElementsByTagName('a');
//alert('running script');
for (var i=0;i<aLinks.length;i++) {
        if (aLinks[i].className == 'popup')
                        {
                                aLinks[i].onclick = function ()
                                {
                                        //alert(linktype);]
                                        //
										//alert('clicked');
                                        var linktype=this.getAttribute('href');
                                        var linktype_array=linktype.split(".");
                                        var linkex=linktype_array[linktype_array.length-1];
                                                                                linkex=linkex.toLowerCase();
                                        //if(this.protocol=="file:"){
                                        if(linkex=='jpg' || linkex=='gif' || linkex=='ipx'){
                                                imgPopup(this.getAttribute('href'),this.getAttribute('title') );}
                                        else{docPopup(this.getAttribute('href'));}
                                return false;
                                }
                                //return false;
                        }
                        aLinks[i].onkeypress = aLinks[i].onclick;
                }
}

function toggleAdvancedOptions(){
	x=document.getElementById('advsearch');
	var newcontrol=document.getElementById('newcontrol');
	if (x.style.display=='none')
	{
		x.style.display='block';
		newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a>  - ';
		}
	else{x.style.display='none';
	newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a> + ';}	
}





function hideAdvancedSearch(){
	if (!document.getElementById('Diary')) return false;
	var x=document.getElementById('advsearch');
	var newcontrol=document.getElementById('newcontrol');
	newcontrol.innerHTML='<a href="javascript:toggleAdvancedOptions();" >more options</a> + ';
	x.style.display='none';
	//alert(x.innerHTML);   
}

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")){
						 return false;
						 }
	  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")){
						 return false;
						 }
      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")){
						 return false;
						 }
    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('txtcontrols') && !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>Text controls</h3>';
		//if(document.location.pathname=="/view.aspx"){
	 	swappedtext=swappedtext+' <img src="/Scripts/artsminds/textcontrols.gif" border="0" usemap="#Map" />';
		//}else{
		//swappedtext=swappedtext+' <img src="/Scripts/artsminds/textcontrols.gif" width="147" height="39" border="0" usemap="#Map" />';
		//}
      	swappedtext=swappedtext+'<map name="Map" id="Map">';
        swappedtext=swappedtext+'<area shape="rect" coords="9,3,26,20" href="javascript:changeTxtSize(\'inc\');" alt="click here to make the text larger" />';
        swappedtext=swappedtext+'<area shape="rect" coords="31,3,48,20" href="javascript:changeTxtSize(\'dec\');" alt="click here to make the text smaller" />';
        swappedtext=swappedtext+'<area shape="rect" coords="69,3,79,20" href="javascript:setActiveStyleSheet(\'high contrast\');"alt="click here to use the inverted high contrast style sheet" />';
        swappedtext=swappedtext+'<area shape="rect" coords="84,3,101,20" 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  WIDTH=\"10\" HEIGHT=\"10\" id=\"soundfx\" ALIGN=\"\">";
   						flashCode=flashCode+"<PARAM NAME=soundfx VALUE=\""+ movieName + "\"> ";
    					flashCode=flashCode+"<PARAM NAME=quality VALUE=high> ";
    					flashCode=flashCode+"<PARAM NAME=bgcolor VALUE=#3fefef> ";
						flashCode=flashCode+"<EMBED src=\""+ movieName + "\" quality=high bgcolor=#3fefef  WIDTH=\"100\" HEIGHT=\"100\" NAME=\"soundfx\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" > ";
    					flashCode=flashCode+"</EMBED> ";
						flashCode=flashCode+"</OBJECT> ";
						
						
						
                        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 (4);
         snds['menu_AboutUs'] =10;
         snds['menu_Gallery'] =20;
         snds['menu_News']=30;
         snds['menu_Publications']=40;
         snds['menu_Links']=50;
         //
         
        //a=document.getElementById(theParent);
        var aLinks=document.getElementsByTagName('a');
         
        for (var i=0;i<aLinks.length;i++) {
                aLinks[i].onmouseover = function ()
                                {
                                theclass=this.parentNode.getAttribute('class');
								if(!theclass){theclass=this.parentNode.getAttribute('className');}
                                if(snds[theclass]&&this.parentNode.nodeName=='LI')
                               	 {
									 //alert(snds[theclass]);
									 //alert(snds[theclass]);
									 goframe(snds[theclass]);
									//alert('send flash audio clip to frame'+snds[theclass]);
									//trans(snds[theclass],thedestination);
									} 

                               //return false;
                     }
                }
 }
function msgpopup(destination){
//document.location=document.location;
document.location=destination;
qPress=0;
}



function loadfunctions(){
	if((document.parent)||document.getElementById('bblitebar'))return false;
	popupLinks();
	hideAdvancedSearch();
	preparelinks();
	//getFontSize();
    //swapTextTool();
	//getstyle();
	//changcalendar();
	//swapflash("/flash/artsandminds/soundfx.swf",'footer',1,1,'soundfxmovie')
}



window.onload=loadfunctions;


