function buildSlider(a, b, c, d, e) {
    if (c == null || c < 1) {
        c = 558;
    }
    if (d == null || d < 1) {
        d = 247
    }
    var slider = $(e);
    slider.css({ width: c + "px", height: d + "px" });
    if (a.length == b.length) {
        if (a.length > 0) {
            var listitems = '<div class="royalLoadingScreen"><img src="' + a[0] + '" alt="" /></div>';
            listitems = listitems + '<ul class="royalSlidesContainer">';
            for (i = 0; i < a.length; i++) {
                listitems = listitems + '<li class="royalSlide" style="background-image:url(' + a[i] + ');">';
                if (b[i] != null && b[i] != "") {
                    listitems = listitems + '<a href="' + b[i] + '">&nbsp;</a>';
                }
                listitems = listitems + '</li>';
            }
            listitems = listitems + '</ul>';
            slider.html(listitems);
        }
    }
    else {
        alert("Image array en link array hebben een ongelijk aantal items!");
    }
}
function RoyalSlider (a,b) {
	if ("ontouchstart" in window) {
		this.hasTouch = true
	}
	else {
		this.hasTouch = false
	}
	this.slider = $(a);
	var c = this;
	this.defaults = {
		directionNavEnabled:true,
		directionNavAutoHide:false,
		slideTransitionSpeed:400,
		slideTransitionEasing:"easeInOutSine",
		captionAnimationEnabled:true,
		captionShowEffects:["fade","moveleft"],
		captionMoveOffset:20,
		captionShowSpeed:400,
		captionShowEasing:"easeOutCubic",
		captionShowDelay:200,
		controlNavEnabled:true,
		controlNavThumbs:false,
		slideshowEnabled:false,
		slideshowDelay:5000,
		slideshowPauseOnHover:true,
		welcomeScreenEnabled:true,
		welcomeScreenShowSpeed:500,
		minSlideOffset:20,
		showSlideNumbers:false,
		hideArrowOnLastSlide:false,
		beforeSlideChange:function() {
		}
		,afterSlideChange:function() {
		}
		,loadingComplete:function() {
		}
	};
	this.settings = $.extend ( {
	},
	this.defaults,b);

	if (this.hasTouch) {
		this.settings.directionNavAutoHide = false;
		this.settings.hideArrowOnLastSlide = true
	}
	this.isSlideshowRunning = false;
	this._az = this.slider.find(".royalSlidesContainer");
	this._by = this._az.wrap ('<div class = "royalWrapper"/>').parent();
	this.slides = this._az.find(".royalSlide");
	this.sliderWidth = 0;
	this.sliderHeight = 0;
	this.slideshowTimer = '';
	this.numSlides = this.slides.length;
	this.currentSlideId = 0;
	this.lastSlideId = -1;
	this.isAnimating = true;
	this._cx = 0;
	this._dw = 0;
	this._ev = [];
	this._fu = 0;
	this._gt = 0;
	this._hs = 0;
	this._ir = 0;
	this._jq = false;
	this._kp = false;
	this._lo = false;
	if (this.settings.slideshowEnabled) {
		if (this.settings.slideshowDelay > 0) {
			if (this.settings.slideshowPauseOnHover) {
				this.slider.hover (function() {
					c._lo = true;
					c.stopSlideshow()
				}, function() {
					c._lo = false;
					c.resumeSlideshow()
					});
			}
		}
	}
	var d = "";
	if ($.browser.msie) {
		if (parseInt($.browser.version) == 7) {
			this.isIE7 = true;
			this._az.css("cursor","move")
		}
		else {
			this.isIE7 = false
		}
	}
	if ($.browser.opera) {
		mn = "move";
		_az1 = "move"
	}
	else {
		if ($.browser.mozilla) {
			mn = "-moz-grab";
			_az1 = "-moz-grabbing"
		}
		else {
			mn = "url (img/cursors/grab.cur), move";
			_az1 = "url (img/cursors/grabbing.cur), move"
		}
		mn = $.browser.mozilla?"-moz-grab":"url (img/cursors/grab.cur), move";
		_az1 = $.browser.mozilla?"-moz-grabbing":"url (img/cursors/grabbing.cur), move"
	}
	this._by1();
	if (this.settings.controlNavEnabled) {
		if (!c.settings.controlNavThumbs) {
			var e = $('<div class = "royalControlNavOverflow"><div class = "royalControlNavContainer"><div class = "royalControlNavCenterer"></div></div></div>')
		}
		else {
			var e = $('<div class = "royalControlNavOverflow royalThumbs"><div class = "royalControlNavContainer"><div class = "royalControlNavCenterer"></div></div></div>')
		}
		var f = e.find('.royalControlNavCenterer');
		var g = 0;
		this.slides.each(function() {
			if (c.settings.controlNavThumbs) {
				f.append ("<a href = '#' class = 'royalThumb' style = 'background-image:url ("+$(this).attr("data-thumb")+");'/>")
			}
			else {
				if (c.settings.showSlideNumbers) {
					f.append ('<a href = "#">' + (g+1) + '</a>')
				}
				else {
					f.append ('<a href = "#" />')
				}
			}
			g++
		});
		this.navItems = f.children();
		this.navItems.eq (0).addClass ("current");
		this.navItems.eq (this.navItems.length-1).addClass ("last");
		this._by.after (e)
	}
	if (this.settings.captionAnimationEnabled) {
		this._by.find(".royalCaption").css("display","none")
	}
	if (this.settings.directionNavEnabled) {
		this._by.after ("<a href = '#' class = 'arrow left'/>");
		this._by.after ("<a href = '#' class = 'arrow right'/>");
		this.arrowLeft = this.slider.find("a.arrow.left");
		this.arrowRight = this.slider.find("a.arrow.right");
		if (this.arrowLeft.length < 1 || this.arrowRight.length < 1) {
			this.settings.directionNavEnabled = false
		}
		else if (this.settings.directionNavAutoHide) {
			this.arrowLeft.hide();
			this.arrowRight.hide();
			this.slider.hover (function() {
				c.arrowLeft.fadeIn ("fast");
				c.arrowRight.fadeIn ("fast")
			}, function() {
				c.arrowLeft.fadeOut ("fast");
				c.arrowRight.fadeOut ("fast")
			})
		}
		if (this.settings.directionNavEnabled) {
			if (this.settings.hideArrowOnLastSlide) {
				this.arrowLeft.css("visibility","hidden")
			}
		}
	}
	this.resizeTimer = null;
	$(window).bind('resize',function() {
		if (this.resizeTimer)clearTimeout (resizeTimer);
		this.resizeTimer = setTimeout (function() {
			c._ev1()
		} ,100)
	});
	this._ev1();
	if (this.settings.welcomeScreenEnabled) {
		var h = this.slides.eq (0).css("background-image");
		if (h!= ""&&h!= "none") {
			var i = new Image();
			$(i).load (function() {
				c.settings.loadingComplete.call (c);
				c.slider.find(".royalLoadingScreen").fadeOut (c.settings.welcomeScreenShowSpeed,function() {
					$(this).remove()
				});
				setTimeout (function() {
					c._fu1()
				}, c.settings.welcomeScreenShowSpeed + 100)
			});
			h = h.substring (4,h.length-1);
			if (h.charAt (0) == '"' || h.charAt (0) == "'") {
				h = h.substring (1, h.length - 1)
			}
			i.src = h
		}
		else {
			var j = this.slider.find(".royalLoadingScreen");
			if (j) {
				c.settings.loadingComplete.call (c);
				j.fadeOut (c.settings.welcomeScreenShowSpeed,function() {
					$(this).remove()
				});
				setTimeout (function() {
				c._fu1()
				}, c.settings.welcomeScreenShowSpeed + 100)
			}
			else {
				setTimeout (function() {
				c._fu1();
				c.slider.find(".royalLoadingScreen").remove();
				c.settings.loadingComplete.call (c)
				}, 100)
			}
		}
	}
}

