// SET VARIABLES
var activeMenu = "";
var numberOfImages = 0;
var activeImage = 0;
var imageArray = new Array("a");
var activeLanguage = "en"
var l_lang;
  if (navigator.userLanguage) // Explorer
    l_lang = navigator.userLanguage;
  else if (navigator.language) // FF
    l_lang = navigator.language;
  else
    l_lang = "en";
if(l_lang == "de-DE")
{
	l_lang = "de";
}else {
	l_lang = "en";
}
var activeLanguage = "de";

// THE AMOUNT OF PIXELS VIDEO AND FILM GALLERY SHOULD SCROLL
var imageScroll = 142*1;

$(document).ready(function(){
	
	var COOKIE_NAME = 'melanie';
	var ACTIVE_LANGUAGE = l_lang;
	var ADDITIONAL_COOKIE_NAME = 'additional';
	var options = { path: '/', expires: 10 };
	
	function changeLanguge() {
		if(activeLanguage == "en") {
			activeLanguage = "de";
			$("#nav").fadeOut(200);
			setTimeout(function(){
				$("#nav_de").fadeIn(200);
			},210);
			$.cookie(ACTIVE_LANGUAGE, 'de', options);
		}else {
			activeLanguage = "en";
			$("#nav_de").fadeOut(200);
			setTimeout(function(){
				$("#nav").fadeIn(200);
			},210);
			$.cookie(ACTIVE_LANGUAGE, 'en', options);
		}
		if(location.hash == "#pictures") {
			loadPictures(activeLanguage);
		}else if(location.hash == "#film") {
			loadFilm(activeLanguage);
		}else if(location.hash == "#biography") {
			loadBiography(activeLanguage);
		}else if(location.hash == "#news") {
			loadNews(activeLanguage);
		}else if(location.hash == "#links") {
			loadLinks();
		}else if(location.hash == "#contact") {
			loadContact(activeLanguage);
		}
	}

	var activeLanguage = $.cookie(ACTIVE_LANGUAGE);
	
	if(activeLanguage == "en") {
		$("#languages .english").fadeTo(200, 1);
		$("#languages .deutsch").fadeTo(200, 0.4);
		$("#nav_de").hide();
	}else {
		$("#languages .deutsch").fadeTo(200, 1);
		$("#languages .english").fadeTo(200, 0.4);
		$("#nav").hide();
	}
	
	$("#top h1").click(function(){
		$("#bottom").fadeOut(100);
		$("#bottomNavigation").fadeOut(100);
		$("#imageDiv").fadeOut(200);
		$("#pictureDiv").fadeOut(200);
		$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
		$("#"+activeMenu+"_active").attr("id", activeMenu);
		activeMenu = "";
		$("#top .active").removeClass('active');
		setTimeout(function(){
			$("#imageDiv").fadeIn(200);
		}, 300)
		setTimeout(function(){
			$("#imageDiv img").attr('src', 'images/melanie/bg1.jpg');
		}, 520);
		changeTitle("Melanie Winiger");
        $('#video_teaser').fadeIn(100);
	});
	
	// SET IMAGE AND VIDEO DIV DIMENSIONS
	$("#pictureDiv").css({"height": $(window).height()+"px"});
	$("#video").css({"height": $(window).height()+"px", "width" : "100%"});
	
	$.preloadImages("images/melanie/bg1.jpg", "images/melanie/bg2.jpg", "images/melanie/bg3.jpg", "images/melanie/bg4.jpg", "images/melanie/bg5.jpg")
	
	// ADJUST IMAGE AND VIDEO DIV DIMENSIONS ON RESIZE
	window.onresize = function() {
		$("#pictureDiv").css({"height": $(window).height()+"px"});
		$("#video").css({"height": $(window).height()+"px", "width" : "100%"});
	};
	
	var img = 1;
	
	$("#languages li").click(function(){
		if(activeLanguage == "de" && $(this).attr('class') == "english") {
			$("#languages .english").fadeTo(200, 1);
			$("#languages .deutsch").fadeTo(200, 0.4);
		}else if(activeLanguage == "en" && $(this).attr('class') == "deutsch") {
			$("#languages .deutsch").fadeTo(200, 1);
			$("#languages .english").fadeTo(200, 0.4);
		}
		changeLanguge();
	});
	
	$("#top h1 a").click(function(){
		return false;
	});
	
	// NAVIGATION
	$("#nav li, #nav_de li").click(function(){
		setActiveMenu($(this).attr("id"));
		exitFilm();
	});
	
	// TRIGGER VIDEO
	$(".films li.active").livequery(function(){
		$(this).click(function(){
			var filmUrl = $(this).attr('fUrl');
			var filmWidth = $(this).attr('fWidth')*1.2;
			var filmHeight = $(this).attr('fHeight')*1.2;
			var fTitle = $(this).attr('fTitle');
			playVideo(filmUrl, filmWidth, filmHeight, fTitle);
			setTimeout(function(){
				$("#video").fadeIn(200);
			}, 300);
			$("#imageDiv, #bottom").fadeTo(200, 0.1);
		});
	});
	
	$("#closeVideo").livequery(function(){
		$(this).click(function(){
			exitFilm();
		})
	})
	
	// TRIGGER VIDEO
	$(".show_video").livequery(function(){
		$(this).click(function(){
			var filmUrl = $(this).attr('fUrl');
			var filmWidth = $(this).attr('fWidth')*1.2;
			var filmHeight = $(this).attr('fHeight')*1.2;
			var fTitle = $(this).attr('fTitle');
			playVideo(filmUrl, filmWidth, filmHeight, fTitle);
			setTimeout(function(){
				$("#video").fadeIn(200);
			}, 300);
			$("#imageDiv, #bottom").fadeTo(200, 0.1);
		});
	});
	$("#closeVideo").livequery(function(){
		$(this).click(function(){
			exitFilm();
		})
	})
	
	// FADE IN/OUT NAVIGATION WHEN BROWSING IMAGES
	$("#bottomNavigation").livequery(function(){
		$(this).hover(function(){
			$("#bottomNavigation").fadeTo(150, 1);
		}, function(){
			$("#bottomNavigation").fadeTo(150, 0.2);
		});
	});
	
	// SCROLL IMAGE/FILM GALLERY TO THE RIGHT
	$("#scrollRight").livequery(function(){
		$(this).click(function(){
			$("#scrollArea").animate({scrollLeft: '+='+ imageScroll +'px'}, 300);
		});
	});
	
	// SCROLL IMAGE/FILM GALLERY TO THE LEFT
	$("#scrollLeft").livequery(function(){
		$(this).click(function(){
			$("#scrollArea").animate({scrollLeft: '-='+ imageScroll +'px'}, 300);
		});
	});
	
	
	// LOAD THUMBS
	$("#thumbnails li").livequery(function(){
		$(this).hover(function(){
			$(this).fadeTo(200, 1);
		}, function(){
			$(this).fadeTo(200, 0.7);
		})
	});
	
	$.historyInit(pageload);
	
	
	// LOAD THUMBS
	$("#thumbnails.tumb1 li").livequery(function(){
		
		var org = $(this).find('img').attr('src');
		
		$(this).hover(function(){
			
			//$(this).fadeTo(200, 1);
			
			// izmena
			var tup = $(this).find('img').attr('src').match(/[^\.]+/) + "_a.jpg";
			$(this).find('img').attr('src', tup);
			
		}, function(){
			
			//$(this).fadeTo(200, 0.7);

			// izmena
			$(this).find('img').attr('src', org);
			
		})
	});
	
	$.historyInit(pageload);
		
});

