$(document).ready(function() {
	$("ul.topmenu > li > ul").each( // renklendirme 
		function(){
			var n = 1;
			var li_count = ($("li",this).length);
			$("li", this).each(
				function(){
					if($(this).index()==(li_count-1))
						$(this).append('<div class="shadow-to-bottom-50 absolute" style="left:0px"></div>');
					if(n==$(this).index()){
						$("a",this).css({'border-right':'1px solid #fff','border-left':'1px solid #fff'});
						n=n+3;
					}
					if($('.topsub',this).size()>0)
						$('a:first span',this).prepend(" <img src='/template/image/template/topmenu/down.png' /><br/>");
					else
						$('a:first span',this).prepend("<br/>");
					
					$this = $(this);
					$("a",this).css('background-color', function(){
						if(($this.index())%2==0)
							return "#f8f8f8";
						return '#efefef';
					});
				}
			);
		}
	);

	$("ul.topmenu > li > ul > li").click(
			function(){
				$("a",this).css('background-color', "#e3e3e3");
				if($('.topsub',this).size()>0){
					$('.topsub a',this).css('background', "url(/template/image/menu_top/backtopmenuhover.png)");
					$('.topsub',this).slideToggle(100);
					$('.shadow-to-top').hide();
				}
			});
	$("ul.topmenu > li > ul > li").hover(
		function(){
			$("a",this).css({'background-color': "#e3e3e3"});
		},
		function(){
			if(($(this).index()+1)%2==0)
					color = "#efefef";
				else
					color = '#f8f8f8';
			$("a",this).css('background-color', color);
			//$('.topsub a',this).css('background-color', "#666666");
			if($('.topsub',this).size()>0){
				$('.topsub',this).slideUp(200);
				$('.shadow-to-top').show();
			}
		}
	);
	
	$("ul.topmenu > li").hoverIntent(
		function() {
			$("ul",this).slideDown(100);
			//$("ul",this).delay(200).slideDown(400);
			/*
			if ($.browser.msie  && parseInt($.browser.version) <= 7)
				$(this).stop().animate({
					paddingBottom:+$("ul",this).height()
					}, 200);
			  //tamamdır bu fade
			else
				$(this).stop().animate({
					marginBottom:+$("ul",this).height()
					}, 200);
			*/
		},
		function() {
			//$("ul",this).hide(200);
			$("ul",this).slideUp(200);
			/*
			if ($.browser.msie  && parseInt($.browser.version) <= 7)
				$(this).stop().animate({
				    paddingBottom:0
			  		}, 200);
			else
				$(this).stop().animate({
				    marginBottom:0
			  		}, 200);
			*/
		}
	);
	
	
	/*
	 * Middle Menu
	 * 
	 * Middle menu animation goes here
	 * CopyRight Serkan Konakci 
	 */
	
	$('#middlemenu li').hover(function(){
		$('ul',this).css('width',$(this).width());
		$('ul',this).slideToggle(100);
	},function(){
		$('ul',this).slideToggle(200);
	});
	
	
	/*
	 * Product Menu
	 * 
	 * product menu animation goes here
	 * CopyRight Serkan Konakci 
	 */
	/*
	$('.services > ul > li').mouseenter(
		function(){
			$('ul',this).animate({'bottom':'47px','opacity':'1'});
			});
	
	$('.services > ul > li').mouseleave(
		function(){
			$this = $(this);
			setTimeout(function () {
				$('ul',$this).animate({'bottom':'57px','opacity':'0'},500,'swing');
		      }, 500);
			}
	);
	
	*/
	
	// options
    var distance = 5;
    var time = 250;
    var hideDelay = 500;
    var height = 100;
    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    var trigger = $('.services > ul > li');
    
    // set the mouseover and mouseout on both element
    $('.services > ul > li').hoverIntent(
			function() {
				//$(this).css({'border':'1px solid red'});
				var popup = $('ul', this);
				popup.append("<div class='ok'></div>");
				width = (($(this).width()) / 2)	- ((popup.width()) / 2);
				height = popup.height();
				popup.css({
						bottom : 37,
						left : width,
						display : 'block' 
					})
					.animate({
						height : (height + 13),
						opacity : 1
					}, 300, 'swing');
			},
			function() {
				var popup = $('ul', this);
				height = popup.height();
				popup.animate({
					height : (height - 13),
					opacity : 0
					}, 300, 'swing',function(){
						$(this).css({
							bottom : 37,
							display: 'none'
						});
						$('.ok',this).remove();
					});
				
			});
			
    $('.expander').hover()
	/*
	$(".services li").hover(function() {
		$(this).find("ul").animate({opacity: "show", top: "-275"}, "slow");
	}, function() {
		$(this).find("ul").animate({opacity: "hide", top: "-285"}, "fast").html();
	});*/
});
