
$(document).ready(function()
{
  //refresh image on admin pages, don't use cahced version
  var current_date = new Date();
  $("#content fieldset ol li img").each(function() 
  {
    $(this).attr("src", $(this).attr("src")+ "?" + current_date.getTime());
  });
	
	$('#member_admin.resources ul li ul').hide();
	
	
	$('#member_admin.resources ul li a.folder').click(function(event)
	{
		event.preventDefault();
		$(this).parent().find('ul').toggle();
	});
	
});

$(document).ready(function()
{
	$('a.new_window').click(function()
  {
		window.open(this.href);
		return false;
	});
	
	$('a.url').click(function()
  {
		window.open(this.href);
		return false;
	});
});

$(document).ready(function()
{
  $("#content ul.message_list li").click(function()
  {
    window.location=$(this).find("p.subject a").attr("href"); 
    return false;
  });
	
	 $("#content ul.message_list li a").click(function()
	 {
		 window.location=$(this).attr('href');
		 return false;
	 });
});



$(document).ready(function()
{
  $("#right_column #latest_news ul li").click(function(event)
  {
		if(event.stopPropagation)
			event.stopPropagation();  //For 'Good' browsers
		else 
			event.cancelBubble = true;  //For IE
  });
});

$(document).ready(function()
{
  $("#right_column #adverts ul li").click(function()
  {
    window.open($(this).find("a").attr("href")); 
    return false;
  });
});

$(document).ready(function()
{
  $("#right_column #member_profiles ul li").click(function()
  {
    window.location=$(this).find("span.member_link a").attr("href"); 
    return false;
  });
});

$(document).ready(function () 
{
  $('form').submit(function ()
	{
	  $('input[type=submit]',this).attr("value",'Please wait...');
	  $('input[type=submit]',this).attr("disabled", true);
	});

	$('input[type=radio]').dblclick(function ()
	{
		$(this).attr("checked",'')
	});
});


$(document).ready(function()
{
  $('#filter.hidden').hide();
	$('#filter.hidden').before('<p id="show_hidden_filter" ><a class="icon filter" href="#">Show Filter</a></p>');
  $('#show_hidden_filter').click(function() 
	{
		$(this).hide('fast');
	  $('#filter.hidden').show('slow')
	});
});

$(document).ready(function()
{
  $(".date_picker").datepicker({ dateFormat: 'dd-M-yy' })
});

$(document).ready(function() {
	if($('#events ul').length > 0)
	{
    var options = {
    newsList: "#events ul",
    startDelay: 10,
    placeHolder1: " _"
    }
    $().newsTicker(options);
	}
});

$(document).ready(function() {
  $(".table_container tr").hover(
	  function () {
		  $(this).addClass("highlight_row");
		},
		function () {
		  $(this).removeClass("highlight_row");
		});
});

$(document).ready(function() {
  $("#content form fieldset input").focus(
	  function () {
		  $(this).addClass("highlight");
	});
});

$(document).ready(function() {
  $("#content form fieldset input").blur(
	function () {
	  $(this).removeClass("highlight");
	});
});

$(document).ready(function() {
  $("#content form fieldset textarea").focus(
	  function () {
		  $(this).addClass("highlight");
	});
});

$(document).ready(function() {
  $("#content form fieldset textarea").blur(
	function () {
	  $(this).removeClass("highlight");
	});
});



$(document).ready( function(){ 
  $('#adverts div.content ul').innerfade({ 
  speed: 750, 
  timeout: 6000, 
  type: 'sequence', 
  containerheight: '120px' }); 
});



$(document).ready( function(){ 
  $('#partner_profiles ul').innerfade({ 
  speed: 750, 
  timeout: 8000, 
  type: 'sequence', 
  containerheight: '150px' }); 
});


$(document).ready( function(){ 
  $('#member_profiles ul').innerfade({ 
  speed: 1000, 
  timeout: 6000, 
  type: 'sequence', 
  containerheight: '220px' }); 
});

/*$(function()
{
  $('#menu ul li.join_us ul.hide').hide(); 
  $('#menu ul li.join_us').mouseover(function()
	{
	  $heading = $(this);
		$heading.find('ul.hide').slideDown(1000);
  });
});*/



$(function() {
  $("#latest_news div.content div.carousel").jCarouselLite({
     vertical: true,
     hoverPause:true,
     visible: 3,
     auto:7000,
     speed:1000
  });
});

$(document).ready(function() 

{
  $("#latest_news ul li").hover(
	  function () {	$(this).addClass("hover");},
		function () {	$(this).removeClass("hover");}
	);
});