pageload = function(hash) {
	if(hash) {
		var nav = location.hash.replace("#", "");
		if(location.hash == "#pictures") {
			loadPictures(activeLanguage);
  	}else if(location.hash == "#film") {
		  loadFilm(activeLanguage);
		}else if(location.hash == "#biography") {
			loadBiography(activeLanguage);
		}else if(location.hash == "#news") {
			loadNews(activeLanguage);
		}else if(location.hash == "#links") {
			loadLinks();
		}else if(location.hash == "#contact") {
			loadContact(activeLanguage);
		}
		setActiveMenu(nav);
	}
}

// CLOSE THE FILM DIV
exitFilm = function() {
	$("#video").fadeOut(50);
	setTimeout(function(){
		$("#video").html("");
		$("#imageDiv, #bottom").fadeTo(200, 1);
	}, 70);
}

// STARTS THE VIDEO
playVideo = function(fUrl, fWidth, fHeight, fTitle) {
	$("#video").html("");
	var s1 = new SWFObject("swf/player.swf","ply",fWidth,fHeight,"9","#FFFFFF");
	s1.addParam("allowfullscreen","true");
	s1.addParam("allowscriptaccess","always");
	s1.addParam("flashvars","file=/"+fUrl+"&controlbar=none&autostart=true");
	s1.write("video");
	$("#video").append("<h3>"+fTitle+"</h3><p id='closeVideo'><a href='javascript:exitFilm();'>Close video</a></p>");
}

