var myWorkURL;
var myProductsURL;

  	 $(document).ready(
        function()
            {
				
			// wstępne przygotowanie
			$(".light").stop().animate({opacity:0},0);
			$(".flag").stop().animate({opacity:0.7},0);
			
			
			$("#productsLayer").stop().animate({opacity:0},0);
			$("#servicesLayer").stop().animate({opacity:0},0);
			$("#supportLayer").stop().animate({opacity:0},0);
			$("#accountLayer").stop().animate({opacity:0},0);
			$("#workLayer").stop().animate({opacity:0},0);
			$("#myProdutsLayer").stop().animate({opacity:0},0);
			
			$("#productsLayer").css("display","none");
			$("#servicesLayer").css("display","none");
			$("#supportLayer").css("display","none");
			$("#accountLayer").css("display","none");
			$("#workLayer").css("display","none");
			$("#myProdutsLayer").css("display","none");
			
			
			// resiziowanie elementów
			$("#productsLayer").css("left",$("#menuProducts").position().left);
			$("#servicesLayer").css("left",$("#menuServices").position().left);
			$("#supportLayer").css("left",$("#menuSupport").position().left);
			$("#workLayer").css("left",$("#menuWork").position().left);
			
		
			
			
			if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
			{
				var _interval = window.setInterval(function ()
				{
					var autofills = $('input:-webkit-autofill');
					if (autofills.length > 0)
					{
						window.clearInterval(_interval); // stop polling
						autofills.each(function()
						{
							var clone = $(this).clone(true, true);
							$(this).after(clone).remove();
							
							if($(this).attr("id") == "usernameInput" || $(this).attr("id") == "passwordInput"){
								$("#username").removeClass("usernameLabled usernameError").addClass("usernameNonLabled")
								$("#password").removeClass("passwordLabled passwordError").addClass("passwordNonLabled")
							}
							
						});
					}
				}, 200);
			}
		
			
			if($("#menuAccount").length ){
				$("#accountLayer").css("left",$("#menuAccount").position().left);
			}
			
			if($("#menuMyProducts").length ){
				$("#myProductsLayer").css("left",$("#menuMyProducts").position().left);
			}
			
			$("#homeIcon").click(function() {
				window.location = "http://web-anatomy.com";
			});
			
			$("#facebookIcon").click(function() {
				window.location = "http://www.facebook.com/pages/Web-Anatomy/151145978291749";
			});
			
			$("#twitterIcon").click(function() {
				window.location = "http://twitter.com/#!/WebAnatomy";
			});
		
			$(window).resize(function() {
 				$("#productsLayer").css("left",$("#menuProducts").position().left);
				$("#servicesLayer").css("left",$("#menuServices").position().left);
				$("#supportLayer").css("left",$("#menuSupport").position().left);
				$("#workLayer").css("left",$("#menuWork").position().left);
				
				if($("#menuAccount").length ){
					$("#accountLayer").css("left",$("#menuAccount").position().left);
				}
			
				if($("#menuMyProducts").length ){
					$("#myProductsLayer").css("left",$("#menuMyProducts").position().left);
				}
			});
			
			$("#usernameInput").focus(function() {
				
					$("#username").removeClass("usernameLabled usernameError").addClass("usernameNonLabled")
					$("#password").removeClass("passwordLabled passwordError").addClass("passwordNonLabled")
				
  			}).focusout(function(){
				
					if($("#usernameInput").val() == ""){
						$("#username").removeClass("usernameNonLabled").addClass("usernameLabled")
					}
					
					if($("#passwordInput").val() == ""){
						$("#password").removeClass("passwordNonLabled").addClass("passwordLabled")
					}
				
			})
			
		
		
			
			
			//
			$("#passwordInput").focus(function() {
				
					$("#username").removeClass("usernameLabled usernameError").addClass("usernameNonLabled")
					$("#password").removeClass("passwordLabled passwordError").addClass("passwordNonLabled")
	
				
  			}).focusout(function(){
	
					if($("#usernameInput").val() == ""){
						$("#username").removeClass("usernameNonLabled").addClass("usernameLabled")
					}
	
					if($("#passwordInput").val() == ""){
						$("#password").removeClass("passwordNonLabled").addClass("passwordLabled")
					}
					
			})
				
				
			// podstawowe roll-over'y itd.	
			$(".box").mouseenter(
				function()
            	{
					$(this).css("cursor","pointer");
					$(this).children(".light").stop().animate({opacity:1},300);
					$(this).children(".light").css("visibility","visible");
					
					switch($(this).attr("id").toString()){
						case "menuProducts":
							productsCount = 2;
							productsLock = true;
							
							$("#productsLayer").css("display","block");
							$("#productsLayer").stop().animate({opacity:1},300);
							
					
							$("#servicesLayer").css("display","none");
							$("#supportLayer").css("display","none");
							$("#accountLayer").css("display","none");
							$("#workLayer").css("display","none");
							$("#myProductsLayer").css("display","none");
							
						break;
						
						case "menuServices":
							servicesCount = 2;
							servicesLock = true;
						
							$("#servicesLayer").css("display","block");
							$("#servicesLayer").stop().animate({opacity:1},300);
							
							$("#productsLayer").css("display","none");
							$("#supportLayer").css("display","none");
							$("#accountLayer").css("display","none");
							$("#workLayer").css("display","none");
							$("#myProductsLayer").css("display","none");
							
						break;
						
						case "menuSupport":
							supportCount = 2;
							supportLock = true;
						
							$("#supportLayer").css("display","block");
							$("#supportLayer").stop().animate({opacity:1},300);
							
							$("#productsLayer").css("display","none");
							$("#servicesLayer").css("display","none");
							$("#accountLayer").css("display","none");
							$("#workLayer").css("display","none");
							$("#myProductsLayer").css("display","none");
							
						break;
						
						case "menuWork":
							workCount = 2;
							workLock = true;
						
							$("#workLayer").css("display","block");
							$("#workLayer").stop().animate({opacity:1},300);
						
							$("#productsLayer").css("display","none");
							$("#servicesLayer").css("display","none");
							$("#supportLayer").css("display","none");
							$("#accountLayer").css("display","none");
							$("#myProductsLayer").css("display","none");
								
						break;
						
						case "menuAccount":
							accountCount = 2;
							accountLock = true;
							
							$("#accountLayer").css("display","block");
							$("#accountLayer").stop().animate({opacity:1},300);
						
							$("#productsLayer").css("display","none");
							$("#servicesLayer").css("display","none");
							$("#supportLayer").css("display","none");
							$("#workLayer").css("display","none");
							$("#myProductsLayer").css("display","none");
							
								
						break;
						
						case "menuMyProducts":
							myProdutsCount = 2;
							myProductsLock = true;
							
							$("#myProductsLayer").css("display","block");
							$("#myProductsLayer").stop().animate({opacity:1},300);
						
						
							$("#productsLayer").css("display","none");
							$("#servicesLayer").css("display","none");
							$("#supportLayer").css("display","none");
							$("#accountLayer").css("display","none");
							$("#workLayer").css("display","none");

								
						break;
					}
					
				}
			).mouseleave(
				function()
            	{
					$(this).css("cursor","none");
					$(this).children(".light").stop().animate({opacity:0},300);
				
					productsLock = false;
					workLock = false;
					servicesLock = false;
					supportLock = false;
					accountLock = false;
					myProductsLock = false;
					
				}
			);
			
			// button ok
			$("#button").mouseenter(
				function()
            	{
					$(this).css("cursor","pointer");
					$(this).removeClass("buttonOut").addClass("buttonOver")
					
				}
			).mouseleave(
				function()
            	{
					$(this).css("cursor","none");
					$(this).removeClass("buttonOver").addClass("buttonOut")
					
				}
			);
			
			// button home
			$("#homeIcon").mouseenter(
				function()
            	{
					$(this).css("cursor","pointer");
					$(this).removeClass("homeOut").addClass("homeOver")
					
				}
			).mouseleave(
				function()
            	{
					$(this).css("cursor","none");
					$(this).removeClass("homeOver").addClass("homeOut")
					
				}
			);
			
			// button facebook
			$("#facebookIcon").mouseenter(
				function()
            	{
					$(this).css("cursor","pointer");
					$(this).removeClass("facebookOut").addClass("facebookOver")
					
				}
			).mouseleave(
				function()
            	{
					$(this).css("cursor","none");
					$(this).removeClass("facebookOver").addClass("facebookOut")
					
				}
			);
			
			// button twitter
			$("#twitterIcon").mouseenter(
				function()
            	{
					$(this).css("cursor","pointer");
					$(this).removeClass("twitterOut").addClass("twitterOver")
					
				}
			).mouseleave(
				function()
            	{
					$(this).css("cursor","none");
					$(this).removeClass("twitterOver").addClass("twitterOut")
					
				}
			);
			
			
			// OK do logowania
			$(".flag").mouseenter(
				function()
            	{
			
					$(this).stop().animate({opacity:1},150);
					
				}
			).mouseleave(
				function()
            	{
					$(this).stop().animate({opacity:0.7},150);
					
				}
			);
			
		
			setInterval(updateFlyingMenus, 1000);
			
			productsLock = false;
			servicesLock = false;
			workLock = false;
			supportLock = false;
			accountLock = false;
			myProductsLock = false;
			
			function updateFlyingMenus(){
				// products
				if(productsCount != 0 && productsLock == false){
					productsCount--;
					if(productsCount == 0){
						if($("#productsLayer").css("display") == "block"){
							$('#productsLayer').stop().animate({opacity: 0}, 300, function() {
								$("#productsLayer").css("display","none");
							});
						}
					}
				}
				// services
				if(servicesCount != 0 && servicesLock == false){
					servicesCount--;
					if(servicesCount == 0){
						if($("#servicesLayer").css("display") == "block"){
							$('#servicesLayer').stop().animate({opacity: 0}, 300, function() {
								$("#servicesLayer").css("display","none");
							});
						}
					}
				}
				// support
				if(supportCount != 0 && supportLock == false){
					supportCount--;
					if(supportCount == 0){
						if($("#supportLayer").css("display") == "block"){
							$('#supportLayer').stop().animate({opacity: 0}, 300, function() {
								$("#supportLayer").css("display","none");
							});
						}
					}
				}
				// account
				if(accountCount != 0 && accountLock==false){
					accountCount--;
					if(accountCount == 0){
						if($("#accountLayer").css("display") == "block"){
							$('#accountLayer').stop().animate({opacity: 0}, 300, function() {
								$("#accountLayer").css("display","none");
							});
						}
					}
				}
				
				// work
				if(workCount != 0 && workLock== false){
					workCount--;
					if(workCount == 0){
						if($("#workLayer").css("display") == "block"){
							$('#workLayer').stop().animate({opacity: 0}, 300, function() {
								$("#workLayer").css("display","none");
							});
						}
					}
				}
				// myProducts
				if(myProdutsCount != 0 && myProductsLock == false){
					myProdutsCount--;
					if(myProdutsCount == 0){
						if($("#myProductsLayer").css("display") == "block"){
							$('#myProductsLayer').stop().animate({opacity: 0}, 300, function() {
								$("#myProductsLayer").css("display","none");
							});
						}
					}
				}
			}
			
			
       });
	   
	   	var productsCount = 0;
		var servicesCount = 0;
		var supportCount = 0;
		var accountCount = 0;
		var workCount = 0;
		var myProdutsCount = 0;
			
		function keepMenu($name){
			switch($name){
				case "productsLayer":
					productsCount = 3
						
				break;	
				
				case "servicesLayer":
					servicesCount = 3
						
				break;	
				
				case "supportLayer":
					supportCount = 3
						
				break;	
				
				case "accountLayer":
					accountCount = 3
						
				break;	
				
				case "workLayer":
					workCount = 3
						
				break;	
				
				case "myProductsLayer":
					myProdutsCount = 3

				break;	
			}
		}
