	jQuery(document).ready(function() {
		$("#divtt").scrollToTop({speed:400,start:200});
		//$(window).scroll(function () {$("#divqc").css("margin-top", "280"); });
		var hd_1 = $("#hd_1");
		var hd_1H = -180;
	
		$("a[href=#hd_1]").click(function()
		{
			if (hd_1.is(":animated")){
				return false;
			}
			if (hd_1.is(":visible")){
				$("#divqc").stop(true).animate({ marginTop: -(0-hd_1H) + "px" }, 750, "swing");
				hd_1.stop(true).animate({ marginTop: hd_1H + "px" }, 750, "swing", function() { $(this).hide(); });
				$("#showintro").attr({"src":"images/btn_intro_show.png"});
			}
			else{
				hd_1.show().stop(true).animate({ marginTop: "0px" }, 750, "swing");
				$("#divqc").show(true).animate({ marginTop: "0px" }, 750, "swing");
				$("#showintro").attr({"src":"images/btn_intro_hide.png"});
			}
			
			return false;
		});		

		var activeMenu = null;
		var activeExtMenu = null;
		var activeSubMenu = null;
		var menuTimer = null;
		$("#topmenu_nav a").click(function(e)
		{
			var relativeX = $("#"+e.target.id).position().left - 27;
				//this.offsetLeft - ($("#"+e.target.id).width()/2);
		    var relativeY = e.pageY;			
			if(activeMenu && activeMenu.height()){
				menuSlideUp(e,relativeX,relativeY);
				return;
			}
			menuSlideDown(e,relativeX,relativeY);					
		});
		menuAction($("#topmenu_ext"),true,false);
		menuAction($("#topmenu_ext_menu"),false,false);
		menuAction($(".topmenu_ul"),false,false);
		menuAction($(".topmenu_li"),false,false);	
			
		menuAction($("#topmenu_home"),false,false);		
		menuAction($("#topmenu_company"),false,false);
		menuAction($("#topmenu_press"),false,false);
		menuAction($("#topmenu_services"),false,false);
		menuAction($("#topmenu_portfolio"),false,false);
		menuAction($("#topmenu_contactus"),false,false);
		
		

		menuAction($("#navhome"),false,true);
		menuAction($("#navcompany"),true,true);
		menuAction($("#navpress"),true,true);
		menuAction($("#navservices"),true,true);
		menuAction($("#navportfolio"),true,true);
		menuAction($("#navourclient"),false,true);
		menuAction($("#navcontactus"),false,true);
		menuAction($("#navsitemap"),true,true);
		$("#topmenu_ext a").click(function()
		{

		});
		function menuSlideDown(e,x,y){
			if(!e){alert('null');return true;}

		    if (e.target.href.substr(e.target.href.length-1)=="#")
			{
			    var submenu = "topmenu_" + e.target.id.substr(3);
			    activeSubMenu = $("#"+submenu); 		
			    var h = activeSubMenu.height();
			    if(h > 0){   		    
			    	activeExtMenu = $("#topmenu_ext_menu");
				    activeMenu = $("#topmenu_ext");x
					if (activeMenu.height() > 0){			
						activeMenu.stop(true).animate({ height: "0px" }, 600, "swing", function() {showSubmenu(false);});				
						activeExtMenu.stop(true).animate({ height: "0px" }, 600, "swing", function() { });
						
					}else{
						activeMenu.show().stop(true).animate({ height: h+"px"}, 600, "swing",function(){});
						activeExtMenu.show().stop(true).animate({ height: h+"px"}, 600, "swing",function(){});
						activeSubMenu.css({"display":"block","left":x});
					}
			    }
				return false;
		    }
		    return true;
		}
		function menuSlideUp(e,x,y){
			if(activeMenu && activeMenu.height()){
				activeMenu.stop(true).animate({ height: "0px" }, 600, "swing", function() {showSubmenu(false);});				
				activeExtMenu.stop(true).animate({ height: "0px" }, 600, "swing", function() { });
			}
			menuTimer = null;
		}
		function menuAction(menu,out,enter){
			menu.mouseover(function(){
				clearTimeout(menuTimer);
				menuTimer = null;
			});
			if(out){			
				menu.mouseout(function(){
					if(menuTimer == null)
						menuTimer = setTimeout(menuSlideUp,900);
				});
			}
			if(enter){
				menu.mouseenter(function(){
					if(activeMenu && activeMenu.height())
						menuSlideUp();
				});
			}			
		}
		function showSubmenu(bshow,id){
			var flag = "block";
			if(!bshow){
				flag = "none";			
				$("#topmenu_company").css({"display":flag});
				$("#topmenu_home").css({"display":flag});
				$("#topmenu_press").css({"display":flag});
				$("#topmenu_services").css({"display":flag});
				$("#topmenu_portfolio").css({"display":flag});
				$("#topmenu_contactus").css({"display":flag});
			}else{
				if(id.length)
					$("#"+id).css({"display":flag});
			}
		}
	});
