$(document).ready(function() {

	$('.post_meta ul').hide();
	
	$('.post_meta p .meta_show').click(function(){
		$(this).toggleClass('selected').parent().parent().children('ul').slideToggle('150');
		return false;
	});

	$('#s').val('Search For...').focus(function(){
		if ($(this).val()=='Search For...') $(this).val('');
	}).blur(function(){
		if ($(this).val()=='') $(this).val('Search For...');
	});

	$('#searchform').append('<div id="searchError">Search Term Required</div>');
	$('#searchError').hide();
	$('#searchform').submit(function() {
		var search_term = $('#s').attr('value');
		if (search_term=='' || search_term.indexOf('Search For') == false) {
			$('#searchError').slideDown(300, function () {setTimeout(function(){$("#searchError").slideUp(500);},500);});
			return false;
		}
	});
	
	$('#comment').addClass('comment_blur').val('Have Your Say...').focus(function(){
		$(this).removeClass('comment_blur').removeClass('error_border');
		if ($(this).val()=='Have Your Say...') $(this).val('');
	}).blur(function(){
		thise = $(this);
		if (thise.val()=='') {
			thise.addClass('comment_blur').val('Have Your Say...');
		}
	});
	$('#commentform').submit(function() {
		if ($('#author').attr('value')=='') {
			$('#author_label').addClass('error');
			errored = true;
		} else {
			$('#author_label').removeClass('error');
		}
		if ($('#email').attr('value')=='') {
			$('#email_label').addClass('error');
			errored = true;
		} else {
			$('#email_label').removeClass('error');
		}
		if ($('#comment').val()=='' || $('#comment').val()=='Have Your Say...') {
			$('#comment').addClass('error_border');
			errored = true;
		}
		if (errored == true) return false;	
	});
	
	$('.carousel_info')
		.addClass('carousel_info_active')
		.click(function(){
			window.location = $(this).find('a').attr('href');
		})
		.hover(function(e){
			$(this).stop().animate({
				bottom: '0px',
				opacity: '0.9'
			},150);
			},function(){
			$(this).stop().animate({
				bottom: '-72px',
				opacity: '0.7'
			},400);
	});
	
    $('#carousel').jcarousel({
    	itemFirstInCallback:  carousel_itemFirstInCallback,
        initCallback: carousel_initCallback
    }).prepend('<div class="carousel_frame"></div>');
    
    
    $('#twitter_wrapper').jcarousel({
    	itemFirstInCallback:  twitter_itemFirstInCallback,
        initCallback: twitter_initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
  
});

function carousel_initCallback(carousel)
{

	$('#carousel_nav a').bind('click', function() {
	    carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
	    $('#carousel_nav a').removeClass('selected');
	    $(this).addClass('selected');
	    return false;
    });

};

function carousel_itemFirstInCallback(carousel, item, idx, state) {
	$('#carousel_nav a').removeClass('selected');
	$('#carousel_nav a[rel='+idx+']').addClass('selected');
};

function twitter_initCallback(carousel)
{

	$('#twitter_nav a').bind('click', function() {
	    carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
	    $('#twitter_nav a').removeClass('selected');
	    $(this).addClass('selected');
	    return false;
    });

};

function twitter_itemFirstInCallback(carousel, item, idx, state) {
	$('#twitter_nav a').removeClass('selected');
	$('#twitter_nav a[rel='+idx+']').addClass('selected');
};



function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    return b;
}