//Animated Collapsible MENU
function animatedcollapse(divId, animatetime, persistexpand, initstate, nHeight){
    this.divId=divId
    this.divObj=document.getElementById(divId)
    this.divObj.style.overflow="hidden"
    this.timelength=animatetime
    this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
    this.isExpanded=persistexpand;
    this.contentheight=parseInt(this.divObj.style.height)
    
    if(navigator.appName == "Netscape") {
        this.divObj.style.height=nHeight+"px";	        
        this.contentheight=276;//parseInt(this.divObj.style.height)
        if(divId=="sub4") this.contentheight=150;
    }
    
    var thisobj=this
    if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
        animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
        if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
	        this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
    }
    else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
        this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}

animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
	    if(direction=="down") { 
	        nSliding = 0;
	    }
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}

animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) { //if content height not available yet (until window.onload)
		    nSliding = 0;
		    return;
			///alert("Please wait until document has fully loaded then click again")
		}
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
		else {
		    nSliding = 0;
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) { //if content height not available yet (until window.onload)
		    nSliding = 0;
		    return;
			///alert("Please wait until document has fully loaded then click again")
		}	
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

/*animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) { //if content height not available yet (until window.onload)
	    nSliding = 0;
		return;
		///alert("Please wait until document has fully loaded then click again")
	}	
	else if (parseInt(this.divObj.style.height)==0)
		this.slidedown()
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}*/

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------
animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}

animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

//*************************************************************************************************
// HTML FILE CODE *********************************************************************************
var timerID;
var nTabCount=5;
var nMSec = 4000;
var collapse = new Array();
window.onload = function() {

    if(navigator.appName == "Netscape") {
        var sHTMLText = '<div class="menuButton" onclick="javascript:hideshow(0, true)" title="Registry Cleaner - RegFix Mantra"><div class="menuHeader">Registry Cleaner</div></div>'
            +'<div id="sub0" class="subContainer"><a href="http://www.pcmantra.com/registry-cleaner.htm"><div style="background-image:url(/Images/regclean.gif);background-repeat:no-repeat;width:181px;height:276px;"></div></a></div>'
            +'<div class="menuButton" onclick="javascript:hideshow(1, true)" title="Instant Recovery - Rollback RX"><div class="menuHeader">Rollback RX</div></div>'
            +'<div id="sub1" class="subContainer"><a href="http://rollbackrx.pcmantra.com/"><div style="background-image:url(/Images/rollback.gif);background-repeat:no-repeat;width:181px;height:276px;"></div></a></div>'
            +'<div class="menuButton" onclick="javascript:hideshow(2, true)" title="Anti Spyware - Spy Noose"><div class="menuHeader">Anti Spyware</div></div>'
            +'<div id="sub2" class="subContainer"><a href="http://www.pcmantra.com/anti-spyware.htm"><div style="background-image:url(/Images/antispy.gif);background-repeat:no-repeat;width:181px;height:276px;"></div></a></div>'
            +'<div class="menuButton" onclick="javascript:hideshow(3, true)" title="Windows Cleaner - CleanMantra"><div class="menuHeader">Windows Cleaner</div></div>'
            +'<div id="sub3" class="subContainer"><a href="http://www.pcmantra.com/cleanmantra.htm"><div style="background-image:url(/Images/winclean.gif);background-repeat:no-repeat;width:181px;height:276px;"></div></a></div>'
            +'<div class="menuButton" onclick="javascript:hideshow(4, true)" title="Resource Center"><div class="menuHeader">Resource Center</div></div>'
            +'<div id="sub4" class="subContainer1"><div class="boxContainer">'
            +'<div style="padding: 7px 0 0 0;"><a href="http://www.pcmantra.com/ResourceCenter.aspx" class="menuHeader">Resources</a></div>'
            +'<div style="padding: 7px 0 0 0;"><a href="http://www.pcmantra.com/RegistryCleanerResource.aspx" class="menuHeader">Registry Cleaner Resources</a></div>'
            +'<div style="padding: 7px 0 0 0;"><a href="http://www.pcmantra.com/AntiSpywareResource.aspx" class="menuHeader">Anti Spyware Resources</a></div>'
            +'<div style="padding: 7px 0 0 0;"><a href="http://www.pcmantra.com/WindowsCleanerResource.aspx" class="menuHeader">Windows Cleaner Resources</a></div>'
            +'</div></div>';
            
        document.getElementById("MenuContainer").innerHTML = sHTMLText;        
    }

    for(var i=0; i<nTabCount; i++) {
        if(navigator.appName == "Netscape") {
            if(i==0) {                    
                collapse[i] = new animatedcollapse("sub"+i, 500, false, "block", 276);
            }
            else {
                collapse[i] = new animatedcollapse("sub"+i, 500, false, "block", 0);
            }
        }
        else {
            if(i==0) {
            collapse[i] = new animatedcollapse("sub"+i, 500, false, "block");
            }
            else {
                collapse[i] = new animatedcollapse("sub"+i, 500, false);
            }
        }        
        //collapse[i].slideup();
    }
    timerID = setTimeout(startSlide, nMSec);

    //run slide show -----    
    if(document.getElementById("lnkMain") != null){
       	runSlideShow();
    }  
	//get recent content -----
	if(document.getElementById("mrqRecent") != null){
	    GetRecentContent('http://www.pcmantra.com/AxSourcePage.aspx?Action=GetArticles');
	}
}
var nSub = 1;
var nSliding = 0;
function hideshow(nIndex, bClicked) {
    if(bClicked == true) {
        clearTimeout(timerID);
    }
    if(nSliding == 1) {
        return;
    }
    nSliding = 1;
    
    for(var i=0; i<nTabCount; i++) {
        if(nIndex != i)
            collapse[i].slideup();
    }
    collapse[nIndex].slidedown();
}

function startSlide() {
    if(nSliding == 0) {
        hideshow(nSub, false);        
        nSub++;
        clearTimeout(timerID);
        timerID = setTimeout(startSlide, nMSec);
        
        if(nSub >= nTabCount) {
            nSub = 0;
        }
    }
}


//*************************************************************************************************
//SLIDE SHOW **************************************************************************************
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 6000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() 
// to add more images, just continue the pattern, adding to the array below

Pic[0] = 'Images/rbx-mid.gif'
Pic[1] = 'Images/rfm-mid.gif'
Pic[2] = 'Images/spy-mid.gif'

var Lnk = new Array()
Lnk[0] = 'http://rollbackrx.pcmantra.com/'
Lnk[1] = 'http://www.pcmantra.com/registry-cleaner.htm'
Lnk[2] = 'http://www.pcmantra.com/anti-spyware.htm'

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   //set anchor links
   document.getElementById("lnkMain").href = Lnk[j]
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

//window.onload = function(){runSlideShow();}


