//Vertical alignment "Menu principal" ("TODOS LOS NAVEGADORES")
menuRelocate = function () {
	
	var mainMenu = document.getElementById("mainMenu");
	mainMenuHeight = parseInt(getStyle(mainMenu,"height","height"),10);
	
	//solo si el alto de mainMenu es 66px (Pagina principal)
	if(mainMenuHeight == 66) {
		//alert(mainMenuHeight);
		var spanTags = mainMenu.getElementsByTagName("span"); 
		
		//Busco los spans
		for (i=0; i<spanTags.length; i++) {
			var parentHeight = spanTags[i].parentNode.offsetHeight;
			var parentWidth = spanTags[i].parentNode.offsetWidth;
			//alert(parentHeight);
			//alert("spanTags[i].className = " + spanTags[i].offsetHeight);
			var halfHeight = Math.round(spanTags[i].offsetHeight / 2);
			var halfWidth = Math.round(spanTags[i].offsetWidth / 2);
			//alert("halfWidth = " + spanTags[i].offsetWidth);
			var Yreloc = (parentHeight/2) - halfHeight;
			var Xreloc = (parentWidth/2) - halfWidth;
			spanTags[i].style.top = Yreloc + "px";
			spanTags[i].style.left = Xreloc + "px";
			spanTags[i].style.position =  "absolute";
		}
		
	}

}



//Coloco elementos con POSICION ABSOLUTA contenidos en elementos de ancho IMPAR ("EXPLORER 6")
adjustFrameBorders = function(classN) {
	
	//Obtengo todos los Tag SPAN de los elementos con CLASE "classN"
	var spanTags = new Array();
	
	//alert("adjustFrameBorders");

	docDivs = document.getElementsByTagName("div");
	for (var i=0; i<docDivs.length; i++) {
		//docDivs[i].style.background = "#00ff00";
		if (docDivs[i].className == classN) {
			
			//alert("target found!!");

			var frameTag = docDivs[i];
			var frameSpanTags = docDivs[i].getElementsByTagName("SPAN");
			
			setCornerPosition(frameTag,frameSpanTags);

		}
		
	}
	
}

//setCornerPosition("EXPLORER 6")
setCornerPosition = function(frameTag,frameSpanTags)	{
	
	//alert("setCornerPosition");

	//coloco apropiadamente
	for (var i=0; i<frameSpanTags.length; i++) {
		if (frameSpanTags[i].className == "topRight") {
			var parentWidth = frameSpanTags[i].parentNode;
			parentWidth = parentWidth.offsetWidth;
			//alert("parentWidth = " + parentWidth);
			var spanWidth = frameSpanTags[i].offsetWidth;
			//alert("spanWidth = " + spanWidth);
			frameSpanTags[i].style.left = (parentWidth - spanWidth) + "px";
		}
		if (frameSpanTags[i].className == "bttmLeft") {
			var parentHeight = frameSpanTags[i].parentNode;
			parentHeight = parentHeight.offsetHeight;
			//alert("parentHeight = " + parentHeight);
			var spanHeight = frameSpanTags[i].offsetHeight;
			//alert("spanHeight = " + spanHeight);
			frameSpanTags[i].style.top = (parentHeight - spanHeight) + "px";
		}
		if (frameSpanTags[i].className == "bttmRight") {
			frameSpanTags[i].style.left = (parentWidth - spanWidth) + "px";
			frameSpanTags[i].style.top = (parentHeight - spanHeight) + "px";
		}
		
		//Un bordes solamente (Items Derecha (Noticias)/Publicidad Derecha)
		if (frameSpanTags[i].className == "bttm") {
			var parentHeight = frameSpanTags[i].parentNode;
			parentHeight = parentHeight.offsetHeight;
			var spanWidth = frameSpanTags[i].offsetWidth;
			var spanHeight = frameSpanTags[i].offsetHeight;
			frameSpanTags[i].style.top = (parentHeight - spanHeight - 2) + "px";
		}
		
	}
}

//Acomoda posicion de "colDestacados" ("EXPLORER 6")
fixPosition = function(fixTag,refTagA,refTagB) {
	
	positionType = getStyle(fixTag,"position","position");
	
	if(positionType == "absolute") {		
		
		refTagAHeight = refTagA.offsetHeight;
		refTagBHeight = refTagB.offsetHeight;
		
		fixTag.style.bottom = "auto";
		fixTag.style.top = (refTagAHeight - refTagBHeight - fixTag.offsetHeight) + "px";
		
		//testVars
		//testVars(fixTag.style.top);
	}
	
}


