//This collection of javascripts have been put together in a single file as they are all compatable and usefull
//simply link to this .js script rather than multiple .js scripts
//it contains STYLESHEET SWITCHER, DOCUMENT TEXT RESIZER, LINK LISTER, PAGE INDEXER, GRADUAL FADER
//This collection of JavaScripts was created by Mr Davy 'Snake' Currie of Clovemill Group (UK)
//Please email to Info@Clovemill.com
//or visit http://Clovemill.com



// Main Popup script
var newWin = null;
function popUp(strURL, strType, strHeight, strWidth) {
 if (newWin != null && !newWin.closed)
   newWin.close();
 var strOptions="";
 if (strType=="console")
   strOptions="resizable,height="+
     strHeight+",width="+strWidth;
 if (strType=="fixed")
   strOptions="status,height="+
     strHeight+",width="+strWidth;
 if (strType=="elastic")
   strOptions="scrollbars,"+
     "resizable,location,height="+
     strHeight+",width="+strWidth;
 newWin = window.open(strURL, 'newWin', strOptions);
 newWin.focus();
}
// for launching the gatekeeper stuff
                var popup = null;
                function showLock() {
                popup = window.open('lock.html', 'theKeeper',
                'width=350,height=120,resizable=0');
                }

// for launching the gatekeeper stuff


//BESIN div hide/show
function toggleMe(a){
  var e=document.getElementById(a);
  if(!e)return true;
  if(e.style.display=="none"){
    e.style.display="block"
  } else {
    e.style.display="none"
  }
  return true;
}

//BESIN STYLESHEET SWITCHER
//invoked by
//    <a href="javascript: document.cookie='style=1'; window.location.reload();">Styled</a>

var StyleFile = "styling/css/style" + document.cookie.charAt(6) + ".css";
document.writeln('<link rel="stylesheet" type="text/css" href="' + StyleFile + '">');
//END STYLESHEET SWITCHER

//begin document text resizer
//invoked by
//    <a href="#" class="texttoggler" rel="xlargeview" title="extra large size">XL</a> |
//    <script type="text/javascript">
//     //documenttextsizer.setup("shared_css_class_of_toggler_controls")
//     documenttextsizer.setup("texttoggler")
//     </script>


var documenttextsizer={

prevcontrol: '', //remember last control clicked on/ selected
existingclasses: '',

setpageclass:function(control, newclass){
        if (this.prevcontrol!='')
                        this.css(this.prevcontrol, 'selectedtoggler', 'remove') //de-select previous control, by removing 'selectedtoggler' from it
        document.documentElement.className=this.existingclasses+' '+newclass //apply new class to document
        this.css(control, 'selectedtoggler', 'add') //select current control
        this.setCookie('pagesetting', newclass, 5) //remember new class added to document for 5 days
        this.prevcontrol=control
},

css:function(el, targetclass, action){
        var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
        if (action=="check")
                return needle.test(el.className)
        else if (action=="remove")
                el.className=el.className.replace(needle, "")
        else if (action=="add")
                el.className+=" "+targetclass
},

getCookie:function(Name){
        var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
        if (document.cookie.match(re)) //if cookie found
                return document.cookie.match(re)[0].split("=")[1] //return its value
        return null
},

setCookie:function(name, value, days){
        if (typeof days!="undefined"){ //if set persistent cookie
                var expireDate = new Date()
                var expstring=expireDate.setDate(expireDate.getDate()+days)
                document.cookie = name+"="+value+"; path=/; expires="+expireDate.toGMTString()
        }
        else //else if this is a session only cookie
                document.cookie = name+"="+value
},

setup:function(targetclass){
        this.existingclasses=document.documentElement.className //store existing CSS classes on HTML element, if any
        var persistedsetting=this.getCookie('pagesetting')
        var alllinks=document.getElementsByTagName("a")
        for (var i=0; i<alllinks.length; i++){
                if (this.css(alllinks[i], targetclass, "check")){
                        if (alllinks[i].getAttribute("rel")==persistedsetting) //if this control's rel attribute matches persisted doc CSS class name
                                this.setpageclass(alllinks[i], alllinks[i].getAttribute("rel")) //apply persisted class to document
                        alllinks[i].onclick=function(){
                                documenttextsizer.setpageclass(this, this.getAttribute("rel"))
                                return false
                        }
                }
        }
}

}

//end of document text resizer

