/**
 * LOGIN
 * @author minoru
 */

jQuery(function(){
	
	var openLogin = jQuery('#login').hasClass('open'),
		carouselLogin = false;
	
	if(openLogin){
		jQuery('#btn-show-hide').addClass('down');
	}
	
	jQuery('#carousel-children-wrapper').css('height','87px');
	
	jQuery('#btn-show-hide, .top-login').click(function(){
		jQuery('#btn-show-hide').toggleClass('down');
		jQuery('#content-login').slideToggle('fast', function(){
			if ( jQuery(this).css('display') == "block" ) {
				jQuery("#form-login input[name='user.username']").focus();
			}
			chkCarousel();
		});
		return false;
	});
	
	jQuery('.login-now').click(function(){
		jQuery('#btn-show-hide').toggleClass('down');
		jQuery('#content-login').slideDown('fast', function(){
			if ( jQuery(this).css('display') == "block" ) {
				jQuery("#form-login input[name='user.username']").focus();
			}
			chkCarousel();
		});
		jQuery.scrollTo(0, 800);
		return false;
	});
	
	function chkCarousel(){
		if (carouselLogin == false && jQuery('#carousel-children-wrapper').length > 0 ){
			var numChild = jQuery("#carousel-children li").length;
			// hide carousel button when there is no reason to move;
			if(numChild>2){
				jQuery('.prev-child-img, .next-child-img,').show();
				jQuery("#carousel-children").jCarouselLite({
				btnNext: ".next-child-img",
				btnPrev: ".prev-child-img",
				visible: 2,
				scroll: 1,
				circular: false,
				mouseWheel: true
			});
			}
			carouselLogin = true;
		}
	}
});
