jQuery(document).ready(function($) {

	if(/webkit(.*)mobile/i.test(navigator.userAgent))
		document.body.className += " isMobileWebkit";

/* Hint ====================== */
	// render placeholder hints on input elements with hint class
	$('input.hint').hint();
/* End Hint ====================== */


/* teaserslider ====================== */
	$('#teaserSlider').slides({
		preload: true,
		pagination: true,
		generatePagination: false,
		play: 7500
	});
//	$('.teaserSlider.inEditor > ul.pagination').attr('data-ipub-editable', 'false');

/* End teaserslider =================== */


/* banner teaser ====================== */
	$(".banner.hover > .control").bind("mouseover",function(){
		$(this).next(".description").show();
	});
	$(".banner.hover > .control").bind("mouseout",function(){
		$(this).next(".description").hide();
	});
/* End banner teaser =================== */


/* IntraCalender ====================== */
	// show first calendar
	// toggle Calendar
	var toggleCalendar = function() {
		var expandableDiv = $(this).next('.expandable');

		if(!expandableDiv.hasClass('expanded')) {
			//reset existing expanded tabs
			$(".content-store-gardencalendar .expanded").children().slideUp()
			$(".content-store-gardencalendar .expanded").removeClass('expanded');

			//expand this tab
			expandableDiv.addClass('expanded');
			expandableDiv.children().slideDown('1000');
		}
	};

	$('div.toggleCalendar').click(toggleCalendar);

	var anchor = document.location.href.split('#')[1],
		items = $('.intraCalendar-container h2');
	if (items.length)	{
		if (anchor) {
			items.each(function(i, el)    {
				if (el.innerHTML.toLowerCase().indexOf(unescape(anchor.toLowerCase())) != -1)	{
					toggleCalendar.call(el.parentNode)
				}
			});
		}
		else
			toggleCalendar.call(items[0].parentNode);
	}

/* End IntraCalender ================== */


/* IntraStore ====================== */
	// toggle Calendar
	$('.toggleExtraOpenTimes').click(function() {
		var expandableList = $('.extraOpenTimes.two');

		if(!expandableList.hasClass('expanded')) {
			//open
			expandableList.addClass('expanded');
			expandableList.slideDown('1000');
		} else {
			//close
			expandableList.slideUp('1000')
			expandableList.removeClass('expanded');
		}
		if (typeof FB != undefined) setTimeout(function()	{
			try {
				FB.Canvas.setSize({
					width: '*',
					height: document.body.offsetHeight
				});
			} catch (e) {};
		},1100);
	});
/* End IntraCalender ================== */

/* Intrawishlist ====================== */
	// toggle wishlist
	$('#wishListHandler').hover(
		function() {
			$('#wishListHandler').addClass('expanded')
			$('#wishlistitems').stop().animate({},'slow');
		}, function() {
			$('#wishListHandler').removeClass('expanded')
			$('#wishlistitems').stop().animate({}, 'slow');
		}
	);

	//delete function
	$('a.deleteWishListItem').click(function() {
		$(this).next('.wishListItem').attr('checked', true);
		$(this).parents('form').submit();
	});
/* End wishlist ================== */


/* Intrasearch ====================== */
	// toggle advancedsearch
	$('#searchBox').focus(function() {
		$('.form-search').addClass('expanded')
		$('.advanced-search').slideDown('1000');
	});

	$(document.body).click(function(e)    {
		var t = $(e.target);
		if (!t.parents("#zoekformulier").length)    {
			$('.form-search').removeClass('expanded')
			$('.advanced-search').slideUp('1000');
		}
	});

	$(".seachPagerContainer ol.paging").quickPager();
/* End intrasearch ================== */

/* antispam anchors ================== */
	function cod(input) {
		var coding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMabcdefghijklmnopqrstuvwxyzabcdefghijklm';

		for (var text = '',i=0;i<input.length;i++) {
			character = input.charAt(i);
			position = coding.indexOf(character);
			if (position > -1)
				character = coding.charAt(position + 13);
			text += character;
		}

		return text;
	}

	function dec() {
		if (this.href.indexOf('mailto:')!=0) {
			this.href=cod(this.href);
		}
	}

	$("a.antispam").mouseover(dec);
/* End antispam anchors ================== */


/* check if .be homepage ================== */
	if(window.location.host=='www.intratuin.be') {
		var beImg = new Image();
		beImg.src = '_project/fromBe.php';
	}
/* END check if .be homepage =============== */

});

/* gallery assist ================== */

	function setupGallery(el) {
		var 
			showPicture = function(e, el) {
				if (!el) el = this;
				if (!el || !el.id) return;
				var id = el.id.split('_')[1],
					src = $('#preload_'+id)[0].getAttribute('data-src'),
					preview = $('.IntraGallery .preview img')[0];
				try {
					preview.onload = null;
					preview.removeAttribute('onload');
				} catch(e){}
				preview.src = src;
				preview.fileId = id;
				$('.IntraGallery a.download')[0].href = src + '&fd=1';
			},
			el = $(el),
			imgArr = el.find('.thumbs img')
		;
		
		/* setup listeners */
		imgArr.click(showPicture);
		/* onload show first */
		showPicture(null,imgArr[0]);
/* remove temlate header */
//$('.content-header').html('').hide();
		/* setup controls: back */
		el.find('a.previous').click(function() {
			var id = el.find('.preview img')[0].fileId,
				prevEl = el.find('img[id=preload_'+id+']')[0].previousSibling;
			showPicture(null, prevEl);
		});
		/* setup controls: forward */
		el.find('a.next').click(function() {
			var id = el.find('.preview img')[0].fileId,
				nextEl = el.find('img[id=preload_'+id+']')[0].nextSibling;
			showPicture(null, nextEl);
		});
		
		/* now we can fetch our preloads */
		el.find('.preloadable').each(function() {
			this.src = this.getAttribute('data-src');
		});
		
	};
	
/* END gallery assist ============== */
