/*----------------------------------------------------------------------

	M A I N . J S
	
----------------------------------------------------------------------*/

$(document).ready(function() {
	
	// Inline labels for forms
	$("label.inline + .form-input").each(function (type) {
		
    if (!($(this).val() == "")) {
       $(this).prev("label.inline").addClass('has-text');
    }

   	$(this).focus(function () {
    		$(this).prev("label.inline").addClass("focus");
   	});
   	$(this).keypress(function () {
    		$(this).prev("label.inline").addClass("has-text").removeClass("focus");
   	});
   	$(this).blur(function () {
    		if($(this).val() == "") {
    			$(this).prev("label.inline").removeClass("has-text").removeClass("focus");
    		}
   	});

	// Front page slider
	$('#features').cycle({
		fx: 'scrollHorz',
		prev: '.nav.features.horz.prev', 
		next: '.nav.features.horz.next',
		pager: '.nav.features.pages',
		timeout: 10000,
		speed: 500,
		pause: true
	});
	
	// Front page accordion
	$('dl.news.accordion').accordion({
		header: 'dt'
	});
	
	// Cufon stuff
	Cufon.replace
		('h1')
		('h2', {
			textShadow: 'rgb(0,0,0) 0 1px',
			hover: true
		})
		('#blog #right .subscribe span', {
			textShadow: 'rgb(0,0,0) 0 1px'
		})
		('h3', {textShadow: 'rgb(0,0,0) 0 1px'})
		('q.lead')
		('#blog .body blockquote.big p')
		('#success p')
		('#profile-header .name')
		('#login-form a.register')
		('p.lead', {
			textShadow: 'rgb(0,0,0) 0 1px',
			hover: true
		});
	
  });
  
  // Guide tabs
	$(function () {
		var tabContainers = $('ul.guides.container > li');
		
		$('.guides.nav a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			
			$('.guides.nav a').removeClass('selected');
			$(this).addClass('selected');
			
			return false;
		}).filter(':first').click();
	});
	
  // Public profile tabs
	$(function () {
		var tabContainers = $('div#profile-tabs ul#tabs > li');
		
		$('div#profile-tabs ul#nav-tabs a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			
			$('div#profile-tabs ul#nav-tabs a').removeClass('selected');
			$(this).addClass('selected');
			
			return false;
		}).filter(':first').click();
	});
	
	// shoutbox auto-scroll
	$("#shouts").attr({ scrollTop: $("#shouts").attr("scrollHeight") });
  
});
