/**
 * @author Tina
 */
$(document).ready(function(){
	
	$(document).ready(function() {
	$('#banner').cycle({
			fx:     'scrollDown',
			speed: 2000,
			timeout:  7000,
			cleartypeNoBg: true,
    		easing: 'easeInOutExpo'
		});
	});
	
	$("#backtotop").hide();
	
		$('#story_year_container').scrollTo('.story_year:eq(0)', 2400, {axis:'x', easing:'easeInOutExpo'});
	
	    $("a[rel^='prettyPhoto'], a[rel^='lightbox']").prettyPhoto({
	    	
	    				theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	    				default_width: 612,
	    				social_tools: false,
	    				show_title: false
	    	
	    });
	
	var scroll_timer;$(window).scroll(function()
{window.clearTimeout(scroll_timer);scroll_timer=window.setTimeout(function()
{var doc_height=$(document).height();var win_height=$(window).height();var win_width=$(window).width();var scroll_top=$(window).scrollTop();
	if((doc_height>win_height && win_width > 500)){
		if(scroll_top>480){
			show=1;$('#backtotop').clearQueue().slideDown(1000,'easeInOutExpo');
		}else{
			show=0;$('#backtotop').clearQueue().slideUp(1000,'easeInOutExpo');}}},100);
		}
	);


    $('.story_image').cycle({
		fx: 'scrollDown', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		speed:    2000, 
    	timeout:  5000,
    	easing: 'easeInOutExpo'
	});


	//map
	$("#map").gMap({ controls: false,
                  scrollwheel: true,                 
                  latitude: 53.355008,
                  longitude: -1.463671,                  
                  zoom: 14,
                  controls: ["GLargeMapControl3D", "GOverviewMapControl"],
				  markers: [{ latitude: 53.352575,
                  			longitude: -1.483119,
                            icon: { image: "/images/map_pointer.png", 
		                            iconsize: [155, 64],
		                            iconanchor: [16, 64]
		                          }
		                    }]                  
                  
                   });
                   
                   
    $('#team figure:nth-child(3n+0)').css({"marginRight":"0px"});

});

function scrollToTop(){$('html').animate({scrollTop:0},'slow','easeInOutExpo');}

$('#phone_number').live('change keyup focus click', function(){
		
	$('#callback_frm div').animate({height:'260px'},'slow', 'easeInOutExpo');
	
	$('#callback_frm #additional_fields').fadeIn('slow');

});

function validate_blog_search_form(){
	
	valid = true;

	if (document.blog_search_form.blog_search.value == "") {

		valid = false;
	}

	if (valid == false) {
		apprise("Please complete all fields marked with *.");
	}

	return valid;
	
}
function validate_contactform()
{
    valid = true;
	
	apos = document.contact_form.email.value.indexOf("@");
	dotpos = document.contact_form.email.value.lastIndexOf(".");


    if ( document.contact_form.name.value == ""){
    	apprise("Please enter your name.");
    	valid = false;
    	
    }else if(document.contact_form.email.value == ""){
    	apprise("Please enter your email address.");
    	valid = false;
    	
    }else if (apos < 1 || dotpos - apos < 2)
	{
		apprise("Please enter a valid email address.");		
		valid = false;
		
	}else if(document.contact_form.message.value == ""){
    	apprise("Please enter your enquiry.");
    	valid = false;	
    	
    }   
   
    return valid;
}

function validate_askben_form()
{
   valid = true;
   
	if ( document.askben_form.name.value == ""){
    	apprise("Please enter your name.");
    	valid = false;
    	
    }else if(document.askben_form.email.value == ""){
    	apprise("Please enter your email address.");
    	valid = false;
    
    }else if(document.askben_form.email.value != ""){
    	
		apos = document.askben_form.email.value.indexOf("@");
		dotpos = document.askben_form.email.value.lastIndexOf(".");
		
		if (apos < 1 || dotpos - apos < 2)
		{
			apprise("Please enter a valid email address.");		
			valid = false;
		} 
		
    }else if ( document.askben_form.question.value == "" ){
        apprise ( "Please make sure all fields are complete." );
        
        valid = false;  
    }   

    return valid;
    
}    
var xmlHttp
var Effect;


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function requestCallback(page_ref)
{
	valid = true;
	
	phone_number = document.callback_frm.phone_number.value;
	name = document.callback_frm.name.value;
	call_time = document.callback_frm.call_time.value;				
	
	if(phone_number == "" || name == "" || call_time == "")		
	{
		alert('Please make sure you complete all fields.');
		valid = false;
	}
	else
	{
		document.getElementById("callback_content").innerHTML = "<h4>Please Wait...</h4><p>Sending your request.</p>";
		
		$('#callback_frm div').animate({height:'90px'},'slow', 'easeInOutExpo');
		
		xmlHttp = GetXmlHttpObject()
		
		if (xmlHttp == null) {
			alert("Your browser does not support AJAX!");
			return;
		}
		
		var url = "php/ajax/processCallBack.php?name=" + name;
		url = url + "&phone_number=" + phone_number;
		url = url + "&call_time=" + call_time;
		url = url + "&page_ref=" + page_ref;						
		url = url + "&sid=" + Math.random();
		xmlHttp.onreadystatechange = callbackRequested;
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
					
	}
	return valid;
}

function callbackRequested() 
{ 	
	if (xmlHttp.readyState==4)
	{ 		
		document.getElementById("callback_content").innerHTML=xmlHttp.responseText;
		//$('#banner').cycle('resume');
	}
}

function scrollTheStory(target)
{
	
	$('#story_nav > a').removeClass('selected');
	
	$('#story_nav_' + target).addClass('selected');
	
	$('#story_year_container').scrollTo('.story_year:eq(' + target + ')', 1900, {axis:'x', easing:'easeInOutExpo'});
	
}

