/*******************************************************************************

  CSS on Sails Framework
  Title: Site Name
  Author: XHTMLized (http://www.xhtmlized.com/)
  Date: May 2010

*******************************************************************************/

$(document).ready(function() {

	$('#navigation a')
		.mouseover(function(){
			$(this).stop().animate(
				{backgroundPosition:"-1380px 0"},
				{duration:400})
			})
		.mouseout(function(){
			$(this).stop().animate(
				{backgroundPosition:"0 0"}, 
				{duration:300})
			});

	if ($('#featuredimages #slideshow').length > 0) {
		setInterval( "slideSwitch()", 5000 );
	}
	
	$("a.lightbox").colorbox({current:" ({current} of {total})",previous:'back'});
	$("a.lightbox-video,.fake-nav a").each(function(){
		$(this).colorbox({
			width				: "425px",
			inline			: true, 
			href				: $(this).attr('href'),
			onComplete	: function(){
											var total = $(this).find('.total-video').text();
											var info = $(this).find('.video-info').text();
											if(Number(total) > 1){
												$('#cboxCurrent')
													.html(info)
													.show();
												
											}
										}
		});
	});

});

// DD_belatedPNG fix for IE6
var PNG_fix_selectors = [
    'selector-1',
    'selector-2'
];
 
if (typeof DD_belatedPNG !== 'undefined') {
    DD_belatedPNG.fix(PNG_fix_selectors.join(','));
}

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
