////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////   DECLAIR VARIABLES   ///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var url =  0;
	
// fetch url variable

$.ajax({  
	type: "GET",  
	url: '../../content/resources/php/url_ajax.php',  
	dataType: "html",  
	success: function(data) { 
	
		url = data;
		
	}  
});

var faded = 0;
var search_expanded = 0;
var searched = 0;
var bannerid = 0;

var content = 0;


bannerfade = 1;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////   FUNCTIONS   ///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////   DOCUMENT READY   //////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function(){
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var username = "enquiries";
var hostname = "digitaloutreach.org.uk";
var linktext = username + "@" + hostname;

$('.email').html('<a href="mailto:'+linktext+'">'+linktext+'</a>');



// search hover

$('#search').hover(function() {
							
	if (search_expanded == 0) {
							
		$(this).fadeTo(100,'0.7')
	
	}
							
},function() {
	
	if (search_expanded == 0) {
							
		$(this).fadeTo(100,'1')	
	
	}
							
});

// search click

$('#search').click(function(){	
							
	if (search_expanded == 0) {						
							
		$(this).animate({width:240,opacity:1},200);
		
		$('#search_field').fadeIn(200,function() {
		
			$('#search_field').focus();
											   
		});
		
		if (searched == 1) {
		
			$('#search_results').fadeIn(200);
			
		}
		
		search_expanded = 1;
		
		
	
	}
							
});


// when click outside search

$('html').click(function() {
						 
	if (search_expanded == 1) {
	
		$('#search').animate({width:28},200);
		
		$('#search_field').fadeOut(200);
		
		$('#search_results').fadeOut(200);
		
		search_expanded = 0;
	
	}
	
});

// exclude box

$('#search,#search_results').click(function(event){
		event.stopPropagation();
});



//when search submitted

$('#search_form').submit(function() {
	
	searchtext = $("input:first").val();
	
	searchtext = $.trim(searchtext);
						 
	$.ajax({  
	
		type: "GET",  
		url: url+'search/index.php?q='+searchtext,  
		dataType: "html",  
		success: function(data) { 
			
			$('#search_results_inner').html(data);
			
			$('#search_results').fadeIn(200);
			
			searched = 1;
		
		}  
		
	});  
	
	return false;
	
});



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// banner image changer



if (bannerfade == 1) {

	setInterval(function(){
						 
		bannerid = $('#bannerid').html();
		
		currentimage = $('.show img').attr('id');
		
		$.ajax({ 
			   
			type: "GET",  
			url: url+'resources/php/banner.php?random='+(Math.random()*99999)+'&currentimage='+currentimage+'&id='+bannerid,
			dataType: "html",  
			success: function(data) {
				
				if (faded == 0) {
					
					$('#banner_img1').css({'z-index': 2});
					
					$('#banner_img2').css({'z-index': 3});
					
					$('#banner_img2').html(data);
					
					$('#banner_img2 img').load(function() {
													 
						$('#banner_img2').fadeIn(1500,function() {
						
							$('#banner_img1').fadeOut(0);	
							
						});
						
						$('#banner_img1').removeClass('show');
						
						$('#banner_img2').addClass('show');
						
						faded = 1;								 
													 
					});
			
					
				
				}
				
				else {
					
				
					$('#banner_img2').css({'z-index': 2});
					
					$('#banner_img1').css({'z-index': 3});
					
					$('#banner_img1').html(data);
					
					$('#banner_img1 img').load(function() {
													 
						$('#banner_img1').fadeIn(1500,function() {
															   
							$('#banner_img1').addClass('show');
						
							$('#banner_img2').removeClass('show');								   
						
							$('#banner_img2').fadeOut(0);	
							
						});
						
						faded = 0;								 
													 
					});
					
				}
			
			}
		
		}); //end ajax
						 
	},5000);
	
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// list drop down

$('#header ul li').hover(function(){
								  
	if ($(this).children('.submenu').length != '') {							  
								  
		$(this).addClass('hover');
	
	}
					 
	$(this).children('.submenu').stop(true, true).slideDown(80);
	
},function(){
	
	$(this).children('.submenu').stop(true, true).delay(150).slideUp(80,function(){
																				 
	if ($(this).length != '') {																			 
																				 
		$(this).parent().removeClass('hover');
		
	}
																				 
	});
	
})

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// quote shrink

$('.quote,.quote_expand').each(function(){
						  
	height = $(this).height();
	
	if (height > 200) {
	
		content = $(this).html();
		
		$(this).html('<div class="quote_inner"><div class="height">'+content+'</div></div><div class="more colour">Read more</div>')
		
		$(this).children('.quote_inner').css('height','200px');
	
	}
						  
});

$('.more').click(function(){
								 
	if ($(this).html() == 'Close') { 
	
		$('.quote_inner').stop().animate({height: 200},400);
		
		$(this).html('Read more');
	
	}
	
	else {
								 
		height = $(this).siblings('.quote_inner').children('.height').height();
		
		$(this).siblings('.quote_inner').animate({height: height},400);
		
		$(this).html('Close');
	
	}
	
	
	
	$('html').click(function() {
	
		$('.quote_inner').stop().animate({height: 200},400);
		
		$('.more').html('Read more');
	
	});

	// exclude box
	
	$(this).parent().click(function(event){
	
		event.stopPropagation();
	
	});
	
});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// profile link hover

$('.rise_link a').hover(function(){
									
	link_height = $(this).height();	
	
	$(this).siblings('.rise').height(link_height+10);
	
	$(this).siblings('.rise').slideDown(80);
									
},function(){
	
	$(this).siblings('.rise').slideUp(80);
	
}); 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////



// VALIDATE FORM
							 
$("#contact_form").validate({
							   
	rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			message: "required",
			phone: {
				phoneUK: true
			}
		},
		messages: {
			name: "<div class=\"error_message\" style=\"width:170px\"><span>Please enter your name</span></div>",
			email:     {
				required: "<div style=\"width:225px\" class=\"error_message\"><span>Please enter your email address</span></div>",
				email:    "<div style=\"width:238px\" class=\"error_message\"><span>Please enter a valid email address</span></div>"
			},
			message: "<div style=\"width:200px;left:338px\" class=\"error_message\"><span>Please enter your message</span></div>",
			phone:     {
				phoneUK:  "<div style=\"width:245px\" class=\"error_message\"><span>Please enter a valid phone number</span></div>"
			}
			
		}						   
											   
});




