﻿// Shows users IP address
//
// Author: Sam Warburton

//Settings
var transparencyLevel = 7; // Sets overlay transparecny, 1 = most translucent 10 = least translucent
var speed = 1; // Sets the speed that the overlay fades in/out, 1 = fast, 10 = slow

//DO NOT EDIT BELOW HERE
var windowTimer = null;
var timer = null;
var opacity = 0;
//Window size
var windowHeight = 0;
var windowWidth = 0;
var scrOfY = 0;
var scrOfX = 0;

//functions
window.onload = function() {
	//Overlay
	ipOverlay = document.createElement("div");
	ipOverlay.style.position = "absolute";
	ipOverlay.style.top = "0";
	ipOverlay.style.left = "0";
	ipOverlay.style.height = "50px";
	ipOverlay.style.width = "50px";
	ipOverlay.style.background = "#000";
	ipOverlay.style.opacity = 0;
	//IE opacity
	ipOverlay.style.filter = "alpha(opacity = 0)"
	ipOverlay.style.display = "none";
	ipOverlay.onclick = function() {
		window.clearInterval(timer);
		timer = null;
		timer = window.setInterval("fadeOut('hide')", (speed));
		window.clearInterval(windowTimer);
		windowTimer = null;
	}
	//IP data
	var ip = document.getElementById("your-ip")
	//ip.style.display = "none";
	ipBox = document.createElement("div");
	ipBox.style.display = "none";
	ipBox.style.position = "absolute";
	ipBox.style.top = "50%";
	ipBox.style.left = "50%";
	ipBox.style.height = "200px";
	ipBox.style.width = "400px";
	ipBox.style.marginLeft = "-200px";
	ipBox.style.marginTop = "-100px";
	ipBox.style.background = "transparent url(../imgs/widgets/ipbg.gif) top left no-repeat";
	//IP Text
	ipBox.innerHTML = "<p style='font-size:15px'>Your IP Address is:</p><p style='font-size:40px;line-height:50px;'>"+ip.innerHTML+"</p><p style='font-size:15px'>Click anywhere off of this panel to go back to abeta.co.uk.</p>";
	//Show ip button
	ipButton = document.createElement("div");
	ipButton.setAttribute("id","show-ip");
	ipButton.style.position = "absolute";
	ipButton.style.bottom = "15px";
	ipButton.style.right = "15px";
	ipButton.style.height = "20px";
	ipButton.style.width = "20px";
	ipButton.style.cursor = "hand";
	ipButton.style.cursor = "pointer";
	ipButton.innerHTML = "<img src='../imgs/widgets/showip.png' alt='Enlarge' />"
	ipButton.onclick = function() {showIp();};
	
	//Append new elements
	document.getElementById("wrapper").appendChild(ipOverlay);
	document.getElementById("wrapper").appendChild(ipBox);
	document.getElementById("ip-wrapper").appendChild(ipButton)
}

function getWindowSize() {
	if(typeof(window.innerWidth) == 'number') {
		//Non-IE
		windowHeight = window.innerHeight;
		scrOfY = window.pageYOffset;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		windowHeight = document.documentElement.clientHeight;
		scrOfY = document.documentElement.scrollTop;
	}
	//Set Positions
	//ipOverlay.innerHTML = "<p>Window height = "+windowHeight+"<br />Window width = "+windowWidth+"<br />scroll X = "+scrOfX+"<br />scroll Y = "+scrOfY+"</p>";
	ipBox.style.top = ""+((windowHeight/2)+scrOfY)+"px";
	if(windowHeight > height) {
		ipOverlay.style.height = ""+windowHeight+"px";
		}
	else {
		ipOverlay.style.heigh = ""+height+"px";
		}
}

var height;

function showIp() {	
	height = document.getElementById("wrapper").scrollHeight;
	ipOverlay.style.width = "100%";
	ipOverlay.style.height = ""+height+"px";
	ipOverlay.style.display = "block";
	timer = window.setInterval("fadeIn('show')", (speed));
	windowTimer = window.setInterval("getWindowSize()", 25);
}

function fadeIn() {
	if(opacity <= (transparencyLevel * 10)) {
		if(opacity == (transparencyLevel * 10)) {
			ipBox.style.display = "block";
		}
		opacity = opacity + 5;
		ipOverlay.style.opacity = opacity/100;
		ipOverlay.style.filter = "alpha(opacity = "+opacity+")";
	}
	else {
		window.clearInterval(timer);
		timer = null;
	}
}

function fadeOut() {
	if(opacity > 0) {
		if(opacity > (transparencyLevel * 10) - 5) {
			ipBox.style.display = "none";
		}
		opacity = opacity - 5;
		ipOverlay.style.opacity = opacity/100;
		ipOverlay.style.filter = "alpha(opacity = "+opacity+")";
		if(opacity < 5) {
			ipOverlay.style.display = "none";
		}
	}
	else {
		window.clearInterval(timer);
		timer = null;
	}
}