I would add a special class (e.g. preview
) to each of the images which should be "clickable" and use the following script instead. With this you can add or remove videos/images easily:
$(".preview").on("click", function(ev) {
var btn = $(this);
// has this image already been clicked? Then it is "out of order"
if (btn.data("clicked")) {
ev.preventDefault();
return false;
}
// mark as clicked
btn.data("clicked", true);
// show video in fancybox
btn.closest("a").fancybox();
// if 3 images have been clicked, redirect to url
if ($('.preview[data-clicked="true"]').length == 3) {
location.href='http://www.thelinktogoto.com';
}
});