// Standard jQuery header
;(function($) {
		   var $json;
$(document).ready(function() {
	$('#logo').live('click',function(){
		window.location = "http://thecastlefuncenter.com/site/";
	});
	$(".draggable").live('click', function (){
		$(this).draggable();
	});
	
	var $bodyW = $(window).width();
	var $bodyH = $(window).height();
	var $pageW = $("body").width();
	var $pageH = $("body").height();
	
//	$(window).stop().resize(function(){
//		$bodyW = $(window).width();
//		var $left = getLeft();
//		$("#mainbodyimg").stop().animate({
//			'width':$bodyW*.9,
//		}, 1000);
//		$("#BgContainer").stop().css({
//			'width': $bodyW,
//			'margin':'0px auto',
//			'padding':0
//		},250);
//	});
	$(window).load(function(){
		var $left = getLeft();
		$left = Math.round($left/2);
		$bodyW = $(window).width();
		$("#BgContainer, body")
			.css({
				'width':$bodyW-10+'px',
				'overflow-x':'hidden'
			});
		$("<img />")
			.attr("id", "mainbodyimg")
			.attr("src", "themes/castle/images/background.jpg")
			.css({
				'position':'relative',
				'padding':'0px',
				'border':'none',
				'margin':'0',
				'width':'100px'
			})
			.appendTo("#ImgContainer");
		$("#mainbodyimg").fadeOut('fast', function(){
			$(this).css({
				'width':$bodyW*.9
			});
		});
		$("#mainbodyimg").fadeIn('slow');
	});
	function getLeft ()
	{
		var imgWidth = 	$("#mainbodyimg").width();
		var winWidth = $(window).width();
		if (imgWidth <= winWidth)
		{
			var newWidth = winWidth - imgWidth;
			newWidth = newWidth/2;
			newWidth = Math.round(newWidth);
		}
		return newWidth;
	}
	
	// Hides the SubMenu area above the ACTIVITIES if there is on menu items
	$(function(){
		var isSubMenu = $("#MenuChildrens").children().length;
		//alert (isSubMenu);
		if (isSubMenu == 0 || isSubMenu === undefined){
			$("#MenuChildrens").remove();
			$(".SubActive").remove();
		}
	});

	// Hides the pricing box on activities pages, it there are no prices listed
	$(function(){
		var isPricingEmpty = $(".pricingList p").children().length;
		//alert (isPricingEmpty);
		if (isPricingEmpty == 0 || isPricingEmpty === undefined){
			$(".pricingList").parent().remove();
		}
	});

	$.getJSON("http://www.google.com/calendar/feeds/o5tavesqgbl5ijaq1ne73v0d1s@group.calendar.google.com/public/full?alt=json&callback=?&orderby=starttime&max-results=7&singleevents=true&sortorder=ascending&futureevents=true", function(data){
		eventsList = data.feed.entry;
		var htmlIns = "<ul>";
		$.each(eventsList, function(i, evt){
			var eventTitle = evt.title.$t;
			var eventStart = evt.gd$when[0].startTime;
			eventStart = formatGCalTime(eventStart);
			htmlIns += "<li><h5>"+eventTitle+"</h5>";
			htmlIns += "<span>"+eventStart+"</span>";
			htmlIns += "</li>";
		});
		if (eventsList.length > 0){
			$("#outputDiv").empty();
			$("#outputDiv").html(htmlIns);
		}
		$("#outputDiv li").live("click", function(){
			window.location.href = "upcoming-events/";
		});
	});
	
$("#Navigation a.link span").hover(function(){
		$(this).fadeTo("fast", 0.5);
	}, function (){
		$(this).fadeTo("fast", 1.0);
	});

$("h2").wrap("<div class='heading_h'><div class='heading_text'></div></div>");
$(".heading_h").append("<div class='close_h'>&nbsp;</div>");

specAnns = $("#special_announcements div").length;

$("#special_announcements span").toggle(function(){
	var parnt = $(this).parent();
	var sbHours = $(parnt).find("div");
	$(sbHours).hide();
	var title = $(parnt).find("a").text();
	$(this).html("<strong style='color:rgb(0, 174, 239);'>"+title+" Announcement</strong> + ");
}, function(){
	var parnt = $(this).parent();
	var sbHours = $(parnt).find("div");
	$(this).text("hide - ");
	$(sbHours).stop().show();	
});

$("#Menu1 li a.sub").parent().addClass("ddown");

$("#Menu1 li.mlevel").hover(function(){
	$(this).closest("a").fadeTo("fast", 0.5);
	$(this).css("height","200px");
	var thisClass = $(this).attr("class");
	//alert (thisClass);
	var thisSubnav = $(this).find("ul");
	var isSubnav = thisSubnav.length;
	if (isSubnav >0){
		thisSubnav.css({
			'display':'block'			
		});
	}
},function(){
	$(this).closest("a").fadeTo("fast", 1.0);
	$(this).css("height","auto");
	var thisSubnav = $(this).find("ul.fly");
	setTimeout( function(){
		thisSubnav.css("display", "none");
	}, 200);
});

var slideShowPresent = $("#sldshow p img").length;
if(slideShowPresent > 0 && slideShowPresent !== undefined){

$("#sldshow p img").removeClass("leftAlone").css({
		'display':'block',
		'margin':'0 auto',
		'border':'2px solid #666666',
		'width':'560px'
		})
		.wrap("<div style='width:560px; height: 380px; overflow:hidden; margin: 0 auto' />");
	$("#sldshow p")
		.css({
			'text-align':'center',
			'font-size':'95%',
			'height':'410px',
			'width':'568px',
			'overflow':'hidden',
			'background':'#666666'
		});
	$("#sldshow").cycle({
		fx: 'fade',
		speed: 2000,
		pause: 1
	});
}

	$(function(){
		$("#JestersPageLink a img").hover(function(){
			$(this).attr("src", "themes/castle/images/jesters-highlight.png");
		}, function(){
			$(this).attr("src", "themes/castle/images/jesters.png");
		})
	});

	$(function(){
		$("#Content ul").css({
			'margin':'0 auto',
			'color':'rgb(15,10,10)',
			'width':'65%'
		});
		$("#Content ul.optionset").css({
			'margin':'0 auto',
			'color':'rgb(15,10,10)',
			'width':'95%'
		});
		$("#Content ul li div").css({
			'text-align':'left'
		});
	});



})

})(jQuery);