var targetlink;
var browser=navigator.userAgent;

$(document).ready(function ()
{
	if (ipad) {
		$('#menu > a').mouseenter(function() {
			targetlink=$(this).attr('href');
			 window.location.href=targetlink;
		});	
	}
		
	$(function() {
    	$(this).bind("contextmenu", function(e) {
        	e.preventDefault();
    	});
	});
	
	$('a.menulinkselected').before('<div class="selectedleft"></div>').after('<div class="selectedright"></div>');
	$('a').focus(function()
	{
		this.blur();
	});
	$('#header').mouseenter(function() { $('#submenu').hide(); });

	$('a.menulink').hover(function() {
		if ($(this).next('#submenu').length) { $(this).next('#submenu').show(); } else { $('#submenu').hide(); }
		if (!ipad && !safari) {
		$(this).before('<div class="hoverleft"></div>');
		$(this).after('<div class="hoverright"></div>');
		}
	},function() {
		if ($(this).next().next('#submenu').length) {
			var state=0;
			$(this).next().next('#submenu').hover(function() { state=1; }, function() { $(this).hide(); state=0; } )
			if (state==1) $(this).next().next('#submenu').hide(); 
		} 
		if (!ipad && !safari) {
		$('.hoverleft').remove();
		$('.hoverright').remove();
		}
	}); 

	$('a.menulinkselected').hover(function() {
		if ($(this).next().next('#submenu').length) { $(this).next().next('#submenu').show(); } else { $('#submenu').hide(); }
	},function() {
		if ($(this).next().next('#submenu').length) {
			var state=0;
			$(this).next().next('#submenu').hover(function() { state=1; }, function() { $(this).hide(); state=0; } )
			if (state==1) $(this).next().next('#submenu').hide(); 
		}
	});

if (lang=="de") {
	jQuery.preLoadImages('images/1/0.jpg','images/1/1.jpg','images/2/1.jpg','images/animation.png','images/animation_inner_canvas1.png','images/animation_inner_canvas2.png'); 
} else if (lang=="en") {
	jQuery.preLoadImages('images/1/en0.jpg','images/1/en1.jpg','images/2/en1.jpg','images/animation.png','images/animation_inner_canvas3.png','images/animation_inner_canvas4.png'); 
}


window.onload=function() {
		if (browser.indexOf("MSIE 6") != -1) { 
			pngfix();
			$('#transparent_layer').css({ 'width':$(window).width()+'px' });
		}
		if (browser.indexOf("MSIE") != -1) { 
			var y=document.documentElement.clientHeight;
			$('#transparent_layer').height(y);
		}
	}

});

function pngfix() {
	for (var i = 0; i < $("img").length; i++)
	{
		var img = $("img")[i];
		var imgName = img.src.toUpperCase();
		if (imgName.substring(imgName.length - 3, imgName.length) == "PNG")
		{
			var imgID = "id='" + img.id + "' ";
			var imgClass = "class='" + img.className + "' ";
			var imgTitle = "title='" + img.title + "' ";
			var imgStyle = "display:inline-block;" + img.style.cssText;
			if (img.align == "left") imgStyle = "float:left;" + imgStyle;
			if (img.align == "right") imgStyle = "float:right;" + imgStyle;
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\');\"></span>"
			img.outerHTML = strNewHTML
			i--;
		}
	}
}

function layershow(uri,status) {
	if (status==1) { $('transparent_layer').show();	}
	if (status==0) { $('transparent_layer').hide(); }		
	location.replace(uri);
}

(function ($)
{
	var cache = [];
	$.preLoadImages = function ()
	{
		var args_len = arguments.length;
		for (var i = args_len; i--;)
		{
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery)
