google.setOnLoadCallback(function(){

	$('#introgallery').cycle({
	 timeout: 3000, 
     speed: 1000,
	 height: 320
	});

	$('#twitter_content').tweetable({username: 'albanypdpsi', time: true, limit: 1});
	
	$('#left_column, #right_column').tabs();
	/* fix chrome adding extra whitespace to bottom of page */
	$('#right_column').bind('tabsselect', function(event, ui) {
	 $('#' + ui.panel.id).show();
	});

	/* need to activate manually, toggling display: block in chrome */
	$('#browser_accordion').accordion({
	 active: false,
	 autoHeight: false
	});
	$('#browser_accordion').accordion('activate', 0);
	$("a[rel='bro']").colorbox({
	 current: '',
	 innerWidth: '750px',
	 innerHeight: '400px',
	 scrolling: false
	});

	var sent = false;
	$('#contact_name').focus(function() {
		$("#contact_error_name").fadeOut('fast');
	});
	$('#contact_email').focus(function() {
		$("#contact_error_email").fadeOut('fast');
	});
	$('#contact_message').focus(function() {
		$("#contact_error_message").fadeOut('fast');
	});

	$('#contact_submit').mouseover(function() {
	 $(this).removeClass('ui-state-default')
	 $(this).addClass('ui-state-hover');
	}).mouseout(function() {
	 $(this).removeClass('ui-state-hover')
	 $(this).addClass('ui-state-default');
	}).click(function() {
		if (!sent) {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailVal = $('#contact_email').val();
		if (emailVal == '' || !emailReg.test(emailVal)) {
			$('#contact_error_email').fadeIn('slow');
			hasError = true;
		}
		var nameVal = $('#contact_name').val();
		if (nameVal == '') {
			$('#contact_error_name').fadeIn('slow');
			hasError = true;
		}
		var messageVal = $('#contact_message').val();
		if (messageVal == '') {
			$('#contact_error_message').fadeIn('slow');
			hasError = true;
		}
		
		if (hasError == false) {
			$('#contact_loading').fadeIn('fast');
			$.post('sendmail.php', {
			  from: emailVal,
			  message: 'From: ' + nameVal + "\n" + messageVal
			 }, function(data) {
				$('#contact_submit').fadeOut('slow');
				$('#contact_loading').hide();
				$('#contact_success').fadeIn('slow');				
				sent = true;
			});
		}
		}
	});
	
	$('#footer a[title]').qtip({
		style: {
			width: 300,
			padding: 10,
			name: 'light',
			border: {
			 radius: 4
			},
			tip: true
		},
		position: {
			adjust: { x: 16, y: -4 },
			corner: {target: 'topLeft', tooltip: 'bottomLeft'}			
		}
	});
});