jo2.queue_load_event(pagecopyright);
//jo2.queue(search);
jo2.queue_load_event(sidebar);

jo2.queue_load_event(geek);

function pagecopyright()
{
	var el = document.getElementById("pagecopyright");
	jo2.dom.clear(el);
	el.appendChild(document.createTextNode("2003 - 2010"));
	
}
function search()
{
	
}
function sidebar()
{
	var el = document.getElementById("sidebar");
	
	/* Shortcuts - css change */
	var shortcuts = document.createElement("div");
		shortcuts.setAttribute("id","shortcuts");
		
		var zmena_css = document.createElement("a");
			zmena_css.setAttribute("href","zmena_css.php");
			zmena_css.setAttribute("title","zmena css štýlu");
			zmena_css.setAttribute("id","sidebarcsschange");
			zmena_css.onclick = function(e){
				show_quick_css_change();
				return false;
			};
		
			var zmena_css_span = document.createElement("span");
				zmena_css_span.appendChild(document.createTextNode("Zmeniť štýl .css "));
			zmena_css.appendChild(zmena_css_span);
		
		shortcuts.appendChild(zmena_css);
		//shortcuts.appendChild(document.createTextNode(", "));
		
	
	el.appendChild(shortcuts);
	
	/* Sidebar menu */
	var sidebarmenu = document.createElement("div");
		sidebarmenu.setAttribute("id","sidebarmenu");
		
		var label = document.createElement("a");
			label.setAttribute("href","index.html");
			label.setAttribute("title","site map");
			label.setAttribute("id","sidebarfiletree");
		
		sidebarmenu.appendChild(label);
			
			var label_span = document.createElement("span");
				label_span.appendChild(document.createTextNode("Sitemap"));
			label.appendChild(label_span);
		
		var menu = jo2.widgets.trees.create_menu(
			[
				{
					href: "about.html", 
					label: "About",
					child_nodes: [
						{href: "about-autor.html", label: "O autorovi"},
						{href: "about-web.html", label: "O webe"}
					]
				},
				{
					href: "umenie.html", 
					label: "Umenie a grafika",
					child_nodes: [
						{href: "umenie-gimp.html", label: "GIMP", child_nodes: [
							{href: "umenie-gimp-skripty.html", label: "skripty"},
							{href: "umenie-gimp-scm.html", label: "scheme"},
							{href: "umenie-gimp-script_fu.html", label: "skript-fu"}
						]},
						{href: "umenie-historia_umenia.html", label: "História umenia"},
						{href: "umenie-obrazky.html", label: "Obrázky"}
					]
				},
				{
					href: "programovanie.html", 
					label: "Programovanie",
					child_nodes: [
						{href: "programovanie-pas.html", label: "Pascal", child_nodes: [
							{href: "programovanie-pas-mo2004.html", label: "mo2004"},
							{href: "programovanie-pas-mo2005.html", label: "mo2005"},
							{href: "programovanie-pas-mo2.html", label: "mo2"},
							{href: "programovanie-pas-koncepty.html", label: "koncepty"}
						]},
						{href: "programovanie-java.html", label: "Java", child_nodes: [
							{href: "programovanie-java-fyz1.html", label: "fyz1"}
						]},
						{href: "programovanie-js.html", label: "JavaScript"}
					]
				},
				{
					href: "zdroje.html", 
					label: "Zdroje",
					child_nodes: [
						{href: "zdroje-ref.html", label: "Práce"},
						{href: "zdroje-uvahy.html", label: "Úvahy"},
						{href: "etablo/index.html", label: "eTablo"},
						{href: "zdroje-matfyz.html", label: "Matfyz"}
					]
				}
			],
			{vertex_anchor_class: "vertex", subtree_class: "submenu"}
		);
		menu.className = "menu";
		sidebarmenu.appendChild(menu);
		
	el.appendChild(sidebarmenu);
}