// SLIDE UP/DOWN THE NAVIGATION
toggleNavigation = function() {
	$("#top").slideToggle(200);
}

setActiveMenu = function(id) {
	/*if(activeLanguage == "en") {
		$("#"+activeMenu+"_active").attr("id", activeMenu);
		activeMenu = id;
		$("#"+activeMenu).attr("id", activeMenu+"_active");
	}else {
		$("#"+activeMenu+"_active").attr("id", activeMenu);
		activeMenu = id;
		$("#"+activeMenu).attr("id", activeMenu+"_active");
	}*/
	id = id.replace("_de", "");
	$("#top .active").removeClass('active');
	if(window.location.hash == "#imageView")
	{
	  $("#pictures, #pictures_de").addClass('active');
	}
	else
	{
  	$("#"+id+", #"+id+"_de").addClass('active');
	}
}

loadBiography = function(lang) {
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/biography_"+lang+".html",
			{ complete: setTimeout(function(){
				$("#loading").fadeOut(200);
				$("#imageDiv img").attr('src', 'images/melanie/bg1.jpg');
				setTimeout(function(){
					$("#imageDiv").fadeIn(500);
					setTimeout(function(){
						$("#bottom").fadeIn(500);
					}, 500);
				}, 300);
			}, 50) 
		});
	}, 520);
	changeTitle("Biography | Melanie Winiger");
}

// ACCESS THE XML AND GENERATES THUMBNAILS
loadPictures = function(lang) {
	numberOfImages = 0;
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/pictures_"+lang+".html",
		{complete: setTimeout(function(){
				$("#bottom").fadeIn(200);
				$("#imageDiv img").attr('src', 'images/melanie/bg2.jpg');
				$.ajax({
					type: "GET",
					url: "xml/images.xml",
					dataType: "xml",
					success: function(xml) {
						var thumbnailsContent = "";
						thumbnailsContent = $('#thumbnails').find('li');
						
						if ('undefined' == typeof(thumbnailsContent.length) || 0 == thumbnailsContent.length){
						
							$(xml).find('image').each(function(){
								var thumb = $(this).attr('thumb')
								var full = $(this).attr('full')
								var fulLink = "'"+full+"'";
								numberOfImages+=1;
								$("#loading").fadeOut(200);
								$("#thumbnails").append('<li id="image_'+numberOfImages+'"><a href="./index.html#imageView"><img src="'+thumb+'" onclick="viewImage('+fulLink+', '+numberOfImages+')" alt="Melanie" /></a></li>');
								imageArray.push(full);
								$("#thumbnails li").fadeTo(0, 0.7);
								var thumbWidth = numberOfImages*142;
								$("#thumbnails").css({ 'width' : thumbWidth+"px" });
							});
							setTimeout(function(){
								$("#imageDiv").fadeIn(500);
							},200);
						}
					}
				});
			}, 200)
		});
		
	}, 200);
	changeTitle("Pictures | Melanie Winiger");
}

