Event.observe(window, 'load', function() {
	Flash.write(
		"Logo", 
		[
			'width', '220',
			'height', '125',
			'src', '/web/swf/logo',
			'id', 'LmsLogo',
			'name', 'LmsLogo',
			'movie', '/web/swf/logo',
			'wmode', 'transparent' 
		] 
	);

	if ($("Nav")) {
		Flash.write(
			"Nav", 
			[
				'suffix', 'NONE',
				'width', '400',
				'height', '135',
				'src', navigation_path,
				'id', 'GralNav',
				'name', 'GralNav',
				'movie', navigation_path,
				'wmode', 'transparent',
				'FlashVars', "currentSection=" + $("section").value
			] 
		);
	}
	
	var h1 = document.getElementsByTagName("h1");
	var fvars = "";
	
	if (h1[1]) {
		if (h1[1].className) {
			var _tmp = h1[1].className.split(" ");
			
			for(var i=0; i<_tmp.length; i++) {
				if (_tmp[i].substr(0,1) == "s") fvars += "&size=" + _tmp[i].substr(1);
				if (_tmp[i].substr(0,1) == "p") fvars += "&spacing=" + _tmp[i].substr(1);
			} 
		}
		
		Flash.write(
			h1[1], 
			[
				'width', '72',
				'height', '29',
				'src', '/web/swf/cat_name',
				'id', 'CatName',
				'name', 'CatName',
				'movie', '/web/swf/cat_name',
				'wmode', 'transparent',
				'align', 'left',
				'FlashVars', "id=CatName&texto=" + URLEncode(h1[1].innerHTML.tagsToLower().replaceAll("\t", "")) + fvars 
			] 
		);
	}
	
	if ($("Categories")) {
		Element.setStyle("Categories", { height: $("Categories").firstChild.offsetHeight + "px" });
		// Event.observe($("Categories").parentNode, "mouseout", function() { GeneralNav.out('portfolio'); }, true);
		
		var elems = $("Categories").getElementsByTagName("*");
		for (var i=0; i<elems.length; i++) {
			Event.observe(elems[i], "mouseover", function() { GeneralNav.over('portfolio', this); });
			Event.observe(elems[i], "mouseout", function() { GeneralNav.out('portfolio', this); }, true);
		}
	}
});

function detectMacXFF() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
		return true;
	}
}

var GeneralNav = 
{
	goTo: function(section) {
		switch(section) {
			case "luminasur":
				document.location = "/web/luminasur.php";
				break;
			case "portfolio":
				GeneralNav.over(section);
				break;
			case "contact":
				document.location = "/web/contact.php";
				break;
			case "news":
				document.location = "/web/news.php";
				break;
		}
	},
	
	portfolioShowed: false,
	portfolioTimer: null,
	elements: new Array(),
	
	over: function(section, obj) {
		// if (section != "portfolio") return;
		
		if (obj == null || !GeneralNav.elements.inArray(obj)) {
			if (obj != null) GeneralNav.elements.push(obj);
		
			if (!GeneralNav.portfolioShowed) {
				if (GeneralNav.portfolioTimer) GeneralNav.portfolioTimer.cancel();
				GeneralNav.portfolioTimer = null;
				
				if (!detectMacXFF()) {
					GeneralNav.portfolioTimer = new Effect.Move($('Categories').firstChild, { y: -parseInt(Element.getStyle($('Categories').firstChild, "top")), duration: .3 });
				} else { 
					Element.setStyle($('Categories').firstChild, { top: "0px" });
				}
			}
			
			GeneralNav.portfolioShowed = true;
		}
	},
	
	out: function(section, obj) {
		if (section != "portfolio") return;
		
		GeneralNav.elements = GeneralNav.elements.without(obj);
		
		if (!GeneralNav.elements.length) {
			if (GeneralNav.portfolioShowed) {
				if (GeneralNav.portfolioTimer) GeneralNav.portfolioTimer.cancel();
				GeneralNav.portfolioTimer = null;
				
				if (!detectMacXFF()) {
					GeneralNav.portfolioTimer = new Effect.Fade(
						$('Categories').firstChild, 
						{
							afterFinish: function() {
								Element.setStyle($('Categories').firstChild, { top: "-100%", opacity: "0.9999", filter: "alpha(opacity=100)", display: "block" });
							},
							duration: .3
						}
					);
				 } else {
				 	Element.setStyle($('Categories').firstChild, { top: "-100%" });
				 }
			}
			
			GeneralNav.portfolioShowed = false;
		}
	},
	
	// only for portfolio
	loadedImages: 0,
	
	retreive: function(btn, url) {
		document.documentElement.style.height = document.documentElement.offsetHeight;
		
		document.getElementsByTagName("body")[0].style.height = document.documentElement.offsetHeight + "px";
		// document.getElementsByTagName("body")[0].style.overflow = "hidden";
		
		if (url) {
			btn.url = url;
		}
		
		if (btn.href) {
			btn.url = btn.href;
			btn.removeAttribute("href");
		}
		
		var _req = new Requester();
		_req.request(btn.url + "?asXML=1", "", function(doc, txt) {
			try {
				document.title = doc.getElementsByTagName("title")[0].textContent;
			} catch(e) {
				document.title = "luminaSur";
			}
			
			var details = $Att(document, "class", "details");
			var images = $("images");
			images.className += " Invisible";

			btn.parentNode.className = "On";
			details.innerHTML = txt.substr(txt.indexOf("<!-- <DETAILS> -->"), txt.indexOf("<!-- </DETAILS> -->")-txt.indexOf("<!-- <DETAILS> -->")+19);
			images.innerHTML = txt.substr(txt.indexOf("<!-- <IMAGES> -->"), txt.indexOf("<!-- </IMAGES> -->")-txt.indexOf("<!-- <IMAGES> -->")+18);
			
			var imgs = $Atts(images, "class", "image");
			for(var i=0; i<imgs.length; i++) {
				imgs[i].onload = function() {
					GeneralNav.loadedImages++;
					if (GeneralNav.loadedImages == imgs.length) {
						GeneralNav.loadedImages = 0;
						
						// PROECT IMAGES PAGER
						Imgs = new ProjectNavigation(null, "imgs", $Class("images", "btnleft"), $Class("images", "btnright"), { display: "block"}, { display: "none" }, -.5, 1);
						Imgs.afterPageChange = function() {
							var lis = $(this.slider).getElementsByTagName("li");
							resizeImagesBox(lis[this.currentPage-1].firstChild);
						}
						
						var h2 = document.getElementsByTagName("h2");
						Flash.write(
							h2[0], 
							[
								'width', '350',
								'height', '26',
								'src', '/web/swf/prj_name',
								'id', 'PrjTitle',
								'name', 'PrjTitle',
								'movie', '/web/swf/prj_name',
								'wmode', 'transparent',
								'align', 'left',
								'FlashVars', "id=PrjTitle&texto=" + URLEncode(h2[0].innerHTML.tagsToLower().replaceAll("\t", "")) 
							] 
						);
						h2[0].className = h2[0].className.replaceAll("Invisible", "");
						
						resizeImagesBox($Class("images", "image"));
						$("images").className = $("images").className.replaceAll("Invisible", "");
						
						document.getElementsByTagName("body")[0].style.height = "";
						document.getElementsByTagName("body")[0].style.overflow = "visible";
					}
				}
			}
		});
	}
}
