/*
 * jQuery for Fleurtacious Designs
 * Stephen Orsini / stephenorsini.com
 */
jQuery(document).ready(function () {

//	Fixes width on WordPress images with a caption
	jQuery('.wp-caption').each(function() {
		// locate elements
		division = jQuery(this);
		image = division.find('img');
		// retrieve widths for elements
		division_width = parseInt(division.css('width'));
		image_width = parseInt(image.css('width'));
		if(division_width != image_width) {
			division.css('width',image_width);
		}
	});

//  Share tab slider
	jQuery('#share_openclose').click(function() {
		jQuery(this).toggleClass('open');
		if(jQuery(this).hasClass('open')) {
			jQuery('#tab').animate({left: -12}, 200);
		} else {
			jQuery('#tab').animate({left: -102}, 300);
		}
		return false;
	});

});


//  Functionality for the header slideshow
var current_image = 0;
var total_images = 0;
var timer = false;
var timer_interval = 5000;
var transition_interval = 1600;

jQuery(document).ready(function() {

	// count total images
	total_images = parseInt( jQuery('#background ul#slides li').length ) - 1;

	if(total_images > 0) {
		// hide all but the first image
		jQuery('#background ul#slides li:gt(0)').hide();

		// setup gallery images
		jQuery('#background ul#slides li').each(function(index) {
			jQuery(this).attr('id','image-' + index);
		});

		// start the carosel
		start_rotation();
	}
});

function swap_image(index) {
	jQuery('#background ul#slides li#image-' + current_image).fadeOut(transition_interval);
	jQuery('#background ul#slides li#image-' + index).fadeIn(transition_interval);
	current_image = index;
}

function start_rotation() {
	timer = setInterval(function() {
		if(current_image == total_images) {
			image_index = 0;
		} else {
			image_index = parseInt(current_image + 1);
		}
		swap_image(image_index);
	}, parseInt(timer_interval));
}

