// JavaScript Document
var doInitScripts = function(){};

function setLiImage(array, img){
	for(i = 0; i < array.length; i++){
		array[i].style.listStyleImage = 'url('+img+')';	
	}
}

function setOpacity(el,num){
	if (nav.GKO || nav.opera){
	document.getElementById(el).style.opacity = num/100;
	}
	else{
	document.getElementById(el).style.filter = "alpha(opacity:"+num+")";
	}
}

function cleanElement(){
	for(i = 0; i < arguments.length; i++){
		var obj = document.getElementById(arguments[i]);
		while(obj.hasChildNodes()){
		obj.removeChild(obj.firstChild);
	}
	}
}

function setOpacity(el, n){
	if ( n > 100 || n < 0) return;
	if (getBrowser() == 'IEG'){
		document.getElementById(el).style.filter = 'alpha(opacity=' + n.toString() + ')';	
	}
	else{
		document.getElementById(el).style.opacity = (n / 100).toString(); 
	}
}

function getBrowser(){
	var c = navigator.userAgent.toLowerCase();
	if (c.indexOf("opera") > -1) return 'OPE';
	if (c.indexOf("msie") > -1) return 'IEG';
	if (c.indexOf("firefox") > -1) return 'FIR';
	if (c.indexOf("chrome") > -1) return 'CHR';
	if (c.indexOf("safari") > -1) return 'SAF';
	if (c.indexOf("konqueror") > -1) return 'KON';
	return 'UNK';
}

function getIEVersion(){
	var c = navigator.userAgent.toLowerCase();
	if (c.indexOf("msie 6") > -1) return 'IE6';
	if (c.indexOf("msie 7") > -1) return 'IE7';
	if (c.indexOf("msie 8") > -1) return 'IE8';
	return 'OBS';
}

function getStyle(){
	var ref = (arguments[0]) ? arguments[0] : document.body;
	try{
		return document.defaultView.getComputedStyle(ref,null);
	}
	catch(e){
		try{
			return ref.currentStyle;
		}
		catch(e){
			return document.getComputedStyle(ref,null);
		}
	}
}

