
var cats                = Array() ;
var increment           = 0.2 ;
var incrementTimeMilli  = 20 ;
var waitBeforeMax       = 200 ;
var waitBeforeMin       = 1500 ;
var waitBeforeEnableZoom  = 2000 ;


// opType:
// 1: opIsMin
// 2: opIsMax
// 3: opIsWaitMin
// 4: opIsWaitMax
// 5: opIsEnalbelCanZoom
function Category(id, handleDiv, handleDivp, maxSize, htmlMin, htmlMax, rightMulti)
{
    this.id             = id ;
    this.handleDiv      = handleDiv ;
    this.handleDivP     = handleDivp ;
    this.currentSize    = 1 ;
    this.maxSize        = maxSize ;
    this.opHandle       = null ;
    this.opType         = null ;
    this.htmlMin        = htmlMin ;
    this.htmlMax        = htmlMax ;
    this.canZoom        = true ;
    this.rightMulti     = rightMulti ;    
}


function moveZoomCloud()
{
    var el = document.getElementById("cl_zoomCloud") ;
    var el2 = document.getElementById("cl_zoomCloud2") ;
    
    var el_left = findPosX(el) ;
    if(el2)
    {
        el2.style.left = el_left + "px" ;
    }
      
}




function initTagCloud()
{

    
        www = getElementStyle("cl_zoomCloudTest", "width", "width") ;
    if(parseFloat(www) < 1)
    {
        return ;
    }
    
    var el = document.getElementById("cl_zoomCloud") ;
    
        var mybody = document.getElementsByTagName("body")[0];
  
    var el2 = document.createElement('div') ;
    el2.setAttribute("id", "cl_zoomCloud2");
    mybody.appendChild(el2);
    
        var el_left     = findPosX(el) ;
    var el_top      = findPosY(el) ;
    var el_width    = el.offsetWidth ; 
    var el_height   = el.offsetHeight ;
 
        el2.innerHTML   = el.innerHTML ;
    el2.style.position = "absolute" ;
    el2.style.margin = "0px auto" ;
    el2.style.height = el_height + "px" ;
    el2.style.width = el_width + "px" ;
    el2.style.zIndez = 800 ;
    el2.style.left = el_left + "px" ;
    el2.style.top = el_top + "px" ;
    
        el.style.height = el_height + "px" ;
    el.style.visibility = "hidden" ;
    //el.innerHTML = '&nbsp;' ;
    el.innerHTML = '<img src="http://www.quizoom.com/images/any/px.gif" width="1" height="' + el_height  + '" />' ;
    

	for(i = 0 ; ; i++)
	{
		oneCatDiv       = document.getElementById("cat_" + i) ;
        oneCatDivP      = document.getElementById("catp_" + i) ;
        oneCatDivMax    = document.getElementById("catmax_" + i) ;
		if(!oneCatDiv || !oneCatDivP || !oneCatDivMax)
		{
			break ;
		}

        oneCatLinks = oneCatDiv.getElementsByTagName("a") ;
        if(oneCatLinks.length == 0)
        {
            break ;
        }
        
                oneCatLinks[0].title = "" ;
        
        		oneCatDiv.onmouseover = function()
		{
			catMouseOver(this) ;
		} ;
		
        		oneCatDiv.onmouseout = function()
		{
            catMouseOut(this) ;
		} ;
        
		oneCatSizeMin = parseFloat(oneCatDivP.style.fontSize) ;
        
                if(oneCatSizeMin <= 1)
        {
            oneCatSizeMax   = 3 ;
            rightMulti      = 1.4 ;
        }
        else if(oneCatSizeMin <= 1.5)
        {
            oneCatSizeMax   = 2 ;
            rightMulti      = 3 ;
        }
        else
        {
            oneCatSizeMax   = 1.5 ;
            rightMulti      = 2 ;
        }
        
        var htmlMin         = oneCatDiv.innerHTML ;
        var htmlMax         = oneCatDivMax.innerHTML ;

        var oneCat = new Category(i, oneCatDiv, oneCatDivP, oneCatSizeMax, htmlMin, htmlMax, rightMulti);
        cats[i] = oneCat ;       
	}
    

    
}

function catMouseOver(div)
{
    var divId = div.id.substring(4) ;
    var oneCat = cats[divId] ;
    
        minimiseAll(divId) ;

    
        if(oneCat.opHandle != null || !oneCat.canZoom)
    {
        return ;
    }
    
        oneCat.canZoom = false ;
    

        if(oneCat.currentSize < oneCat.maxSize)
    {
        oneCat.opType = 4 ;
        var cmd = "waitAndMax(" + divId + ")" ;
        oneCat.opHandle = setTimeout(cmd, waitBeforeMax) ;

    }
}


function catMouseOut(div)
{
    var divId = div.id.substring(4) ;
    var oneCat = cats[divId] ;
    
        if(oneCat.opHandle != null && oneCat.opType == 4)
    {
        clearTimeout(oneCat.opHandle) ;
        oneCat.opHandle = null ;
        oneCat.canZoom = true ;
    }

    
    return ;
}

