$(document).ready(function(){

	/*
	* carousel
	*/


	$('#carousel ul').jcarousel({
		scroll: 6,				//The number of items to scroll by.
		wrap: 'circular',
		easing: 'swing',
		auto: 0,					//Specifies how many seconds to periodically autoscroll the content. If set to 0 (default) then autoscrolling is turned off.
		animation: 3000,
		initCallback: function(carousel){

			$container = $('.jcarousel-container');
			$container.initBottom = $container.css('bottom');
			$container.append('<a class="jcarousel-switch">Switch</a>')

			//apply carousel-pop-up-animation
			$('.jcarousel-container, .shadow.left, .shadow.right')
			.bind('mouseenter',function(){

				$container.animate({bottom:'-3px'},{
					duration: 300,
					easing: 'swing',
					queue: false,
					complete: function(){
						//console.log('top done');
					}
				});
			})
			.bind('mouseleave',function(){
				$container.animate({bottom:$container.initBottom},{
					duration: 300,
					easing: 'swing',
					queue: false,
					complete: function(){
						//console.log('bottom done');
					}
				});
			});

			$('#carousel .left').bind('click', function() {
				carousel.prev();
				return false;
			});
			$('#carousel .right').bind('click', function() {
				carousel.next();
				return false;
			});

		}
	});


	/* toggle selector form fields  */
	$('form.selector fieldset h4').click(function(){
		fieldset = $(this).parent();
		fields = $(this).next();
		if(fieldset.hasClass('open')) {
			fields.animate({'opacity':'0'},100,function(){
				fields.slideUp(200);
			});
			fieldset.removeClass('open');
		} else {
			fields.slideDown(200,function(){
				fields.animate({'opacity':'1'},100);
			});
			fieldset.addClass('open');
		}
	});

	/*tabs collection details*/
	$('#collDetail .tabsbigcontainer').tabs({});
	$('#collDetail .details').tabs({});
	$('#collDetail #tabmuurarmenmasten').tabs({});

	$('#klantenservice ul.tabs').parent().tabs({});

	/* Neem contact op */
	$('#quickcontact form').submit(function(){
		var form = $(this);
		var url = form.attr('action');
		var data = form.serialize();
		var htmlContainer = $('#quickcontact');

		htmlContainer.html('<p class="msg">Verzenden...</p>');

		$.ajax({
			url: url,
			type: 'POST',
			async: true,
			data: data,
			success: function(html){
				htmlContainer.html(html);
			}
		});

		return false;
	});

	/* placeholder inputs */
    $('.placeholder').each(function(){
        $(this).attr({'rel':$(this).val()}).focus(function(){
                if($(this).val() == $(this).attr('rel')){
                        $(this).val('');
                }
        }).blur(function(){
                if($(this).val() == ''){
                        $(this).val( $(this).attr('rel') )
                }
        });
    });

});

function initFotoSlider(id){
	/* fotoslide */
	$('#' + id).before('<ul class="fotoslideNav" id="ul' + id + '">').cycle({
	    fx:     'fade',
		autoplay: true,
	    timeout: 3000,
	    pager:  '#ul' + id,
		pause: 1,
	    pagerAnchorBuilder: function(idx, slide) {
	        return '<li><a href="#"><img src="' + slide.src + '" width="80" height="50" /></a></li>';
	    }
	});
}
