/*
* Custom jQuery functions
**/


/* Sitemap */
function toggleSitemap(id, aId) {
	if($('#'+id).css('display') == 'none') {
		$('#'+id).css('display','block');
		$('a#'+aId+' img.toggleButton').attr('src',imgPath+'sitemap/min.png');
	}else{
		$('#'+id).css('display','none');
		$('a#'+aId+' img.toggleButton').attr('src',imgPath+'sitemap/plus.png');
	}
}


var stopAuto = false;
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
    	initCallback: mycarousel_initCallback,
        scroll: 1,
		wrap: 'circular',
		auto: 10,
		buttonNextHTML: null,
		animation: 'slow',
		buttonPrevHTML: null,
		itemVisibleInCallback: updateControl, // update control for next button
		itemLoadCallback: stopCarousel // check whether carousel is step
    });
    
    jQuery('.carousel').jcarousel({
    	scroll: 1
    });
    
	$('.naildAdviceBtn').click(function() {
    	$('#nailAdviceForm').submit();
	});
	
	$('.submitBtn').click(function() {
    	$('#contactForm').submit();
	});
});


// stop the carousel
function stopCarousel(carousel){
	if(stopAuto){
		carousel.stopAuto();
	}
	
}

// update control
function updateControl(carousel, li, currentItem){
	
	//set active button	
	activeNumber = currentItem%4
	if(activeNumber%4 == 0){
		activeNumber = 4;
	}
	switchImage(activeNumber);	
}

function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {	
    	stopCarouselNow(carousel);
    	// scroll to item
    	carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
    	switchImage(jQuery(this).text());
    	//stopCarouselNow(carousel);
    	stopAuto = true;
    	return false;
    });   
    
    /*jQuery('.jcarousel-control a').bind('mouseup', function() {	
    	stopCarouselNow(carousel);
    });*/  


};

function stopCarouselNow(carousel){
	// stop carousel
	carousel.stopAuto();  
	//carousel.animation = 0;
	return false;	
}

function switchImage(activeNumber){
	//alert(activeNumber);		
	$('.jcarousel-control a').removeClass('active');
	$('#control'+activeNumber).addClass('active');
}

// active answer
var activeAnswer = '';
function changeAnswer(answerId){
	if(answerId != ''){
		// reset active label
		$('#contentStep label').removeClass('active');
		// set active label
		$('#answerLabel'+answerId).addClass('active');
		// hide main image
		$('#mainImage').hide();
		// if active answer is true, hide that block to
		if(activeAnswer != ''){
			$('#answerRightBlock' + activeAnswer).hide();
		}
		// show current answer block
		$('#answerRightBlock' + answerId).show();
		// set new active answer
		activeAnswer = answerId;
	}
}




