
function addHover()
{
	//var nav = document.getElementById('dropdown');
	//nav.className='hover';
}

function undoHover()
{
	//var nav = document.getElementById('dropdown');
	//nav.className='';
}

//json plugin 2.2.min.js
;(function(jQuery){jQuery.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return jQuery.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return jQuery.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push(jQuery.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=jQuery.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=jQuery.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};jQuery.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};jQuery.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*jQuery/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};jQuery.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);

jQuery.fn.serializeObject=function(){var o={};var a=this.serializeArray();jQuery.each(a,function(){if(o[this.name]){if(!o[this.name].push){o[this.name]=[o[this.name]];}o[this.name].push(this.value||'');}else{o[this.name]=this.value||'';}});return o;};


jQuery.fn.dynaHeight = function(elements) {
	  jQuery(this).each(function() {
	var top = jQuery(this).offset().top;
	var maxBottom = 0;
	jQuery(elements).each(function() {
	  var pos = jQuery(this).offset();
	  var height = jQuery(this).outerHeight();
	  var bottom = pos.top + height;
	  if (bottom > maxBottom) {
	    maxBottom = bottom;
	  }
	});
    jQuery(this).css({"height": (maxBottom - top) + "px"});
  });
  return this;
};





function clearAllText()
{
	var message = document.getElementById('message');
	if (message.value == 'Enter your message here')
	{
		message.value='';
	}
}

