/*
	SCRIPTS - Danacol
	Borja Delgado	- http://www.orangeside.org
	Adapted from Sergi Meseguer - http://zigotica.com/
	01 - 2006
*/

if(!window.EXTRAS) EXTRAS = {};

DANACOL = {
	popThisUp : function(obj) {
		w=450;h=350;t=0;l=0;
			obj.onclick = function() {
				window.open(obj.href, 'autopop', 'width='+w+', height='+h+', top='+t+', left='+l+', scrollbars=no, resizable=no'); 
				return false;
			}
	},

	autoPopup : function() {
		var pops = EXTRAS.getElementsByClass('popup',0);
		for (var i = 0; i < pops.length; i++) {
			DANACOL.popThisUp(pops[i]);
		}
	},

	fixMenu : function() {
		var titles = EXTRAS.getElementsByClass('titularseccion',0);
		for (var i = 0; i < titles.length; i++) {
			if(!(document.all && navigator.userAgent.toLowerCase().indexOf("mac") != -1)) 
			titles[i].href = "javascript:void(0)";
		}
	},

	toggle : function(obj,id) {
		obj.onclick = function() {
			var prods = EXTRAS.getElementsByClass('datos_producto',1);
			for (var i = 0; i < prods.length; i++) {
				if(prods[i].id != id) prods[i].parentNode.style.display = "none";
				else prods[i].parentNode.style.display = "block";
			}
		}
	},

	linkem : function(obj) {
		var h = obj.hash.replace(/#/, ""); 
		obj.href = "javascript:void(0)";
		
		obj.parentNode.onclick = function() { //LI
			document.getElementById("misproductos").style.display = "block";
			document.getElementById("productos_menu_principal").style.display = "none";
			
			var prods = EXTRAS.getElementsByClass('datos_producto',1);
			for (var i = 0; i < prods.length; i++) {
				if(prods[i].id != h) prods[i].parentNode.style.display = "none";
				else prods[i].parentNode.style.display = "block"; //class="danacol_producto"
			}
		}
	},

	togglerinit : function() {
		// togglers iniciales
		var togglers = EXTRAS.getElementsByClass('toggleprods',0);
		for (var i = 0; i < togglers.length; i++) {
			DANACOL.linkem(togglers[i]);
		}

		var hmax = 0;
		var prods = EXTRAS.getElementsByClass('danacol_producto',1);
		for (var i = 0; i < prods.length; i++) {
			if(CSS.getH(prods[i]) > hmax) hmax = CSS.getH(prods[i]); 
			prods[i].style.position = "absolute";
			prods[i].style.top = "0px";
			prods[i].style.left = "0px";
		}
		if (document.getElementById("misproductos")) {
    		document.getElementById("misproductos").style.position = "relative";
    		document.getElementById("misproductos").style.clear = "both";
    		document.getElementById("misproductos").style.height = hmax+"px";
    		document.getElementById("misproductos").style.display = "none";
	    }
		
		// togglers desde menu secundario
		var newlincs = EXTRAS.getElementsByClass('danacol_menu_secundario',0); 
		for (var a = 0; a < newlincs.length; a++) {
			var nh = newlincs[a].hash.replace(/#/, ""); 
			newlincs[a].href = "javascript:void(0)";
			DANACOL.toggle(newlincs[a],nh);
		}
	},

	addPrinter : function() {
		if(document.getElementById('imprimir_receta')) 	document.getElementById('imprimir_receta').innerHTML = '<a href="javascript:window.print()"><img src="grafica/contenido/tus_recetas_imprimir.gif" alt="Imprimir" /></a>';
	}

}
