/*////////////////////////*/
/*Google Boooks Preview*/
/*////////////////////////*/

function ProcessGBSBookInfo(booksInfo) {
	
    for (isbn in booksInfo) {
        var element = document.getElementById(isbn);
        var bookInfo = booksInfo[isbn];
          
        if (bookInfo) {
  
            //element.href = bookInfo.preview_url;
            if (bookInfo.preview == "full" ||
                bookInfo.preview == "partial") {
                element.style.display = '';
            }
        }
    }
}

///////////////////////////////////////////////////
//VENTANA PARA REDES SOCIALES
///////////////////////////////////////////////////
function socialWindow(zoomUrl) {
	
	//Init Vars
	wWidth = 1010;
	wHeight = 600;
	
	properties = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=" + wWidth + ", height=" + wHeight + ", left=10, top=10";
	mywin = window.open(zoomUrl,"win",properties);
	mywin.self.focus();
	
}

/*////////////////////////*/
/*Busqueda rapida*/
/*////////////////////////*/

setUpSimpleSearch = function () {
	
	//Init Vars
	var defaultText = "buscar...";
		
	var searchContainer = document.getElementById("buscar");
	var searchForms = searchContainer.getElementsByTagName("form");
	var containerTags = searchContainer.getElementsByTagName("input");
	var inputTextFields = new Array;
	
	searchForm = searchForms[0];
	
	//alert(containerTags.length);
	
	//Busco campo y formateo y aņado eventos
	for(var i=0; i<containerTags.length; i++) {
		var tagAttributes = containerTags[i].attributes;
		//alert(tagAttributes.length);
		for(var j=0; j<tagAttributes.length; j++) {
			if(tagAttributes[j].name == "type" && tagAttributes[j].value == "text") {
				containerTags[i].value = defaultText;
				containerTags[i].defaultText = defaultText;
				
				inputTextFields.push(containerTags[i]);
				
				addEvent(containerTags[i]);
			}
		}
	}
	
	//aņado eventos al formulario
	searchForm.onsubmit = function () {
		
		for(var i=0; i<inputTextFields.length; i++) {
			if(inputTextFields[i].value == defaultText) {
				inputTextFields[i].value = "";
				//alert(inputTextFields[i].value);	
			}
		}
		
	}

}

//Eventos del campo "input text"
addEvent = function(field) {
	
	field.onclick = function () {
		field.value = "";
	}
	field.onblur = function () {
		if (field.value == "") {
			field.value = field.defaultText;
		}
	}
	
}



//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.75;
		
		
		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;
				
			shadowDivs.push(divShadowA);
			
			//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 = "#134A56";
				//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]);
			}

		}
		
	}
}


//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;
}




//Initial setUp
setUpPage = function() {
	//alert ("settingUp!!");
	
	//Texto Busqueda rapida
	setUpSimpleSearch();
	
	//Drop Shadows
	dropShadow();

} 

window.onload = setUpPage;