//dropShaddow
function dropShadow () {
	
	//First test CSS
	stylesDisabled = testCSS();
	
	if(stylesDisabled == false) {
		//alert("stylesDisabled = " + stylesDisabled);
		
		var shadows = new Array();
		var shadowsInfo = new Array();
		var shadowsAlpha = 0.15;
		
		
		var cotainer = document.getElementById("principal");
		var spanTags = cotainer.getElementsByTagName("span");
		
		//alert("cotainer = " + cotainer.offsetHeight);
		
		//alert("spanTags Length = " +  spanTags.length );
  	
		//search SPANS
		for (var i=0; i<spanTags.length; i++) {
			if(spanTags[i].className == "shadow") {
				
				var tempInfo = new Array();
				
				var shadowItem_text = spanTags[i].firstChild.nodeValue;
				var shadowItem_width = spanTags[i].offsetWidth;
				var shadowItem_height = spanTags[i].offsetHeight;
				
				//get styles
				//var shadowItem_width = parseInt(getStyle(spanTags[i], "width", "width"),10);
				//var shadowItem_height = parseInt(getStyle(spanTags[i], "height", "height"),10);
				//alert(shadowItem_width);
				
				//alert("shadowItem_width = " + shadowItem_width + "\nshadowItem_height = " + shadowItem_height);
				
				tempInfo.push(shadowItem_text);	
				tempInfo.push(shadowItem_width);
				tempInfo.push(shadowItem_height);
				
				//alert("tempInfo = " + tempInfo);
				
				shadows.push(spanTags[i]);
				shadowsInfo.push(tempInfo);
				
				//spanTags[i].parentNode.style.height = spanTags[i].offsetHeight + "px";
				
				//shadowsPaddingBottom += (parseInt(getStyle(spanTags[i],"paddingBottom","padding-bottom"),10));
						
			}
		}
		
		//alert("shadows.length = " + shadows.length);
		//alert("shadowsInfo test value" + shadowsInfo[1][1]);
		
		
		//compose texts and shadows
		for (var i=0; i<shadows.length; i++) {
			
			var divText = document.createElement("SPAN");
			var shadowDivs = new Array(); 
			
			//these are the bottom shadows
			var divShadowA = document.createElement("SPAN");
				divShadowA.left = 1;
				divShadowA.top = 1;
			
			var divShadowB = document.createElement("SPAN");
				divShadowB.left = 2;
				divShadowB.top = 2;
	
			var divShadowC = document.createElement("SPAN");
				divShadowC.left = 3;
				divShadowC.top = 3;
			
			var divShadowD = document.createElement("SPAN");
				divShadowD.left = 4;
				divShadowD.top = 4;
			
			//these are the top shadows
			var divShadowE = document.createElement("SPAN");
				divShadowE.left = 0;
				divShadowE.top = -1;
				
			var divShadowF = document.createElement("SPAN");
				divShadowF.left = 0;
				divShadowF.top = -2;
			
			//this is the left shadow
			var divShadowG = document.createElement("SPAN");
				divShadowG.left = -1;
				divShadowG.top = 0;
				
			var divShadowH = document.createElement("SPAN");
				divShadowH.left = -2;
				divShadowH.top = 0;
				
			shadowDivs.push(divShadowA,divShadowB,divShadowC,divShadowD,divShadowE,divShadowF,divShadowG,divShadowH);
			
			//alert("shadowDivs = " + shadowDivs);
			
			var shadowsNodeLength = shadows[i].childNodes.length;
			//alert("shadowsNodeLength =" + shadowsNodeLength);
			//alert(shadows[i].childNodes[0].nodeValue);
			//alert("width = " + shadowsInfo[i][1] + "||height = " + shadowsInfo[i][2]);
			
			//Apply width and height to shadow container
			shadows[i].style.width = shadowsInfo[i][1] + "px";
			shadows[i].style.height = shadowsInfo[i][2] + "px";
			

			//shadows[i].style.backgroundColor = "#00ff00";
			
			//compose text
			divText.innerHTML = shadowsInfo[i][0];
			divText.style.width = shadowsInfo[i][1] + "px";
			divText.style.height = shadowsInfo[i][2] + "px";
			divText.style.left = "0px";
			divText.style.top = "0px";
			/*divText.style.backgroundColor = "#00ffff";*/
			divText.style.display = "block";
			divText.style.zIndex = "1";
			divText.style.position = "absolute";
						
			//compose shadows
			//alert("shadowDivs.length = " + shadowDivs.length);
			
			for (var j=0; j<shadowDivs.length; j++) {
				
				shadowDivs[j].className = "spanShadow";
				shadowDivs[j].innerHTML = shadowsInfo[i][0];
				shadowDivs[j].style.width = shadowsInfo[i][1] + "px";
				shadowDivs[j].style.height = shadowsInfo[i][2] + "px";
				shadowDivs[j].style.left = shadowDivs[j].left + "px";
				shadowDivs[j].style.top = shadowDivs[j].top + "px";
				shadowDivs[j].style.color = "#242E24";
				//divShadow.style.backgroundColor = "#00ff00";
				shadowDivs[j].style.display = "block";
				shadowDivs[j].style.position = "absolute";
				shadowDivs[j].style.opacity = shadowsAlpha;
				
				//set Alpha for Explorer
				if (navigator.appName.indexOf("Explorer") > 0 && navigator.userAgent.indexOf("MSIE 6.0") > 0) {
					shadowDivs[j].style.filter = "alpha(opacity=" + (shadowsAlpha*100) + ")";
				}
				
			}
			
			//delete original text
			var elementToErase = shadows[i].firstChild;
			shadows[i].removeChild(elementToErase);
			
			//add New text And Shadow
			shadows[i].appendChild(divText);
			
			for (var j=0; j<shadowDivs.length; j++) {
				shadows[i].appendChild(shadowDivs[j]);
			}

		}
		
	}
}