fadeOutImage = function(ii) {
	$("#image_"+ii).fadeTo(200, 0.7);
}

fadeInImage = function(ii) {
	$("#image_"+ii).fadeTo(200, 1.0);
}

nextImage = function() {
	if(activeImage == numberOfImages) {
		var nextImage = 1;
	}else {
		var nextImage = activeImage+=1;
	}
	viewImage(imageArray[nextImage], nextImage);
}

previousImage = function() {
	if(activeImage == 1) {
		var nextImage = numberOfImages;
	}else {
		var nextImage = activeImage-=1;
	}
	viewImage(imageArray[nextImage], nextImage);
}

// FADES OUT THE IMAGE AND RETURNS TO MAIN
leaveFullscreen = function() {
	$("#bottomNavigation").fadeOut(200);
	setTimeout(function(){
		loadPictures(activeLanguage)
	}, 220);
}

viewImage = function(img, act) {
	activeImage = act;
	if($("#images").css('display') == "block") {
		$("#bottom").fadeOut(200);
		$("#bottomNavigation").load("content/imageNavigation.html",
			{ complete: setTimeout(function(){
				$("#bottomNavigation").fadeIn(200);
			}, 220)
		});
	}
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
	$.each(arguments,function(e) {
		$(new Image()).load(function() {
			setTimeout(function(){
				$("#pictureDiv").html('<img src="'+img+'" />');
				setTimeout(function(){
					setTimeout(function(){
						$("#pictureDiv").fadeIn(200);
					}, 220);
					$("#loading").fadeOut(200);
				}, 250)
			}, 200);
		}).attr('src',this);
	});
}
var inTeaser = false;
loadFilmTeaser = function() {
  playVideo('videos/navyboot_LA.flv', 512, 340, 'Navyboot');
  setTimeout(function(){
    $("#video").fadeIn(200);
    $("#imageDiv, #bottom").fadeTo(200, 0.1);
    loadFilm();
  }, 300);
}
loadFilm = function() {
	numberOfImages = 0;
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/film.html",
		{complete: setTimeout(function(){
				$("#imageDiv img").attr('src', 'images/melanie/bg3.jpg');
                if (!inTeaser) {
                  $("#bottom").fadeIn(200);
                }
				$.ajax({
					type: "GET",
					url: "xml/videos.xml",
					dataType: "xml",
					success: function(xml) {
						$("#loading").fadeOut(200);
                        if (!inTeaser) {
                          setTimeout(function(){
                              $("#imageDiv").fadeIn(200);
                          },250);
                        }
                        inTeaser = false;
						$(xml).find('video').each(function(){
							var fUrl = $(this).attr('url');
							var fTitle = $(this).attr('title');
							var fWidth = $(this).attr('width');
							var fHeight = $(this).attr('height');
							var fThumb = $(this).attr('thumb');
							
							if(fUrl == undefined) {
								$("#thumbnails").append('<li class="inactive" fWidth="'+fWidth+'" fHeight="'+fHeight+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');
							}
							else {
								$("#thumbnails").append('<li class="active" fWidth="'+fWidth+'" fTitle="'+fTitle+'" fHeight="'+fHeight+'" fUrl="'+fUrl+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');								
							}

							$("#thumbnails li").fadeTo(0, 0.7);
							var thumbWidth = $(xml).find('video').length*142;
							$("#thumbnails").css({ 'width' : thumbWidth+"px" });
						});
					}
				});
			}, 200)
		});
	}, 520);
	changeTitle("Film | Melanie Winiger");
}