function waitAndMax(divId)
{
    var oneCat = cats[divId] ;

    clearTimeout(oneCat.opHandle) ;
    oneCat.opHandle = null ;

    	oneCat.handleDiv.style.zIndex = 5000 ;
    oneCat.handleDivP.style.zIndex = 5000 ;
    

        oneCat.handleDiv.innerHTML = oneCat.htmlMax ;

        oneCat.opType = 2 ;
    var cmd = "catmax(" + divId + ")" ;
    oneCat.opHandle = setInterval(cmd, incrementTimeMilli) ; 

}

function catmax(divId)
{
    var oneCat = cats[divId] ;
    
        if(oneCat.currentSize < oneCat.maxSize)
    { 
                oneCat.currentSize = Math.round((oneCat.currentSize + increment)*10)/10 ; 
        oneCat.handleDiv.style.fontSize = oneCat.currentSize + "em" ;
        
        

        

                if(screen.width > 800)
        {
            oneCat.handleDiv.style.right = Math.round((parseFloat(oneCat.handleDiv.style.right) - (oneCat.rightMulti * increment))*10)/10 + "em" ;
        }
        
        oneCat.handleDiv.style.top = Math.round(((parseFloat(oneCat.handleDiv.style.top) - increment) / 1.3)*10)/10 + "em" ;

    }
    
        if(oneCat.currentSize >= oneCat.maxSize)
    {
                oneCat.handleDiv.style.fontSize = oneCat.maxSize + "em" ;
          
        
                if(oneCat.opHandle != null && oneCat.opType == 2)
        {
            clearInterval(oneCat.opHandle) ;
            oneCat.opHandle = null ;

                        oneCat.opType = 3 ;
            var cmd = "catWaitAndMin(" + divId + ")" ;
            oneCat.opHandle = setTimeout(cmd, waitBeforeMin) ;     
        }
    }
}

function minimiseAll(divIdToExclude)
{
    for(i = 0 ; i < cats.length; i++)
    {
                var oneCat = cats[i] ;
        if((divIdToExclude == null || i != divIdToExclude))
        {
            if(oneCat.opHandle != null)
            {
                if(oneCat.opType == 3 || oneCat.opType == 4 || oneCat.opType == 5)
                {
                    clearTimeout(oneCat.opHandle) ;
                }
                else
                {
                    clearInterval(oneCat.opHandle) ;
                }
                oneCat.opHandle = null ;
            }
            
                        oneCat.canZoom = true ;
            
                        if(oneCat.currentSize > 1)
            {
                oneCat.opType = 1 ;
                var cmd = "catmin(" + i + ")" ;
                oneCat.opHandle = setInterval(cmd, incrementTimeMilli) ; 
            }
            else
            {
                catReset(oneCat) ;
            } 
        }
    }
}

function catWaitAndMin(divId)
{
    var oneCat = cats[divId] ;
    
        if(oneCat.currentSize < oneCat.maxSize || oneCat.opType != 3)
    {
        return ;
    }
    
    clearTimeout(oneCat.opHandle) ;
    oneCat.opHandle = null ;
    
        oneCat.opType = 1 ;
    var cmd = "catmin(" + divId + ")" ;
    oneCat.opHandle = setInterval(cmd, incrementTimeMilli) ;      
}

function catmin(divId)
{

    var oneCat = cats[divId] ;
    
        if(oneCat.currentSize >= 1)
    {
    
                if(screen.width > 800)
        {
            oneCat.handleDiv.style.right = Math.round((parseFloat(oneCat.handleDiv.style.right) + (oneCat.rightMulti * increment))*10)/10 + "em" ; 
        }
    
		oneCat.handleDiv.style.top = Math.round(((parseFloat(oneCat.handleDiv.style.top) + increment) / 1.5)*10)/10 + "em" ;
    
    
                oneCat.currentSize = Math.round((oneCat.currentSize - increment)*10)/10 ;
		oneCat.handleDiv.style.fontSize = oneCat.currentSize + "em" ;
		
    }
    
    
        if(oneCat.currentSize <= 1)
    {
                if(oneCat.opHandle != null && oneCat.opType == 1)
        {
            clearInterval(oneCat.opHandle) ;
            oneCat.opHandle = null ;
        }
        
                catReset(oneCat) ;
        
                oneCat.opType = 5
        cmd = "enableCanZoom(" + divId + ")" ;
        oneCat.opHandle = setTimeout(cmd, waitBeforeEnableZoom) ;
    }
}

function catReset(oneCat)
{
    oneCat.handleDiv.style.fontSize = "1em" ;
    
    oneCat.handleDiv.style.right = "0px" ;
    oneCat.handleDiv.style.top = "0px" ;

    oneCat.handleDiv.style.zIndex = 1 ;
    oneCat.handleDivP.style.zIndex = 1 
    
    oneCat.handleDiv.innerHTML = oneCat.htmlMin ;   
}

function enableCanZoom(divId)
{
    var oneCat = cats[divId] ;
    oneCat.canZoom = true ;
    clearTimeout(oneCat.opHandle) ;
    oneCat.opHandle = null ;
}
