/** ********************************************
 *	Effects starter by Hradecon
 *	(C) copyright Vaclav Hradec 2003-2010
 *	file: 	title.js 
 *	email: 	vh@hradecon.com
 * 	web:	http://Hradecon.com
 * *********************************************/

$(document).ready(function() {
    // CAROUSELS
	$('#board').jcarousel({
        scroll: 1,
        auto: 5,
        wrap: 'last',
        easing: 'easeInBack',
        itemVisibleInCallback: board_itemVisibleInCallback,
        initCallback: board_initCallback
    });
    
    $('#board .ctrl div').hover(function(){
    	$(this).toggleClass('hover');
    });
});

/* ***************************** FUNC *********************************** */
function board_itemVisibleInCallback(carousel, element, index, state) 
{
	var doSelect = jQuery('#board .ctrl div:nth-child('+index+')');
	doSelectCallback(doSelect);
}

function board_initCallback(carousel) 
{
    jQuery('#board .ctrl div').bind('click', function() {
    	carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr('title')));
    	doSelectCallback(jQuery(this));
    	return false;
    });

    jQuery('#board .jcarousel-prev').bind('click', function() {
    	carousel.startAuto(0);
    	
    	carousel.prev();
        return false;
    });

    jQuery('#board .jcarousel-next').bind('click', function() {
    	carousel.startAuto(0);
    	
    	carousel.next();
        return false;
    });
    
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
}

function doSelectCallback(select)
{
	jQuery('#board .ctrl div.selected').toggleClass('selected');
	select.toggleClass('selected');
}

