$(function(){
	$("#sidebar > ul > li > ul").hide();
	
	//giving accordion functionality to the components
//	$("#sidebar > ul > li").hoverIntent({
//		sensitivity:3,
//		interval:200,
//		timeout:1000,
//		over:function(){
//			$(this).children("ul").slideDown(300);
//		},
//		out:function(){
//			$(this).children("ul").slideUp(300);
//		}
//	});

	
	$("#sidebar > ul > li > a").each(function(){
		var $this = $(this);
		this.currentLink = false;
		this.isChildFind = false;

		if($this.attr("href") == document.location.pathname){
			this.currentLink = true;
		}else{
			$this.next("ul").find("a").each(function(){
				if($(this).attr("href")==document.location.pathname){
					$this.get(0).currentLink = true;
					$this.get(0).isChildFind = true;
					this.currentLink = true;
					$(this).css({paddingLeft:"15px"});
				}else{
					this.currentLink = false;
				}
			});
		}
		
		if(this.currentLink){
			$this.css({
				backgroundPosition:"-196px 0px",
				paddingLeft: "35px",
				color: "#D1E4F1"
			});
			$this.next("ul").show();				
			
			/*if(this.isChildFind){
				
			}else{
				/*$this.animate({
					backgroundPosition:"-196px 0px",
					paddingLeft: "35px",
					color: "#D1E4F1"
				},500);
				setTimeout(function(){
					$this.next("ul").slideDown(500);
				},500);
			}*/
		}
	}).hoverIntent({
		sensitivity:3,
		interval:50,
		timeout:500,
		over:function(){
			if(this.currentLink) return;
			$(this).animate({
				//backgroundPosition:"-196px 0px",
				paddingLeft: "35px",
				//color: "#D1E4F1"
			},200);
		},
		out:function(){
			if(this.currentLink) return;
			$(this).animate({
				//backgroundPosition:"0px 0px",
				paddingLeft: "25px",
				//color: "#444455"
			},200)
		}
	});
	

	$("#sidebar li li a").bind('mouseenter',function(){
		if(this.currentLink) return;
		$(this).animate({
			paddingLeft: "15px",
		},300);
	});	
	$("#sidebar li li a").bind('mouseleave',function(){
		if(this.currentLink) return;
		$(this).animate({
			paddingLeft: "10px",
		},300);
	});
	
	
	setInterval(fadeCycleAds,3000);
	fadeCycleAds();
	
	dp.SyntaxHighlighter.ClipboardSwf = '/site/scripts/clipboard.swf';
	dp.SyntaxHighlighter.HighlightAll('code');
	
})

var currentAdIndex=-1;
function fadeCycleAds(){
	var $adImages = $(".adImage");
	
	currentAdIndex++;
	if(currentAdIndex >= $adImages.length){
		currentAdIndex=0;
	}
	
	for(var i=0; i< $adImages.length; i++){
		if(i==currentAdIndex){
			$adImages.eq(i).css({right:"50px",display:"block"}).animate({opacity:1,right:"0px"},1000);
		}else{
			$adImages.eq(i).css({right:"0px"}).animate({opacity:0},1000,function(){
				$(this).css({display:"none"});
			});
		}
	}
}
