$(document).ready(function() {


/*
$("#search_form").submit(function(e){
	e.preventDefault();
	var $this = $(this);
	var d = $this.serialize();
	alert(d);
	
	$.post("includes/searchresults.inc",d,function(data,html)
{	
	$("text").html(data);
})
	});
*/

    
    
$(".consultationul").each(function(){
	var $this = $(this);
	var n = $($this).children("li").length;
			if(n < 1){
		$this.remove();
	}
	});
	
$(".text a").each(function(){
var $this = $(this);
var dest = $this.attr("href");
$.post("php/ajax_links.php",{destination:dest} ,function(data,html)
{	

if(data=='loggedin')
{
$this.addClass("loggedinlink").attr("title", "Please log in to visit this page");;
}

if(data=='notloggedin')
{
$this.addClass("notloggedinlink");
}

if((data!=='loggedin') && (data!=='notloggedin')) 
{
  $this.append(data);
}



});
});


$("#top_nav ul").accordian({
speed: 150, 
style: 'dropdown',
delay: 300
});

$(".expandinglist.notfixed").slidelist({
fixtop:"false"
});
$(".expandinglist.fixed").slidelist({
fixtop:"true"
});

//$(".expandinglist").slidelist();
/*
$(".expandinglist.map").slidelist({
	fixtop:"false",
	speed: 500,
	ease: "swing"
});
*/






$("#jargonbusterlisting dt").live('click', function(){
if($(this).next('dd').is(":visible")){
	$("#jargonbusterlisting dd").slideUp();
}else{
	$("#jargonbusterlisting dd").slideUp();
	$(this).next("dd").slideDown();
}
});



$(".expandingnewslist dt").live('click', function(){
if($(this).next('dd').is(":visible")){
	$(".expandingnewslist dd").slideUp();
	$(this).css({"background-image":"url('graphics/Tbullet.png')"});
}else{
	$(".expandingnewslist dd").slideUp();
	$(this).next("dd").slideDown();
	$(this).css({"background-image":"url('graphics/Tbullet_down.png')"});

}

});



$("#breadcrumb ul li:last").addClass("last");


/* On this Page */
$("#center .text :header").not("h1").not("h6").each(function(i){
		var link_text = $(this).text();
		$(this).wrap("<a name='anchor_"+ i +"'/>").parent().css({"text-decoration":"none"});
		$("#listanchors").append("<a href='#anchor_"+ i +"' >"+ link_text +"</a>");
});
var lngth = $("#center .text :header").length;
if( lngth > 1){
//alert("true");
}else{
$("#on_this_page").fadeTo(100, 0.3);

}
		
		$(".news_column .wide_story:first").addClass("first");
		$(".news_column .wide_story:last").addClass("last");
		



//Slider

		$(".slider .holder").animate({"opacity":"0.1"});
		
		function slider(){
			var block = $('.holder'),
		    i = 0;
		    
		    (function() {
		    	if(i <= 3){
		    	
		    	$("#indicator img").attr("src","graphics/ring.png");
		
				$("#ind_"+i).attr("src","graphics/dot.png");
					  $(block[i++]).animate({
					  opacity: 1,
					  left: 15
					  }, 1200, function () {
        if (!$.support.opacity) {
            this.style.removeAttribute('filter');
        }}).delay(6500).animate({
					  opacity: 0.1,
					  left: -465
					  },1000,arguments.callee);
				}
				else{
					$(block).css({"left":"470px"});
					slider();
				}
				})();
		}
		$(".slider .holder img").load(slider());
		
		$("div#form").hide();
		
		$("#login").click(function(){
			$(this).parents("#original").fadeOut(function(){
			$("#form").fadeIn();
		});
		return false;
		});
		
//------------------------------------------------		START LOGIN FORM --------------------------------------	
		
		$("#loginform").submit(function(){

			var getpagename = $("#pagecurrentlyon").val();


		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().fadeIn(1000);
		//check the username exists or not from ajax
		$.post("php/ajax_login.php",{sct_username:$('#sct_username').val(),sct_password:$('#sct_password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $("#loginform").fadeTo(100, 0.2);	

			  $(this).html('<img style="padding-top:5px;" src="indicator.gif" alt="progress indicator"/>').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location=getpagename;
			  });
			  
			});
		  }


//------------------------------------------------

		    if(data=='passwordwrong') {
			
			
			  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<p class="msgbox">Password does not match username, please re-enter. All passwords are case sensitive. Check your caps lock key...</p>').fadeTo(900,1);
			  $('#sct_password').css('background-color','#FFFFAB');
			   $('#sct_username').css('background-color','#ffffff');
			});	
			
			
			 } 
			 
//------------------------------------------------			 
			 
   if(data=='no') {
		  
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			
		  $(this).html('<p class="msgbox">Username not registered...</p>').fadeTo(900,1);
	
			});	
			$('#sct_username').css('background-color','#FFFFAB');
			 $('#sct_password').css('background-color','#ffffff');

			$("#sct_password").val(''); 
			} //end of if check
			
			
//------------------------------------------------			 
			 
   if(data=='suspended') {
		  
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			
		  $(this).html('<p class="msgbox">Account suspended...</p>').fadeTo(900,1);
	
			});	
			$('#sct_username').css('background-color','#FFFFAB');
			 $('#sct_password').css('background-color','#ffffff');

			$("#sct_password").val(''); 
			} //end of if check			
			
			
//------------------------------------------------			 
		});		 
	return false;
	});
		
		
		$("#top_nav ul li ul li:last").addClass("last");

		
		
		
		
				
//------------------------------------------------------ end login

$(".lButton").each(function(){
	$(this).click(function(){
		var my_value = $(this).val();
		$.post("php/ajax_jargonbuster.php",{jargon_selector:my_value},function(data)
        {
		  	$("#jargonbusterlisting").fadeTo(200,0.1,function()  
			{ 
			  $(this).html('<img style="padding-top:5px;" src="indicator.gif" alt="progress indicator"/>').fadeTo(900,1,
              function()
			  { 
				  $(this).html(data).fadeTo(900,1);
			  });
			  
			});
	});
	});
	});


//--------------------------------------------

$(".news_col.two:first").addClass("first");
$(".news_col.four:first").addClass("first");

$(".news_col.two:last").addClass("last");
$(".news_col.four:last").addClass("last");

var b4height = $(".block_of_four").height();
$(".block_of_four .four").height(b4height);


$("#newsletters > li:even").before("<div class='n_block'>");

$("#newsletters > li:odd").addClass("odd").after("</div>");



});//end doc ready 

