var preloadFlag = false;
var ie = document.all?1:0
var ns4 = document.layers?1:0
var isSafari=navigator.userAgent.toLowerCase().indexOf("safari")!=-1;

var updelay = 100;
var downdelay = 10;
var counter = new Array();
var statedown = new Array();
var stateup = new Array();

function initialize()
{
	var sections = new Array("resume", "weblog", "services", "portfolio", "contact", "xtras");
	for (var i=0; i<sections.length; i++)
	{
		counter[sections[i]] = 1;
		statedown[sections[i]] = 1;
	}
}

function hL(elementName, count)
{
	var E = document.getElementById(elementName);
	
	if (ie) while (E.tagName!="DIV") E=E.parentElement;
	else while (E.tagName!="DIV") E=E.parentNode;

	var pxval = -1 * count * 25;
	
	if (isSafari) E.style.backgroundPositionY = pxval+'px';
	else E.style.backgroundPosition = '0px '+pxval+'px';
}

function startbuttondown(section)
{
	//alert("startbuttondown: " + section);
	statedown[section] = 1;
	stateup[section] = 0;
	buttondown(section);
}

function startbuttonup(section)
{
	//alert("startbuttonup: " + section);
	stateup[section] = 1;
	statedown[section] = 0;
	buttonup(section);
}

function buttondown(section)
{
	//alert("buttondown: " + section + "; stateup[section]: " + stateup[section] + "; counter[section]: " + counter[section]);
	if (!stateup[section])
	{
		//alert("buttondown: " + section);
		if (counter[section] < 4)
		{
			hL(section,counter[section]);
			if (counter[section] < 3)
			{
				counter[section] = counter[section] + 1;
				setTimeout("buttondown('" + section + "')",downdelay);
			}
		}
	}
}

function buttonup(section)
{
	//alert("buttonup: " + section + "; stateup[section]: " + stateup[section] + "; counter[section]: " + counter[section]);
	if (!statedown[section])
	{
		if (counter[section] > -1)
		{
			hL(section,counter[section]);
			if (counter[section] > 0)
			{
				counter[section] = counter[section] - 1;
				setTimeout("buttonup('" + section + "')",updelay);
			}
		}
	}
}

initialize();


var startanchor = '<a href="', endanchor = '">', endquote = '"'; endgt = '>'; closeanchor = '</a>';

var data = new Array(85,89,81,84,76,87,2,82,82,95,90,120,85,89,91,22,91,87,85,56);
function encodedEmail() {
	var theEmail = '';
	var idx = 0, n = data[data.length-1]; 
	while (data[idx] != n) theEmail += '&#'+(data[idx++]^n)+';';
	return theEmail;
}

function justEmail() {
	var theEmail = '';
	var idx = 7, n = data[data.length-1]; 
	while (data[idx] != n) theEmail += '&#'+(data[idx++]^n)+';';
	return theEmail;
}

// Abre ventana con screenshot
function openscreenshot(url, width, height, size, fullname, number, totalpictures)
{
    win_location = url;
	
	width += 20;
	height += 20;
	
	//var width = 195; var height = 202;
	var features = '"toolbar=no,status=no,menubar=no,titlebar=no,height=' + height + ',width=' + width;
	features += ',left=' + ((screen.availWidth - width) / 2) + ',top=' + ((screen.availHeight - height) / 2) + '"';
		
	newwindow = open("", "ventana", features);
	newwindow.location = win_location;
	newwindow.opener = self;
	newwindow.focus();
}

function displayCounter(site, section, type)
{
	var myref=document.referrer;
	if (top.document.referrer!=null) myref=top.document.referrer;
	var height=10;
	var width=42;
	
	var url='http://gbtopia.com/counter?site='+site+'&amp;d=6&amp;section='+section+'&amp;ref='+escape(myref);
	
	if (type!='gbc') url += '&amp;t='+type;
	if (type=='blank') { width = 2; height = 2; }
		
	document.write('<img src="'+url+'" alt="counter" width="'+width+'" height="'+height+'" border="0" />');
}

function downloadLink(site, url)
{
	var myref=document.referrer;
	if (top.document.referrer!=null) myref=top.document.referrer;
	
	return 'http://gbtopia.com/counter?site='+site+'&amp;ref='+escape(myref)+'&amp;url='+escape(url);
}

function downloadAnchor(site, url, content)
{
	document.write(startanchor+downloadLink(site,url)+endanchor+content+closeanchor);
}

function writeAnchor(url, content)
{
	document.write(startanchor+url+endanchor+content+closeanchor);
}

function PDFImage(alt)
{
	return '<img src="binaries/images/DownloadPDF.gif" width="123" height="57" border="0" alt="'+alt+'" />'
}

