//var process=0;
$(document).ready(function() {
	if ( $("#leftColsNav").length > 0 )
			setAccordion('leftColsNav','subOpen');
			
	if ( $("#leftLinks").length > 0 )
			setAccordion('leftLinks','lLinkOpen');
			
	 $('#leftColsNav h3 b').hover(function(){$(this).prev().addClass('hover');}, function(){$(this).prev().removeClass('hover');});
	 $('button').hover(function(){$(this).css('background-position','left bottom');}, function(){$(this).css('background-position','left top');});
	 $('.searchSubmit').hover(function(){$(this).parent(".searchHere").css('background-position','left bottom');}, function(){$(this).parent(".searchHere").css('background-position','left top');});
	 
	 //$('#mainNav li').hover(function(){  if(process==0){ process=1; $(this).children('ul').slideDown('fast',function(){process=0}); $(this).addClass('hover'); } }, function(){ if(process==0){ $(this).children('ul').hide(); $(this).removeClass('hover'); }});
	 
	 $('#mainNav li').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
	 $('#leftLinks li h3 b').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
	 
	 //if sub links are unavailable, then hide [+/-];
	 var allLiTags = $('#leftColsNav').children('li');
	 for(i=0; i < allLiTags.length; i++){
		 if($(allLiTags[i]).find('ul').length == 0)
		 	$(allLiTags[i]).find('h3 b').hide();
	 }
	 
	 $('.editPop').click(
		function(){
			$(this).nextAll(".popUpByEdit").show("slow");
			if($(this.parentNode).hasClass("bFeature")){
				$("#botmFeature").css('z-index','5');
			}
		}
	);
	
	$('.submitPop').click(
		function(){
			$(this).offsetParent().hide("slow");
			var allPopInBFeature = $('.bFeature .popUpByEdit');
			var index=$('.bFeature .submitPop').index(this);
			var reSetZIndex=1;
			for(i=0; i < allPopInBFeature.length; i++){
				if(index!==i && !$(allPopInBFeature[i]).is(":hidden")){
					reSetZIndex=0;
				}
			}
			if($(this.parentNode.parentNode.parentNode.parentNode).hasClass("bFeature") && reSetZIndex==1 ){
				$("#botmFeature").css('z-index','1');
			}
		}
	);
	 
});

	var curLink=0;
	function setAccordion(id,cls){
		$('#'+ id +' h3 b').click(
			function() {
				var allNav=$('#'+ id).children('li');
				var index = $('#'+ id +' h3 b').index(this);
				
				//alert(curLink+'>>'+index);
				if ($(allNav[index]).find('ul').is(":hidden")){
					if( curLink!=-1){	
						$(allNav[curLink]).find('ul').slideUp("slow", function(){$(this.parentNode).removeClass(cls);});
					}
					$(allNav[index]).find('ul').slideDown("slow");
					$(allNav[index]).addClass(cls);
					curLink=index;
				}
				else{
					$(allNav[index]).find('ul').slideUp("slow", function(){$(this.parentNode).removeClass(cls);});
					curLink=-1;
				}
			}
		);
	}
		