$("#subscribe_form").validate({
							   
	rules: {
			name: "required",
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			name: "<div class=\"error_message\" style=\"width:170px;background-image: url(resources/images/error_arrow_right.png); background-position: right center; padding-right: 15px; padding-left: 0px; left: auto; right: 295px;\"><span>Please enter your name</span></div>",
			email:     {
				required: "<div style=\"width:225px;background-image: url(resources/images/error_arrow_right.png); background-position: right center; padding-right: 15px; padding-left: 0px; left: auto; right: 295px;\" class=\"error_message\"><span>Please enter your email address</span></div>",
				email:    "<div style=\"width:238px;background-image: url(resources/images/error_arrow_right.png); background-position: right center; padding-right: 15px; padding-left: 0px; left: auto; right: 295px;\" class=\"error_message\"><span>Please enter a valid email address</span></div>"
			}
			
		}						   
											   
});

$("#quest").validate({
							   
	rules: {
			org_name: "required",
			email: {
				required: true,
				email: true
			},
			how_many_employ: {
				digits: true
			},
			how_many_vol: {
				digits: true
			},
			vol_active: {
				digits: true
			},
			main_contact: "required",
			agree: "required",
			phone: {
				required: true,
				phoneUK: true
			}
		},
		messages: {
			org_name: "<div class=\"error_message\" style=\"width:260px\"><span>Please enter the Organisation's name</span></div>",
			email:     {
				required: "<div style=\"width:225px\" class=\"error_message\"><span>Please enter an email address</span></div>",
				email:    "<div style=\"width:238px\" class=\"error_message\"><span>Please enter a valid email address</span></div>"
			},
			how_many_employ: {
				digits: "<div style=\"width:220px\" class=\"error_message\"><span>Please enter a numerical value</span></div>"
			},
			how_many_vol: {
				digits: "<div style=\"width:220px\" class=\"error_message\"><span>Please enter a numerical value</span></div>"
			},
			vol_active: {
				digits: "<div style=\"width:220px\" class=\"error_message\"><span>Please enter a numerical value</span></div>"
			},
			main_contact: "<div style=\"width:230px;\" class=\"error_message\"><span>Please enter a primary contact</span></div>",
			agree: "<div style=\"width:150px;left:20px;top:-5px\" class=\"error_message\"><span>Please tick to agree</span></div>",
			phone:     {
				required: "<div style=\"width:225px\" class=\"error_message\"><span>Please enter a phone number</span></div>",
				phoneUK:  "<div style=\"width:245px\" class=\"error_message\"><span>Please enter a valid phone number</span></div>"
			}
			
		}						   
											   
});


////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////  END DOCUMENT READY   ///////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
});
////////////////////////////////////////////////////////////////////////////////////////////////////////////////