//get Style ("FUNCION GENERICA")
getStyle = function (htmlTag,ccsStyle,cssStylAlt) {

	//Sending ID as Var OR ID as String
	if(document.getElementById(htmlTag) != null) {
		var x = document.getElementById(htmlTag);
		//alert("htmlTag noNull");
	}
	else {
		var x = htmlTag;
		//alert("htmlTag Null");
	}
	
	//Getting The Style
	if (x.currentStyle) {//Explorer and Opera Handlig
		var y = x.currentStyle[ccsStyle];
	}
	else if (window.getComputedStyle) {//Firefox and Safari Handlig
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(cssStylAlt);
	}
	
	return y;
}

//verify CSS is active ("FUNCION GENERICA")
function testCSS() {
	var cssdisabled = false; // must be proven otherwise
	var testcss = document.createElement('div');
	
	testcss.innerHTML = "testing...";
	
	
	testcss.style.position = "absolute";
	document.getElementsByTagName("body")[0].appendChild(testcss);
	if (testcss.currentStyle) {
		var currstyle = testcss.currentStyle["position"];
		//alert(currstyle);
	}
	else if (window.getComputedStyle) {
		//alert(currstyle);
		var currstyle = document.defaultView.getComputedStyle(testcss, null).getPropertyValue("position");
		
	}
	var cssdisabled = (currstyle == "static") ? true : false;
	document.getElementsByTagName("body")[0].removeChild(testcss);
	//alert(cssdisabled);
	
	return cssdisabled;
}

//Test vars
function testVars(positionType) {
	
	var outPutVars = ""
	+ '<strong>FIXPOSITION</strong><br />'
	+ '<strong>'
	+ 'positionType=' + positionType
	+ '<br />'
	+ '<br /></strong>';
	
	
	document.getElementById("testVars").innerHTML = outPutVars;

}


window.onresize = function () {
	if (navigator.appName.indexOf("Explorer") > 0 && navigator.userAgent.indexOf("MSIE 6.0") > 0) {
		var refTagA = document.getElementById("principal");
		var refTagB = document.getElementById("footer");
		var fixTag = document.getElementById("colDestacados");
		fixPosition(fixTag,refTagA,refTagB);
	}

}


//Initial setUp
setUpPage = function() {
	//alert ("settingUp!!");
	
	//menuRelocate
	menuRelocate("mainMenu");

	//adjustFrameBorders
	if (navigator.appName.indexOf("Explorer") > 0 && navigator.userAgent.indexOf("MSIE 6.0") > 0) {
		//adjustFrameBorders("modCol modBoletin");
		adjustFrameBorders("item itemNoticia");
		adjustFrameBorders("imagen single");
	}
	
	//Drop Shadows
	dropShadow();
	
} 


window.onload = setUpPage;