$(document).ready(function() 
{
  $("input[type='submit']").hover(
	  function () {	$(this).addClass("submit_hover");},
		function () {	$(this).removeClass("submit_hover");}
	);
});


$(document).ready(function() {
  $('a.icon img.delete').click(function() 
	{
		return confirm('You are about to delete this record.');
	});
});

$(document).ready(function() {
  $('a.delete').click(function() 
	{
		return confirm('You are about to delete this record.');
	});
});


$(document).ready(function() {
    $('.wymeditor').wymeditor({
        stylesheet: 'styles.css',
				boxHtml:   "<div class='wym_box'>"
									+ "<div class='wym_area_top'>" 
									+ WYMeditor.TOOLS
									+ "</div>"
									+ "<div class='wym_area_left'></div>"
									+ "<div class='wym_area_right'>"
									+ "</div>"
									+ "<div class='wym_area_main'>"
									+ WYMeditor.HTML
									+ WYMeditor.IFRAME
									+ WYMeditor.STATUS
									+ "</div>"
									+ "<div class='wym_area_bottom'>"
									+ "</div>"
									+ "</div>",
        toolsItems: [
        {'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
        {'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
        {'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
        {'name': 'InsertUnorderedList', 'title': 'Unordered_List','css': 'wym_tools_unordered_list'},
        {'name': 'Paste', 'title': 'Paste_From_Word',    'css': 'wym_tools_paste'}],
     		postInit: function(wym) {
            //construct the button's html
            var html = "<li class='wym_tools_h2'>"
                     + "<a title=\"Sub Heading2\" name='NewButton' href='#'>H2</a></li>"
										 + "<li class='wym_tools_h3'>"
                     + "<a title=\"Sub Heading3\" name='NewButton' href='#'>H3</a></li>"
										 + "<li class='wym_tools_p'>"
                     + "<a title=\"Normal Paragraph\" name='NewButton' href='#'>P</a></li>";										 
            //add the button to the tools box
            $(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).prepend(html);
            //handle click event
            $(wym._box).find('li.wym_tools_h2 a').click(function() {
 								wym.container('H2');
                return(false);
            });
						$(wym._box).find('li.wym_tools_h3 a').click(function() {
 								wym.container('H3');
                return(false);
            });
						$(wym._box).find('li.wym_tools_p a').click(function() {
 								wym.container('P');
                return(false);
            });						
        }
    });
});

$(document).ready(function() 
{  
  if($("div.memberbar").length > 0)
  {
    $("div.memberbar").hide(); 
    $("div.memberbar").slideDown(2400); 
  }
  if($("div#member_menu ul li#logout span").length > 0)
  { 
    setTimeout(function(){$("div#member_menu ul li#logout span").fadeOut(800);},4000); 
  }
});

//add show hide page description link
$(document).ready(function()
{
  var html = "<p><a class=\"icon help\" href=\"#page_help\" id=\"show_page_help\">What is this page for?</a></p>";
	$('#page_help').before(html);

  $('#show_page_help').click(function()
	{
		$('#show_page_help').hide();
		$('#page_help').show();
	});
});



$(document).ready(function(){
   // set the max chars
   $("textarea[maxlength]").each(function(){
     var max  = this.getAttribute('maxlength');
     var curLength = this.value.length; 
     var html_counter = "<div class=\"characters_remaining\" id=\"characters_remaining_" + this.name + "\">" + (max - curLength) + " characters remaining</div>";
      $(this).after(html_counter);
    });

     // check the max chars
     $("textarea").keyup(function(){
       var maxLength     = this.getAttribute('maxlength');
       var currentLength = this.value.length;
       if(currentLength >= maxLength) {
         $("#characters_remaining_"+this.name).className = 'toomuch';
         this.value = this.value.substring(0, maxLength);
       } else {
         $("#characters_remaining_"+this.name).className = '';
       }
       $("#characters_remaining_"+this.name).html((maxLength - this.value.length) + " characters remaining");
     });

});

$(document).ready(function(){
  $("a.advert").click(function(){
    var advertLink = ($(this).attr("href").slice(0,-1))+'c/';
    this.href = advertLink; 
  });
}); 


$(document).ready(function(){
$('#club_tabs h2.hide').hide();
$('#club_tabs > div').hide();
$('#club_tabs div:first').show();
$('#club_tabs ul.menu li:first').addClass('active');
$('#club_tabs ul.menu  li a').click(function(){ 
$('#club_tabs ul.menu  li').removeClass('active');
$(this).parent().addClass('active'); 
var currentTab = $(this).attr('href'); 
$('#club_tabs > div').hide();
$(currentTab).show();
return false;
});
});
