
//Gallery Variables
var header_height = "";
var content_height = "";
var gallery_height = "0px";

var header_inheight = "30px";
var content_inheight = "0px";
var gallery_inheight = "600px";

var selectnewstable=0;
var dirset="";

var scTo=null;

$(document).ready(function(){
	
	$('#baf #txtbox').val("email address");
	
	$('#baf').submit(function(){
		thisVal=$('#baf #txtbox').val();
		if(CheckEmail(thisVal))
		{
			
			locAtion=dir+"media/php/baf.php";
			$.post(locAtion,{emailadd:thisVal},function(data){
					
					dlCheight=$('.fadDlC .dlCon').height();
					$('.fadDlC').animate({height:dlCheight},{duration:300,queue:false});
					$('#baf #txtbox').val("email address");
			});
		}
		else
		{
			$('#bafreturn').AnimateMessage("Please enter a valid email address.");
			$('.fadDlC').animate({height:0},{duration:300,queue:false});
		}
		return false;
	});
	
	$(window).bind("load",function(){
		if (typeof( deactivate ) == 'undefined'){
			ReturnNews();
			ReturnEvents();
		}
		

	});

	$('.pop_content').animate({opacity:0.8},100);
	
	$('.wedpakclick').click(function(){		
		
		$('#content').append("<div class=\"pop_container\"><div class=\"pop_content\">"+
		"</div><a href=\"#\" class=\"closebutton\">Close</a></div>");
		
		$('.pop_container').css({left: ($(window).width()/2)-330,top:0});
		$('.pop_content').css({'background-color':'#E9E9E9'}).html($('#dispinfo').html());
		
		$('.pop_content').fadeIn(300,function(){
			if(jQuery.browser.msie){$(this).get(0).style.removeAttribute('filter');}
			$('.closebutton').show();
		});
		
		$('.closebutton').click(function(){
			$(this).hide();
				$('.pop_content').fadeOut(300,function(){
					$(this).empty();									   
				});
			return false;								 
		});
		
		return false;
	});
	

	
	
	/*$('#options a').click(function(){
		
		if($('.pop_container').length<1) {
			pcontent = "<div class=\"pop_container\"><div class=\"pop_content\"></div><a href=\"#\" class=\"closebutton\">Close</a></div>";
			$('#content').append(pcontent);
		}
		
		$('.pop_container').css({
			left: ($(window).width()/2)-330
		});
		
		
		selectedlink=$(this).attr('href')+" #ldcontent";
		
		$('.pop_content').load(selectedlink,function(){
			
			$(this).fadeIn(300,function(){
				if(jQuery.browser.msie){$(this).get(0).style.removeAttribute('filter');}
				$('.closebutton').show();
			});
			
			$('.closebutton').click(function(){
				$(this).hide();
				$('.pop_content').fadeOut(300,function(){
					$(this).empty();									   
				});
				return false;								 
			});
			
			$('h4').click(function(){
				thisselectindex=$('h4').index(this);
				$('.slideinfo').slideUp().eq(thisselectindex).slideToggle(300);				   
			});
		});
		
		return false;
	});*/
	
	
	
	
	
	/* loads form */
	
	$('.tnc a').click(function(){
		selectedlink=$(this).attr('href')+" #ldcontent";
		$('.pop_content').load(selectedlink,function(){
			$(this).fadeIn(300,function(){
				if(jQuery.browser.msie){$(this).get(0).style.removeAttribute('filter');}
				$('.closebutton').show();
			});
			$('.closebutton').click(function(){
				$(this).hide();
				$('.pop_content').fadeOut(300,function(){
					$(this).empty();									   
				});
				return false;								 
			});
			
			$('h4').click(function(){
				thisselectindex=$('h4').index(this);
				$('.slideinfo').eq(thisselectindex).slideToggle(300);				   
			});
			
			
		});
		return false;
	});
	

	
	
	var content_height = $('#content').height();
	
	//$('#c_right').height(content_height);
						   
	//open/close gallery	


	
	
	$('a#gallerytoggle').toggle(function(){
		//IN
		header_height = $('#header').height() + "px";

		$('#header')
		.animate({ height: header_inheight });
		
		content_height = $('#content').height() + "px";
		
		$('#content')
		.animate({ height: content_inheight });
		
		$('#gallery')
		.animate({ height: gallery_inheight });
		
		
		var loadgallery = $('a#gallerytoggle').attr('href') + " #gal";
		
		
		$('#gallery').load(loadgallery, gallery_inheight, function(){
			//start gallery functions
			/*$('#g_img').cycle({
			speed: 500,
			timeout: 0				  
			});*/
			$('#g_img img').animate({
				opacity: 0
			},{queue:false})
			.eq(0)
			.animate({
				opacity: 1
			},{queue:false});
			
			
			$('#g_img img').each(function(i){
				var source = $(this).attr('src');
				$('#g_thumbs').append("<div><img src=\"" + source + "\" alt=\"\" /></div>")
			});
			
			var g_thumbs_width = $('#g_thumbs div').size() * $('#g_thumbs div').outerWidth();
			
			
			
			$('#g_thumbs div').mouseover(function(){
				var i	= $('#g_thumbs div').index(this);
				
				$('#g_img img')
				.animate({
					opacity: 0
				},{queue:false})
				.eq(i)
				.animate({
					opacity: 1
				},{queue:false});
			});
			
				//window that "crops" slider
				slideview = $("#g_thumbs_con");
				
				//div that holds slides on absolute pos
				slidecontain = $("#g_thumbs");
				slidecontain_imgs = $("#g_thumbs div");
				
				//ids of left / right buttons
				bleft = $("#leftarrow");
				bright = $("#rightarrow");
				
				//div containing cycling large images
			
				
				//speed of the slides moving
				duration = 500;
				
				
				// DONT GO BEYOND THIS POINT!
				// nasty monsters lurk, be warned!!!
				
				
				// calculate width for image slider 
				numImages = slidecontain_imgs.size();
				imgWidth = slidecontain_imgs.width();
				fullWidth = numImages * imgWidth;
				
				// set width for image slider
				slidecontain.width(fullWidth);
				
				
				//calculate the endpoint (left position) (relative to the width of the view area)
				viewWidth = slideview.width();
				finalval = fullWidth - viewWidth;
				finalWidth = finalval * 2;
				finalLeft = finalval - finalWidth;
				
				//onclick functions for left and right
				
				
				bleft.click(function(){	
					curL = slidecontain.css('left');
					curL = parseFloat(curL);
					curL = curL + 100;
					if (curL > 0) {
						curLcomp = curL - 100;
						if (curLcomp == 0) {		
							slidecontain.animate({left: finalLeft},duration);
						} else {
							slidecontain.animate({left: 0},duration);
						}
						
					} else {
						slidecontain.animate({left: curL},duration);
					}
				return false;
				});
				
					
				bright.click(function(){	
					curR = slidecontain.css('left');
					curR = parseFloat(curR);
					curR = curR - 100;
					if (curR < finalLeft) {
						curRcomp = curR + 100;
						if (curRcomp == finalLeft) {		
							slidecontain.animate({left: 0},duration);
						} else {
							slidecontain.animate({left: finalLeft},duration);
						}
						
					} else {
						slidecontain.animate({left: curR},duration);
					}
					
				return false;
				}
				);
			
			
			
			
			// end gallery functions
			
		});
		
	},function(){
		
		//OUT
		$('#header')
		.animate({ height: header_height },function(){
				$(this).css({ overflow: "hidden" });
		});
		
		$('#content')
		.animate({ height: content_height },function(){
				$(this).css({ overflow: "hidden" });
		});
		
		$('#gallery')
		.animate({ height: gallery_height });
		
	});	
	
	
	
	imgSze=$('#header_images img').size();
	if(imgSze>1){
		$('#header_images').imgCrossFade({aniDuration:800,aniInterval:4000});	
	}
	else if(imgSze==1){
		$('#header_images img').animate({opacity:0},{duration:0}).css({display:'block'}).animate({opacity:1},{duration:300});
	}
	
	
	
	
	$('a#map').toggle(function(){
		//IN
		header_height = $('#header').height() + "px";
		$('#header').animate({ height: header_inheight });		
		content_height = $('#content').height() + "px";		
		$('#content')
		.animate({ height: content_inheight });		
		$('#gallery')
		.animate({ height: gallery_inheight });		
		
		var loadmap = $('a#map').attr('href') + " #mapo";
		
		
		$('#gallery').load(loadmap, gallery_inheight);
		
	},function(){
		
		//OUT
		$('#header')
		.animate({ height: header_height },function(){
				$(this).css({ overflow: "hidden" });
		});
		
		$('#content')
		.animate({ height: content_height },function(){
				$(this).css({ overflow: "hidden" });
		});
		
		$('#gallery')
		.animate({ height: gallery_height });
		
		
	});	
	
	
	
});


$(function(){
	$.fn.AnimateMessage = function(returnmessage){
		$(this).text(returnmessage).fadeIn(300,function(){
			$(this).animate({opacity:1},3000,function(){$(this).fadeOut(300,function(){
				$(this).css({display:'block'}).html("&nbsp;");																		
			});});
		});
	};		   
});

function ReturnNews()
{
	phpfilelocation=dirset+"media/php/returnnews.php";
	$.post(phpfilelocation,{newstable: selectnewstable, dirset: dirset},function(data){
		$('#news').html(data);					  
	});
}
function ReturnEvents()
{
	phpfilelocation=dirset+"media/php/returnevents.php";
	$.post(phpfilelocation,{newstable: selectnewstable, dirset: dirset},function(data){
		$('#events').html(data);					  
	});
}

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

	if (AtPos == -1 || StopPos == -1)
	{
		return false;
	}
	else
	{
		return true;	
	}

}
