$(document).ready(function() {

//	Meetings page has a dropdown to filter by month.
var currentURL = String(location);
var targetURL = currentURL.split("?",1);
	
$("select[name='FilterDate']").change(function(){

	if($(this).val()==""){
	}
	else{
		var FilterDate = $(this).val();
		window.location = targetURL+"?FilterDate="+FilterDate;
	}
});

$("select[name='Date_Month']").change(function(){

	if($(this).val()==""){
	}
	else{
		var month = $(this).val();
		window.location = targetURL+"?month="+month;
	}
});

$("a#inline").fancybox({
	"titleShow":false,
	"width":250,
	"height":290,
	"overlayOpacity":0.6,
	"overlayColor":"#333",
	"speedIn":50
});

/*$("#forgotpwreturn").click(function(){
	history.go(-1);
	return false;
});*/

$("a#closewindowlink").click(function(){
	parent.$.fancybox.close();
});

if (top.location != location) {
	$("body#login #loginsearch").hide();
	$("body#login #topcontent").hide();
	$("body#login #breadcrumb").hide();
	$("body#login #sidebar").hide();
	$("body#login #footer").hide();
	$("body#login #content").css({
		width:230,
		marginLeft:0
	});
	$("body#login #innerwrapper").css({
		width:230
	});
}

$("#me62b2feu_input_username").focus();


if ($('.error_message.newsletter').length || $("body.loggedout#icmsa-publications").length || $("body.loggedin#latest-news").length) {
		$("#box_publications").hide();
		$("#box_newsletter").show();
		$("#box_meetings").show();
		$("#tab_publications").removeClass("selected");
		$("#tab_publications").addClass("idle");
		$("#tab_newsletter").removeClass("idle");
		$("#tab_newsletter").addClass("selected");
		$("#footer_publications").hide();
//		$("#sidebar_footers").hide();
		$("#footer_newsletter").show();
}
else{
		$("#box_publications").show();
		$("#box_newsletter").hide();
		$("#box_meetings").hide();
		$("#tab_publications").addClass("selected");
		$("#tab_publications").removeClass("idle");
		$("#tab_newsletter").addClass("idle");
		$("#tab_newsletter").removeClass("selected");
		$("#footer_publications").show();
		$("#sidebar_footers").show();
		$("#footer_newsletter").hide();
}

if ($(".error_message.contact").length && $(".error_message.newsletter").length) {

	$(".error_message.newsletter").html("<p>Register to receive email updates when new Market Information Documentation is added to the ICMSA website.</p>");

	$("#box_newsletter").hide();
	$("#box_meetings").hide();
	$("#box_publications").show();
	$("#tab_newsletter").removeClass("selected");
	$("#tab_newsletter").addClass("idle");
	$("#tab_publications").removeClass("idle");
	$("#tab_publications").addClass("selected");
	$("#footer_newsletter").hide();
	$("#sidebar_footers").show();
	$("#footer_publications").show();
}
else{}
	
	$("#tab_newsletter").click(function(){
		$("#box_publications").hide();
		$("#box_newsletter").show();
		$("#box_meetings").show();
		$("#tab_publications").removeClass("selected");
		$("#tab_publications").addClass("idle");
		$("#tab_newsletter").removeClass("idle");
		$("#tab_newsletter").addClass("selected");
		$("#footer_publications").hide();
		$("#sidebar_footers").show();
		$("#footer_newsletter").show();
		return false;
	});

	$("#tab_publications").click(function(){
		$("#box_newsletter").hide();
		$("#box_meetings").hide();
		$("#box_publications").show();
		$("#tab_newsletter").removeClass("selected");
		$("#tab_newsletter").addClass("idle");
		$("#tab_publications").removeClass("idle");
		$("#tab_publications").addClass("selected");
		$("#footer_newsletter").hide();
		$("#sidebar_footers").show();
		$("#footer_publications").show();
		return false;
	});
	
// Forums! Hide BBCode options that we don't want and make the help text function work:

/*$("a#bbc_code").hide();
$("a#bbc_image").hide();
$("a#bbc_center").hide();
$("#bbc_colour").hide();*/

$("#helpline").hide();
//$("#helpline").attr("disabled","disabled");
$("a#bbc_help").click(function(){
	$("#helpline").slideToggle();
	return false;
});
//$('.resizable').autoResize();


	
	// Blockquotes - add speech marks around top and bottom paragraphs in blockquotes.
	
	// 1. Write img tags with classes etc into variables
	
	var quoteLeft = "<img src=\"images/img_blockquote_left.png\" alt=\"\" class=\"quoteleft\">";
	var quoteRight = "<img src=\"images/img_blockquote_right.png\" alt=\"\" class=\"quoteright\">";
	
	// Add left speech mark to start of first paragraph
	
	$("blockquote p:first-child").prepend(quoteLeft);
	
	// Add right speech mark to end of final paragraph
	
	$("blockquote p:last-child").append(quoteRight);
	
});
