
// Fellowship website script


	if (top.location != location) {
		top.location.href = document.location.href ;
	}



	// Font replacement
		Cufon.replace('h1', {
			fontFamily: 'Freehand591 BT',
			fontSize:'50pt',
			color: '-linear-gradient(#F05924,#F07924,#F05924,#F05924)',
			textShadow: '#ddd 1px 1px'
		});
		Cufon.replace('#headline_cell h1', {
			fontFamily: 'Freehand591 BT',
			fontSize:'28pt',
			textShadow: '#222 1px 1px'
		});					
		Cufon.replace('h2>span', {
			fontFamily: 'Freehand591 BT',
			fontSize:'18pt',
			textShadow: '#222 1px 1px'
		});
		Cufon.replace('#articles h2>span', {
			fontFamily: 'Freehand591 BT',
			fontSize:'24pt',
			textShadow: '#ddd 1px 1px',
			color: '#483956'
		});
		

		Cufon.replace('#footer blockquote', {
			fontFamily: 'Freehand591 BT',
			textShadow: '#222 1px 1px'
		});
		Cufon.replace('#footer_nav h3', {
			fontFamily: 'Freehand591 BT',
			fontSize:'18pt',
			textShadow: '#222 1px 1px'
		});
		Cufon.replace('#thought_for_day .title', {
			fontFamily: 'Freehand591 BT',
			fontSize:'14pt',
			textShadow: '#222 1px 1px'
		});
		Cufon.replace('div#share_article h4', {
			fontFamily: 'Freehand591 BT',
			fontSize:'28pt'
		});
		Cufon.replace('.article_list h2', {
			fontFamily: 'Freehand591 BT',
			fontSize:'28pt',
			color: '-linear-gradient(#F05924,#F07924,#F05924,#F05924)',
			textShadow: '#ddd 1px 1px'
		});
		Cufon.replace('h2.section', {
			fontFamily: 'Freehand591 BT',
			fontSize:'18pt',
			textShadow: '#222 1px 1px'
		});

		
	
	$(document).ready(function() {
		// Add MP3 play button
		$('a.mediaMP3').jmp3({
			forecolor:'483956',
			showdownload:'true',
			outputToID:'true'
		});
	});










	// Define the magic line function generically...
	(function($){
		jQuery.fn.magicLine= function(options) {

			return this.each(function()
			{
				var settings = jQuery.extend({},jQuery.fn.magicLine.defaults, options);
				var $el, leftPos, newWidth, containerWidth,
					navContainer,$mainNav;
				
				/* ---- Get the id of the object to add this slider to
				*/
				navContainer="#"+$(this).attr('id');
				$mainNav=$(navContainer);
				
				
				/* ---- Initialisation
				*/
				$mainNav.append("<li class='magic-line'></li>");
				var $magicLine = $(navContainer+" .magic-line");
				
				
				/* ---- Store current selected item position
				*/
				mywidth=$(navContainer+" .thisPage").width();
				mywidthVal=parseInt(mywidth);
				myheight=$(navContainer+" .thisPage").height();
				myheightVal=parseInt(myheight);
				
				
				// If no element has .thisPage class then don't add magic line...
				if ($(navContainer+" .thisPage a").html()!=null)
				{
					/* ---- Underline the current item
					*/
					$magicLine
						.css("width",mywidthVal)
						.css("left", $(navContainer+" .thisPage a").position().left)
						.css("top", $(navContainer+" .thisPage a").height());
					$magicLine
						.data("origLeft", $magicLine.position().left)
						.data("origWidth", $magicLine.width());
						
					containerWidth=$mainNav.width();
					
					
					/* ----- Add the event to move and reset the line on hover...
					*/
					$(navContainer+" li a").hover(function() {
							$el = $(this);
							leftPos = $el.position().left;
							newWidth = $el.parent().width();
							$magicLine.stop().animate({
									left: leftPos,
									width: newWidth
								});
							if (typeof settings['hoverOverCall']== 'function') { // make sure the callback is a function 
									settings['hoverOverCall'].call(this); // brings the scope to the callback
							}
						}, function() {
								if (settings['hoverReturn'])
								{
									$magicLine.stop().animate({
											left: $magicLine.data("origLeft"),
											width: $magicLine.data("origWidth")
										});
								}
								if (typeof settings['hoverOutCall']== 'function') { // make sure the callback is a function 
										settings['hoverOutCall'].call(this); // brings the scope to the callback 
								}
						});
				}
				
			})
		}

		/*	--------- Defaults for Magic Line
		*/
		jQuery.fn.magicLine.defaults = {
					 hoverReturn: true,
					 hoverOverCall:function(){},
					 hoverOutCall: function(){}
			};
	})(jQuery);



	// Populate the article headline box with article summary...
	function update_article_headline(aid)
	{
		// Only do call if article currently show is different to one requested...
		currentAID=$('#headline_cell div').attr('id');
		if (aid!=currentAID)
		{
			$('#headline_cell div').attr('id',aid);
	
			// Ajax call...
			var myajax=$.ajax({
				type: "GET",
				url: "ajax/article_headlines.php",
				cache: false,
				data:{aid:aid},
				success: function(data,status,xhr){
					if (data!="" && xhr.status)
					{
						$('#headline_cell .content').hide().html(data).show();
						Cufon.replace('#headline_cell h1');
/*			
						$('#headline_cell .content').hide('slide',{direction:'left'},200);
						$('#headline_cell .content').html(data).show('slide',{direction:'right'},200);
							Cufon.replace('#headline_cell h1');
						
*/
					}
				
				
				},
				error: err,
				timeout:2000
			});
		}
	}


		// ajax error
		function err(xhr,reason,ex)
		{
//			alert("Sorry, there's been a problem with the AJAX request giving the following error: "+reason);
		}




	$(document).ready(function() {
		
		
		// Add magic line to menus 
		$('#subNav').magicLine();
		$('#headlineChooser').magicLine({
				hoverReturn:false,
				hoverOverCall:function(){
					// Call ajax handler to load info
					update_article_headline($(this).attr('id'));
				}
			});
		
		
		// Process bible refs...
		$('.bibleRef').each(function(){
			
			$(this).addClass('bibleRefExtra');
			$(this).click(function(){
				
				lookupRef=$(this).attr("title");
				// Ajax call...
				var myajax=$.ajax({
					type: "GET",
					url: "ajax/bible.php",
					cache: false,
					data:{lookup:lookupRef},
					success: function(data,status,xhr){
						if (data!="" && xhr.status)
						{
							// Successful return...
							
							// First load the image....
							var img = new Image();
							$(img)
								// once the image has loaded, execute this code
								.load(function () {
									
									// Background image has loaded so okay to display the window....
									var y = $(window).scrollTop()+100;
									
									// Create the div's to greyout main screen and create window...
									$("<div>").attr("id", "greyout").appendTo("body").css({opacity:0}).height($("body").height()).fadeTo(200,0.7,function(){
										$("<div>").attr("id", "fulldivOutter").appendTo("body");
										$("<div>").attr("id", "fulldiv").appendTo("#fulldivOutter").css({'top':y});
										$("<div>").attr("id", "fullRef").html(data).appendTo("#fulldiv");
										
										// Event to close down the windows...
										$("#fulldiv").bind("click",function(){
											$("#fulldiv").fadeTo(100,0,function(){
												$("#fulldiv").empty();
												$("#fulldiv").remove();
												$("#greyout").fadeTo(400,0,function(){
													$(this).remove();
													});
												});
										});
										
										$("<div>").attr("id", "closediv").appendTo("#fulldiv");
										$("<div>Click to close</div>").appendTo("#closediv");
										
									});
									
								})
								// this is the image we're looking to load...
								.attr('src', 'images/bible_lookup.png');
								
						}
					
					},
					error: err,
					timeout:2000
				});
				
				return false; // propagates up to <a> to cancel default behavior of click
			});
		
		});


		



		// Add Event listing links...
		$(".event_list .event_entry").hover(function(){
				// Mouse over
				$(this).addClass("hover");
				
			},function(){
				// Mouse out
				$(this).removeClass("hover");
			
			}
		);
		
		// Redirect is event_entry is clicked...
		$(".event_list .event_entry").click(function(){
			url=$(this+"p.title a").attr('href');
			window.location.replace(url);
		});
		
		
		
		// Thought for the day drop down...
			// Ajax call...
			$.ajax({
				type: "GET",
				url: "ajax/thought.php",
				cache: false,
				data:"",
				success: function(data,status,xhr){
					if (data!="" && xhr.status)
					{
						// Activate button background...
						$("#thought_for_day div.content a").addClass("activate");
						// Intercept and prevent click
						$("#thought_for_day div.content a").click(function(){return false});
						// Show/hide on hover...
						$("#thought_for_day div.content a").hover(function(){
								position=$(this).offset();
								// Create drop down box...
								$('#thought').stop().remove();
								$("<div>").stop().attr("id", "thought").appendTo("#pageContent")
									.css({opacity:1,top:position.top+$(this).height(),left:position.left-130,'z-index':100})
									.html(data).hide().slideDown(500,function(){
										this.style.removeAttribute('filter'); 
								
									});
						},function(){
							$("#thought").stop().slideUp(500,function(){$(this).remove()});
						});
					}
				},
				error: err,
				timeout:2000
			});
		
	});

	$(window).load(function() {
		
		$('.TransBlindX').cycle({fx:'blindX'});
		$('.TransBlindY').cycle({fx:'blindY'});
		$('.TransBlindZ').cycle({fx:'blindZ'});
		$('.TransCover').cycle({fx:'cover'});
		$('.TransCurtainX').cycle({fx:'curtainX'});
		$('.TransCurtainY').cycle({fx:'curtainY'});
		$('.TransFadeZoom').cycle({fx:'fadeZoom'});
		$('.TransGrowX').cycle({fx:'growX'});
		$('.TransGrowY').cycle({fx:'growY'});
		$('.TransScrollUp').cycle({fx:'scrollUp'});
		$('.TransScrollDown').cycle({fx:'scrollDown'});
		$('.TransScrollLeft').cycle({fx:'scrollLeft'});
		$('.TransScrollRight').cycle({fx:'scrollRight'});
		$('.TransScrollHoriz').cycle({fx:'scrollHorz'});
		$('.TransScrollVert').cycle({fx:'scrollVert'});
		$('.TransShuffle').cycle({fx:'shuffle'});
		$('.TransSlideX').cycle({fx:'slideX'});
		$('.TransSlideY').cycle({fx:'slideY'});
		$('.TransToss').cycle({fx:'toss'});
		$('.TransTurnUp').cycle({fx:'turnUp'});
		$('.TransTurnDown').cycle({fx:'turnDown'});
		$('.TransTurnLeft').cycle({fx:'turnLeft'});
		$('.TransTurnRight').cycle({fx:'turnRight'});
		$('.TransUncover').cycle({fx:'uncover'});
		$('.TransWipe').cycle({fx:'wipe'});
		$('.TransZoom').cycle({fx:'zoom'});
		$('.TransFadeSlow').cycle({fx:'fade',speed:2000,timeout:5000,cleartype:true});
		$('.TransFadeFast').cycle({fx:'fade',speed:1000,timeout:3000});
		$('.TransFadeFast').cycle({fx:'fade',speed:1000,timeout:3000});		
		
		
	});
