$(document).ready(function () { var animatedone = true; function getindirectiontween(e, movedirecrion, moveinspeed, moveintype) { moveinspeed = parseint(moveinspeed); e.css("opacity", "0"); switch (movedirecrion) { case '0': e.css("left", "0").css("top", "0"); e.animate({ "left": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '1': e.css("left", "0").css("top", "-460px"); e.animate({ "top": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '2': e.css("left", "460px").css("top", "-460px"); e.animate({ "top": "0", "left": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '3': e.css("left", "460px").css("top", "0"); e.animate({ "left": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '4': e.css("left", "460px").css("top", "460px"); e.animate({ "left": "0", "top": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '5': e.css("left", "0").css("top", "460px"); e.animate({ "top": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '6': e.css("left", "-460px").css("top", "460px"); e.animate({ "left": "0", "top": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '7': e.css("left", "-460px").css("top", "0"); e.animate({ "left": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; case '8': e.css("left", "-460px").css("top", "-460px"); e.animate({ "left": "0", "top": "0", "opacity": "1" }, { duration: moveinspeed, easing: moveintype }); break; } } function getoutdirectiontween(e, movedirecrion, moveinspeed, moveintype) { moveinspeed = parseint(moveinspeed); switch (movedirecrion) { case '0': e.animate({ "left": "0", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '1': e.animate({ "left": "0", "top": "-460px", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '2': e.animate({ "top": "-460px", "left": "460px", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '3': e.animate({ "left": "460px", "top": "0", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '4': e.animate({ "left": "460px", "top": "460px", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '5': e.animate({ "top": "460px", "left": "0", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '6': e.animate({ "left": "-460px", "top": "460px", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '7': e.animate({ "left": "-460px", "top": "0", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; case '8': e.animate({ "left": "-460px", "top": "-460px", "opacity": 0 }, { duration: moveinspeed, easing: moveintype }); break; } } function animatein(e) { var moveinderection = e.attr('moveinderection'); var moveinspeed = e.attr('moveinspeed'); var moveintype = e.attr('moveintype'); getindirectiontween(e, moveinderection, moveinspeed, moveintype); } function animateout(e) { var moveoutderection = e.attr('moveoutderection'); var moveoutspeed = e.attr('moveoutspeed'); var moveouttype = e.attr('moveouttype'); getoutdirectiontween(e, moveoutderection, moveoutspeed, moveouttype); } function getmaxfromarray(arr) { var max = arr[0]; for (i = 0; i < arr.length; i++) { if (arr[i] > max) max = arr[i]; } return max; } $(".banner-bt .pointer").click(function () { var currentclick = false; var current = $(".banner-bt").find(".active"); var pretarget = current.attr("target"); var target = $(this).attr("target"); if (pretarget == target) currentclick = true; if (!currentclick) { if (animatedone) { current.removeclass("active"); $(this).addclass("active"); animatedone = false; var preobjectleft = $(".left" + pretarget); var preobjectright = $(".right" + pretarget); var objectleft = $(".left" + target); var objectright = $(".right" + target); preobjectleft.css("z-index", "0"); preobjectright.css("z-index", "0"); objectleft.css("z-index", "9999"); objectright.css("z-index", "9999"); var speedarray = [objectleft.attr('moveinspeed'), objectleft.attr('fadeinspeed'), objectright.attr('moveinspeed'), objectright.attr('fadeinspeed'), ]; var animatetime = parseint(getmaxfromarray(speedarray)) + 1000; animateout(preobjectleft); animateout(preobjectright); animatein(objectleft); animatein(objectright); settimeout(animatedonefunction, animatetime); } } }); function animatedonefunction() { animatedone = true; } function initilanimate() { $($(".banner-bt .pointer")[0]).click(); var autoswitch = function () { $(".banner-bt .pointer").each(function (e) { if ($(this).hasclass("active")) { if (e == 3) $(".banner-bt .pointer:eq(0)").click(); else $(".banner-bt .pointer:eq(" + (e + 1) + ")").click(); } else { } }); } window.setinterval(autoswitch, 3750); } initilanimate(); });