var eventsheight="";
var bafheight=0;

$(document).ready(function(){	
	
	bafheight=$('#baf').height();
	$('#baf').height(30);
	
	$('#bafex').click(function(){
		if($('#baf').height()==30)
		{
			$('#baf').animate({
				height: bafheight+"px",
				"opacity": 0.9
			},300,function(){
				if(jQuery.browser.msie)
				{
					$('#baf').get(0).style.removeAttribute('filter');
				}
				$('#bafex').text("Hide");
			});
		}
		else
		{
			$('#baf').animate({
				height: "30px",
				"opacity": 1
			},300, function(){
				if(jQuery.browser.msie)
				{
					$('#baf').get(0).style.removeAttribute('filter');
				}
				$('#bafex').text("Show");
			});
		}
	});
	
	$(window).bind("load", function(){
		$('#gal_nye').cycle({ 
			fx:    'fade', 
			speed:  800,
			timeour: 8000
		 });						
	});
	
	if(readCookie('addclicked'))
	{
		$('.fp').css("display","none");	
	}
	else
	{
		//$('.fp').css("display","block");

		
		//$('#main_offer').css("display","block").parent('.fp').css("display","block");
		
		$('.mask').animate({
			"opacity": 0.8				   
		},300);
		$('#signupbox').css("display","none");
	}
	
	$('#main_offer').click(function(){
		$('.fp').css("display","none");	
		createCookie('addclicked', 'yes',0);
	});

	$('#x_button').click(function(){
		$('.fp').css("display","none");
		$('#text').height(eventsheight+"px");
	});
	
	$('#popup_reg').submit(function(){
		emailvl=$('#emailaddress').val();
		interest=$('#pop_interest').val();
		
		$('#reg_return').text("Processing...");
		$.post("media/scripts/snd_pop.php",{email_address: emailvl, inte_rest: interest},function(data){
			$('#reg_return').text(data);					  
		});
		return false;
	})
	
	
	
	$('#emailsignup').submit(function(){
		$('#returnresult').text("Processing...");
		
		if(CheckForVals() && CheckEmail($('.txtfield').eq(1).val()))
		{
			parr=new Array($('.txtfield').eq(0).val(), $('.txtfield').eq(1).val());
			
			$('.chkbx').each(function(){
				parr.push($(this).attr("checked"));						  
			});
			
			$.post("media/scripts/nl_sub.php",{func: "add", f1: parr[0], f2: parr[1], f3: parr[2], f4: parr[3], f5: parr[4]},function(data){
				$('#returnresult').text(data);			  
			});
		}
		else
		{
			$('#returnresult').text("Please ensure all fields have been filled in currently");
		}
		return false;								  
	});
	
	
	
	
	$('#item17').click(function(){GetInfo(17);});
	$('#item18').click(function(){GetInfo(18);});
	$('#item19').click(function(){GetInfo(19);});
	

	$('.fomimg a').stop().lightBox();

	
	
	$('#baf_form').submit(function(){
		inpemail=$('.inp_emal').val();
		$('.info_txt').text("processing...");
		
		$.post("media/scripts/baf.php",{email_address: inpemail},function(data){
			$('.info_txt').text(data);				  
		});
		return false;
	});

});

$(function(){	
	$.fn.AnimateMessage = function(returnmessage){
		$(this).text(returnmessage).fadeIn(300,function(){
			$(this).animate({opacity:1},3000,function(){$(this).fadeOut(300);});
		});
	};
	$.fn.subNav=function(){
		thsName=$(this);
		$('.sN').css({display:'none'});
		thsName.css({display:'block'});
	};
});


function ShowEventsNav()
{
	$('#events_nav').css("display","block");
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

	function RunCycleOver(sectionid, cycleid)
	{
		$(sectionid).cycle(cycleid);
	}
	
	function GetInfo(itemid)
	{
		eventsheight=$('#text').height();
		$('#text').height("600px");
		
		$(function(){
			$.post("media/scripts/snd_pop.php",{itemident: itemid},function(data){
				$('#pop_heading').text(data);
				$('#pop_interest').val(data);
			});
			$.post("media/scripts/snd_pop.php",{para: itemid},function(data){
				$('#pop_para').text(data);																
			});
			
			//$('.fp').css("display","block");
			$('#main_offer').css("display","none");
			$('#signupbox').css("display","block").parent('.fp').css("display","block");
		
		});
	}

	function clearDefault(el)
	{
  		if (el.defaultValue==el.value) el.value = ""
	}
	
	function showhide(divid)
	{
		if(document.getElementById(divid).style.display=='none')
		{
			$('.sN').css({display:'none'});
			document.getElementById(divid).style.display='block';
		}
		else
		{
			document.getElementById(divid).style.display='none';
		}
	}
	
	function showhidev(divid)
	{
		if(document.getElementById(divid).style.visibility=='hidden')
		{
			document.getElementById(divid).style.visibility='visible';
		}
		else
		{
			document.getElementById(divid).style.visibility='hidden';
		}
	}
	
function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");

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

}

function CheckForVals()
{
	j=0
	$('.txtfield').each(function(i){
		if($(this).val()!="")
		{
			j++;	
		}
	});
	if(j==$('.txtfield').size())
	{
		return true;
	}
	else
	{
		return false;	
	}
}