//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).addClass('hover'); $(this).prev().addClass('hover');}, function(){$(this).removeClass('hover'); $(this).prev().removeClass('hover');});
	 $('#leftLinks li h3 b').hover(function(){ $(this).addClass('hover'); }, function(){ $(this).removeClass('hover'); });
	 
	 $('button, .loginButn input').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'); });
	 
	 
	 
	 //form tab display
	 $(".comnTab em").click( function(){
		$('.comnTab .comnTab').hide();
		$('.comnTab .tabMain').hide();
		$('.comnTab .butn_div').hide();
		$('.comnTab em').removeClass('tabOpen');
		
		$(this).addClass('tabOpen');
		$(this).next('.tabMain').show();
		$(this.parentNode).find('.butn_div').show()
	 } );
	 
	 $('.butnNextImgry').click( function(){
		var res = formValidation();
		if( res ){
			$('.comnTab .comnTab').hide();
			$('.comnTab .tabMain').hide();
			$('.comnTab .butn_div').hide();
			$('.comnTab em').removeClass('tabOpen');
			
			$('#cc_tab2 em').addClass('tabOpen');
			$('#cc_tab2 .tabMain').show();
			$('#cc_tab2 .butn_div').show();
		}
	 } );
	 
	 $('.butnNextDisplay').click( function(){
	 	var res = formValidation();
		if( res ){
			$('.comnTab .comnTab').hide();
			$('.comnTab .tabMain').hide();
			$('.comnTab .butn_div').hide();
			$('.comnTab em').removeClass('tabOpen');
			
			$('#cc_tab3 em').addClass('tabOpen');
			$('#cc_tab3 .tabMain').show();
			$('#cc_tab3 .butn_div').show();
		}
	 } );
	 $('.butnNextMeta').click( function(){
	 	var res = formValidation();
		if( res ){
			$('.comnTab .comnTab').hide();
			$('.comnTab .tabMain').hide();
			$('.comnTab .butn_div').hide();
			$('.comnTab em').removeClass('tabOpen');
			
			$('#cc_tab4 em').addClass('tabOpen');
			$('#cc_tab4 .tabMain').show();
			$('#cc_tab4 .butn_div').show();
		}
	 } );
	 
	 
	 $('#qckLInk1 input:even').click(function(){ $("#quickLinkBox").slideDown(); });
	 $('#qckLInk1 input:odd').click(function() { $("#quickLinkBox").slideUp();   });
	 
	 $('#qckLInk2 input:even').click(function(){ $("#homePageBox").slideDown(); });
	 $('#qckLInk2 input:odd').click(function() { $("#homePageBox").slideUp();   });
	 
	 //limit text input for the textarea of class 'limitTextArea'
	 
	 $('.charCount1').keyup( function(e){
	 	//alert( $(this).val().length );
		if( $(this).val().length>50 ){
			var tmp = $('#hpc1').val();
			tmp = tmp.substr(0,50);
			$('.charCount1').val(tmp);
		}
		$('#hpcc1').html( $(this).val().length );
		return false;
	 } );
	 $('.charCount2').keyup( function(e){
	 	//alert( $(this).val().length );
		if( $(this).val().length>50 ){
			var tmp = $('#hpc2').val();
			tmp = tmp.substr(0,50);
			$('.charCount2').val(tmp);
		}
		$('#hpcc2').html( $(this).val().length );
		return false;
	 } );
	 
	//table hover effect  
	$('.tbl_04 tr, .tbl_05 tr, .tbl_02 tr').hover(function(){ $(this).addClass('clr_01'); }, function(){ $(this).removeClass('clr_01'); } );
	$('.tbl_03 tr').hover(function(){ $(this).addClass('clr_02'); }, function(){ $(this).removeClass('clr_02'); } );
	$('.tbl_01 tr').hover(function(){ $(this).addClass('clr_01'); $(this).removeClass('clr_02'); }, function(){ $(this).addClass('clr_02'); $(this).removeClass('clr_01'); } );

	 //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');
			}
		}
	);
	
	$('.closePop').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');
			}
		}
	);
	 
});

	function setAccordion(id,cls){
		$('#'+ id +' h3 b').click(
			function() {
				if ($(this).parent().next().is(":hidden")){
					$(this).parent().next().slideDown("slow");
					$(this).parent().parent().addClass(cls);
					$(this).parent().parent().siblings().find('ul').slideUp("slow", function(){$(this.parentNode).removeClass(cls);});
				}
				else{
					$(this).parent().parent().find('ul').slideUp("slow", function(){$(this.parentNode).removeClass(cls);});
				}
			}
		);
	}