function createAjax( url , vars , fn , bool , args ){
	var obj;
	vars = vars || null;
	try{
		obj = new XMLHttpRequest();
	} 
	catch(e){
		obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	obj.open('POST', url, true);
	if(!bool){ 
		obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		obj.send(vars);
		obj.onreadystatechange = function(){
			if(obj.readyState == 4){
				fn(obj.responseText, args);
			}
		}
	}
	else{
		obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		obj.send(vars);
		obj.onreadystatechange = function(){
			if(obj.readyState == 4){
				fn(obj.responseXML, args);
			}
		}
	}
}

var absoluteCoords = function(el){
	this.top = 0;
	this.left = 0;
	this.element = document.getElementById(el);
	this.getAbsolutePosition = function(){
		var y = 0;
		var x = 0;
  		while (this.element.offsetParent) {
	    		x += this.element.offsetLeft;
	    		y += this.element.offsetTop;
	   		this.element = this.element.offsetParent;
	  	}
	  	this.top = y;
	  	this.left = x;		
	}
	this.getAbsolutePosition(el);
}

function getCookie(name){
	var result = null;
	var cookies = document.cookie.split(';');
	for(var i = 0; i < cookies.length; i++){ 
		if(cookies[i].indexOf(name) != -1){
			result = cookies[i].split('=');
			return result[1];
		}
	}
	return result;
}

function deleteCookie(name){
    	var expirationDate = new Date;
	expirationDate.setMonth(expirationDate.getMonth()-1);	
	document.cookie = name + "=expired; expires=" + expirationDate.toGMTString();
}

function showElement(id){
	document.getElementById(id).style.display = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
}

var createFullDiv = function(){
	
	this.posX = 50;
	this.width = 500;
	this.oName ='fullDivOuter';
	this.iName = 'fullDivInner';
	this.oBgColor = '#FFF';
	this.iBgColor = '#FFF';
	this.iPadding = 40;
	
	this.make = function(callback){
		var top = (getBrowser() == 'IEG' && getIEVersion() != 'IE8') ? Number(getStyle().marginTop.replace('px','')) : 0;
		var left = (getBrowser() == 'IEG' && getIEVersion() != 'IE8') ? Number(getStyle().marginLeft.replace('px','')) : 0;
		var div = document.createElement("div");
		div.id =  this.oName;
		div.style.position = 'absolute';
		div.style.zIndex = 1000;
		div.style.backgroundColor = this.oBgColor;
		div.style.top = top + 'px';
		div.style.left = left +  'px';
		div.style.height = (getBrowser() == 'IEG') ?  (document.documentElement.clientHeight - (top * 2)).toString() + 'px' : (window.innerHeight - (top * 2)).toString() + 'px' ;
		div.style.width = (getBrowser() == 'IEG') ?  (document.documentElement.clientWidth - (left * 2)).toString() + 'px'  : (window.innerWidth - (left * 2)).toString() + 'px' ;
		document.body.appendChild(div);
		setOpacity(this.oName, 50);
		div = document.createElement("div");
		div.id =  this.iName;
		div.style.position = 'absolute';
		div.style.padding = this.iPadding + 'px';
		div.style.width = this.width.toString() + 'px';
		div.style.backgroundColor = this.iBgColor;
		div.style.zIndex = 1001;
		div.style.visibility = 'hidden';
		document.body.appendChild(div);	
		setOpacity(this.iName, 0);
		document.getElementById(this.iName).style.visibility = 'visible';
		callback.call();
		document.getElementById(this.iName).style.left = ((document.getElementById(this.oName).style.width.replace('px','') - document.getElementById(this.iName).offsetWidth) / 2).toString() + 'px';
		document.getElementById(this.iName). style.top = this.posX.toString() + 'px';
		setOpacity(this.iName, 100);
	}
}

var counterDisplay = 0;
var indexOpacity = 0;
var texts = new Array('Dise&ntilde;o y<br />Programaci&oacute;n', 'Marketing<br />en Internet','Comercio<br />Electr&oacute;nico','Protecci&oacute;n<br />de Datos');
var indexContent = parseInt(Math.random() * 2);
var textOpacity = 100;
var indexText=0;

function centerBackground(){
	if (topMargin == maxTop && leftMargin == maxLeft){
		setOpacity("bannerTop",100);
		setTimeout(moveText,1);
		//document.getElementById('headerLeft').style.borderColor = '#BCBABC';
		return;
	}
	var a = (indexOpacity==200) ? 100 : parseInt(indexOpacity/2);
	setOpacity("bannerTop",a);
	indexOpacity ++;
	if (indexContent == 0){
		if (topMargin >maxTop) topMargin -= 1;
		else topMargin +=1;	
		if(topMargin == maxTop || counterDisplay == 50){
			indexContent = 1;
			counterDisplay = 0;
		}
	}
	else if(indexContent == 1){
		if (leftMargin >maxLeft) leftMargin -= 1;
		else leftMargin +=1;
		if(leftMargin == maxLeft || counterDisplay == 50) {
			indexContent = 0;
			coounterDisplay = 0;
		}
	}
	document.getElementById('bannerTop').style.backgroundPosition = '-' + leftMargin.toString()+'px -' + topMargin.toString()+'px';
	counterDisplay++;
	setTimeout(centerBackground,3);
	}
	

function moveText(){
	if(textOpacity <= 0){
		setOpacity("bannerTopInfo",100);
		setText();
		return;
	}
	setOpacity("bannerTopInfo",textOpacity);
	textOpacity-=1;
	setTimeout(moveText,3);
}
	
function setText(){
	document.getElementById('bannerTopInfo0').innerHTML = texts[indexText];
	indexText = indexText == (texts.length-1) ? 0 : indexText + 1; 
	textOpacity = 100;
	setTimeout(moveText,10000);		
}

