$(function(){
	// homepage scroller
	$("#home_scroll").scrollable({
		vertical: true,
		keyboard: 'static',
		circular: true
	}).navigator(".navi").autoscroll({ autoplay: true,
					circular: true,
					interval:6000
					});
	
	// subscribe box
	$("#email_subscribe, #name_callback, #phone_callback").focus(function(){
		if($(this).val() == $(this).attr('title')) { 
			$(this).val('');
		}
	});
	$("#email_subscribe, #name_callback, #phone_callback").blur(function(){
		if($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	});
	$("#submit_subscribe").click(function(){
		if($('#email_subscribe').val() != '') {
			
			$.ajax({
					url: "/ajax.php",
					global:false,
					type: "POST",
					data: ({action: 'subscribe',email: $('#email_subscribe').val()}),
					dataType: "xml",
					async:false,
					success: function(msg) {
						$('#email_subscribe').remove();
						$('#submit_subscribe').remove();
						$('#subscribe_form').append('<span>Thank you for subscribing</span>');
					}, 
					error: function(a,b,c) {
						return false;
					}
					
				});
		}
	});
	
	// request a callback box
	$("#submit_callback").click(function(){
		
		if($('#email_subscribe').val() != '') {
			$('#email_subscribe').remove();
			$('#submit_subscribe').remove();
			$('#subscribe_form').append('<span>Thank you for subscribing</span>');
		}
	});
	
	// contact form
	$("#contact_submit").click(function(){
		$("#contact_form").validate({
			rules: {
				contact_name: "required",
				contact_email: {required:true, email: true}
			}, 
			messages: {
				contact_name : "Please enter your name",
				contact_email: "Please enter your email"
			},
			errorPlacement: function(error, element) {
				error.appendTo(element.parent());
				element.addClass('error');
			},
			submitHandler: function() {
				
				$.ajax({
					url: "/ajax.php",
					global:false,
					type: "POST",
					data: ({action: 'contact',
							name: $('#contact_name').val(),
							email: $('#contact_email').val(),
							phone: $('#contact_tel_number').val(),
							enquiry: $('#contact_enquiry').val(),
						}),
					dataType: "xml",
					async:false,
					success: function(msg) {
						$('#contact_form_fieldset').remove();
						$('#contact_form').append('<strong>Thank you for your enquiry</strong><br /><br />Your request has been sent to Tiger Eye Consulting and we will respond shorly.');
					
					}, 
					error: function(a,b,c) {
						return false;
					}
					
				});
			}
		});
	});
	
	//cancel buttons
	$('#contact_cancel').click(function(e) {
		$('label.error').remove();
	});
	
	//open links in a new window
	$('.blank').click(function(){
		e.preventDefault(); 
		window.open($(this).attr('href'));
		return false;
	});
	
	// bookmark
	$(".addtofav").click(function(e){
		e.preventDefault(); 
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
	 
		if (window.sidebar) { 
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		
		} else if( window.external || document.all) { 
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		
		} else if(window.opera) { // For Opera Browsers
			$(".addtofav").attr("href",bookmarkUrl);
			$(".addtofav").attr("title",bookmarkTitle);
			$(".addtofav").attr("rel","sidebar");
		
		} else { 
			 return false;
		}
	});
});

$(document).ready(function(){
  	$(".tweet").tweet({
            	username: "Tiger_Eye_UK",
            	join_text: "auto",
            	avatar_size: 30,
            	count: 3,
            	refresh_interval: 60,
            	auto_join_text_default: "",
          	auto_join_text_ed: "",
            	auto_join_text_ing: "",
           	auto_join_text_reply: "",
          	auto_join_text_url: "",
          	loading_text: "loading tweets...",
		template: "{avatar}  {text}"
       	});
});