$.noConflict();
jQuery(document).ready( function(){



		var me = '';
		jQuery("#calendar").load("/calendar?month=&year=&event=&rnd=" + String((new Date()).getTime()).replace(/\D/gi, ''), function(){
				jQuery("#calendar").removeClass("loading");
		});

		jQuery(".event a").live("hover", function(event) {

			event.preventDefault();

			var currentId = jQuery(this).attr("id");
			var day = jQuery(this).attr("day");
			var month = jQuery(this).attr("month");
			var year = jQuery(this).attr("year");
			me = jQuery(this);




			if(!me.hasClass('decorated')) {
	            me.tooltip({

					tip: '.tooltip',
	                effect: 'slide',
	                lazy: false,
	                fadeOutSpeed: 0,
	                predelay: 400,
	                delay: 100,
	                offset: [20, -30],
	                onBeforeShow: function() {
	                     jQuery(".tooltip").load('/calendar/eventDayDetails/'+currentId+"?rnd=" + String((new Date()).getTime()).replace(/\D/gi, ''))
	                     jQuery(".tooltipTop").css('display','block');
	                     jQuery(".tooltipBottom").css('display','block');
	                },

	                position: "top right",
	                api: true
	            }).show();
	            me.addClass('decorated');
	        }
	    });

		 jQuery(".paging").live("click", function(event) {
			event.preventDefault();
			var currentId = jQuery(this).attr("id");
			var currentPage = jQuery(this).attr("currentPage");
			jQuery(".tooltip").load('/calendar/eventDayDetails/'+currentId+"?rnd=" + String((new Date()).getTime()).replace(/\D/gi, '')+'&currentpage='+currentPage)

			});




		if (jQuery('#js-news').length > 0)
		{
			jQuery('#js-news').ticker({
					titleText: '',
					speed: 0.1,
					fadeInSpeed: 500,
					fadeOutSpeed: 500,
					pauseOnItems: 5000
				});
		}




		jQuery('#eNewsSubscribe').click(function() {
			jQuery.ajax({
					type: "POST",
					url: "/home/subscribe/",
					data: "data="+jQuery.toJSON(jQuery('#formENews').serializeObject()),
					dataType: 'json',
					async: false,
					success: function(data) {
						if(data.subscriberForename == 'required')
						{
							jQuery('#subscriberForename').removeClass('inputGreyBorder');
             				jQuery('#subscriberForename').addClass('inputRedBorder');
						}
						else
						{
							jQuery('#subscriberForename').removeClass('inputRedBorder');
             						jQuery('#subscriberForename').addClass('inputGreyBorder');
						}

						if(data.subscriberSurname == 'required')
						{
							jQuery('#subscriberSurname').removeClass('inputGreyBorder');
             						jQuery('#subscriberSurname').addClass('inputRedBorder');
						}
						else
						{
							jQuery('#subscriberSurname').removeClass('inputRedBorder');
             						jQuery('#subscriberSurname').addClass('inputGreyBorder');
						}

						if(data.subscriberEmail == 'required' || data.subscriberEmail == 'email')
						{
							jQuery('#subscriberEmail').removeClass('inputGreyBorder');
             						jQuery('#subscriberEmail').addClass('inputRedBorder');
						}
						else
						{
							jQuery('#subscriberEmail').removeClass('inputRedBorder');
             				jQuery('#subscriberEmail').addClass('inputGreyBorder');
						}

						if (data.error != 0)
						{
							Recaptcha.reload();
						}
						else
						{
							jQuery('#innerENewsMiddle').hide()
							jQuery('#eNewsSubscribe').hide()
							jQuery('#eNewsToggle').height(40)
						}
						jQuery('#errorsENews').html(data.message);
					}
				});
		});

		jQuery('.calloutSubmit').click(function() {
			var compId = jQuery(this).attr('id').substring(12)
			var toggle = "#toggle"+jQuery(this).attr('id').substring(6);
			var formId = "#form"+jQuery(this).attr('id').substring(6);
			var error = "#error"+jQuery(this).attr('id').substring(6);
			var innerToggle = "#innerToggle"+jQuery(this).attr('id').substring(6);
			var submitButton = "#submit"+jQuery(this).attr('id').substring(6);


			jQuery.ajax({
					type: "POST",
					url: "/home/competitionentry/",
					data: "data="+jQuery.toJSON(jQuery(formId).serializeObject()),
					dataType: 'json',
					async: false,
					success: function(data) {

						if(data.competitionAnswer == 'required')
						{
             				jQuery('.competitionAnswers').addClass('inputRedBorder');
						}
						else
						{
							jQuery('.competitionAnswers').removeClass('inputRedBorder');
						}

						if(data.competitionForename == 'required')
						{
							jQuery('#competitionForename'+compId).removeClass('inputGreyBorder');
             				jQuery('#competitionForename'+compId).addClass('inputRedBorder');
						}
						else
						{
							jQuery('#competitionForename'+compId).removeClass('inputRedBorder');
             				jQuery('#competitionForename'+compId).addClass('inputGreyBorder');
						}

						if(data.competitionSurname == 'required')
						{
							jQuery('#competitionSurname'+compId).removeClass('inputGreyBorder');
             				jQuery('#competitionSurname'+compId).addClass('inputRedBorder');
						}
						else
						{
							jQuery('#competitionSurname'+compId).removeClass('inputRedBorder');
             				jQuery('#competitionSurname'+compId).addClass('inputGreyBorder');
						}

						if(data.competitionEmail == 'required' || data.competitionEmail == 'email')
						{
							jQuery('#competitionEmail'+compId).removeClass('inputGreyBorder');
             				jQuery('#competitionEmail'+compId).addClass('inputRedBorder');
						}
						else
						{
							jQuery('#competitionEmail'+compId).removeClass('inputRedBorder');
             				jQuery('#competitionEmail'+compId).addClass('inputGreyBorder');
						}

						if (data.error != 0)
						{
							Recaptcha.reload();
						}
						else
						{
							jQuery(innerToggle).hide();
							jQuery(submitButton).hide();
							jQuery(toggle).height(50);
						}
						jQuery(error).html(data.message);
					}
				});
		});

		/*jQuery('.slimBoxCalloutTriangle').toggle(function()
		{
		  jQuery(".cover", this.parentNode).stop().animate({top:'0px'},{queue:false,duration:460});
			jQuery(this).attr("src", "/images/slimBoxMinus.gif");
			jQuery('.slimBoxCalloutTitle').height(40);

		}, function() {
		  	jQuery(".cover", this.parentNode).stop().animate({top:'238px'},{queue:false,duration:460});
			jQuery(this).attr("src", "/images/slimBoxPlus.gif");
		});*/

		jQuery('.slimBoxCallout').hover(function()
		{
		  	var cover = jQuery(this).find('div.cover');
		  	jQuery(cover).stop().animate({top:'0px'},{queue:false,duration:460});
			var image = jQuery(this).find('img');
			jQuery(image).attr("src", "/images/slimBoxMinus.gif");
			jQuery('.slimBoxCalloutTitle').height(40);

		}, function() {
		  	jQuery(".cover", this.parentNode).stop().animate({top:'238px'},{queue:false,duration:460});
			var image = jQuery(this).find('img');
			jQuery(image).attr("src", "/images/slimBoxPlus.gif");
		});




		jQuery("#recaptcha_image").width(200);


		jQuery('.inputGreyBorder, .answerTextArea, .inputRedBorder').live("focus", function(event) {

			var form = jQuery(this).parents('form:first');
			var recap = jQuery(form).find('.recapContainer');


			if (jQuery(recap).is('.staticRecap'))
			{

				var recapId = '#'+jQuery(recap).attr('id');

				jQuery('.recapContainer').html('<div id="recaptchaWidget"><div id="recaptchaImage"><img src="/images/smallCaptcha.png" /></div><span class="recaptcha_only_if_image">Enter the words above:</label><input class="inputGreyBorder" id="recaptchaResponseField" name="recaptchaResponseField" type="text"><br/><div style="font-size: 10px;"><a style="float:left; width:100px;" href="javascript:void(0);" onclick="Recaptcha.reload();">Reload image</a> <a style="float:left;width:100px;" href="#" class="recapHelpAction">Help</a><div style="clear:both"></div></div></div>');
			 	jQuery('.recapContainer').removeClass('activeRecap');
				jQuery('.recapContainer').addClass('staticRecap');


			 	var  recapHtml = '<div id="recaptcha_widget"><div id="recaptcha_image"></div><div class="recaptcha_only_if_incorrect_sol" style="color: red;">Incorrect please try again</div><span class="recaptcha_only_if_image">Enter the words above:</label><input class="inputGreyBorder" id="recaptcha_response_field" name="recaptcha_response_field" type="text"><br/><div style="font-size: 10px;"><a style="float:left;width:100px;" href="javascript:void(0);" onclick="Recaptcha.reload();">Reload image</a> <a style="float:left;width:100px;" class="recapHelpAction" href="#">Help</a><div style="clear:both"></div></div></div>'

				jQuery(recapId).html(recapHtml);
				jQuery(recapId).addClass('activeRecap');
				jQuery(recapId).removeClass('staticRecap');
				Recaptcha.destroy();
				Recaptcha.create("6LfM37sSAAAAAL3viYA1SFny1Q87RKRw1mfrnBXS", "recaptcha_widget1", {
			        "theme": "custom",
			        "lang": "en"
			    });

			}


		});

		jQuery("#recapHelp").dialog({
		   	bgiframe: true,
			height: 430,
			width: 480,
			resizable: false,
			title: 'reCAPTCHA: Stop Spam, Read Books',
			autoOpen: false
		});
		jQuery('.recapHelpAction').live("click", function(event) {
	   		jQuery("#recapHelp").load('/home/recap').dialog('open');
		    return false;
       	});





	var i = 0;
	var divHeight = 0;
	jQuery('.showHideButton').toggle(function() {
		var toggle = "#toggle"+jQuery(this).attr('id');
		var button = "#showHideButton"+jQuery(this).attr('id');
		var recap = "#recap"+jQuery(this).attr('id');
		var color = jQuery(this).attr('color');
		jQuery(this).parent().parent().clone().removeAttr('id').attr('id','toggleClone').prependTo('#cloneContainer');
		jQuery('#toggleClone').find('.toggle').height('auto');
		divHeight = jQuery('#toggleClone').find('.toggle').outerHeight()-25

		if (i != 0)
		{
			divHeight = divHeight - 110;
		}
		i++;

		jQuery('#cloneContainer').html('');

	 	jQuery('.recapContainer').html('<div id="recaptchaWidget"><div id="recaptchaImage"><img src="/images/smallCaptcha.png" /></div><span class="recaptcha_only_if_image">Enter the words above:</label><input class="inputGreyBorder" id="recaptchaResponseField" name="recaptchaResponseField" type="text"> <div style="font-size: 10px;"><a style="float:left;width:100px;" href="#" onclick="Recaptcha.reload();">Reload image</a> <a style="float:left;width:100px;" href="#" class="recapHelpAction">Help</a><div style="clear:both"></div></div></div>');
	 	jQuery('.recapContainer').removeClass('activeRecap');
		jQuery('.recapContainer').addClass('staticRecap');



		var  recapHtml = '<div id="recaptcha_widget"><div id="recaptcha_image"></div><div class="recaptcha_only_if_incorrect_sol" style="color: red;">Incorrect please try again</div><span class="recaptcha_only_if_image">Enter the words above:</label><input class="inputGreyBorder" id="recaptcha_response_field" name="recaptcha_response_field" type="text"> <div style="font-size: 10px;"><a style="float:left;width:100px;" href="#" class="reloadRecaptcha">Reload image</a> <a style="float:left;width:100px;" href="#" class="recapHelpAction">Help</a><div style="clear:both"></div></div></div>'
		jQuery(recap).html(recapHtml);
		jQuery(recap).addClass('activeRecap');
		jQuery(recap).removeClass('staticRecap');
		myRecaptcha();

		jQuery(".reloadRecaptcha").live("click", function(event) {
			 event.preventDefault();
			 Recaptcha.reload();
			});


		//alert(divHeight);
		jQuery(toggle).animate(
			{ height: divHeight + 150 /* temp, just so it opens fully (JM)*/ },{
			  duration: 1700,
			  complete: function() {
			  		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
					{
					 	var ieversion=new Number(RegExp.$1);
						if (ieversion>=6)
						{
							myRecaptcha();
						}
					}
					jQuery(button).attr("src", "/images/buttons/hideButton"+color+".png");
				}
			});
		},
		function ()	{
			var toggle = "#toggle"+jQuery(this).attr('id');
			var button = "#showHideButton"+jQuery(this).attr('id');
			var color = jQuery(this).attr('color');
			jQuery(toggle).animate(
			{ height: 0 }, {
			  duration: 1700,
			  complete: function() {jQuery(button).attr("src", "/images/buttons/showButton"+color+".png");}
			});
		 }
	);

	/* faqs */
	initFaqs();


});


