$(window).load(function()
{
	// INITIALIZE SCROLLER AND MANUALLY REINITIALISE WHEN NEW CONTENT IS ADDED
	var settings = {showArrows: true,hijackInternalLinks: true};
	var pane = $('.scroll-pane')
	pane.jScrollPane(settings);
	var api = pane.data('jsp');

	if(api != null)
	{
		setInterval(function()
		{
			api.getContentPane()
			api.reinitialise();
		},
			1000
		);
	}
	
	// INITIALIZE SHADOWBOX
	Shadowbox.init();		
});

// SET blog_ajax_year VARIABLE
// CONTINUED ON LINE 133
var blog_ajax_year = '';

$(document).ready(function()
{	
	// USING THIS BECAUSE IE DOES NOT SUPPORT PLACEHOLDER ON INPUT ELEMENT
	// http://www.hagenburger.net/BLOG/HTML5-Input-Placeholder-Fix-With-jQuery.html
	$('[placeholder]').focus(function()
	{
		var input = $(this);
		if(input.val() == input.attr('placeholder'))
		{
			input.val('');
			input.removeClass('placeholder');
		}
	}).blur(function()
	{
		var input = $(this);
		if(input.val() == '' || input.val() == input.attr('placeholder'))
		{
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
	}).blur().parents('form').submit(function()
	{
		$(this).find('[placeholder]').each(function()
		{
			var input = $(this);
			if(input.val() == input.attr('placeholder'))
			{
				input.val('');
			}
		})
	});
	
	// REMOVE PADDING FROM LAST PARAGRAPH ON HOME PAGE
	$('#home-column-intro p:last').css({'padding':'0'});	
 
    // GALLERY THUMBNAIL CAPTIONS
	$('#albums .item').find('.caption').css({'opacity':'0'});
	
	$('#albums .item').hover(function() 
	{              
        //Display the caption at 90% opacity
        $(this).find('.caption').stop().animate({opacity:0.90});
    }, function() 
	{ 
        //Hide the caption
        $(this).find('.caption').stop().animate({opacity:0});
    });
	
	// GALLERY SLIDER
	$('#slider').cycle({fx:'scrollHorz',timeout:0,speed:750,prev:'#prev',next:'#next',pager:'#slider-nav'});	
	
	// ONLY DISPLAY SLIDER NAVIGATION IF THERE IS MORE THAN 4 GALLERIES
	var galleries = $('#slider .gallery-wrap').length;
	if(galleries <= 1)
	{
		$('#next, #prev, #slider-nav').hide();
		$('#albums').css({'margin-bottom':'122px'});
	}	
	
	// PHOTO SLIDER
	$('#photo-slider').cycle({fx:'scrollHorz',timeout:0,speed:750,prev:'#photo-prev',next:'#photo-next',pager:'#photo-nav'});		
	
	// ONLY DISPLAY PHOTO NAVIGATION IF THERE IS MORE THAN 1 SET OF IMAGES
	var photos = $('#photo-slider .photo-wrap').length;
	if(photos <= 1)
	{
		$('#photo-next, #photo-prev, #photo-nav').hide();	
		$('#photo-slider-wrap').css({'margin-bottom':'52px'});
	}
    
    // CUSTOM BLOG ARCHIVES
    $('#archive-year li').click(function()
	{
        blog_ajax_year = $(this).attr('title');
        blogYear(this, blog_ajax_year);
    });
    
    $("#archive-months li").live("click", function()
	{
        var month = $(this).attr('title');
        blogMonth(this, month)
    });
    
    if($.cookie('blog_year') && $.cookie('blog_month'))
	{
        blogYear($('#archive-year li[title="'+$.cookie('blog_year')+'"]'), $.cookie('blog_year'), true);
    }
});

// LOADING GIF
var loader = '<img src="/wp-content/themes/janicestain/images/ajax-loader.gif" width="16" height="11" alt="Loading" />';

// BLOG YEAR DATA
function blogYear(el, year, callmonth)
{
    $('#archive-year li').removeClass('active');
	$(el).addClass('active');
    $.cookie('blog_year', year);
    $('#archives-found').html('');
    $('#archive-posts').html('');
    $('#archive-months').html(loader);
    $.post('/wp-content/themes/janicestain/blog-ajax.php', {year:year}, function(data)
	{
        $('#archive-months').html(data.data);
        if(callmonth)
		{
            blogMonth($('#archive-months li[title="'+$.cookie('blog_month')+'"]'), $.cookie('blog_month'));
        }
    }, 'json');
}

// BLOG MONTH DATA
function blogMonth(el, month)
{
    $('#archive-months li').removeClass('active');
    $(el).addClass('active');
    $.cookie('blog_month', month);
    $('#archives-found').html(loader);
    $('#archive-posts').html(loader);
    $.post('/wp-content/themes/janicestain/blog-ajax.php', {year:blog_ajax_year,month:month}, function(data)
	{
        $('#archives-found').html(data.data);
        $('#archive-posts').html(data.data2);
    }, 'json');
}