// izmena
loadFilm2 = function() {
	numberOfImages = 0;
	
	  playVideo('videos/Navyboot_SCHIFFBAU.flv', 512, 340, 'Navyboot');
	  setTimeout(function(){
		$("#video").fadeIn(200);
		$("#imageDiv, #bottom").fadeTo(200, 0.1);
		loadFilm();
	  }, 300);
	
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/film.html",
		{complete: setTimeout(function(){
				$("#imageDiv img").attr('src', 'images/melanie/bg3.jpg');
                if (!inTeaser) {
                  $("#bottom").fadeIn(200);
                }
				$.ajax({
					type: "GET",
					url: "xml/videos.xml",
					dataType: "xml",
					success: function(xml) {
						$("#loading").fadeOut(200);
                        if (!inTeaser) {
                          setTimeout(function(){
                              $("#imageDiv").fadeIn(200);
                          },250);
                        }
                        inTeaser = false;
						$(xml).find('video').each(function(){
							var fUrl = $(this).attr('url');
							var fTitle = $(this).attr('title');
							var fWidth = $(this).attr('width');
							var fHeight = $(this).attr('height');
							var fThumb = $(this).attr('thumb');
							
							if(fUrl == undefined) {
								$("#thumbnails").append('<li class="inactive" fWidth="'+fWidth+'" fHeight="'+fHeight+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');
							}
							else {
								$("#thumbnails").append('<li class="active" fWidth="'+fWidth+'" fTitle="'+fTitle+'" fHeight="'+fHeight+'" fUrl="'+fUrl+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');								
							}

							$("#thumbnails li").fadeTo(0, 0.7);
							var thumbWidth = $(xml).find('video').length*142;
							$("#thumbnails").css({ 'width' : thumbWidth+"px" });
						});
					}
				});
			}, 200)
		});
	}, 520);
	changeTitle("Film | Melanie Winiger");
}
// end izmena

loadPresentation = function() {
	numberOfImages = 0;
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/film.html",
		{complete: setTimeout(function(){
				$("#imageDiv img").attr('src', 'images/melanie/bg3.jpg');
				$("#bottom").fadeIn(200);
				$.ajax({
					type: "GET",
					url: "xml/presentation.xml",
					dataType: "xml",
					success: function(xml) {
						$("#loading").fadeOut(200);
						setTimeout(function(){
							$("#imageDiv").fadeIn(200);
						},250)
						$(xml).find('video').each(function(){
							var fUrl = $(this).attr('url');
							var fTitle = $(this).attr('title');
							var fWidth = $(this).attr('width');
							var fHeight = $(this).attr('height');
							var fThumb = $(this).attr('thumb');
							
							if(fUrl == undefined) {
								$("#thumbnails").append('<li class="inactive" fWidth="'+fWidth+'" fHeight="'+fHeight+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');
							}
							else {
								$("#thumbnails").append('<li class="active" fWidth="'+fWidth+'" fTitle="'+fTitle+'" fHeight="'+fHeight+'" fUrl="'+fUrl+'"><img src="'+fThumb+'" alt="" title="'+fTitle+'" /></li>');								
							}

							$("#thumbnails li").fadeTo(0, 0.7);
							var thumbWidth = $(xml).find('video').length*142;
							$("#thumbnails").css({ 'width' : thumbWidth+"px" });
						});
					}
				});
			}, 200)
		});
	}, 520);
	changeTitle("Presentation | Melanie Winiger");
}

loadContact = function(lang) {
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/contact_"+lang+".html",
			{ complete: setTimeout(function(){
				$("#loading").fadeOut(200);
				$("#imageDiv img").attr('src', 'images/melanie/bg4.jpg');
				setTimeout(function(){
					$("#imageDiv").fadeIn(500);
					setTimeout(function(){
						$("#bottom").fadeIn(500);
					}, 500);
				}, 300);
			}, 100) 
		});
	}, 510);
	changeTitle("Contact | Melanie Winiger");
}