function myRecaptcha()
{
	Recaptcha.destroy();
	Recaptcha.create("6LfM37sSAAAAAL3viYA1SFny1Q87RKRw1mfrnBXS", "recaptcha_widget1", {
	       "theme": "custom",
	       "lang": "en"
	   });
}

function navigate(month,year,evt)
{
	var url = "/calendar?month="+month+"&year="+year+"&rnd=" + String((new Date()).getTime()).replace(/\D/gi, '');
	jQuery("#calendar").html("").addClass("loading");
	jQuery("#calendar").load(url, function(){
			cache: false,
			jQuery("#calendar").removeClass("loading");

		});
}


function initFaqs(){
	var faqs = jQuery('#faqs');
	if(faqs.length > 0){
		faqs.find('dl').hide();
		faqs.find('dt').click(function (){
			var ans = jQuery(this).siblings('.' + this.id);
			if(ans.is(':visible')){
				ans.slideUp('fast');
				jQuery(this).attr('title', 'Click to show the answer');
				if(jQuery(this).hasClass('faq-openx')){
					jQuery(this).removeClass('faq-openx');
				}
			} else {
				ans.slideDown('fast');
				jQuery(this).attr('title', 'Click to hide the answer').addClass('faq-openx');
			}
		}).attr('title', 'click to show the answer');
	}
}



