/*
window.popupActive = false;
window.popupZoom = false;	
window.popupComment = true;
*/

// REALTIME ACTIONS
window.onresize = function () {
	if (window.popupActive) { darkenPage(); }
	if (document.popupMaximize) { zoomFile(1); }
}



function toggleDisplay(objId,d,force)
{
	var obj = document.getElementById(objId);
	
	if (force == 1) { obj.style.display = d; return;}
	if (force == 0) { obj.style.display = 'none'; return;}
	
	if (obj.style.display == d || obj.style.display == '') {
		obj.style.display = 'none';
	} else {
		obj.style.display = d;
	}
	return;
}

function getPos (obj) {
	var output = new Object();
	var mytop=0, myleft=0;
	while( obj) {
		mytop+= obj.offsetTop;
		myleft+= obj.offsetLeft;
		obj= obj.offsetParent;
	}
	output.left = myleft;
	output.top = mytop;
	return output;
}

function presentPopup(panel,w,h) {
	hideQtMovies();
    darkenPage();
    showPopup(panel,w,h);
}

function refreshCaptcha(captchaImageId) {
	if (document.getElementById( captchaImageId ) == null) {
		exit;
	}
	document.getElementById( captchaImageId ).src = "functions/captcha_image.php#" + Math.random();
}

function showPopup(panel,w,h) {
    var popup_panel = document.getElementById(panel);
    var scroll_height = document.body.parentNode.scrollHeight;
    var scroll_top = document.body.scrollTop;
    
/*
	//Default Settings, if nothing is set
    if (w == "") w = "100%";
    if (h == "") h = "100%";
*/
    
    // get the x and y coordinates to center the popup panel
    xc = Math.round((window.innerWidth/2)-(w/2))
    yc = Math.round((scroll_top + 0))
    
    // show the popup panel
/*
    popup_panel.style.height = h + "px";
    popup_panel.style.width = w + "px";
    popup_panel.style.left = xc + "px";
    popup_panel.style.top  = yc + "px";
*/
    popup_panel.style.display = 'block';

    //For keyboard.js
    window.popupActive = true;
}

function hideQtMovies() {
	if (document.getElementById('qtDiv')) {
		var movie_panel = document.getElementById('qtDiv');
   		movie_panel.style.display = 'none';
   	}
}

function showQtMovies() {
	if (document.getElementById('qtDiv')) {
		var movie_panel = document.getElementById('qtDiv');
		movie_panel.style.display = 'block';
	}
}

function hidePopup(panel) {
    // hide the popup panel
    var popup_panel = document.getElementById(panel);
    popup_panel.style.display = 'none';
    lightenPage();
    showQtMovies();
    
    //For keyboard.js
    window.popupActive = false;
}

function hideAllPopups() {
	var b = document.getElementsByTagName('div')
	for(var i = 0; i < b.length; i++)
		if(b[i].getAttribute('popup') == "1"){
			b[i].style.display = "none"
		}
    lightenPage();
    showQtMovies();
    
    //For keyboard.js
    window.popupActive = false;
}

// this function puts the dark screen over the entire page
function darkenPage() {
    var page_screen = document.getElementById('page_screen');
    var page_height =  document.body.scrollHeight;

    page_screen.style.height = page_height + 'px';
    if (page_screen.style.display != 'block') {
    	page_screen.style.display = 'block';
	    doOpacityFade(page_screen,0,95,95,5,5,2);
    }
/*
	//not sure what this is... delete?
	page_screen.style.filter = 0;
	page_screen.style.opacity = 0;
*/
}


// this function removes the dark screen and the page is light again
function lightenPage() {
    var page_screen = document.getElementById('page_screen');
    doOpacityFade(page_screen,95,0,0,5,5,2);
}

 

//-------------------------------------------------------------------------------
// FADE TESTS
//-------------------------------------------------------------------------------
//Source script: BG Fader by www.hesido.com
function doBGFade(elem,startRGB,endRGB,finalColor,steps,intervals,powr) {
	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.backgroundColor = "rgb("+
				easeInOut(startRGB[0],endRGB[0],steps,actStep,powr)+","+
				easeInOut(startRGB[1],endRGB[1],steps,actStep,powr)+","+
				easeInOut(startRGB[2],endRGB[2],steps,actStep,powr)+")";
			actStep++;
			if (actStep > steps) {
			elem.style.backgroundColor = finalColor;
			window.clearInterval(elem.bgFadeInt);
			}
		}
		,intervals)
}
//Opacity Fader
function doOpacityFade(elem,startOpacity,endOpacity,finalOpacity,steps,intervals,powr) {
	if (elem.bgFadeInt) window.clearInterval(elem.bgFadeInt);
	var actStep = 0;
	elem.bgFadeInt = window.setInterval(
		function() {
			elem.style.filter = "alpha(opacity="+ easeInOut(startOpacity,endOpacity,steps,actStep,powr)+")";
   			elem.style.opacity = easeInOut(startOpacity,endOpacity,steps,actStep,powr) / 100;
			
			actStep++;
			if (actStep > steps) {
				elem.style.filter = finalOpacity;
				elem.style.opacity = finalOpacity / 100;
				window.clearInterval(elem.bgFadeInt);
			
				if (finalOpacity <= 0) {
					elem.style.display = 'none';
				}else{
					elem.style.display = 'block';
				}
			}
		}
		,intervals)

}
//Generic Animation Step Value Generator By www.hesido.com
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}
