jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        start: 1,
		scroll:1,
		visible:1
		
    });
	
	
    
    $("#competitionform").hide();
    $("#quizNav li").children("ul").hide();  	
    
    
   
    $("#quizDrop").mouseover(function() {
    	$(this).show();
    }).mouseout(function() {
    	$(this).hide();
    });
    
    $("#quizTourDrop").mouseover(function() {
    	$(this).show();
    }).mouseout(function() {
    	$(this).hide();
    });
    
    $("#Drop").mouseover(function() {
    	$("#quizTourDrop").hide();
    	$("#quizDrop").show();  	
    });
    
    $("#TourDrop").mouseover(function() {
    	$("#quizDrop").hide();
    	$("#quizTourDrop").show();
    });
    
    $("#entercomp").click(function(){
		$("#competitionform").toggle();
    });
    
    
    var options = {
    	dataType:	'json',
    	success:    showResponse
    };

    $("#questionnaire").submit(function(){
    	if ($("#entercomp").is(':checked')) {
			var email = $("#ea").val();
			var filter = /^[a-z0-9!#$%&*+-=?^_`{|}~]+(\.[a-z0-9!#$%&*+-=?^_`{|}~]+)*@([-a-z0-9]+\.)+([a-z]{2,6})$/;
			if (!filter.test(email)) {
				$("#error-response").html('Please provide a valid email address');
				email.focus;
				return false;
			}
			if (! $("#pname").val()) {
				$("#error-response").html('Please enter your name.');
				$("#pname").focus;
				return false;
			}
			if (! $("#pnumber").val()) {
				$("#error-response").html('Please enter your contact number.');
				$("#pnumber").focus;
				return false;
			}
			if (! $("#tnc").is(':checked')) {
				$("#error-response").html('Please ensure you check the box to confirm you have read the terms and conditions.');
				return false;
			}
    	}
    	$(this).ajaxSubmit(options);
		return false;
    });
    
    function showResponse(responseJSON)  {
		var name = responseJSON.name;
	    var description = responseJSON.description;
	    var image = responseJSON.image;
	    $("#typology").removeClass('hidden');
	    $("#sharethis").removeClass('hidden');
	    $("#typology-title").html(name);
	    $("#typology").append(description);
	    $(".hideBlurb").hide();    	
	    $("#typology-image").removeClass('hidden').attr('src', image);
	    $("#competitionform").hide();
	    $("#questionNumber").hide();
	    
	}
    
    var counter = 1;
    var c = 1;
    
    $(".jcarousel-next").click(function(){
    	counter = counter+1;
    	c = c+1;
    	showPageInfo();
    });
    
    $(".jcarousel-prev").click(function(){
    	counter = counter-1;
    	if (c == 13) {
    		counter = 12;
    	}
    	c = c-1;
    	showPageInfo();
    });
    
    function showPageInfo() {
    	if (counter > 12) { 
    		counter = 12; 
    	}
    	if (c == 14) {
    		$(".jcarousel-prev-horizontal").hide();
    		$(".jcarousel-next-horizontal").hide();
    	}

    	if (c > 12) {
    		$("#questionNumber").html("About you");
    	} else {
	    	$("#questionNumber").html("Question " + counter + " of 12");
	    	$("#typology-image").attr('src', '/wp-content/themes/bthomezone/images/quiz/quiz_' + counter + '.jpg');
    	}
    }
    
    
	DD_belatedPNG.fix('div, h1, h3, span, img');
	
	
});

	