jQuery(document).ready( function(){


		jQuery('.sub').hover( function(){
			jQuery(this).parent('li').children('a').css('background-color','#F5D2D7');
			jQuery(this).parent('li').css('border-color','#F5D2D7');
			jQuery(this).parent('li').next().css('border-color','#F5D2D7');
		}, function(){
			jQuery(this).parent('li').children('a').css('background-color','transparent');
			jQuery(this).parent('li').css('border-color','#58595B');
			jQuery(this).parent('li').next().css('border-color','#58595B');
		});

		jQuery('#nav li a').hover( function(){


			if (jQuery(this).parent('li').children('.sub').length!=0) {
				jQuery(this).css('background-color','#F5D2D7');
				jQuery(this).parent('li').css('border-color','#F5D2D7');
				jQuery(this).parent('li').next().css('border-color','#F5D2D7');
			}
		}, function(){
			if (jQuery(this).parent('li').children('.sub').length!=0) {
				jQuery(this).css('background-color','transparent');
				jQuery(this).parent('li').css('border-color','#58595B');
				jQuery(this).parent('li').next().css('border-color','#58595B');
			}
		});

		function megaHoverOver(){
			jQuery(this).find(".sub").stop().fadeTo('fast', 1).show();

			//Calculate width of all ul's
			(function(jQuery) {
					jQuery.fn.calcSubWidth = function() {
						rowWidth = 0;
						//Calculate row
						jQuery(this).find("ul").each(function() {
								rowWidth += jQuery(this).width();
							});
					};
				})(jQuery);


		//		var subWidth = jQuery(this).width();

		//		jQuery(this).calcSubWidth();
				//Set Width
			//	jQuery(this).find(".sub").css({'width' : subWidth});

		}

		function megaHoverOut(){
			jQuery(this).find(".sub").stop().fadeTo('fast', 0, function() {
					jQuery(this).hide();
				});
		}



		var config = {
			sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
			interval: 1, // number = milliseconds for onMouseOver polling interval
			over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
			timeout: 1, // number = milliseconds delay before onMouseOut
			out: megaHoverOut // function = onMouseOut callback (REQUIRED)
		};

		jQuery("#nav li .sub").css({'opacity':'0'});
		jQuery("#nav li").hoverIntent(config);
		});
