$(document).ready( function () {

	/*
	 * Animation for slogan
	 */

	$('#qlbtns_list').innerfade({ speed: 1500, timeout: 7000, type: 'sequence', containerheight: '49px' });

	/*
	 * Animation for page block images
	 */

	$(".pb_images").each( function() {

		// get counter value of current page_block
		var id = $(this).attr("id");
		id_array = id.split('_');
		var i = id_array.pop();

		/*
		 * Mouseover on page block image slider
		 */

		var items = $(this).find(".nav").mouseenter (function () {

			// Clear interval
			clearInterval (slider);

			// Remove active and addclas inactive
			$("#pb_images_"+i).find(".nav").removeClass('active');
			$("#pb_images_"+i).find(".nav").addClass('inactive');

			// Set active
			$(this).removeClass('inactive');
			$(this).addClass('active');

			// Calculate the offset
			offset = items.index(this) + 1;
			offset = (offset * 218) - 218;

			// Set offset
			$("#pb_images_"+i).find(".scroll-container").stop().animate({marginLeft: '-' + offset}, 700, 'easeOutQuad');

		});


		/*
		 * Page block image slider
		 */

		var slider = setInterval (function () {

			// Remove active
			active = $("#pb_images_"+i).find("a.active");

			// Calculate next
			next = items.index(active) + 1;

			// Check for offset
			if (next == items.length)
				next = 0;

			// Fetch next
			slide = $(items).get(next);

			// Remove active
			$("#pb_images_"+i).find(".nav").removeClass('active');
			$("#pb_images_"+i).find(".nav").addClass('inactive');
			$(slide).removeClass("inactive");
			$(slide).addClass("active");

			offset = (next * 218);

			// Set offset
			$("#pb_images_"+i).find(".scroll-container").stop().animate({marginLeft: '-' + offset}, 700, 'easeOutQuad');

		}, 6000);
	});

	/*
	 * Set position of category overview div
	 */

	var cat_height = $("#categorie-overview").height();
	var cat_top = 0 - cat_height;

	$("#categorie-overview").css({"top": cat_top, "height": cat_height});

	/*
	 *  categorie-select
	 */

	$("#subcat").mouseenter(function (){

		$('#showpopup').css('display', 'none');

		$("#categorie-overview").stop().animate(
			{top: 0}, {
				duration: 'medium',
				easing: 'easeOutQuint'
			}
		);
	});

	$("#subcat").mouseleave(function (){

		$('#showpopup').css('display', 'block');

		$("#categorie-overview").stop().animate(
			{top: cat_top}, {
				duration: 'medium',
				easing: 'easeOutQuint'
		});
	});

	
	/*
	 * Tel a friend button (position)
	 */
	 
	var p_detail_height = $("#productdetail").height();
	var mailer_header_height = $("#mailer-header").height();
	$("#mailer").css({"bottom": 0});
	
	// set full height when mailer has class "active"
	if ($("#mailer").hasClass("active")) {
		$("#mailer").css({
			height: 500
		});
	}

	/*
	 * Tel a friend button (action)
	 */

	$("#btn_tellfriend").click(function () {

		if ($("#mailer").hasClass("active")) {
			$("#mailer").removeClass("active");
		}

		// get height of form body
		var height = $("#mailer").height();
		
		if (height == 20) {
			$("#mailer").stop().animate(
						{
							height: 500
						},
					'slow',
					'easeOutQuint',
					function () {
						$("#btn_tellfriend").attr("src", "./gfx/btn_tell-a-friend_up.png");
			});

		} else {
			$("#mailer").stop().animate(
					{height: 20},
					'slow',
					'easeOutQuint',
					function () {
						$("#btn_tellfriend").attr("src", "./gfx/btn_tell-a-friend_down.png");
			});
		}
	});
	
	
	
	/*
	 * Initialize shadowbox
	 */

	Shadowbox.init({
		overlayColor: "#222",
		overlayOpacity: 0.9,
		players: ["iframe", "html", "img"]
	});

	/*
	 * Action selector
	 */

	$('.action_selector').each(function () {

		$(this).click( function () {

			/**
			 * Clear and remove all forms and show active form
			 */
			$('.action_inputter').each( function () {

				if ($(this).val() == '') {
					if ($(this).hasClass('user_name')) {
						$(this).val('Naam');
					}
					if ($(this).hasClass('user_mobile')) {
						$(this).val('Mobiele nummer');
					}
					if ($(this).hasClass('user_actioncode')) {
						$(this).val('Actiecode');
					}
					if ($(this).hasClass('user_email')) {
						$(this).val('Emailadres');
					}
				}

				if ($(this).val() != 'Naam' && $(this).val() != 'Mobiele nummer' && $(this).val() != 'Actiecode' && $(this).val() != 'Emailadres') {
					$(this).val('');
				}
			});

			$('.action_userform').each(function () {
				$(this).css('visibility', 'hidden');
			});

			$(this).parent().parent().find('.action_userform').css('visibility', 'visible');

			$('#error_message').css('display', 'none');
		});
	});

	/**
	 * Action input fields
	 */
	$('.action_inputter').each( function () {

		$(this).click( function () {

			if ($(this).val() == 'Naam' || $(this).val() == 'Mobiele nummer' || $(this).val() == 'Actiecode' || $(this).val() == 'Emailadres') {

				$(this).val('');
			}
		});
	});

});

function checkAdress(checked) {

	if (checked == true) {

		if ($('#address_delivery').hasClass('disabled')) {
			$('#address_delivery').removeClass('disabled');
		}

		if ($('#postal_delivery').hasClass('disabled')) {
			$('#postal_delivery').removeClass('disabled');
		}

		if ($('#city_delivery').hasClass('disabled')) {
			$('#city_delivery').removeClass('disabled');
		}

		$('#address_delivery').addClass('disabled');
		$('#address_delivery').attr('disabled', 'disabled');
		$('#address_delivery').attr("value", "");

		$('#postal_delivery').addClass('disabled');
		$('#postal_delivery').attr('disabled', 'disabled');
		$('#postal_delivery').attr("value", "");

		$('#city_delivery').addClass('disabled');
		$('#city_delivery').attr('disabled', 'disabled');
		$('#city_delivery').attr("value", "");

	} else {

		$('#postal_delivery').removeClass('disabled');
		$('#address_delivery').removeClass('disabled');
		$('#city_delivery').removeClass('disabled');

		$('#postal_delivery').removeAttr('disabled');
		$('#address_delivery').removeAttr('disabled');
		$('#city_delivery').removeAttr('disabled');

		$('#postal_delivery').removeClass('disabled');
		$('#address_delivery').removeClass('disabled');
		$('#city_delivery').removeClass('disabled');

	}
}