RoyalSlider.prototype = {
	goTo:function (a) {
		if (!this.isAnimating) {
			this.isAnimating = true;
			var b = this;
			this._az.unbind("mousedown").unbind("touchstart").unbind("MozTouchDown");
			if (this.settings.controlNavEnabled) {
				this.navItems.unbind("click");
				this.navItems.eq (this.currentSlideId).removeClass ('current');
				this.navItems.eq (a).addClass ("current")
			}
			this.lastSlideId = this.currentSlideId;
			this.currentSlideId = a;
			if (this.settings.directionNavEnabled) {
				if (this.settings.hideArrowOnLastSlide) {
					if (this.lastSlideId == 0) {
						this.arrowLeft.css("visibility","visible")
					}
					else if (this.lastSlideId == this.numSlides - 1) {
						this.arrowRight.css("visibility","visible")
					}
					if (this.currentSlideId == 0) {
						this.arrowLeft.css("visibility","hidden")
					}
					else if (this.currentSlideId == this.numSlides - 1) {
						this.arrowRight.css("visibility","hidden")
					}
					this.arrowRight.unbind("click");
					this.arrowLeft.unbind("click")
				}
			}
			this.settings.beforeSlideChange.call (this);
			this.stopSlideshow();
			this._az.animate ({
				left:-this.currentSlideId*this.sliderWidth
			}, this.settings.slideTransitionSpeed, this.settings.slideTransitionEasing, function() {
				b._fu1()
			})
		}
	},
	prev:function() {
		if (this.currentSlideId <= 0) {
			this.goTo (this.numSlides - 1)
		}
		else {
			this._gt1()
		}
	},
	next:function() {
		if (this.currentSlideId >= this.numSlides - 1) {
			this.goTo (0)
		}
		else {
			this._hs1()
		}
	},
	resumeSlideshow:function() {
		if (this.settings.slideshowEnabled) {
			if (this.slideshowTimer == ''&&!this._lo) {
				var a = this;
				this.slideshowTimer = setInterval (function() {
				a.next()}, this.settings.slideshowDelay);
				this.isSlideshowRunning = true
			}
		}
	},
	stopSlideshow:function() {
		if (this.settings.slideshowEnabled) {
			clearInterval (this.slideshowTimer);
			this.slideshowTimer = '';
			this.isSlideshowRunning = false
		}
	},
	_by1:function() {
		if (!this.isIE7) {
			this._az.css("cursor",mn)
		}
	},
	_ir1:function() {
		if (!this.isIE7) {
			this._az.css("cursor",_az1)
		}
	},
	_hs1:function() {
		if (this.currentSlideId < this.numSlides - 1) {
			this.goTo (this.currentSlideId + 1)
		}
		else {
			this.goTo (this.currentSlideId)
		}
	},
	_gt1:function() {
		if (this.currentSlideId > 0) {
			this.goTo (this.currentSlideId - 1)
		}
		else {
			this.goTo (this.currentSlideId)
		}
	},
	_ev1:function() {
		var a = parseInt(this._by.width());
		var b = parseInt(this._by.height());
		if (a != this.sliderWidth || b != this.sliderHeight) {
			this.sliderWidth = a;
			this.slides.each(function() {
				$(this).css( {
					height:b + "px", width:a + "px"
				})
			});
			this._az.css({
				"left":-this.currentSlideId * this.sliderWidth, width:this.sliderWidth * this.numSlides
			})
		}
	},
	_jq1:function (e) {
		this.goTo ($(e.currentTarget).index())
	},
	_kp1:function (e) {
		if (!this._jq) {
			var a;
			if (this.hasTouch) {
				var b = e.originalEvent.touches;
				if (b && b.length > 0) {
					a = b[0]
				}
				else {
					return false
				}
			}
			else {
				a = e;
				e.preventDefault()
			}
			if (this.slideshowTimer!= '') {
				this.wasSlideshowPlaying = true;
				this.stopSlideshow()
			}
			else {
				this.wasSlideshowPlaying = false
			}
			this._ir1();
			this._jq = true;
			var c = this;
			$(document).bind("mousemove touchmove MozTouchMove",function (e) {
				c._lo1 (e)
			});
			$(document).bind("mouseup touchend MozTouchRelease",function (e) {
				c.mn1 (e)
			});
			this._fu = parseInt(this._az.css("left"));
			this._gt = a.clientX;
			this._hs = a.clientY;
			this._ir = parseInt(this._az.css("left"))
		}
		return false
	},
	_lo1:function (e) {
		var a;
		if (this.hasTouch) {
			var b = e.originalEvent.touches;
			if (b.length > 1) {
				return false
			}
			a = b[0];
			if (Math.abs(a.clientY - this._hs) + 10 > Math.abs (a.clientX - this._gt)) {
				return false
			}
			e.preventDefault()
		}
		else {
			a = e;
			e.preventDefault()
		}
		this._dw = this._cx;
		var c = a.clientX-this._gt;
		if (this._dw!= c) {
			this._cx = c
		}
		if (c!= 0) {
			if (this.currentSlideId == 0) {
				if (c > 0) {
					c = Math.sqrt(c) * 5
				}
			}
			else if (this.currentSlideId == (this.numSlides - 1)) {
				if (c < 0) {
					c = -Math.sqrt(-c) * 5
				}
			}
			this._az.css("left",this._fu+c)
		}
		return false
	},
	mn1:function (e) {
		if (this.wasSlideshowPlaying) {
			this.resumeSlideshow()
		}
		if (this._jq) {
			this._jq = false;
			this._by1();
			this.endPos = parseInt(this._az.css("left"));
			this.isdrag = false;
			$(document).unbind("mousemove").unbind("touchmove").unbind("MozTouchMove").unbind("mouseup").unbind("touchend").unbind("MozTouchRelease");
			if (this.endPos == this._ir) {
				return
			}
			if (this._ir - this.settings.minSlideOffset > this.endPos) {
				if (this._dw < this._cx) {
					this.goTo (this.currentSlideId);
					return false
				}
				this._hs1()
			}
			else if (this._ir + this.settings.minSlideOffset < this.endPos) {
				if (this._dw > this._cx) {
					this.goTo (this.currentSlideId);
					return false
				}
				this._gt1()
			}
			else {
				this.goTo (this.currentSlideId)
			}
		}
		return false
	},
	_fu1:function() {
		var a = this;
		this.resumeSlideshow();
		if (this.settings.controlNavEnabled) {
			this.navItems.bind("click",function (e) {
				e.preventDefault();
				a._jq1 (e)
			})
		}
		this._az.bind("mousedown touchstart MozTouchDown",function (e) {
			a._kp1 (e)
		});
		if (this.settings.directionNavEnabled) {
			this.arrowRight.bind('click',function (e) {
				e.preventDefault();
				a.next()
			});
			this.arrowLeft.bind('click',function (e) {
				e.preventDefault();
				a.prev()
			})
		}
		if (this.settings.captionAnimationEnabled&&this.lastSlideId!= this.currentSlideId) {
			if (this.lastSlideId!= -1) {
				this.slides.eq (this.lastSlideId).find(".royalCaption").css("display","none")
			}
			setTimeout (function() {
				a._az2 (this.currentSlideId)
			} ,10)
		}
		this.isAnimating = false;
		this.settings.afterSlideChange.call(this)
	},
	_az2:function (e) {
		var f = this.slides.eq(this.currentSlideId).find(".royalCaption");
		if (f.length) {
			f.css("display","block");
			var g = this;
			var h;
			var j = f.children();
			var k;
			var l;
			var m;
			var n;
			var o;
			var p;
			var r;
			var s;
			var t;
			var u;
			var v;
			var w;
			if (this._ev.length > 0) {
				for (var a = this._ev.length; a > -1; a--) {
					clearTimeout (this._ev.splice (a,1))
				}
			}
			for (var i = 0; i < j.length; i++) {
				h = $(j[i]);
				n = {};
				k = false;
				l = false;
				o = "";
				if (h.attr("data-show-effect") == undefined) {
					p = this.settings.captionShowEffects
				}
				else {
					p = h.attr("data-show-effect").split (" ")
				}
				for (var q = 0; q < p.length; q++) {
					if (k && l) {
						break
					}
					m = p[q].toLowerCase();
					if (!k && m == "fade") {
						k = true;
						n['opacity'] = 1
					}
					else if (l) {
						break
					}
					else if (m == "movetop") {
						o = "margin-top"
					}
					else if (m == "moveleft") {
						o = "margin-left"
					}
					else if (m == "movebottom") {
						o = "margin-bottom"
					}
					else if (m == "moveright") {
						o = "margin-right"
					}
					if (o != "") {
						n['moveProp'] = o;
						n['moveStartPos'] = parseInt(h.css(o));
						l = true
					}
				}
				s = parseInt(h.attr("data-move-offset"));
				if (isNaN (s)) {
					s = this.settings.captionMoveOffset
				}
				t = parseInt(h.attr("data-delay"));
				if (isNaN (t)) {
					t = g.settings.captionShowDelay * i + 10
				}
				u = parseInt(h.attr("data-speed"));
				if (isNaN (u)) {
					u = g.settings.captionShowSpeed
				}
				v = h.attr("data-easing");
				if (v == undefined) {
					v = g.settings.captionShowEasing
				}
				r = {};
				if (l) {
					w = n.moveProp;
					if (w == "margin-right") {
						w = "margin-left";
						r[w] = n.moveStartPos + s + "px"
					}
					else if (w == "margin-bottom") {
						w = "margin-top";
						r[w] = n.moveStartPos + s + "px"
					}
					else {
						r[w] = n.moveStartPos - s + "px"
					}
				}
				if (k) {
					r.opacity = 0
				}
				h.hide().css(r);
				if (l) {
					r[w] = n.moveStartPos + "px"
				}
				if (k) {
					r.opacity = 1
				}
				this._ev.push(setTimeout((function (a,b,c,d) {
					return function() {
						a.show().animate(b,c,d)
					}
				}) (h,r,u,v),t))
			}
		}
	}
};
