/** Animations and other user interface general functions */

KASSI_ELEM_WIDTH = 0

/** turns elem into a dialog that hovers on top of the rest of the window */
function kassiShowMainElement(elem, w, h) {
	KASSI_ELEM_WIDTH = w
	// console.debug('opening main view')
	container = document.getElementById('kassiSide-container')
	
	elem.style.opacity = '0.0'
    elem.style.filter = ' alpha(opacity=0)'
    
    container.appendChild(elem)
    container.style.height = h
    container.style.display = 'none'
    
    var winH = 0
    var winW = 0
    if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
		    winH = document.body.offsetHeight;
		}
    }
    
    // console.debug('window size is '+winW+"x"+winH)
    elem.style.display = 'block'

    new Effect.Scale('kassiSide-margin', winH*100, {scaleX: false, scaleContent: false, 
            scaleMode: { originalHeight: 1, originalWidth: 25 }, duration: 0.5, 
            afterFinish: function(obj) {
            	// console.debug('background done, scaling to '+w+" and "+h)
    		    container.style.display = 'block'
			    new Effect.Scale('kassiSide-container', w*100, {scaleY: false, scaleContent: false,
			        scaleMode: { originalHeight: 1, originalWidth: 1 }, duration: 0.5, 
			        afterFinish: function(obj) {
			            // console.debug('scale done width is '+container.style.width)
			            elem.style.height = h - 30
                        elem.style.width = w - 50
                        container.style.overflow = 'auto'
                        new Effect.Opacity(elem, {duration: 0.7, from: 0.0, to: 1.0})    
			        }})
            }       
    })		
}


function kassiHideMainElement(afterFunction) {
    var elem = document.getElementById('kassiSide-container')
    // console.debug(KASSI_ELEM_WIDTH)
    new Effect.Scale(elem, 1/KASSI_ELEM_WIDTH, {scaleY: false, scaleContent: false,
        scaleMode: { originalHeight: elem.style.height, originalWidth: KASSI_ELEM_WIDTH }, 
        afterFinish: function(obj) { 
           afterFunction(obj)
       }})
    new Effect.Opacity(elem, {delay: 0.5, duration: 0.5, from: 1.0, to: 0.0})
}


function kassiTagCloud(element) {
    var container = element
    var minSize = 9
    ajaxPostCall('request_handlers/get_tags.php', {}, function(response) {
            eval('var tags ='+response)
            for(i in tags) {
            	var a = document.createElement('a')
            	a.appendChild( document.createTextNode(i+' ') )
            	a.href=""
            	a.name = i
            	a.style.fontSize = minSize + parseInt(tags[i])
            	a.addEventListener('click', function(e) {
            		//e.target.name 
            	}, false)
            	container.appendChild(a)
            }
        })
}

function showRightLoadingAnimation() {
	document.getElementById('right-side-loading-animation').style.display = 'block'
}
function hideRightLoadingAnimation() {
	document.getElementById('right-side-loading-animation').style.display = 'none'
}
function showLeftLoadingAnimation() {
	document.getElementById('left-side-loading-animation').style.display = 'block'
}
function hideLeftLoadingAnimation() {
	document.getElementById('left-side-loading-animation').style.display = 'none'
}
function showGlobalLoadingAnimation() {
	document.getElementById('global-loading-animation').style.display = 'block'
}
function hideGlobalLoadingAnimation() {
	document.getElementById('global-loading-animation').style.display = 'none'
}
