$(document).ready(function() {

// STARTSEITE
	var stepToPage;
	
	$(document).ready(function() {
		$("body").removeClass("noJS");
		
		// Links für Animationen entfernen
		$("#startwrapper a:not(.logo)").attr({'href' : '#'});
		
		// Fading Menu
		ArrMenuID = new Array("startabout", "startprojekte", "startkontakt", "startdatenschutz", "startimpressum");
		function GetRandom( min, max ) {
			if( min > max ) {
				return( -1 );
			}
			if( min == max ) {
				return( min );
			}
				return( min + parseInt( Math.random() * ( max-min+1 ) ) );
		}	
		function animateMenu() {
			$(document).everyTime(3000, "fademenu", function(i) {
				var MenuElement = ArrMenuID[GetRandom(0,5)];
				$("#" + MenuElement + " a").animate({ color: "#004071" }, 1000, function () 
					{
						$("#" + MenuElement + " a").animate({ color: "#929497" }, 1000);
					});
			});
		}
		
		// Mouseover Fading
		$("#startwrapper a").mouseover(function() {
			var actualColor = $(this).css("color");
			$(this).stop(true, true);
			$(document).stopTime("fademenu");
			$(this).stop(true, true);
			$(this).css({"color" : actualColor});
			$(this).animate({ color: "#DC7602" }, 500);
			
		}).mouseout(function() {
			$(this).stop(true, true);
			$(this).stop(true, true);
			$(this).animate({ color: "#929497" }, 500);
			animateMenu();
			
		});
		animateMenu();
		
		// OnClick 
		$("#startwrapper a:not(.logo)").click(function() {
			$(document).stopTime("fademenu");
			stepToPage = ($(this).html()).toLowerCase();
			$(this).blur();
			
			// Image Preload
			(function($) {
			var cache = [];
			// Arguments are image paths relative to the current page.
			$.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)
			jQuery.preLoadImages("/assets/templates/brlnr-template-v1/images/header.gif", "/assets/templates/brlnr-template-v1/images/footer.gif");
			
			
			$("#startcopyright").after("<div id=\"startcontent\"></div>");
			
			$("#startcontent").animate({
				width: 'show'
				},{
				duration: 1500, 
				width: 'swing'
			});
			  
			$("#startcontent").html("<ul id=\"startmenu\">" +
				"<li id=\"li-home\"><a href=\"#\" title=\"zur brlnr Webdesign Startseite\">HOME</a></li>" + 
				"<li id=\"li-about\"><a href=\"#\" title=\"über brlnr.de\">ABOUT</a></li>" + 
				"<li id=\"li-projekte\"><a href=\"#\" title=\"Projekte\">PROJEKTE</a></li>" + 
				"<li id=\"li-kontakt\"><a href=\"#\" title=\"Kontakt aufnehmen\">KONTAKT</a></li></ul>");

			var active = false;
			$("#startmenu a").mouseover(function() {
					
					var actualColor = $(this).css("color").replace(/\s/, "").toLowerCase();
					$(this).animate({ color: "#008AC9" }, 500);
					if ($.browser.msie){
						if ((actualColor == "rgb(0,138,201)") || (actualColor == "#008ac9"))
						{
							active = true;
						}else{
							active = false;
						}							
					}else{	
						if ((actualColor == "rgb(0,138,201)") || (actualColor == "#008ac9"))
						{
							active = true;
						}else{
							active = false;
						}
					}
						
				}).mouseout(function () {
					if (active)
					{
						$(this).animate({ color: "#008AC9" }, 500);
					}else{
						$(this).animate({ color: "#929497" }, 500);
					}
				});	

			$("#li-" + stepToPage + " a").css("color", "#008AC9");
			
			$("#li-home").animate({
				top: [+0, 'swing'],
				opacity: '1'
			  }, 2000
			);
			
			$("#li-about").animate({
				top: [+41, 'swing'],
				opacity: '1'
			  }, 2000
			);
			
			$("#li-projekte").animate({
				top: [+82, 'swing'],
				opacity: '1'
			  }, 2000
			);
			
			$("#li-kontakt").animate({
				top: [+123, 'swing'],
				opacity: '1'
			  }, 2000, function () {
				forwarding();
			  }
			);
		});
	
	});
	function forwarding(){
		window.location.href = "http://brlnr.de/" + stepToPage + "/";
	}	
	
	
	
// DEFAULT JQUERY

	// Menu
	$("#menu > li > a:not(.active)").mouseover(function() {
		$(this).stop(true, true);
		$(this).animate({ color: "#008AC9" }, 500);
	}).mouseout(function () {
		$(this).animate({ color: "#929497" }, 500);
	});	
	
	
	// Submenu
	$(".submenu > li > a:not(.active)").mouseover(function() {
		$(this).stop(true, true);
		$(this).animate({ color: "#004071" }, 500);
	}).mouseout(function () {
		$(this).animate({ color: "#929497" }, 500);
	});	

	
	// Contentlinks
	$("#content a").mouseover(function() {
		$(this).stop(true, true);
		$(this).animate({ color: "#008AC9" }, 500);
	}).mouseout(function () {
		$(this).animate({ color: "#004071" }, 500);
	});	
	
	// Footerlinks
	$("#footerlinks a:not(.active)").mouseover(function() {
		$(this).stop(true, true);
		$(this).animate({ color: "#008AC9" }, 500);
	}).mouseout(function () {
		$(this).animate({ color: "#929497" }, 500);
	});		
	
	// FancyBox
	$("a#fancy_image").fancybox({
		'hideOnContentClick': true,
		'title' : 'BILDTITEL',
		'titlePosition'	:	'outside',
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	400, 
		'speedOut'		:	200,
		'easingIn'		:	'swing',
		'easingOut'		:	'swing'
	});
	
	// E-Mail Adresse verschlüsseln
	$("#impressumsmail").html("<a href=\"mailto:kontakt@brlnr.de\" title=\"Christian Lange eine E-Mail schicken\">kontakt@brlnr.de</a>");
	// Telefon/Fax ("8" entfernen)
	$("#impressumstelefon").html("+49 (0) 30 / 60 92 70 14");
	$("#impressumsfax").html("+49 (0) 30 / 60 92 70 15");
	
	// Captcha Reload
	$("#captchaimg").click(function() {
		$('#captchaimg').attr('src','/manager/includes/veriword.php?rand='+new Date().getTime());
	});	

	// Externe Links tracken
	$("#content a:not([href^='http://brlnr'])[href^='http']").click(function (){
		_gaq.push(['_trackEvent', 'Externer Link', 'click', $(this).attr('href')]);
	});
		
});	

