jQuery(document).ready(function($) {

	/* ------------------------------------------------- */
	/* Beelden swappen
	/* ------------------------------------------------- */
	if($('div#product-pictures').size() > 0) {
		$('#big-pictures a').hide();
		$('#big-pictures a:first-child').show();

		$('div#product-pictures ul li a').click(function (e) {
			e.preventDefault();
			var active = $(this).attr('rel');
			$('#big-pictures a').hide();
			$('#big-pictures #' + active).fadeIn();
		});
	}
	/* ------------------------------------------------- */
	/* Scroll text
	/* ------------------------------------------------- */
	$('#scroll-text').jScrollPane({scrollbarWidth:11,dragMinHeight:49,dragMaxHeight:49});

	/* ------------------------------------------------- */
	/* Scroller
	/* ------------------------------------------------- */
	$("#scroller").smoothDivScroll({autoScroll:'always',autoScrollDirection:'endlessloop',pauseAutoScroll:'mouseover',scrollingSpeed:1});
	$("div.slideshow").cycle();
	/* ------------------------------------------------- */
	/* NEWSLETTER 
	/* ------------------------------------------------- */
	$('#SubscriptionAddForm #feedback').hide();
	function initNewsletter()
	{
		$('#SubscriptionAddForm button').unbind('click').click(function(e) {
			e.preventDefault();
			var url = 'proxy.php';
			$(this).ajaxStart(function() { $(this).attr('disabled', 'disabled'); })
			$.ajax({
				url: url,
				type: 'POST',
				data: $.param($('#SubscriptionAddForm #SubscriptionEmail')),
				complete: function() {
					initNewsletter();
				},
				success: function(data, textStatus) {
					if(textStatus == 'success')
					{
						console.log(data);
						$('#SubscriptionAddForm').replaceWith(data);
					}
				}
			});
			return false;
			}).removeAttr('disabled');
		}
		initNewsletter();
		/* ------------------------------------------------- */
		/* PAGINATION
		/* ------------------------------------------------- */
		// The elements that will be displayed are in a hidden DIV and are
		// cloned for display. The elements are static, there are no Ajax
		// calls involved.

		/**
		* Callback function that displays the content.
		*
		* Gets called every time the user clicks on a pagination link.
		*
		* @param {int} page_index New Page index
		* @param {jQuery} jq the container with the pagination links as a jQuery object
		*/

		var items_per_page = 12;

		function pageselectCallback(page_index, jq){

			var total = $('#category-list-hidden li').length ;
			var content = '';

			$('#category-list').empty();

			var i = page_index * items_per_page;

			for(var j = i; j < (i + items_per_page); j++) {
				$('#category-list').append($('#category-list-hidden li:eq('+ j +')').clone());
			}

			return false;
		}

		/**
		* Initialisation function for pagination
		*/
		function initPagination() {
			// count entries inside the hidden content
			var num_entries = $('#category-list-hidden li').length;

			if(num_entries <= items_per_page){
				$('#paginator').hide();
			}

			if(num_entries > 0){
				// Create content inside pagination element
				$("#paginator").pagination(num_entries, {
					callback: pageselectCallback,
					items_per_page:items_per_page,
					current_page: 0,
					next_text: 'next',
					prev_text: 'previous'
				});
			}
		}

		// initialize pagination
		initPagination();
		/* ------------------------------------------------- */
		/* PAGINATE PERS
		/* ------------------------------------------------- */
		if($('#pers-items div').size() > 0) $('#pers-items div').quickpaginate({perpage:4,showcounter:false,pager:$('#pager')});
		/* ------------------------------------------------- */
		/* VALIDATION FORM
		/* ------------------------------------------------- */
		if($('#form-contact').size() > 0) {
			$("#form-contact").validate();
		}
});

/*
* Tooltip script 
* powered by jQuery (http://www.jquery.com)
* 
* written by Alen Grakalic (http://cssglobe.com)
* 
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
*/
tooltip = function(){	
	/* CONFIG */		
	xOffset = 20;
	yOffset = 20;		
	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e) {
		this.t = this.title;
		this.title = "";
		$("body").append("<div id='tooltip'>"+ this.t +"</div>");
		$("#tooltip")
		.css("top",(e.pageY + yOffset) + "px")
		.css("left",(e.pageX - xOffset) + "px")
		.fadeIn("fast");
	},
	function(){
		this.title = this.t;
		$("#tooltip").remove();
	}); 
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
		.css("top",(e.pageY + yOffset) + "px")
		.css("left",(e.pageX - xOffset) + "px")
	});
};

// starting the script on page load
$(document).ready(function(){
	tooltip();
});
