var headerImages = new Array();
var headerImagesCounter = 0;

$(document).ready(function () {
	//--- Lightbox ---// 
	if($(".lightbox")) {
		$(".lightbox").lightbox();
	}
	
//header image switch
	/*
	$('#logo a').each(function(){
		var href = '/de/header.xml';//$(this).attr('href');
		$(this).attr('href', 'javascript:void(0)');
		$(this).click(function(){
			$.ajax({
				url: href,
				type: 'GET',
				dataType: 'html',
				timeout: 5000,
				success: function(html) {
					alert(html);
					//$("#lightbox").html(html);
				}
			});
		});
	});
	*/
	$.ajax({
        type: "GET",
        url: "/de/header.xml",
        dataType: "xml",
        success: function(xml) {
			var cnt = 0;
            $(xml).find('item').each(function(){
            	headerImages[cnt++] = $(this).text();
            });
            switchHeader(0);
        }
    });
	

	function switchHeader(p_index) {
		index_0 = p_index % headerImages.length;
		index_1 = (++p_index) % headerImages.length;
		mode = 'slow';
		timeout = 5000;
		
		if (!p_index) {
			$("#header_bg_1").hide();
		}
		
		switch (headerImagesCounter++ % 2) {
			case 0:
				$("#header_bg_0").css('background-image', 'url(' + headerImages[index_0] + ')');
				window.setTimeout(function(){
					$("#header_bg_1").fadeOut(mode);
				},
				1000);
				$("#header_bg_0").fadeIn(mode);
				timeout += 1000;
				break;
			case 1:
				$("#header_bg_1").css('background-image', 'url(' + headerImages[index_1] + ')');
				window.setTimeout(function(){
					$("#header_bg_0").fadeOut(mode);
				},
				1000);
				$("#header_bg_1").fadeIn(mode);
				timeout -= 1000;
				break;
		}

		window.setTimeout(function(){
			switchHeader(++p_index)
		},
		timeout);
	}
	
});








//Source: http://www.sitepoint.com/print/standards-compliant-world/
function externalLinks() {	
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}

window.onload = externalLinks;