function geek(){
	if(/.*MSIE.*/.test(window.navigator.appVersion)){
		var anchor = document.createElement("a");
		anchor.setAttribute("href","http://www.mozilla.org");
		
		var img = document.createElement("img");
		img.src = "images/get_firefox_large.png"
		img.style.position = "absolute";
		img.style.top = "0";
		img.style.right = "0";
		img.style.zIndex = "200";
		img.style.border = "none";
		img.setAttribute("title","your browser seems to be unstable: get firefox");
		img.alt = "your browser seems to be unstable: get firefox";
		
		anchor.appendChild(img);
		
		document.getElementsByTagName("body")[0].appendChild(anchor);
	}
}



/*
	higher control
*/

var overlay_show;
var overlay_hide;
function prepare_page_overlay_if_not(){
	var overlay = document.getElementById("overlay");
	if(!overlay){
		overlay = document.createElement("div");
		overlay.setAttribute("id","overlay");
		overlay.style.display = "none";
		document.getElementsByTagName("body")[0].appendChild(overlay);
		
		(overlay_show = new jo2.animations.Animation(overlay))
			.queue({opacity: "0",display: "block"})
			.queue({opacity: {start: 0, end: 0.9, unit: ""}},400);
		(overlay_hide = new jo2.animations.Animation(overlay))
			.queue({opacity: {start: 0.9, end: 0, unit: ""}},400)
			.queue({display: "none"});
	}
}

function resize_overlay(){
	var overlay = document.getElementById("overlay");
	overlay.style.width = (jo2.window.get_inner_width()+100)+"px";
	overlay.style.height = (jo2.window.get_inner_height()+100)+"px";
}

/* Quick css change */

var css_change_show;
var css_change_hide;
function prepare_css_change_if_not(){
	prepare_page_overlay_if_not();
	
	var css_change = document.getElementById("quickcsschange");
	if(!css_change){
		css_change = document.createElement("div");
		css_change.style.display = "none";
		css_change.setAttribute("id","quickcsschange");
		document.getElementsByTagName("body")[0].appendChild(css_change);
		
		(css_change_show = new jo2.animations.Animation(css_change))
			.queue({display: "block", top: "-334px"})
			.queue({top: {start: -500, end: 0, unit: "px"}},800);
		(css_change_hide = new jo2.animations.Animation(css_change))
			.queue({top: {start: 0, end: -334, unit: "px"}},800)
			.queue({display: "none"});
		
		content = document.createElement("div");
		content.className = "content";
		
		css_change.appendChild(content);
		
			header = document.createElement("h2");
			header.innerHTML = "Choose your style <span>(click on image)</span>";
			
			styles = document.createElement("div");
			styles.className = "styles";
			
			close = document.createElement("a");
			close.className = "close";
			close.setAttribute("href","javascript:void(0);");
			close.onclick = function(){hide_quick_css_change();};
				close_content = document.createElement("span");
				close_content.innerHTML = "close";
			close.appendChild(close_content);
			
			
			content.appendChild(header);
			content.appendChild(styles);
			content.appendChild(close);
			
			var data = [
				["images/css_change-001-oldbook.png", "zmena_css.php?css=http://jo2.ethome.sk/001-oldbook.css"],
				["images/css_change-none.png", "zmena_css.php?css=http://jo2.ethome.sk/none.css"]
				
			];
			
			for(var i = 0; i < data.length; i++){
				var style_anchor = document.createElement("a");
				style_anchor.setAttribute("href",data[i][1]);
				var style_image = document.createElement("img");
				style_image.width = 100;
				style_image.height = 75;
				style_image.src = data[i][0];
				
				style_anchor.appendChild(style_image);
					styles.appendChild(style_anchor);
			}
	}
}

//jo2.queue(function(){show_quick_css_change();});

function show_quick_css_change(){
	prepare_css_change_if_not();
	resize_overlay();
	
	overlay_show.run(function(){
		css_change_show.run();
	});
}

function hide_quick_css_change(){
	overlay_show.stop();
	css_change_show.stop();
	
	css_change_hide.stop().run(function(){
		overlay_hide.stop().run();
	});
}