/*
 * Updated		: 04/14/2011
 * Updated by	: Hogan Lee (http://337studio.com)
 * Description	: initiate jQuery functions
 *
 */

$(document).ready(function() {
	
	// slideshow plugin - seen on homepage
	$('#slideshow')
		.after('<div id="slideshow-nav" />')
		.cycle({
			fx: 'fade',
			delay:  -1000,
			speed: 1200,
			timeout: 5000,
			pager: '#slideshow-nav'
	  	})
		.next()
		.wrap('<div id="slideshow-navwrap" />')
		.find('a:last')
		.css({'margin-right' : '0'});
	
	// calculate total width of nav btns
	var navWidth = 0; 
	$('#slideshow-nav a').each(function() {
		navWidth += $(this).outerWidth( true ); // set to true to include margins
	});
	
	// need to give container a width here so we
	// can center the nav btns
	$('#slideshow-nav').css({'width' : navWidth + 'px'});

	// pause/play button to pause/play slideshow
	$('#btn-pause-play').click(function( e ) {
    	$(this).toggleClass('play');

		if ( $(this).text() == 'Pause' ) {
			$('#slideshow').cycle('pause');
			$(this)
				.css({'background-position': '0 -58px'})
				.attr('title', 'Resume slideshow')
				.text('Play');
		} else {
			$('#slideshow').cycle('resume');
			$(this)
				.css({'background-position': '0 0'})
				.attr('title', 'Pause slideshow')
				.text('Pause');
		}
		
    	e.preventDefault();
  	})
	.hover(function() {
		if ( $(this).text() == 'Pause' ) {
			$(this).css({'background-position': '0 -29px'})
		} else {
			$(this).css({'background-position': '0 -87px'})
		}
	}, function() {
		if ( $(this).text() == 'Pause' ) {
			$(this).css({'background-position': '0 0'})
		} else {
			$(this).css({'background-position': '0 -58px'})
		}
	});

	// use jQuery to add <p> element in case JS disabled
	// animate the Thank You msg that appears after user submits contact form
	$("p.confirmation").append("<a class='close' href='#' title='Close this message'>Close</a>");
	$("a.close").click(function( e ){
		e.preventDefault();
		$("p.confirmation").hide("slow");
	});

	// zebra stripe data tables - tables that are wrapped in div.data
	$(".data tbody tr:nth-child(odd)").addClass('odd');

	// hide images on home page - could potentially break layout
	$('#b-home #sidebar img').filter(function() {
		return !$(this).hasClass('show');
	}).hide();
	/*$('.archives-list')
		.wrap('<div class="archives-wrap" />')
		.clone()
		.addClass('col-2')
		.appendTo('.archives-wrap')
	
	//var items = $('.archives-list:first > li').length;
	//var len = items / 2;

	$('.archives-list:eq(0)').find('li:gt(14)').remove();
	
	$('.archives-list:eq(1)').find('li:lt(14)').remove();*/

});