loadLinks = function() {
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/links.html",
			{ complete: setTimeout(function(){
				$("#loading").fadeOut(200);
				$("#imageDiv img").attr('src', 'images/melanie/bg5.jpg');
				/*$.ajax({
					type: "GET",
					url: "xml/links.xml",
					dataType: "xml",
					success: function(xml) {
						$(xml).find('link').each(function(){
							var title = $(this).attr('title');
							var url = $(this).attr('url');
							$("#linklist").append('<li><a href="'+url+'" title="'+title+'" target="_blank">'+title+'</a></li>');
						});
					}
				});*/
				setTimeout(function(){
					$("#imageDiv").fadeIn(500);
					setTimeout(function(){
						$("#bottom").fadeIn(500);
					}, 500);
				}, 300);
			}, 100) 
		});
	}, 520);
	changeTitle("Links | Melanie Winiger");
}

loadNews = function(lang) {
    $('#video_teaser').fadeOut(100);
	$("#bottom").fadeOut(100);
	$("#bottomNavigation").fadeOut(100);
	$("#imageDiv").fadeOut(200);
	$("#pictureDiv").fadeOut(200);
	$("#imageDiv img").attr('src', 'images/melanie/black.jpg');
	setTimeout(function(){
		$("#loading").fadeIn(200);
	}, 300);
	setTimeout(function(){
		$("#bottom").load("content/news_"+lang+".html",
			{ complete: setTimeout(function(){
				$("#loading").fadeOut(200);
				$("#imageDiv img").attr('src', 'images/melanie/bg4.jpg');
				//$.ajax({
				//	type: "GET",
				//	url: "xml/news_de.xml",
				//	dataType: "xml",
				//	success: function(xml) {
				//		$(xml).find('node').each(function(){
				//			var id = $(this).attr('id')
				//			var title = $(this).find('title').text()
				//			var posted = $(this).find('posted').text()
				//			$('#nodes2').append("<li><a href=\"javascript:findData("+id+", '"+lang+"');\">"+title+"</a> <span class='date'>"+posted+"</span></li>");
				//		});
				//	}
				//});
				setTimeout(function(){
					$("#imageDiv").fadeIn(500);
					setTimeout(function(){
						$("#bottom").fadeIn(500);
					}, 500);
				}, 300);
			}, 50) 
		});
	}, 520);
	changeTitle("News | Melanie Winiger");
}

findData = function(id, lang) {
	$("#node").slideUp(750);
	$.ajax({
		type: "GET",
		url: "xml/news_de.xml",
		dataTtype: "xml",
		success: function(xml) {
			$(xml).find('node').each(function(){
				if($(this).attr('id') == id) {
					var title = $(this).find('title').text()
					var posted = $(this).find('posted').text()
					var intro = $(this).find('intro').text()
					var body = $(this).find('body').text()
					$("#node").html("<h3>"+title+"</h3><p>"+intro+"</p><br /><p>"+body+"</p><br /><p><a href='#media_archive' onclick='javascript: showMedia();'>Back</a></p>");
					setTimeout(function(){
						$("#news_start").slideUp(750);
						setTimeout(function(){
							$("#node").slideDown(750);
						}, 800);
					}, 550);
					changeTitle(title+" | Melanie Winiger");
				}
			});
		}
	});	
}

changeTitle = function(tit) {
	document.title=tit;
}

jQuery.preloadImages = function() {
	var totalImages = arguments.length;
	for(var i = 0; i<arguments.length; i++) {
		jQuery("<img>").attr("src", arguments[i]);
	}
	$.each(arguments,function(e) {
		$(new Image()).load(function() {
			totalImages-=1;
			if(totalImages == 0) {
				$("#loading").fadeOut(200);
				setTimeout(function(){
					$("#imageDiv").fadeIn(200);
                    if (!location.hash || location.hash == '') {
                      $('#video_teaser').fadeIn(100);
                    }
				}, 250);
			}
		}).attr('src',this);
	});
}

function display_news(year)
{
	$("#nodes").load("news/"+year+".html");
}