//begin link lister - lists all hyperlinks on a page
//invoked by - <a href="javascript:LinkList();">view the links</a>
function LinkList() {
var myheader = "<head><title>Links In "+document.title+"</title></head>";
myheader = myheader + "<body>";
var myfont = "<font style=\"font: 8pt Verdana, Arial, Helvetica, Sans-serif; line-height:18pt;\" face=\"verdana, tahoma, geneva\" size=\"-1\" >";
var mytext = "<center><b>Link List<br>Heres the list of hyperlinks in " + document.title + "</b></center><ol>";
var myendfont = "</ol></font>";
var myendheader = "</body>";

windowprops = "menubars=no,location=no,toolbars=no,scrollbars=yes,"+"width=350,height=400,top=50,left=50";
self.name = "main";

if(document.all) {
for (i=0; i<document.links.length; i++) {
if(document.links[i].innerText)
if(document.links[i].innerText != " ")
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].innerText+"</a><br>";
else
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i]+"</a><br>" ;
   }
}
else {
for (i=0; i<document.links.length; i++) {
if(document.links[i].text) {
if(((document.links[i].text).indexOf("javascript:")) == -1) {
mytext += "<li><a target='_new' href="+document.links[i]+">"+document.links[i].text+"</a><br>" ;
   }
}
else { }
   }
}
mytext = mytext + "</ol><center><a href='javascript:window.close()'>close</a></center><BR>";

linkswin = window.open("","",windowprops);
with (linkswin.document) {
open();
write(myheader + myfont + mytext + myendfont + myendheader);
close();
   }
}
//end of link lister

//begin page indexer - lists all H2 headings and allows you to link to them - to bullet each, use - <img src="styling/imgs/bullet.gif" alt="bullet" align="middle"> before <a href="#quickIDX'+i+'">
//invoked by  <div id='indexDiv'><div id='indexContents'></div></div>
function pageIndex() {
  var els=document.getElementsByTagName('h2');
  if (!els.length) {
    document.getElementById('indexDiv').style.display='none';
  } else {
    var idx='';
    for (i=0; i<els.length; i++) {
      idx += '<li><a href="#quickIDX'+i+'">'+els[i].innerHTML+'</a><BR>';
      els[i].innerHTML='<a name="quickIDX'+i+'"></a></li>'+els[i].innerHTML;
    }
    document.getElementById('indexContents').innerHTML=idx;
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  pageIndex();
});
//end page indexer

//begin gradual fader - adds a 'glow' to images which are classed as 'gradualfade'
var gradualFader={}
gradualFader.baseopacity=0.5 //set base opacity when mouse isn't over element (decimal below 1)
gradualFader.increment=0.2 //amount of opacity to increase after each iteration (suggestion: 0.1 or 0.2)
document.write('<style type="text/css">\n') //write out CSS to enable opacity on "gradualfader" class
document.write('.gradualfader{filter:progid:DXImageTransform.Microsoft.alpha(opacity='+gradualFader.baseopacity*100+'); -moz-opacity:'+gradualFader.baseopacity+'; opacity:'+gradualFader.baseopacity+';}\n')
document.write('</style>')
gradualFader.setopacity=function(obj, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
        var targetobject=obj
        if (targetobject && targetobject.filters && targetobject.filters[0]){ //IE syntax
                if (typeof targetobject.filters[0].opacity=="number") //IE6
                        targetobject.filters[0].opacity=value*100
                else //IE 5.5
                        targetobject.style.filter="alpha(opacity="+value*100+")"
                }
        else if (targetobject && typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
                targetobject.style.MozOpacity=value
        else if (targetobject && typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
                targetobject.style.opacity=value
        targetobject.currentopacity=value
}
gradualFader.fadeupdown=function(obj, direction){
        var targetobject=obj
        var fadeamount=(direction=="fadeup")? this.increment : -this.increment
        if (targetobject && (direction=="fadeup" && targetobject.currentopacity<1 || direction=="fadedown" && targetobject.currentopacity>this.baseopacity)){
                this.setopacity(obj, targetobject.currentopacity+fadeamount)
                window["opacityfader"+obj._fadeorder]=setTimeout(function(){gradualFader.fadeupdown(obj, direction)}, 50)
       }

}



gradualFader.clearTimer=function(obj){

if (typeof window["opacityfader"+obj._fadeorder]!="undefined")

        clearTimeout(window["opacityfader"+obj._fadeorder])

}



gradualFader.isContained=function(m, e){

        var e=window.event || e

        var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)

        while (c && c!=m)try {c=c.parentNode} catch(e){c=m}

        if (c==m)

                return true

        else

                return false

}



gradualFader.fadeinterface=function(obj, e, direction){

        if (!this.isContained(obj, e)){

                gradualFader.clearTimer(obj)

                gradualFader.fadeupdown(obj, direction)

        }

}



gradualFader.collectElementbyClass=function(classname){ //Returns an array containing DIVs with specified classname

        var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element

        var pieces=[]

        var alltags=document.all? document.all : document.getElementsByTagName("*")

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

                if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)

                        pieces[pieces.length]=alltags[i]

        }

        return pieces

}



gradualFader.init=function(){

        var targetobjects=this.collectElementbyClass("gradualfader")

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

                targetobjects[i]._fadeorder=i

                this.setopacity(targetobjects[i], this.baseopacity)

                targetobjects[i].onmouseover=function(e){gradualFader.fadeinterface(this, e, "fadeup")}

                targetobjects[i].onmouseout=function(e){gradualFader.fadeinterface(this, e, "fadedown")}

        }

}
//end gradual fader