idangerous.swiper.js 122 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874
/*
 * Swiper 2.7.5
 * Mobile touch slider and framework with hardware accelerated transitions
 *
 * http://www.idangero.us/sliders/swiper/
 *
 * Copyright 2010-2015, Vladimir Kharlampidi
 * The iDangero.us
 * http://www.idangero.us/
 *
 * Licensed under GPL & MIT
 *
 * Released on: January 4, 2015
 */

/*
 * Modified by chenglong.wang@yoho.cn on 2015/1/13
 */
define("plugins/idangerous.swiper", [], function(require, exports, module) {

    var Swiper = function(selector, params) {
        'use strict';

        /*=========================
          A little bit dirty but required part for IE8 and old FF support
          ===========================*/
        if (!document.body.outerHTML && document.body.__defineGetter__) {
            if (HTMLElement) {
                var element = HTMLElement.prototype;
                if (element.__defineGetter__) {
                    element.__defineGetter__('outerHTML', function() {
                        return new XMLSerializer().serializeToString(this);
                    });
                }
            }
        }

        if (!window.getComputedStyle) {
            window.getComputedStyle = function(el, pseudo) {
                this.el = el;
                this.getPropertyValue = function(prop) {
                    var re = /(\-([a-z]){1})/g;
                    if (prop === 'float') prop = 'styleFloat';
                    if (re.test(prop)) {
                        prop = prop.replace(re, function() {
                            return arguments[2].toUpperCase();
                        });
                    }
                    return el.currentStyle[prop] ? el.currentStyle[prop] : null;
                };
                return this;
            };
        }
        if (!Array.prototype.indexOf) {
            Array.prototype.indexOf = function(obj, start) {
                for (var i = (start || 0), j = this.length; i < j; i++) {
                    if (this[i] === obj) {
                        return i;
                    }
                }
                return -1;
            };
        }
        if (!document.querySelectorAll) {
            if (!window.jQuery) return;
        }

        function $$(selector, context) {
            if (document.querySelectorAll)
                return (context || document).querySelectorAll(selector);
            else
                return jQuery(selector, context);
        }

        /*=========================
          Check for correct selector
          ===========================*/
        if (typeof selector === 'undefined') return;

        if (!(selector.nodeType)) {
            if ($$(selector).length === 0) return;
        }

        /*=========================
         _this
         ===========================*/
        var _this = this;

        /*=========================
         Default Flags and vars
         ===========================*/
        _this.touches = {
            start: 0,
            startX: 0,
            startY: 0,
            current: 0,
            currentX: 0,
            currentY: 0,
            diff: 0,
            abs: 0
        };
        _this.positions = {
            start: 0,
            abs: 0,
            diff: 0,
            current: 0
        };
        _this.times = {
            start: 0,
            end: 0
        };

        _this.id = (new Date()).getTime();
        _this.container = (selector.nodeType) ? selector : $$(selector)[0];
        _this.isTouched = false;
        _this.isMoved = false;
        _this.activeIndex = 0;
        _this.centerIndex = 0;
        _this.activeLoaderIndex = 0;
        _this.activeLoopIndex = 0;
        _this.previousIndex = null;
        _this.velocity = 0;
        _this.snapGrid = [];
        _this.slidesGrid = [];
        _this.imagesToLoad = [];
        _this.imagesLoaded = 0;
        _this.wrapperLeft = 0;
        _this.wrapperRight = 0;
        _this.wrapperTop = 0;
        _this.wrapperBottom = 0;
        _this.isAndroid = navigator.userAgent.toLowerCase().indexOf('android') >= 0;
        var wrapper, slideSize, wrapperSize, direction, isScrolling, containerSize;

        /*=========================
          Default Parameters
          ===========================*/
        var defaults = {
            eventTarget: 'wrapper', // or 'container'
            mode: 'horizontal', // or 'vertical'
            touchRatio: 1,
            speed: 300,
            freeMode: false,
            freeModeFluid: false,
            momentumRatio: 1,
            momentumBounce: true,
            momentumBounceRatio: 1,
            slidesPerView: 1,
            slidesPerGroup: 1,
            slidesPerViewFit: true, //Fit to slide when spv "auto" and slides larger than container
            simulateTouch: true,
            followFinger: true,
            shortSwipes: true,
            longSwipesRatio: 0.5,
            moveStartThreshold: false,
            onlyExternal: false,
            createPagination: true,
            pagination: false,
            paginationElement: 'span',
            paginationClickable: false,
            paginationAsRange: true,
            resistance: true, // or false or 100%
            scrollContainer: false,
            preventLinks: true,
            preventLinksPropagation: false,
            noSwiping: false, // or class
            noSwipingClass: 'swiper-no-swiping', //:)
            initialSlide: 0,
            keyboardControl: false,
            mousewheelControl: false,
            mousewheelControlForceToAxis: false,
            useCSS3Transforms: true,
            // Autoplay
            autoplay: false,
            autoStopPlay: true, //当用户手动切换页面的时候是否自动停止播放
            autoplayDisableOnInteraction: true,
            autoplayStopOnLast: false,
            //Loop mode
            loop: false,
            loopAdditionalSlides: 0,
            // Round length values
            roundLengths: false,
            //Auto Height
            calculateHeight: false,
            //Apply CSS for width and/or height
            cssWidthAndHeight: false, // or true or 'width' or 'height'
            //Images Preloader
            updateOnImagesReady: true,
            //Form elements
            releaseFormElements: true,
            //Watch for active slide, useful when use effects on different slide states
            watchActiveIndex: false,
            //Slides Visibility Fit
            visibilityFullFit: false,
            //Slides Offset
            offsetPxBefore: 0,
            offsetPxAfter: 0,
            offsetSlidesBefore: 0,
            offsetSlidesAfter: 0,
            centeredSlides: false,
            //Queue callbacks
            queueStartCallbacks: false,
            queueEndCallbacks: false,
            //Auto Resize
            autoResize: true,
            resizeReInit: false,
            //DOMAnimation
            DOMAnimation: true,
            //Slides Loader
            loader: {
                slides: [], //array with slides
                slidesHTMLType: 'inner', // or 'outer'
                surroundGroups: 1, //keep preloaded slides groups around view
                logic: 'reload', //or 'change'
                loadAllSlides: false
            },
            // One way swipes
            swipeToPrev: true,
            swipeToNext: true,
            //Namespace
            slideElement: 'div',
            slideClass: 'swiper-slide',
            slideActiveClass: 'swiper-slide-active',
            slideVisibleClass: 'swiper-slide-visible',
            slideDuplicateClass: 'swiper-slide-duplicate',
            wrapperClass: 'swiper-wrapper',
            paginationElementClass: 'swiper-pagination-switch',
            paginationActiveClass: 'swiper-active-switch',
            paginationVisibleClass: 'swiper-visible-switch'
        };
        params = params || {};
        for (var prop in defaults) {
            if (prop in params && typeof params[prop] === 'object') {
                for (var subProp in defaults[prop]) {
                    if (!(subProp in params[prop])) {
                        params[prop][subProp] = defaults[prop][subProp];
                    }
                }
            } else if (!(prop in params)) {
                params[prop] = defaults[prop];
            }
        }
        _this.params = params;
        if (params.scrollContainer) {
            params.freeMode = true;
            params.freeModeFluid = true;
        }
        if (params.loop) {
            params.resistance = '100%';
        }
        var isH = params.mode === 'horizontal';

        /*=========================
          Define Touch Events
          ===========================*/
        var desktopEvents = ['mousedown', 'mousemove', 'mouseup'];
        if (_this.browser.ie10) desktopEvents = ['MSPointerDown', 'MSPointerMove', 'MSPointerUp'];
        if (_this.browser.ie11) desktopEvents = ['pointerdown', 'pointermove', 'pointerup'];

        _this.touchEvents = {
            touchStart: _this.support.touch || !params.simulateTouch ? 'touchstart' : desktopEvents[0],
            touchMove: _this.support.touch || !params.simulateTouch ? 'touchmove' : desktopEvents[1],
            touchEnd: _this.support.touch || !params.simulateTouch ? 'touchend' : desktopEvents[2]
        };

        /*=========================
          Wrapper
          ===========================*/
        for (var i = _this.container.childNodes.length - 1; i >= 0; i--) {
            if (_this.container.childNodes[i].className) {
                var _wrapperClasses = _this.container.childNodes[i].className.split(/\s+/);
                for (var j = 0; j < _wrapperClasses.length; j++) {
                    if (_wrapperClasses[j] === params.wrapperClass) {
                        wrapper = _this.container.childNodes[i];
                        wrapper.style.backgroundColor = "#fff";
                    }
                }
            }
        }

        _this.wrapper = wrapper;
        /*=========================
          Slide API
          ===========================*/
        _this._extendSwiperSlide = function(el) {
            el.append = function() {
                if (params.loop) {
                    el.insertAfter(_this.slides.length - _this.loopedSlides);
                } else {
                    _this.wrapper.appendChild(el);
                    _this.reInit();
                }

                return el;
            };
            el.prepend = function() {
                if (params.loop) {
                    _this.wrapper.insertBefore(el, _this.slides[_this.loopedSlides]);
                    _this.removeLoopedSlides();
                    _this.calcSlides();
                    _this.createLoop();
                } else {
                    _this.wrapper.insertBefore(el, _this.wrapper.firstChild);
                }
                _this.reInit();
                return el;
            };
            el.insertAfter = function(index) {
                if (typeof index === 'undefined') return false;
                var beforeSlide;

                if (params.loop) {
                    beforeSlide = _this.slides[index + 1 + _this.loopedSlides];
                    if (beforeSlide) {
                        _this.wrapper.insertBefore(el, beforeSlide);
                    } else {
                        _this.wrapper.appendChild(el);
                    }
                    _this.removeLoopedSlides();
                    _this.calcSlides();
                    _this.createLoop();
                } else {
                    beforeSlide = _this.slides[index + 1];
                    _this.wrapper.insertBefore(el, beforeSlide);
                }
                _this.reInit();
                return el;
            };
            el.clone = function() {
                return _this._extendSwiperSlide(el.cloneNode(true));
            };
            el.remove = function() {
                _this.wrapper.removeChild(el);
                _this.reInit();
            };
            el.html = function(html) {
                if (typeof html === 'undefined') {
                    return el.innerHTML;
                } else {
                    el.innerHTML = html;
                    return el;
                }
            };
            el.index = function() {
                var index;
                for (var i = _this.slides.length - 1; i >= 0; i--) {
                    if (el === _this.slides[i]) index = i;
                }
                return index;
            };
            el.isActive = function() {
                if (el.index() === _this.activeIndex) return true;
                else return false;
            };
            if (!el.swiperSlideDataStorage) el.swiperSlideDataStorage = {};
            el.getData = function(name) {
                return el.swiperSlideDataStorage[name];
            };
            el.setData = function(name, value) {
                el.swiperSlideDataStorage[name] = value;
                return el;
            };
            el.data = function(name, value) {
                if (typeof value === 'undefined') {
                    return el.getAttribute('data-' + name);
                } else {
                    el.setAttribute('data-' + name, value);
                    return el;
                }
            };
            el.getWidth = function(outer, round) {
                return _this.h.getWidth(el, outer, round);
            };
            el.getHeight = function(outer, round) {
                return _this.h.getHeight(el, outer, round);
            };
            el.getOffset = function() {
                return _this.h.getOffset(el);
            };
            return el;
        };

        //Calculate information about number of slides
        _this.calcSlides = function(forceCalcSlides) {
            var oldNumber = _this.slides ? _this.slides.length : false;
            _this.slides = [];
            _this.displaySlides = [];
            for (var i = 0; i < _this.wrapper.childNodes.length; i++) {
                if (_this.wrapper.childNodes[i].className) {
                    var _className = _this.wrapper.childNodes[i].className;
                    var _slideClasses = _className.split(/\s+/);
                    for (var j = 0; j < _slideClasses.length; j++) {
                        if (_slideClasses[j] === params.slideClass) {
                            _this.slides.push(_this.wrapper.childNodes[i]);
                        }
                    }
                }
            }
            for (i = _this.slides.length - 1; i >= 0; i--) {
                _this._extendSwiperSlide(_this.slides[i]);
            }
            if (oldNumber === false) return;
            if (oldNumber !== _this.slides.length || forceCalcSlides) {

                // Number of slides has been changed
                removeSlideEvents();
                addSlideEvents();
                _this.updateActiveSlide();
                if (_this.params.pagination) _this.createPagination();
                _this.callPlugins('numberOfSlidesChanged');
            }
        };

        //Create Slide
        _this.createSlide = function(html, slideClassList, el) {
            slideClassList = slideClassList || _this.params.slideClass;
            el = el || params.slideElement;
            var newSlide = document.createElement(el);
            newSlide.innerHTML = html || '';
            newSlide.className = slideClassList;
            return _this._extendSwiperSlide(newSlide);
        };

        //Append Slide
        _this.appendSlide = function(html, slideClassList, el) {
            if (!html) return;
            if (html.nodeType) {
                return _this._extendSwiperSlide(html).append();
            } else {
                return _this.createSlide(html, slideClassList, el).append();
            }
        };
        _this.prependSlide = function(html, slideClassList, el) {
            if (!html) return;
            if (html.nodeType) {
                return _this._extendSwiperSlide(html).prepend();
            } else {
                return _this.createSlide(html, slideClassList, el).prepend();
            }
        };
        _this.insertSlideAfter = function(index, html, slideClassList, el) {
            if (typeof index === 'undefined') return false;
            if (html.nodeType) {
                return _this._extendSwiperSlide(html).insertAfter(index);
            } else {
                return _this.createSlide(html, slideClassList, el).insertAfter(index);
            }
        };
        _this.removeSlide = function(index) {
            if (_this.slides[index]) {
                if (params.loop) {
                    if (!_this.slides[index + _this.loopedSlides]) return false;
                    _this.slides[index + _this.loopedSlides].remove();
                    _this.removeLoopedSlides();
                    _this.calcSlides();
                    _this.createLoop();
                } else _this.slides[index].remove();
                return true;
            } else return false;
        };
        _this.removeLastSlide = function() {
            if (_this.slides.length > 0) {
                if (params.loop) {
                    _this.slides[_this.slides.length - 1 - _this.loopedSlides].remove();
                    _this.removeLoopedSlides();
                    _this.calcSlides();
                    _this.createLoop();
                } else _this.slides[_this.slides.length - 1].remove();
                return true;
            } else {
                return false;
            }
        };
        _this.removeAllSlides = function() {
            var num = _this.slides.length;
            for (var i = _this.slides.length - 1; i >= 0; i--) {
                _this.slides[i].remove();
                if (i === num - 1) {
                    _this.setWrapperTranslate(0);
                }
            }
        };
        _this.getSlide = function(index) {
            return _this.slides[index];
        };
        _this.getLastSlide = function() {
            return _this.slides[_this.slides.length - 1];
        };
        _this.getFirstSlide = function() {
            return _this.slides[0];
        };

        //Currently Active Slide
        _this.activeSlide = function() {
            return _this.slides[_this.activeIndex];
        };

        /*=========================
         Wrapper for Callbacks : Allows additive callbacks via function arrays
         ===========================*/
        _this.fireCallback = function() {
            var callback = arguments[0];
            if (Object.prototype.toString.call(callback) === '[object Array]') {
                for (var i = 0; i < callback.length; i++) {
                    if (typeof callback[i] === 'function') {
                        callback[i].apply(arguments[1], [arguments[2], arguments[3], arguments[4], arguments[5]]);
                        //callback[i](arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
                    }
                }
            } else if (Object.prototype.toString.call(callback) === '[object String]') {
                if (params['on' + callback]) _this.fireCallback(params['on' + callback], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
            } else {
                callback(arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
                //console.log (typeof callback)
                // callback.apply(arguments[1], [arguments[2], arguments[3], arguments[4], arguments[5]]);
            }
        };

        function isArray(obj) {
            if (Object.prototype.toString.apply(obj) === '[object Array]') return true;
            return false;
        }

        /**
         * Allows user to add callbacks, rather than replace them
         * @param callback
         * @param func
         * @return {*}
         */
        _this.addCallback = function(callback, func) {
            var _this = this,
                tempFunc;
            if (_this.params['on' + callback]) {
                if (isArray(this.params['on' + callback])) {
                    return this.params['on' + callback].push(func);
                } else if (typeof this.params['on' + callback] === 'function') {
                    tempFunc = this.params['on' + callback];
                    this.params['on' + callback] = [];
                    this.params['on' + callback].push(tempFunc);
                    return this.params['on' + callback].push(func);
                }
            } else {
                this.params['on' + callback] = [];
                return this.params['on' + callback].push(func);
            }
        };
        _this.removeCallbacks = function(callback) {
            if (_this.params['on' + callback]) {
                _this.params['on' + callback] = null;
            }
        };

        /*=========================
          Plugins API
          ===========================*/
        var _plugins = [];
        //console.dir(_this.plugins);
        for (var plugin in _this.plugins) {
            if (params[plugin]) {
                var p = _this.plugins[plugin](_this, params[plugin]);
                if (p) _plugins.push(p);
            }
        }
        _this.callPlugins = function(method, args) {
            if (!args) args = {};
            for (var i = 0; i < _plugins.length; i++) {
                if (method in _plugins[i]) {
                    _plugins[i][method](args);
                }
            }
        };

        /*=========================
          Windows Phone 8 Fix
          ===========================*/
        if ((_this.browser.ie10 || _this.browser.ie11) && !params.onlyExternal) {
            _this.wrapper.classList.add('swiper-wp8-' + (isH ? 'horizontal' : 'vertical'));
        }

        /*=========================
          Free Mode Class
          ===========================*/
        if (params.freeMode) {
            _this.container.className += ' swiper-free-mode';
        }

        /*==================================================
            Init/Re-init/Resize Fix
        ====================================================*/
        _this.initialized = false;
        _this.init = function(force, forceCalcSlides) {
            var _width = _this.h.getWidth(_this.container, false, params.roundLengths);
            var _height = _this.h.getHeight(_this.container, false, params.roundLengths);
            if (_width === _this.width && _height === _this.height && !force) return;

            _this.width = _width;
            _this.height = _height;

            var slideWidth, slideHeight, slideMaxHeight, wrapperWidth, wrapperHeight, slideLeft;
            var i; // loop index variable to avoid JSHint W004 / W038
            containerSize = isH ? _width : _height;
            var wrapper = _this.wrapper;

            if (force) {
                _this.calcSlides(forceCalcSlides);
            }

            if (params.slidesPerView === 'auto') {
                //Auto mode
                var slidesWidth = 0;
                var slidesHeight = 0;

                //Unset Styles
                if (params.slidesOffset > 0) {
                    wrapper.style.paddingLeft = '';
                    wrapper.style.paddingRight = '';
                    wrapper.style.paddingTop = '';
                    wrapper.style.paddingBottom = '';
                }
                wrapper.style.width = '';
                wrapper.style.height = '';
                if (params.offsetPxBefore > 0) {
                    if (isH) _this.wrapperLeft = params.offsetPxBefore;
                    else _this.wrapperTop = params.offsetPxBefore;
                }
                if (params.offsetPxAfter > 0) {
                    if (isH) _this.wrapperRight = params.offsetPxAfter;
                    else _this.wrapperBottom = params.offsetPxAfter;
                }

                if (params.centeredSlides) {
                    if (isH) {
                        _this.wrapperLeft = (containerSize - this.slides[0].getWidth(true, params.roundLengths)) / 2;
                        _this.wrapperRight = (containerSize - _this.slides[_this.slides.length - 1].getWidth(true, params.roundLengths)) / 2;
                    } else {
                        _this.wrapperTop = (containerSize - _this.slides[0].getHeight(true, params.roundLengths)) / 2;
                        _this.wrapperBottom = (containerSize - _this.slides[_this.slides.length - 1].getHeight(true, params.roundLengths)) / 2;
                    }
                }

                if (isH) {
                    if (_this.wrapperLeft >= 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px';
                    if (_this.wrapperRight >= 0) wrapper.style.paddingRight = _this.wrapperRight + 'px';
                } else {
                    if (_this.wrapperTop >= 0) wrapper.style.paddingTop = _this.wrapperTop + 'px';
                    if (_this.wrapperBottom >= 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px';
                }
                slideLeft = 0;
                var centeredSlideLeft = 0;
                _this.snapGrid = [];
                _this.slidesGrid = [];

                slideMaxHeight = 0;
                for (i = 0; i < _this.slides.length; i++) {
                    slideWidth = _this.slides[i].getWidth(true, params.roundLengths);
                    slideHeight = _this.slides[i].getHeight(true, params.roundLengths);
                    if (params.calculateHeight) {
                        slideMaxHeight = Math.max(slideMaxHeight, slideHeight);
                    }
                    var _slideSize = isH ? slideWidth : slideHeight;
                    if (params.centeredSlides) {
                        var nextSlideWidth = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getWidth(true, params.roundLengths);
                        var nextSlideHeight = i === _this.slides.length - 1 ? 0 : _this.slides[i + 1].getHeight(true, params.roundLengths);
                        var nextSlideSize = isH ? nextSlideWidth : nextSlideHeight;
                        if (_slideSize > containerSize) {
                            if (params.slidesPerViewFit) {
                                _this.snapGrid.push(slideLeft + _this.wrapperLeft);
                                _this.snapGrid.push(slideLeft + _slideSize - containerSize + _this.wrapperLeft);
                            } else {
                                for (var j = 0; j <= Math.floor(_slideSize / (containerSize + _this.wrapperLeft)); j++) {
                                    if (j === 0) _this.snapGrid.push(slideLeft + _this.wrapperLeft);
                                    else _this.snapGrid.push(slideLeft + _this.wrapperLeft + containerSize * j);
                                }
                            }
                            _this.slidesGrid.push(slideLeft + _this.wrapperLeft);
                        } else {
                            _this.snapGrid.push(centeredSlideLeft);
                            _this.slidesGrid.push(centeredSlideLeft);
                        }
                        centeredSlideLeft += _slideSize / 2 + nextSlideSize / 2;
                    } else {
                        if (_slideSize > containerSize) {
                            if (params.slidesPerViewFit) {
                                _this.snapGrid.push(slideLeft);
                                _this.snapGrid.push(slideLeft + _slideSize - containerSize);
                            } else {
                                if (containerSize !== 0) {
                                    for (var k = 0; k <= Math.floor(_slideSize / containerSize); k++) {
                                        _this.snapGrid.push(slideLeft + containerSize * k);
                                    }
                                } else {
                                    _this.snapGrid.push(slideLeft);
                                }
                            }

                        } else {
                            _this.snapGrid.push(slideLeft);
                        }
                        _this.slidesGrid.push(slideLeft);
                    }

                    slideLeft += _slideSize;

                    slidesWidth += slideWidth;
                    slidesHeight += slideHeight;
                }
                if (params.calculateHeight) _this.height = slideMaxHeight;
                if (isH) {
                    wrapperSize = slidesWidth + _this.wrapperRight + _this.wrapperLeft;
                    if (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height') {
                        wrapper.style.width = (slidesWidth) + 'px';
                    }
                    if (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width') {
                        wrapper.style.height = (_this.height) + 'px';
                    }
                } else {
                    if (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height') {
                        wrapper.style.width = (_this.width) + 'px';
                    }
                    if (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width') {
                        wrapper.style.height = (slidesHeight) + 'px';
                    }
                    wrapperSize = slidesHeight + _this.wrapperTop + _this.wrapperBottom;
                }

            } else if (params.scrollContainer) {
                //Scroll Container
                wrapper.style.width = '';
                wrapper.style.height = '';
                wrapperWidth = _this.slides[0].getWidth(true, params.roundLengths);
                wrapperHeight = _this.slides[0].getHeight(true, params.roundLengths);
                wrapperSize = isH ? wrapperWidth : wrapperHeight;
                wrapper.style.width = wrapperWidth + 'px';
                wrapper.style.height = wrapperHeight + 'px';
                slideSize = isH ? wrapperWidth : wrapperHeight;

            } else {
                //For usual slides
                if (params.calculateHeight) {
                    slideMaxHeight = 0;
                    wrapperHeight = 0;
                    //ResetWrapperSize
                    if (!isH) _this.container.style.height = '';
                    wrapper.style.height = '';

                    for (i = 0; i < _this.slides.length; i++) {
                        //ResetSlideSize
                        _this.slides[i].style.height = '';
                        slideMaxHeight = Math.max(_this.slides[i].getHeight(true), slideMaxHeight);
                        if (!isH) wrapperHeight += _this.slides[i].getHeight(true);
                    }
                    slideHeight = slideMaxHeight;
                    _this.height = slideHeight;

                    if (isH) wrapperHeight = slideHeight;
                    else {
                        containerSize = slideHeight;
                        _this.container.style.height = containerSize + 'px';
                    }
                } else {
                    slideHeight = isH ? _this.height : _this.height / params.slidesPerView;
                    if (params.roundLengths) slideHeight = Math.ceil(slideHeight);
                    wrapperHeight = isH ? _this.height : _this.slides.length * slideHeight;
                }
                slideWidth = isH ? _this.width / params.slidesPerView : _this.width;
                if (params.roundLengths) slideWidth = Math.ceil(slideWidth);
                wrapperWidth = isH ? _this.slides.length * slideWidth : _this.width;
                slideSize = isH ? slideWidth : slideHeight;

                if (params.offsetSlidesBefore > 0) {
                    if (isH) _this.wrapperLeft = slideSize * params.offsetSlidesBefore;
                    else _this.wrapperTop = slideSize * params.offsetSlidesBefore;
                }
                if (params.offsetSlidesAfter > 0) {
                    if (isH) _this.wrapperRight = slideSize * params.offsetSlidesAfter;
                    else _this.wrapperBottom = slideSize * params.offsetSlidesAfter;
                }
                if (params.offsetPxBefore > 0) {
                    if (isH) _this.wrapperLeft = params.offsetPxBefore;
                    else _this.wrapperTop = params.offsetPxBefore;
                }
                if (params.offsetPxAfter > 0) {
                    if (isH) _this.wrapperRight = params.offsetPxAfter;
                    else _this.wrapperBottom = params.offsetPxAfter;
                }
                if (params.centeredSlides) {
                    if (isH) {
                        _this.wrapperLeft = (containerSize - slideSize) / 2;
                        _this.wrapperRight = (containerSize - slideSize) / 2;
                    } else {
                        _this.wrapperTop = (containerSize - slideSize) / 2;
                        _this.wrapperBottom = (containerSize - slideSize) / 2;
                    }
                }
                if (isH) {
                    if (_this.wrapperLeft > 0) wrapper.style.paddingLeft = _this.wrapperLeft + 'px';
                    if (_this.wrapperRight > 0) wrapper.style.paddingRight = _this.wrapperRight + 'px';
                } else {
                    if (_this.wrapperTop > 0) wrapper.style.paddingTop = _this.wrapperTop + 'px';
                    if (_this.wrapperBottom > 0) wrapper.style.paddingBottom = _this.wrapperBottom + 'px';
                }

                wrapperSize = isH ? wrapperWidth + _this.wrapperRight + _this.wrapperLeft : wrapperHeight + _this.wrapperTop + _this.wrapperBottom;
                if (parseFloat(wrapperWidth) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height')) {
                    wrapper.style.width = wrapperWidth + 'px';
                }
                if (parseFloat(wrapperHeight) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width')) {
                    wrapper.style.height = wrapperHeight + 'px';
                }
                slideLeft = 0;
                _this.snapGrid = [];
                _this.slidesGrid = [];
                for (i = 0; i < _this.slides.length; i++) {
                    _this.snapGrid.push(slideLeft);
                    _this.slidesGrid.push(slideLeft);
                    slideLeft += slideSize;
                    if (parseFloat(slideWidth) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'height')) {
                        _this.slides[i].style.width = slideWidth + 'px';
                    }
                    if (parseFloat(slideHeight) > 0 && (!params.cssWidthAndHeight || params.cssWidthAndHeight === 'width')) {
                        _this.slides[i].style.height = slideHeight + 'px';
                    }
                }

            }

            if (!_this.initialized) {
                _this.callPlugins('onFirstInit');
                if (params.onFirstInit) _this.fireCallback(params.onFirstInit, _this);
            } else {
                _this.callPlugins('onInit');
                if (params.onInit) _this.fireCallback(params.onInit, _this);
            }
            _this.initialized = true;
        };

        _this.reInit = function(forceCalcSlides) {
            _this.init(true, forceCalcSlides);
        };

        _this.resizeFix = function(reInit) {
            _this.callPlugins('beforeResizeFix');

            _this.init(params.resizeReInit || reInit);

            // swipe to active slide in fixed mode
            if (!params.freeMode) {
                _this.swipeTo((params.loop ? _this.activeLoopIndex : _this.activeIndex), 0, false);
                // Fix autoplay
                if (params.autoplay) {
                    if (_this.support.transitions && typeof autoplayTimeoutId !== 'undefined') {
                        if (typeof autoplayTimeoutId !== 'undefined') {
                            clearTimeout(autoplayTimeoutId);
                            autoplayTimeoutId = undefined;
                            _this.startAutoplay();
                        }
                    } else {
                        if (typeof autoplayIntervalId !== 'undefined') {
                            clearInterval(autoplayIntervalId);
                            autoplayIntervalId = undefined;
                            _this.startAutoplay();
                        }
                    }
                }
            }
            // move wrapper to the beginning in free mode
            else if (_this.getWrapperTranslate() < -maxWrapperPosition()) {
                _this.setWrapperTransition(0);
                _this.setWrapperTranslate(-maxWrapperPosition());
            }

            _this.callPlugins('afterResizeFix');
        };

        /*==========================================
            Max and Min Positions
        ============================================*/
        function maxWrapperPosition() {
            var a = (wrapperSize - containerSize);
            if (params.freeMode) {
                a = wrapperSize - containerSize;
            }
            // if (params.loop) a -= containerSize;
            if (params.slidesPerView > _this.slides.length && !params.centeredSlides) {
                a = 0;
            }
            if (a < 0) a = 0;
            return a;
        }

        /*==========================================
            Event Listeners
        ============================================*/
        function initEvents() {
            var bind = _this.h.addEventListener;
            var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container;
            //Touch Events
            if (!(_this.browser.ie10 || _this.browser.ie11)) {
                if (_this.support.touch) {
                    bind(eventTarget, 'touchstart', onTouchStart);
                    bind(eventTarget, 'touchmove', onTouchMove);
                    bind(eventTarget, 'touchend', onTouchEnd);
                }
                if (params.simulateTouch) {
                    bind(eventTarget, 'mousedown', onTouchStart);
                    bind(document, 'mousemove', onTouchMove);
                    bind(document, 'mouseup', onTouchEnd);
                }
            } else {
                bind(eventTarget, _this.touchEvents.touchStart, onTouchStart);
                bind(document, _this.touchEvents.touchMove, onTouchMove);
                bind(document, _this.touchEvents.touchEnd, onTouchEnd);
            }

            //Resize Event
            if (params.autoResize) {
                bind(window, 'resize', _this.resizeFix);
            }
            //Slide Events
            addSlideEvents();
            //Mousewheel
            _this._wheelEvent = false;
            if (params.mousewheelControl) {
                if (document.onmousewheel !== undefined) {
                    _this._wheelEvent = 'mousewheel';
                }
                if (!_this._wheelEvent) {
                    try {
                        new WheelEvent('wheel');
                        _this._wheelEvent = 'wheel';
                    } catch (e) {}
                }
                if (!_this._wheelEvent) {
                    _this._wheelEvent = 'DOMMouseScroll';
                }
                if (_this._wheelEvent) {
                    bind(_this.container, _this._wheelEvent, handleMousewheel);
                }
            }

            //Keyboard
            function _loadImage(img) {
                var image, src;
                var onReady = function() {
                    if (typeof _this === 'undefined' || _this === null) return;
                    if (_this.imagesLoaded !== undefined) _this.imagesLoaded++;
                    if (_this.imagesLoaded === _this.imagesToLoad.length) {
                        _this.reInit();
                        if (params.onImagesReady) _this.fireCallback(params.onImagesReady, _this);
                    }
                };

                if (!img.complete) {
                    src = (img.currentSrc || img.getAttribute('src'));
                    if (src) {
                        image = new Image();
                        image.onload = onReady;
                        image.onerror = onReady;
                        image.src = src;
                    } else {
                        onReady();
                    }

                } else { //image already loaded...
                    onReady();
                }
            }

            if (params.keyboardControl) {
                bind(document, 'keydown', handleKeyboardKeys);
            }
            if (params.updateOnImagesReady) {
                _this.imagesToLoad = $$('img', _this.container);

                for (var i = 0; i < _this.imagesToLoad.length; i++) {
                    _loadImage(_this.imagesToLoad[i]);
                }
            }
        }

        //Remove Event Listeners
        _this.destroy = function(removeStyles) {
            var unbind = _this.h.removeEventListener;
            var eventTarget = params.eventTarget === 'wrapper' ? _this.wrapper : _this.container;
            //Touch Events
            if (!(_this.browser.ie10 || _this.browser.ie11)) {
                if (_this.support.touch) {
                    unbind(eventTarget, 'touchstart', onTouchStart);
                    unbind(eventTarget, 'touchmove', onTouchMove);
                    unbind(eventTarget, 'touchend', onTouchEnd);
                }
                if (params.simulateTouch) {
                    unbind(eventTarget, 'mousedown', onTouchStart);
                    unbind(document, 'mousemove', onTouchMove);
                    unbind(document, 'mouseup', onTouchEnd);
                }
            } else {
                unbind(eventTarget, _this.touchEvents.touchStart, onTouchStart);
                unbind(document, _this.touchEvents.touchMove, onTouchMove);
                unbind(document, _this.touchEvents.touchEnd, onTouchEnd);
            }

            //Resize Event
            if (params.autoResize) {
                unbind(window, 'resize', _this.resizeFix);
            }

            //Init Slide Events
            removeSlideEvents();

            //Pagination
            if (params.paginationClickable) {
                removePaginationEvents();
            }

            //Mousewheel
            if (params.mousewheelControl && _this._wheelEvent) {
                unbind(_this.container, _this._wheelEvent, handleMousewheel);
            }

            //Keyboard
            if (params.keyboardControl) {
                unbind(document, 'keydown', handleKeyboardKeys);
            }

            //Stop autoplay
            if (params.autoplay && params.autoStopPlay === true) {
                _this.stopAutoplay();
            }
            // Remove styles
            if (removeStyles) {
                _this.wrapper.removeAttribute('style');
                for (var i = 0; i < _this.slides.length; i++) {
                    _this.slides[i].removeAttribute('style');
                }
            }
            // Plugins
            _this.callPlugins('onDestroy');

            // Check jQuery/Zepto data
            if (window.jQuery && window.jQuery(_this.container).data('swiper')) {
                window.jQuery(_this.container).removeData('swiper');
            }
            if (window.Zepto && window.Zepto(_this.container).data('swiper')) {
                window.Zepto(_this.container).removeData('swiper');
            }

            //Destroy variable
            _this = null;
        };

        function addSlideEvents() {
            var bind = _this.h.addEventListener,
                i;

            //Prevent Links Events
            if (params.preventLinks) {
                var links = $$('a', _this.container);
                for (i = 0; i < links.length; i++) {
                    bind(links[i], 'click', preventClick);
                }
            }
            //Release Form Elements
            if (params.releaseFormElements) {
                var formElements = $$('input, textarea, select', _this.container);
                for (i = 0; i < formElements.length; i++) {
                    bind(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
                    if (_this.support.touch && params.simulateTouch) {
                        bind(formElements[i], 'mousedown', releaseForms, true);
                    }
                }
            }

            //Slide Clicks & Touches
            if (params.onSlideClick) {
                for (i = 0; i < _this.slides.length; i++) {
                    bind(_this.slides[i], 'click', slideClick);
                }
            }
            if (params.onSlideTouch) {
                for (i = 0; i < _this.slides.length; i++) {
                    bind(_this.slides[i], _this.touchEvents.touchStart, slideTouch);
                }
            }
        }

        function removeSlideEvents() {
            var unbind = _this.h.removeEventListener,
                i;

            //Slide Clicks & Touches
            if (params.onSlideClick) {
                for (i = 0; i < _this.slides.length; i++) {
                    unbind(_this.slides[i], 'click', slideClick);
                }
            }
            if (params.onSlideTouch) {
                for (i = 0; i < _this.slides.length; i++) {
                    unbind(_this.slides[i], _this.touchEvents.touchStart, slideTouch);
                }
            }
            //Release Form Elements
            if (params.releaseFormElements) {
                var formElements = $$('input, textarea, select', _this.container);
                for (i = 0; i < formElements.length; i++) {
                    unbind(formElements[i], _this.touchEvents.touchStart, releaseForms, true);
                    if (_this.support.touch && params.simulateTouch) {
                        unbind(formElements[i], 'mousedown', releaseForms, true);
                    }
                }
            }
            //Prevent Links Events
            if (params.preventLinks) {
                var links = $$('a', _this.container);
                for (i = 0; i < links.length; i++) {
                    unbind(links[i], 'click', preventClick);
                }
            }
        }
        /*==========================================
            Keyboard Control
        ============================================*/
        function handleKeyboardKeys(e) {
            var kc = e.keyCode || e.charCode;
            if (e.shiftKey || e.altKey || e.ctrlKey || e.metaKey) return;
            if (kc === 37 || kc === 39 || kc === 38 || kc === 40) {
                var inView = false;
                //Check that swiper should be inside of visible area of window
                var swiperOffset = _this.h.getOffset(_this.container);
                var scrollLeft = _this.h.windowScroll().left;
                var scrollTop = _this.h.windowScroll().top;
                var windowWidth = _this.h.windowWidth();
                var windowHeight = _this.h.windowHeight();
                var swiperCoord = [
                    [swiperOffset.left, swiperOffset.top],
                    [swiperOffset.left + _this.width, swiperOffset.top],
                    [swiperOffset.left, swiperOffset.top + _this.height],
                    [swiperOffset.left + _this.width, swiperOffset.top + _this.height]
                ];
                for (var i = 0; i < swiperCoord.length; i++) {
                    var point = swiperCoord[i];
                    if (
                        point[0] >= scrollLeft && point[0] <= scrollLeft + windowWidth &&
                        point[1] >= scrollTop && point[1] <= scrollTop + windowHeight
                    ) {
                        inView = true;
                    }

                }
                if (!inView) return;
            }
            if (isH) {
                if (kc === 37 || kc === 39) {
                    if (e.preventDefault) e.preventDefault();
                    else e.returnValue = false;
                }
                if (kc === 39) _this.swipeNext();
                if (kc === 37) _this.swipePrev();
            } else {
                if (kc === 38 || kc === 40) {
                    if (e.preventDefault) e.preventDefault();
                    else e.returnValue = false;
                }
                if (kc === 40) _this.swipeNext();
                if (kc === 38) _this.swipePrev();
            }
        }

        _this.disableKeyboardControl = function() {
            params.keyboardControl = false;
            _this.h.removeEventListener(document, 'keydown', handleKeyboardKeys);
        };

        _this.enableKeyboardControl = function() {
            params.keyboardControl = true;
            _this.h.addEventListener(document, 'keydown', handleKeyboardKeys);
        };

        /*==========================================
            Mousewheel Control
        ============================================*/
        var lastScrollTime = (new Date()).getTime();

        function handleMousewheel(e) {
            var we = _this._wheelEvent;
            var delta = 0;

            //Opera & IE
            if (e.detail) delta = -e.detail;
            //WebKits
            else if (we === 'mousewheel') {
                if (params.mousewheelControlForceToAxis) {
                    if (isH) {
                        if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) delta = e.wheelDeltaX;
                        else return;
                    } else {
                        if (Math.abs(e.wheelDeltaY) > Math.abs(e.wheelDeltaX)) delta = e.wheelDeltaY;
                        else return;
                    }
                } else {
                    delta = e.wheelDelta;
                }
            }
            //Old FireFox
            else if (we === 'DOMMouseScroll') delta = -e.detail;
            //New FireFox
            else if (we === 'wheel') {
                if (params.mousewheelControlForceToAxis) {
                    if (isH) {
                        if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) delta = -e.deltaX;
                        else return;
                    } else {
                        if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) delta = -e.deltaY;
                        else return;
                    }
                } else {
                    delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? -e.deltaX : -e.deltaY;
                }
            }

            if (!params.freeMode) {
                if ((new Date()).getTime() - lastScrollTime > 60) {
                    if (delta < 0) _this.swipeNext();
                    else _this.swipePrev();
                }
                lastScrollTime = (new Date()).getTime();

            } else {
                //Freemode or scrollContainer:
                var position = _this.getWrapperTranslate() + delta;

                if (position > 0) position = 0;
                if (position < -maxWrapperPosition()) position = -maxWrapperPosition();

                _this.setWrapperTransition(0);
                _this.setWrapperTranslate(position);
                _this.updateActiveSlide(position);

                // Return page scroll on edge positions
                if (position === 0 || position === -maxWrapperPosition()) return;
            }
            if (params.autoplay && params.autoStopPlay === true) _this.stopAutoplay(true);

            if (e.preventDefault) e.preventDefault();
            else e.returnValue = false;
            return false;
        }
        _this.disableMousewheelControl = function() {
            if (!_this._wheelEvent) return false;
            params.mousewheelControl = false;
            _this.h.removeEventListener(_this.container, _this._wheelEvent, handleMousewheel);
            return true;
        };

        _this.enableMousewheelControl = function() {
            if (!_this._wheelEvent) return false;
            params.mousewheelControl = true;
            _this.h.addEventListener(_this.container, _this._wheelEvent, handleMousewheel);
            return true;
        };

        /*=========================
          Grab Cursor
          ===========================*/
        if (params.grabCursor) {
            var containerStyle = _this.container.style;
            containerStyle.cursor = 'move';
            containerStyle.cursor = 'grab';
            containerStyle.cursor = '-moz-grab';
            containerStyle.cursor = '-webkit-grab';
        }

        /*=========================
          Slides Events Handlers
          ===========================*/

        _this.allowSlideClick = true;

        function slideClick(event) {
            if (_this.allowSlideClick) {
                setClickedSlide(event);
                _this.fireCallback(params.onSlideClick, _this, event);
            }
        }

        function slideTouch(event) {
            setClickedSlide(event);
            _this.fireCallback(params.onSlideTouch, _this, event);
        }

        function setClickedSlide(event) {

            // IE 6-8 support
            if (!event.currentTarget) {
                var element = event.srcElement;
                do {
                    if (element.className.indexOf(params.slideClass) > -1) {
                        break;
                    }
                    element = element.parentNode;
                } while (element);
                _this.clickedSlide = element;
            } else {
                _this.clickedSlide = event.currentTarget;
            }

            _this.clickedSlideIndex = _this.slides.indexOf(_this.clickedSlide);
            _this.clickedSlideLoopIndex = _this.clickedSlideIndex - (_this.loopedSlides || 0);
        }

        _this.allowLinks = true;

        function preventClick(e) {
            if (!_this.allowLinks) {
                if (e.preventDefault) e.preventDefault();
                else e.returnValue = false;
                if (params.preventLinksPropagation && 'stopPropagation' in e) {
                    e.stopPropagation();
                }
                return false;
            }
        }

        function releaseForms(e) {
            if (e.stopPropagation) e.stopPropagation();
            else e.returnValue = false;
            return false;

        }

        /*==================================================
            Event Handlers
        ====================================================*/
        var isTouchEvent = false;
        var allowThresholdMove;
        var allowMomentumBounce = true;

        function onTouchStart(event) {
            if (params.preventLinks) _this.allowLinks = true;
            //Exit if slider is already was touched
            if (_this.isTouched || params.onlyExternal) {
                return false;
            }

            // Blur active elements
            var eventTarget = event.target || event.srcElement;
            if (document.activeElement && document.activeElement !== document.body) {
                if (document.activeElement !== eventTarget) document.activeElement.blur();
            }

            // Form tag names
            var formTagNames = ('input select textarea').split(' ');

            // Check for no swiping
            if (params.noSwiping && (eventTarget) && noSwipingSlide(eventTarget)) return false;
            allowMomentumBounce = false;
            //Check For Nested Swipers
            _this.isTouched = true;
            isTouchEvent = event.type === 'touchstart';

            // prevent user enter with right and the swiper move (needs isTouchEvent)
            if (!isTouchEvent && 'which' in event && event.which === 3) {
                _this.isTouched = false;
                return false;
            }

            if (!isTouchEvent || event.targetTouches.length === 1) {
                _this.callPlugins('onTouchStartBegin');
                if (!isTouchEvent && !_this.isAndroid && formTagNames.indexOf(eventTarget.tagName.toLowerCase()) < 0) {

                    if (event.preventDefault) event.preventDefault();
                    else event.returnValue = false;
                }

                var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX);
                var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY);

                //Start Touches to check the scrolling
                _this.touches.startX = _this.touches.currentX = pageX;
                _this.touches.startY = _this.touches.currentY = pageY;

                _this.touches.start = _this.touches.current = isH ? pageX : pageY;

                //Set Transition Time to 0
                _this.setWrapperTransition(0);

                //Get Start Translate Position
                _this.positions.start = _this.positions.current = _this.getWrapperTranslate();

                //Set Transform
                _this.setWrapperTranslate(_this.positions.start);

                //TouchStartTime
                _this.times.start = (new Date()).getTime();

                //Unset Scrolling
                isScrolling = undefined;

                //Set Treshold
                if (params.moveStartThreshold > 0) {
                    allowThresholdMove = false;
                }

                //CallBack
                if (params.onTouchStart) _this.fireCallback(params.onTouchStart, _this, event);
                _this.callPlugins('onTouchStartEnd');

            }
        }
        var velocityPrevPosition, velocityPrevTime;

        function onTouchMove(event) {
            // If slider is not touched - exit
            if (!_this.isTouched || params.onlyExternal) return;
            if (isTouchEvent && event.type === 'mousemove') return;

            var pageX = isTouchEvent ? event.targetTouches[0].pageX : (event.pageX || event.clientX);
            var pageY = isTouchEvent ? event.targetTouches[0].pageY : (event.pageY || event.clientY);

            //check for scrolling
            if (typeof isScrolling === 'undefined' && isH) {
                isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) > Math.abs(pageX - _this.touches.startX));
            }
            if (typeof isScrolling === 'undefined' && !isH) {
                isScrolling = !!(isScrolling || Math.abs(pageY - _this.touches.startY) < Math.abs(pageX - _this.touches.startX));
            }
            if (isScrolling) {
                _this.isTouched = false;
                return;
            }

            // One way swipes
            if (isH) {
                if ((!params.swipeToNext && pageX < _this.touches.startX) || ((!params.swipeToPrev && pageX > _this.touches.startX))) {
                    return;
                }
            } else {
                if ((!params.swipeToNext && pageY < _this.touches.startY) || ((!params.swipeToPrev && pageY > _this.touches.startY))) {
                    return;
                }
            }

            //Check For Nested Swipers
            if (event.assignedToSwiper) {
                _this.isTouched = false;
                return;
            }
            event.assignedToSwiper = true;

            //Block inner links
            if (params.preventLinks) {
                _this.allowLinks = false;
            }
            if (params.onSlideClick) {
                _this.allowSlideClick = false;
            }

            //Stop AutoPlay if exist
            if (params.autoplay && params.autoStopPlay === true) {
                _this.stopAutoplay(true);
            }
            if (!isTouchEvent || event.touches.length === 1) {

                //Moved Flag
                if (!_this.isMoved) {
                    _this.callPlugins('onTouchMoveStart');

                    if (params.loop) {
                        _this.fixLoop();
                        _this.positions.start = _this.getWrapperTranslate();
                    }
                    if (params.onTouchMoveStart) _this.fireCallback(params.onTouchMoveStart, _this);
                }
                _this.isMoved = true;

                // cancel event
                if (event.preventDefault) event.preventDefault();
                else event.returnValue = false;

                _this.touches.current = isH ? pageX : pageY;

                _this.positions.current = (_this.touches.current - _this.touches.start) * params.touchRatio + _this.positions.start;

                //Resistance Callbacks
                if (_this.positions.current > 0 && params.onResistanceBefore) {
                    _this.fireCallback(params.onResistanceBefore, _this, _this.positions.current);
                }
                if (_this.positions.current < -maxWrapperPosition() && params.onResistanceAfter) {
                    _this.fireCallback(params.onResistanceAfter, _this, Math.abs(_this.positions.current + maxWrapperPosition()));
                }
                //Resistance
                if (params.resistance && params.resistance !== '100%') {
                    var resistance;
                    //Resistance for Negative-Back sliding
                    if (_this.positions.current > 0) {
                        resistance = 1 - _this.positions.current / containerSize / 2;
                        if (resistance < 0.5)
                            _this.positions.current = (containerSize / 2);
                        else
                            _this.positions.current = _this.positions.current * resistance;
                    }
                    //Resistance for After-End Sliding
                    if (_this.positions.current < -maxWrapperPosition()) {

                        var diff = (_this.touches.current - _this.touches.start) * params.touchRatio + (maxWrapperPosition() + _this.positions.start);
                        resistance = (containerSize + diff) / (containerSize);
                        var newPos = _this.positions.current - diff * (1 - resistance) / 2;
                        var stopPos = -maxWrapperPosition() - containerSize / 2;

                        if (newPos < stopPos || resistance <= 0)
                            _this.positions.current = stopPos;
                        else
                            _this.positions.current = newPos;
                    }
                }
                if (params.resistance && params.resistance === '100%') {
                    //Resistance for Negative-Back sliding
                    if (_this.positions.current > 0 && !(params.freeMode && !params.freeModeFluid)) {
                        _this.positions.current = 0;
                    }
                    //Resistance for After-End Sliding
                    if (_this.positions.current < -maxWrapperPosition() && !(params.freeMode && !params.freeModeFluid)) {
                        _this.positions.current = -maxWrapperPosition();
                    }
                }
                //Move Slides
                if (!params.followFinger) return;

                if (!params.moveStartThreshold) {
                    _this.setWrapperTranslate(_this.positions.current);
                } else {
                    if (Math.abs(_this.touches.current - _this.touches.start) > params.moveStartThreshold || allowThresholdMove) {
                        if (!allowThresholdMove) {
                            allowThresholdMove = true;
                            _this.touches.start = _this.touches.current;
                            return;
                        }
                        _this.setWrapperTranslate(_this.positions.current);
                    } else {
                        _this.positions.current = _this.positions.start;
                    }
                }

                if (params.freeMode || params.watchActiveIndex) {
                    _this.updateActiveSlide(_this.positions.current);
                }

                //Grab Cursor
                if (params.grabCursor) {
                    _this.container.style.cursor = 'move';
                    _this.container.style.cursor = 'grabbing';
                    _this.container.style.cursor = '-moz-grabbin';
                    _this.container.style.cursor = '-webkit-grabbing';
                }
                //Velocity
                if (!velocityPrevPosition) velocityPrevPosition = _this.touches.current;
                if (!velocityPrevTime) velocityPrevTime = (new Date()).getTime();
                _this.velocity = (_this.touches.current - velocityPrevPosition) / ((new Date()).getTime() - velocityPrevTime) / 2;
                if (Math.abs(_this.touches.current - velocityPrevPosition) < 2) _this.velocity = 0;
                velocityPrevPosition = _this.touches.current;
                velocityPrevTime = (new Date()).getTime();
                //Callbacks
                _this.callPlugins('onTouchMoveEnd');
                if (params.onTouchMove) _this.fireCallback(params.onTouchMove, _this, event);

                return false;
            }
        }

        function onTouchEnd(event) {
            //Check For scrolling
            if (isScrolling) {
                _this.swipeReset();
            }
            // If slider is not touched exit
            if (params.onlyExternal || !_this.isTouched) return;
            _this.isTouched = false;

            //Return Grab Cursor
            if (params.grabCursor) {
                _this.container.style.cursor = 'move';
                _this.container.style.cursor = 'grab';
                _this.container.style.cursor = '-moz-grab';
                _this.container.style.cursor = '-webkit-grab';
            }

            //Check for Current Position
            if (!_this.positions.current && _this.positions.current !== 0) {
                _this.positions.current = _this.positions.start;
            }

            //For case if slider touched but not moved
            if (params.followFinger) {
                _this.setWrapperTranslate(_this.positions.current);
            }

            // TouchEndTime
            _this.times.end = (new Date()).getTime();

            //Difference
            _this.touches.diff = _this.touches.current - _this.touches.start;
            _this.touches.abs = Math.abs(_this.touches.diff);

            _this.positions.diff = _this.positions.current - _this.positions.start;
            _this.positions.abs = Math.abs(_this.positions.diff);

            var diff = _this.positions.diff;
            var diffAbs = _this.positions.abs;
            var timeDiff = _this.times.end - _this.times.start;

            if (diffAbs < 5 && (timeDiff) < 300 && _this.allowLinks === false) {
                if (!params.freeMode && diffAbs !== 0) _this.swipeReset();
                //Release inner links
                if (params.preventLinks) {
                    _this.allowLinks = true;
                }
                if (params.onSlideClick) {
                    _this.allowSlideClick = true;
                }
            }

            setTimeout(function() {
                //Release inner links
                if (typeof _this === 'undefined' || _this === null) return;
                if (params.preventLinks) {
                    _this.allowLinks = true;
                }
                if (params.onSlideClick) {
                    _this.allowSlideClick = true;
                }
            }, 100);

            var maxPosition = maxWrapperPosition();

            //Not moved or Prevent Negative Back Sliding/After-End Sliding
            if (!_this.isMoved && params.freeMode) {
                _this.isMoved = false;
                if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event);
                _this.callPlugins('onTouchEnd');
                return;
            }
            if (!_this.isMoved || _this.positions.current > 0 || _this.positions.current < -maxPosition) {
                _this.swipeReset();
                if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event);
                _this.callPlugins('onTouchEnd');
                return;
            }

            _this.isMoved = false;

            //Free Mode
            if (params.freeMode) {
                if (params.freeModeFluid) {
                    var momentumDuration = 1000 * params.momentumRatio;
                    var momentumDistance = _this.velocity * momentumDuration;
                    var newPosition = _this.positions.current + momentumDistance;
                    var doBounce = false;
                    var afterBouncePosition;
                    var bounceAmount = Math.abs(_this.velocity) * 20 * params.momentumBounceRatio;
                    if (newPosition < -maxPosition) {
                        if (params.momentumBounce && _this.support.transitions) {
                            if (newPosition + maxPosition < -bounceAmount) newPosition = -maxPosition - bounceAmount;
                            afterBouncePosition = -maxPosition;
                            doBounce = true;
                            allowMomentumBounce = true;
                        } else newPosition = -maxPosition;
                    }
                    if (newPosition > 0) {
                        if (params.momentumBounce && _this.support.transitions) {
                            if (newPosition > bounceAmount) newPosition = bounceAmount;
                            afterBouncePosition = 0;
                            doBounce = true;
                            allowMomentumBounce = true;
                        } else newPosition = 0;
                    }
                    //Fix duration
                    if (_this.velocity !== 0) momentumDuration = Math.abs((newPosition - _this.positions.current) / _this.velocity);

                    _this.setWrapperTranslate(newPosition);

                    _this.setWrapperTransition(momentumDuration);

                    if (params.momentumBounce && doBounce) {
                        _this.wrapperTransitionEnd(function() {
                            if (!allowMomentumBounce) return;
                            if (params.onMomentumBounce) _this.fireCallback(params.onMomentumBounce, _this);
                            _this.callPlugins('onMomentumBounce');

                            _this.setWrapperTranslate(afterBouncePosition);
                            _this.setWrapperTransition(300);
                        });
                    }

                    _this.updateActiveSlide(newPosition);
                }
                if (!params.freeModeFluid || timeDiff >= 300) _this.updateActiveSlide(_this.positions.current);

                if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event);
                _this.callPlugins('onTouchEnd');
                return;
            }

            //Direction
            direction = diff < 0 ? 'toNext' : 'toPrev';

            //Short Touches
            if (direction === 'toNext' && (timeDiff <= 300)) {
                if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset();
                else _this.swipeNext(true, true);
            }

            if (direction === 'toPrev' && (timeDiff <= 300)) {
                if (diffAbs < 30 || !params.shortSwipes) _this.swipeReset();
                else _this.swipePrev(true, true);
            }

            //Long Touches
            var targetSlideSize = 0;
            if (params.slidesPerView === 'auto') {
                //Define current slide's width
                var currentPosition = Math.abs(_this.getWrapperTranslate());
                var slidesOffset = 0;
                var _slideSize;
                for (var i = 0; i < _this.slides.length; i++) {
                    _slideSize = isH ? _this.slides[i].getWidth(true, params.roundLengths) : _this.slides[i].getHeight(true, params.roundLengths);
                    slidesOffset += _slideSize;
                    if (slidesOffset > currentPosition) {
                        targetSlideSize = _slideSize;
                        break;
                    }
                }
                if (targetSlideSize > containerSize) targetSlideSize = containerSize;
            } else {
                targetSlideSize = slideSize * params.slidesPerView;
            }
            if (direction === 'toNext' && (timeDiff > 300)) {
                if (diffAbs >= targetSlideSize * params.longSwipesRatio) {
                    _this.swipeNext(true, true);
                } else {
                    _this.swipeReset();
                }
            }
            if (direction === 'toPrev' && (timeDiff > 300)) {
                if (diffAbs >= targetSlideSize * params.longSwipesRatio) {
                    _this.swipePrev(true, true);
                } else {
                    _this.swipeReset();
                }
            }
            if (params.onTouchEnd) _this.fireCallback(params.onTouchEnd, _this, event);
            _this.callPlugins('onTouchEnd');
        }


        /*==================================================
            noSwiping Bubble Check by Isaac Strack
        ====================================================*/
        function hasClass(el, classname) {
            return el && el.getAttribute('class') && el.getAttribute('class').indexOf(classname) > -1;
        }

        function noSwipingSlide(el) {
            /*This function is specifically designed to check the parent elements for the noSwiping class, up to the wrapper.
            We need to check parents because while onTouchStart bubbles, _this.isTouched is checked in onTouchStart, which stops the bubbling.
            So, if a text box, for example, is the initial target, and the parent slide container has the noSwiping class, the _this.isTouched
            check will never find it, and what was supposed to be noSwiping is able to be swiped.
            This function will iterate up and check for the noSwiping class in parents, up through the wrapperClass.*/

            // First we create a truthy variable, which is that swiping is allowd (noSwiping = false)
            var noSwiping = false;

            // Now we iterate up (parentElements) until we reach the node with the wrapperClass.
            do {

                // Each time, we check to see if there's a 'swiper-no-swiping' class (noSwipingClass).
                if (hasClass(el, params.noSwipingClass)) {
                    noSwiping = true; // If there is, we set noSwiping = true;
                }

                el = el.parentElement; // now we iterate up (parent node)

            } while (!noSwiping && el.parentElement && !hasClass(el, params.wrapperClass)); // also include el.parentElement truthy, just in case.

            // because we didn't check the wrapper itself, we do so now, if noSwiping is false:
            if (!noSwiping && hasClass(el, params.wrapperClass) && hasClass(el, params.noSwipingClass))
                noSwiping = true; // if the wrapper has the noSwipingClass, we set noSwiping = true;

            return noSwiping;
        }

        function addClassToHtmlString(klass, outerHtml) {
            var par = document.createElement('div');
            var child;

            par.innerHTML = outerHtml;
            child = par.firstChild;
            child.className += ' ' + klass;

            return child.outerHTML;
        }


        /*==================================================
            Swipe Functions
        ====================================================*/
        _this.swipeNext = function(runCallbacks, internal) {
            if (typeof runCallbacks === 'undefined') runCallbacks = true;
            if (!internal && params.loop) _this.fixLoop();
            if (!internal && params.autoplay && params.autoStopPlay === true) _this.stopAutoplay(true);
            _this.callPlugins('onSwipeNext');
            var currentPosition = _this.getWrapperTranslate().toFixed(2);
            var newPosition = currentPosition;
            if (params.slidesPerView === 'auto') {
                for (var i = 0; i < _this.snapGrid.length; i++) {
                    if (-currentPosition >= _this.snapGrid[i].toFixed(2) && -currentPosition < _this.snapGrid[i + 1].toFixed(2)) {
                        newPosition = -_this.snapGrid[i + 1];
                        break;
                    }
                }
            } else {
                var groupSize = slideSize * params.slidesPerGroup;
                newPosition = -(Math.floor(Math.abs(currentPosition) / Math.floor(groupSize)) * groupSize + groupSize);
            }
            if (newPosition < -maxWrapperPosition()) {
                newPosition = -maxWrapperPosition();
            }
            if (newPosition === currentPosition) return false;
            swipeToPosition(newPosition, 'next', {
                runCallbacks: runCallbacks
            });
            return true;
        };
        _this.swipePrev = function(runCallbacks, internal) {
            if (typeof runCallbacks === 'undefined') runCallbacks = true;
            if (!internal && params.loop) _this.fixLoop();
            if (!internal && params.autoplay && params.autoStopPlay === true) _this.stopAutoplay(true);
            _this.callPlugins('onSwipePrev');

            var currentPosition = Math.ceil(_this.getWrapperTranslate());
            var newPosition;
            if (params.slidesPerView === 'auto') {
                newPosition = 0;
                for (var i = 1; i < _this.snapGrid.length; i++) {
                    if (-currentPosition === _this.snapGrid[i]) {
                        newPosition = -_this.snapGrid[i - 1];
                        break;
                    }
                    if (-currentPosition > _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) {
                        newPosition = -_this.snapGrid[i];
                        break;
                    }
                }
            } else {
                var groupSize = slideSize * params.slidesPerGroup;
                newPosition = -(Math.ceil(-currentPosition / groupSize) - 1) * groupSize;
            }

            if (newPosition > 0) newPosition = 0;

            if (newPosition === currentPosition) return false;
            swipeToPosition(newPosition, 'prev', {
                runCallbacks: runCallbacks
            });
            return true;

        };
        _this.swipeReset = function(runCallbacks) {
            if (typeof runCallbacks === 'undefined') runCallbacks = true;
            _this.callPlugins('onSwipeReset');
            var currentPosition = _this.getWrapperTranslate();
            var groupSize = slideSize * params.slidesPerGroup;
            var newPosition;
            var maxPosition = -maxWrapperPosition();
            if (params.slidesPerView === 'auto') {
                newPosition = 0;
                for (var i = 0; i < _this.snapGrid.length; i++) {
                    if (-currentPosition === _this.snapGrid[i]) return;
                    if (-currentPosition >= _this.snapGrid[i] && -currentPosition < _this.snapGrid[i + 1]) {
                        if (_this.positions.diff > 0) newPosition = -_this.snapGrid[i + 1];
                        else newPosition = -_this.snapGrid[i];
                        break;
                    }
                }
                if (-currentPosition >= _this.snapGrid[_this.snapGrid.length - 1]) newPosition = -_this.snapGrid[_this.snapGrid.length - 1];
                if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition();
            } else {
                newPosition = currentPosition < 0 ? Math.round(currentPosition / groupSize) * groupSize : 0;
                if (currentPosition <= -maxWrapperPosition()) newPosition = -maxWrapperPosition();
            }
            if (params.scrollContainer) {
                newPosition = currentPosition < 0 ? currentPosition : 0;
            }
            if (newPosition < -maxWrapperPosition()) {
                newPosition = -maxWrapperPosition();
            }
            if (params.scrollContainer && (containerSize > slideSize)) {
                newPosition = 0;
            }

            if (newPosition === currentPosition) return false;

            swipeToPosition(newPosition, 'reset', {
                runCallbacks: runCallbacks
            });
            return true;
        };

        _this.swipeTo = function(index, speed, runCallbacks) {
            index = parseInt(index, 10);
            _this.callPlugins('onSwipeTo', {
                index: index,
                speed: speed
            });
            if (params.loop) index = index + _this.loopedSlides;
            var currentPosition = _this.getWrapperTranslate();
            if (index > (_this.slides.length - 1) || index < 0) return;
            var newPosition;
            if (params.slidesPerView === 'auto') {
                newPosition = -_this.slidesGrid[index];
            } else {
                newPosition = -index * slideSize;
            }
            if (newPosition < -maxWrapperPosition()) {
                newPosition = -maxWrapperPosition();
            }

            if (newPosition === currentPosition) return false;

            if (typeof runCallbacks === 'undefined') runCallbacks = true;
            swipeToPosition(newPosition, 'to', {
                index: index,
                speed: speed,
                runCallbacks: runCallbacks
            });
            return true;
        };

        function swipeToPosition(newPosition, action, toOptions) {
            var speed = (action === 'to' && toOptions.speed >= 0) ? toOptions.speed : params.speed;
            var timeOld = +new Date();

            function anim() {
                var timeNew = +new Date();
                var time = timeNew - timeOld;
                currentPosition += animationStep * time / (1000 / 60);
                condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition;
                if (condition) {
                    _this.setWrapperTranslate(Math.ceil(currentPosition));
                    _this._DOMAnimating = true;
                    window.setTimeout(function() {
                        anim();
                    }, 1000 / 60);
                } else {
                    if (params.onSlideChangeEnd) {
                        if (action === 'to') {
                            if (toOptions.runCallbacks === true) _this.fireCallback(params.onSlideChangeEnd, _this, direction);
                        } else {
                            _this.fireCallback(params.onSlideChangeEnd, _this, direction);
                        }

                    }
                    _this.setWrapperTranslate(newPosition);
                    _this._DOMAnimating = false;
                }
            }

            if (_this.support.transitions || !params.DOMAnimation) {
                _this.setWrapperTranslate(newPosition);
                _this.setWrapperTransition(speed);
            } else {
                //Try the DOM animation
                var currentPosition = _this.getWrapperTranslate();
                var animationStep = Math.ceil((newPosition - currentPosition) / speed * (1000 / 60));
                var direction = currentPosition > newPosition ? 'toNext' : 'toPrev';
                var condition = direction === 'toNext' ? currentPosition > newPosition : currentPosition < newPosition;
                if (_this._DOMAnimating) return;

                anim();
            }

            //Update Active Slide Index
            _this.updateActiveSlide(newPosition);

            //Callbacks
            if (params.onSlideNext && action === 'next' && toOptions.runCallbacks === true) {
                _this.fireCallback(params.onSlideNext, _this, newPosition);
            }
            if (params.onSlidePrev && action === 'prev' && toOptions.runCallbacks === true) {
                _this.fireCallback(params.onSlidePrev, _this, newPosition);
            }
            //'Reset' Callback
            if (params.onSlideReset && action === 'reset' && toOptions.runCallbacks === true) {
                _this.fireCallback(params.onSlideReset, _this, newPosition);
            }

            //'Next', 'Prev' and 'To' Callbacks
            if ((action === 'next' || action === 'prev' || action === 'to') && toOptions.runCallbacks === true)
                slideChangeCallbacks(action);
        }
        /*==================================================
            Transition Callbacks
        ====================================================*/
        //Prevent Multiple Callbacks
        _this._queueStartCallbacks = false;
        _this._queueEndCallbacks = false;

        function slideChangeCallbacks(direction) {
            //Transition Start Callback
            _this.callPlugins('onSlideChangeStart');
            if (params.onSlideChangeStart) {
                if (params.queueStartCallbacks && _this.support.transitions) {
                    if (_this._queueStartCallbacks) return;
                    _this._queueStartCallbacks = true;
                    _this.fireCallback(params.onSlideChangeStart, _this, direction);
                    _this.wrapperTransitionEnd(function() {
                        _this._queueStartCallbacks = false;
                    });
                } else _this.fireCallback(params.onSlideChangeStart, _this, direction);
            }
            //Transition End Callback
            if (params.onSlideChangeEnd) {
                if (_this.support.transitions) {
                    if (params.queueEndCallbacks) {
                        if (_this._queueEndCallbacks) return;
                        _this._queueEndCallbacks = true;
                        _this.wrapperTransitionEnd(function(swiper) {
                            _this.fireCallback(params.onSlideChangeEnd, swiper, direction);
                        });
                    } else {
                        _this.wrapperTransitionEnd(function(swiper) {
                            _this.fireCallback(params.onSlideChangeEnd, swiper, direction);
                        });
                    }
                } else {
                    if (!params.DOMAnimation) {
                        setTimeout(function() {
                            _this.fireCallback(params.onSlideChangeEnd, _this, direction);
                        }, 10);
                    }
                }
            }
        }

        /*==================================================
            Update Active Slide Index
        ====================================================*/
        _this.updateActiveSlide = function(position) {
            if (!_this.initialized) return;
            if (_this.slides.length === 0) return;
            _this.previousIndex = _this.activeIndex;
            if (typeof position === 'undefined') position = _this.getWrapperTranslate();
            if (position > 0) position = 0;
            var i;
            if (params.slidesPerView === 'auto') {
                var slidesOffset = 0;
                _this.activeIndex = _this.slidesGrid.indexOf(-position);
                if (_this.activeIndex < 0) {
                    for (i = 0; i < _this.slidesGrid.length - 1; i++) {
                        if (-position > _this.slidesGrid[i] && -position < _this.slidesGrid[i + 1]) {
                            break;
                        }
                    }
                    var leftDistance = Math.abs(_this.slidesGrid[i] + position);
                    var rightDistance = Math.abs(_this.slidesGrid[i + 1] + position);
                    if (leftDistance <= rightDistance) _this.activeIndex = i;
                    else _this.activeIndex = i + 1;
                }
            } else {
                _this.activeIndex = Math[params.visibilityFullFit ? 'ceil' : 'round'](-position / slideSize);
            }

            if (_this.activeIndex === _this.slides.length) _this.activeIndex = _this.slides.length - 1;
            if (_this.activeIndex < 0) _this.activeIndex = 0;

            // Check for slide
            if (!_this.slides[_this.activeIndex]) return;

            // Calc Visible slides
            _this.calcVisibleSlides(position);

            // Mark visible and active slides with additonal classes
            if (_this.support.classList) {
                var slide;
                for (i = 0; i < _this.slides.length; i++) {
                    slide = _this.slides[i];
                    slide.classList.remove(params.slideActiveClass);
                    if (_this.visibleSlides.indexOf(slide) >= 0) {
                        slide.classList.add(params.slideVisibleClass);
                    } else {
                        slide.classList.remove(params.slideVisibleClass);
                    }
                }
                _this.slides[_this.activeIndex].classList.add(params.slideActiveClass);
            } else {
                var activeClassRegexp = new RegExp('\\s*' + params.slideActiveClass);
                var inViewClassRegexp = new RegExp('\\s*' + params.slideVisibleClass);

                for (i = 0; i < _this.slides.length; i++) {
                    _this.slides[i].className = _this.slides[i].className.replace(activeClassRegexp, '').replace(inViewClassRegexp, '');
                    if (_this.visibleSlides.indexOf(_this.slides[i]) >= 0) {
                        _this.slides[i].className += ' ' + params.slideVisibleClass;
                    }
                }
                _this.slides[_this.activeIndex].className += ' ' + params.slideActiveClass;
            }

            //Update loop index
            if (params.loop) {
                var ls = _this.loopedSlides;
                _this.activeLoopIndex = _this.activeIndex - ls;
                if (_this.activeLoopIndex >= _this.slides.length - ls * 2) {
                    _this.activeLoopIndex = _this.slides.length - ls * 2 - _this.activeLoopIndex;
                }
                if (_this.activeLoopIndex < 0) {
                    _this.activeLoopIndex = _this.slides.length - ls * 2 + _this.activeLoopIndex;
                }
                if (_this.activeLoopIndex < 0) _this.activeLoopIndex = 0;
            } else {
                _this.activeLoopIndex = _this.activeIndex;
            }
            //Update Pagination
            if (params.pagination) {
                _this.updatePagination(position);
            }
        };
        /*==================================================
            Pagination
        ====================================================*/
        _this.createPagination = function(firstInit) {
            if (params.paginationClickable && _this.paginationButtons) {
                removePaginationEvents();
            }
            _this.paginationContainer = params.pagination.nodeType ? params.pagination : $$(params.pagination)[0];
            if (params.createPagination) {
                var paginationHTML = '';
                var numOfSlides = _this.slides.length;
                var numOfButtons = numOfSlides;
                if (params.loop) numOfButtons -= _this.loopedSlides * 2;
                for (var i = 0; i < numOfButtons; i++) {
                    paginationHTML += '<' + params.paginationElement + ' class="' + params.paginationElementClass + '"></' + params.paginationElement + '>';
                }
                _this.paginationContainer.innerHTML = paginationHTML;
            }
            _this.paginationButtons = $$('.' + params.paginationElementClass, _this.paginationContainer);
            if (!firstInit) _this.updatePagination();
            _this.callPlugins('onCreatePagination');
            if (params.paginationClickable) {
                addPaginationEvents();
            }
        };

        function removePaginationEvents() {
            var pagers = _this.paginationButtons;
            if (pagers) {
                for (var i = 0; i < pagers.length; i++) {
                    _this.h.removeEventListener(pagers[i], 'click', paginationClick);
                }
            }
        }

        function addPaginationEvents() {
            var pagers = _this.paginationButtons;
            if (pagers) {
                for (var i = 0; i < pagers.length; i++) {
                    _this.h.addEventListener(pagers[i], 'click', paginationClick);
                }
            }
        }

        function paginationClick(e) {
            var index;
            var target = e.target || e.srcElement;
            var pagers = _this.paginationButtons;
            for (var i = 0; i < pagers.length; i++) {
                if (target === pagers[i]) index = i;
            }
            if (params.autoplay && params.autoStopPlay === true) {
                _this.stopAutoplay(true);
            }
            _this.swipeTo(index);
        }
        _this.updatePagination = function(position) {
            if (!params.pagination) return;
            if (_this.slides.length < 1) return;
            var activePagers = $$('.' + params.paginationActiveClass, _this.paginationContainer);
            if (!activePagers) return;

            //Reset all Buttons' class to not active
            var pagers = _this.paginationButtons;
            if (pagers.length === 0) return;
            for (var i = 0; i < pagers.length; i++) {
                pagers[i].className = params.paginationElementClass;
            }

            var indexOffset = params.loop ? _this.loopedSlides : 0;
            if (params.paginationAsRange) {
                if (!_this.visibleSlides) _this.calcVisibleSlides(position);
                //Get Visible Indexes
                var visibleIndexes = [];
                var j; // lopp index - avoid JSHint W004 / W038
                for (j = 0; j < _this.visibleSlides.length; j++) {
                    var visIndex = _this.slides.indexOf(_this.visibleSlides[j]) - indexOffset;

                    if (params.loop && visIndex < 0) {
                        visIndex = _this.slides.length - _this.loopedSlides * 2 + visIndex;
                    }
                    if (params.loop && visIndex >= _this.slides.length - _this.loopedSlides * 2) {
                        visIndex = _this.slides.length - _this.loopedSlides * 2 - visIndex;
                        visIndex = Math.abs(visIndex);
                    }
                    visibleIndexes.push(visIndex);
                }

                for (j = 0; j < visibleIndexes.length; j++) {
                    if (pagers[visibleIndexes[j]]) pagers[visibleIndexes[j]].className += ' ' + params.paginationVisibleClass;
                }

                if (params.loop) {
                    if (pagers[_this.activeLoopIndex] !== undefined) {
                        pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass;
                    }
                } else {
                    if (pagers[_this.activeIndex]) pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass;
                }
            } else {
                if (params.loop) {
                    if (pagers[_this.activeLoopIndex]) pagers[_this.activeLoopIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass;
                } else {
                    if (pagers[_this.activeIndex]) pagers[_this.activeIndex].className += ' ' + params.paginationActiveClass + ' ' + params.paginationVisibleClass;
                }
            }
        };
        _this.calcVisibleSlides = function(position) {
            var visibleSlides = [];
            var _slideLeft = 0,
                _slideSize = 0,
                _slideRight = 0;
            if (isH && _this.wrapperLeft > 0) position = position + _this.wrapperLeft;
            if (!isH && _this.wrapperTop > 0) position = position + _this.wrapperTop;

            for (var i = 0; i < _this.slides.length; i++) {
                _slideLeft += _slideSize;
                if (params.slidesPerView === 'auto')
                    _slideSize = isH ? _this.h.getWidth(_this.slides[i], true, params.roundLengths) : _this.h.getHeight(_this.slides[i], true, params.roundLengths);
                else _slideSize = slideSize;

                _slideRight = _slideLeft + _slideSize;
                var isVisibile = false;
                if (params.visibilityFullFit) {
                    if (_slideLeft >= -position && _slideRight <= -position + containerSize) isVisibile = true;
                    if (_slideLeft <= -position && _slideRight >= -position + containerSize) isVisibile = true;
                } else {
                    if (_slideRight > -position && _slideRight <= ((-position + containerSize))) isVisibile = true;
                    if (_slideLeft >= -position && _slideLeft < ((-position + containerSize))) isVisibile = true;
                    if (_slideLeft < -position && _slideRight > ((-position + containerSize))) isVisibile = true;
                }

                if (isVisibile) visibleSlides.push(_this.slides[i]);

            }
            if (visibleSlides.length === 0) visibleSlides = [_this.slides[_this.activeIndex]];

            _this.visibleSlides = visibleSlides;
        };

        /*==========================================
            Autoplay
        ============================================*/
        var autoplayTimeoutId, autoplayIntervalId;
        _this.startAutoplay = function() {
            if (_this.support.transitions) {
                if (typeof autoplayTimeoutId !== 'undefined') return false;
                if (!params.autoplay) return;
                _this.callPlugins('onAutoplayStart');
                if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this);
                autoplay();
            } else {
                if (typeof autoplayIntervalId !== 'undefined') return false;
                if (!params.autoplay) return;
                _this.callPlugins('onAutoplayStart');
                if (params.onAutoplayStart) _this.fireCallback(params.onAutoplayStart, _this);
                autoplayIntervalId = setInterval(function() {
                    if (params.loop) {
                        _this.fixLoop();
                        _this.swipeNext(true, true);
                    } else if (!_this.swipeNext(true, true)) {
                        if (!params.autoplayStopOnLast) _this.swipeTo(0);
                        else {
                            clearInterval(autoplayIntervalId);
                            autoplayIntervalId = undefined;
                        }
                    }
                }, params.autoplay);
            }
        };
        _this.stopAutoplay = function(internal) {
            if (_this.support.transitions) {
                if (!autoplayTimeoutId) return;
                if (autoplayTimeoutId) clearTimeout(autoplayTimeoutId);
                autoplayTimeoutId = undefined;
                if (internal && !params.autoplayDisableOnInteraction) {
                    _this.wrapperTransitionEnd(function() {
                        autoplay();
                    });
                }
                _this.callPlugins('onAutoplayStop');
                if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this);
            } else {
                if (autoplayIntervalId) clearInterval(autoplayIntervalId);
                autoplayIntervalId = undefined;
                _this.callPlugins('onAutoplayStop');
                if (params.onAutoplayStop) _this.fireCallback(params.onAutoplayStop, _this);
            }
        };

        function autoplay() {
            autoplayTimeoutId = setTimeout(function() {
                if (params.loop) {
                    _this.fixLoop();
                    _this.swipeNext(true, true);
                } else if (!_this.swipeNext(true, true)) {
                    if (!params.autoplayStopOnLast) _this.swipeTo(0);
                    else {
                        clearTimeout(autoplayTimeoutId);
                        autoplayTimeoutId = undefined;
                    }
                }
                _this.wrapperTransitionEnd(function() {
                    if (typeof autoplayTimeoutId !== 'undefined') autoplay();
                });
            }, params.autoplay);
        }
        /*==================================================
            Loop
        ====================================================*/
        _this.loopCreated = false;
        _this.removeLoopedSlides = function() {
            if (_this.loopCreated) {
                for (var i = 0; i < _this.slides.length; i++) {
                    if (_this.slides[i].getData('looped') === true) _this.wrapper.removeChild(_this.slides[i]);
                }
            }
        };

        _this.createLoop = function() {
            if (_this.slides.length === 0) return;
            if (params.slidesPerView === 'auto') {
                _this.loopedSlides = params.loopedSlides || 1;
            } else {
                _this.loopedSlides = params.slidesPerView + params.loopAdditionalSlides;
            }

            if (_this.loopedSlides > _this.slides.length) {
                _this.loopedSlides = _this.slides.length;
            }

            var slideFirstHTML = '',
                slideLastHTML = '',
                i;
            var slidesSetFullHTML = '';
            /**
                    loopedSlides is too large if loopAdditionalSlides are set.
                    Need to divide the slides by maximum number of slides existing.

                    @author        Tomaz Lovrec <tomaz.lovrec@blanc-noir.at>
            */
            var numSlides = _this.slides.length;
            var fullSlideSets = Math.floor(_this.loopedSlides / numSlides);
            var remainderSlides = _this.loopedSlides % numSlides;
            // assemble full sets of slides
            for (i = 0; i < (fullSlideSets * numSlides); i++) {
                var j = i;
                if (i >= numSlides) {
                    var over = Math.floor(i / numSlides);
                    j = i - (numSlides * over);
                }
                slidesSetFullHTML += _this.slides[j].outerHTML;
            }
            // assemble remainder slides
            // assemble remainder appended to existing slides
            for (i = 0; i < remainderSlides; i++) {
                slideLastHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML);
            }
            // assemble slides that get preppended to existing slides
            for (i = numSlides - remainderSlides; i < numSlides; i++) {
                slideFirstHTML += addClassToHtmlString(params.slideDuplicateClass, _this.slides[i].outerHTML);
            }
            // assemble all slides
            var slides = slideFirstHTML + slidesSetFullHTML + wrapper.innerHTML + slidesSetFullHTML + slideLastHTML;
            // set the slides
            wrapper.innerHTML = slides;

            _this.loopCreated = true;
            _this.calcSlides();

            //Update Looped Slides with special class
            for (i = 0; i < _this.slides.length; i++) {
                if (i < _this.loopedSlides || i >= _this.slides.length - _this.loopedSlides) _this.slides[i].setData('looped', true);
            }
            _this.callPlugins('onCreateLoop');

        };

        _this.fixLoop = function() {
            var newIndex;
            //Fix For Negative Oversliding
            if (_this.activeIndex < _this.loopedSlides) {
                newIndex = _this.slides.length - _this.loopedSlides * 3 + _this.activeIndex;
                _this.swipeTo(newIndex, 0, false);
            }
            //Fix For Positive Oversliding
            else if ((params.slidesPerView === 'auto' && _this.activeIndex >= _this.loopedSlides * 2) || (_this.activeIndex > _this.slides.length - params.slidesPerView * 2)) {
                newIndex = -_this.slides.length + _this.activeIndex + _this.loopedSlides;
                _this.swipeTo(newIndex, 0, false);
            }
        };

        /*==================================================
            Slides Loader
        ====================================================*/
        _this.loadSlides = function() {
            var slidesHTML = '';
            _this.activeLoaderIndex = 0;
            var slides = params.loader.slides;
            var slidesToLoad = params.loader.loadAllSlides ? slides.length : params.slidesPerView * (1 + params.loader.surroundGroups);
            for (var i = 0; i < slidesToLoad; i++) {
                if (params.loader.slidesHTMLType === 'outer') slidesHTML += slides[i];
                else {
                    slidesHTML += '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>';
                }
            }
            _this.wrapper.innerHTML = slidesHTML;
            _this.calcSlides(true);
            //Add permanent transitionEnd callback
            if (!params.loader.loadAllSlides) {
                _this.wrapperTransitionEnd(_this.reloadSlides, true);
            }
        };

        _this.reloadSlides = function() {
            var slides = params.loader.slides;
            var newActiveIndex = parseInt(_this.activeSlide().data('swiperindex'), 10);
            if (newActiveIndex < 0 || newActiveIndex > slides.length - 1) return; //<-- Exit
            _this.activeLoaderIndex = newActiveIndex;
            var firstIndex = Math.max(0, newActiveIndex - params.slidesPerView * params.loader.surroundGroups);
            var lastIndex = Math.min(newActiveIndex + params.slidesPerView * (1 + params.loader.surroundGroups) - 1, slides.length - 1);
            //Update Transforms
            if (newActiveIndex > 0) {
                var newTransform = -slideSize * (newActiveIndex - firstIndex);
                _this.setWrapperTranslate(newTransform);
                _this.setWrapperTransition(0);
            }
            var i; // loop index
            //New Slides
            if (params.loader.logic === 'reload') {
                _this.wrapper.innerHTML = '';
                var slidesHTML = '';
                for (i = firstIndex; i <= lastIndex; i++) {
                    slidesHTML += params.loader.slidesHTMLType === 'outer' ? slides[i] : '<' + params.slideElement + ' class="' + params.slideClass + '" data-swiperindex="' + i + '">' + slides[i] + '</' + params.slideElement + '>';
                }
                _this.wrapper.innerHTML = slidesHTML;
            } else {
                var minExistIndex = 1000;
                var maxExistIndex = 0;

                for (i = 0; i < _this.slides.length; i++) {
                    var index = _this.slides[i].data('swiperindex');
                    if (index < firstIndex || index > lastIndex) {
                        _this.wrapper.removeChild(_this.slides[i]);
                    } else {
                        minExistIndex = Math.min(index, minExistIndex);
                        maxExistIndex = Math.max(index, maxExistIndex);
                    }
                }
                for (i = firstIndex; i <= lastIndex; i++) {
                    var newSlide;
                    if (i < minExistIndex) {
                        newSlide = document.createElement(params.slideElement);
                        newSlide.className = params.slideClass;
                        newSlide.setAttribute('data-swiperindex', i);
                        newSlide.innerHTML = slides[i];
                        _this.wrapper.insertBefore(newSlide, _this.wrapper.firstChild);
                    }
                    if (i > maxExistIndex) {
                        newSlide = document.createElement(params.slideElement);
                        newSlide.className = params.slideClass;
                        newSlide.setAttribute('data-swiperindex', i);
                        newSlide.innerHTML = slides[i];
                        _this.wrapper.appendChild(newSlide);
                    }
                }
            }
            //reInit
            _this.reInit(true);
        };

        /*==================================================
            Make Swiper
        ====================================================*/
        function makeSwiper() {
            _this.calcSlides();
            if (params.loader.slides.length > 0 && _this.slides.length === 0) {
                _this.loadSlides();
            }
            if (params.loop) {
                _this.createLoop();
            }
            _this.init();
            initEvents();
            if (params.pagination) {
                _this.createPagination(true);
            }

            if (params.loop || params.initialSlide > 0) {
                _this.swipeTo(params.initialSlide, 0, false);
            } else {
                _this.updateActiveSlide(0);
            }
            if (params.autoplay) {
                _this.startAutoplay();
            }
            /**
             * Set center slide index.
             *
             * @author        Tomaz Lovrec <tomaz.lovrec@gmail.com>
             */
            _this.centerIndex = _this.activeIndex;

            // Callbacks
            if (params.onSwiperCreated) _this.fireCallback(params.onSwiperCreated, _this);
            _this.callPlugins('onSwiperCreated');
        }

        makeSwiper();
    };

    Swiper.prototype = {
        plugins: {},

        /*==================================================
            Wrapper Operations
        ====================================================*/
        wrapperTransitionEnd: function(callback, permanent) {
            'use strict';
            var a = this,
                el = a.wrapper,
                events = ['webkitTransitionEnd', 'transitionend', 'oTransitionEnd', 'MSTransitionEnd', 'msTransitionEnd'],
                i;

            function fireCallBack(e) {
                if (e.target !== el) return;
                callback(a);
                if (a.params.queueEndCallbacks) a._queueEndCallbacks = false;
                if (!permanent) {
                    for (i = 0; i < events.length; i++) {
                        a.h.removeEventListener(el, events[i], fireCallBack);
                    }
                }
            }

            if (callback) {
                for (i = 0; i < events.length; i++) {
                    a.h.addEventListener(el, events[i], fireCallBack);
                }
            }
        },

        getWrapperTranslate: function(axis) {
            'use strict';
            var el = this.wrapper,
                matrix, curTransform, curStyle, transformMatrix;

            // automatic axis detection
            if (typeof axis === 'undefined') {
                axis = this.params.mode === 'horizontal' ? 'x' : 'y';
            }

            if (this.support.transforms && this.params.useCSS3Transforms) {
                curStyle = window.getComputedStyle(el, null);
                if (window.WebKitCSSMatrix) {
                    // Some old versions of Webkit choke when 'none' is passed; pass
                    // empty string instead in this case
                    transformMatrix = new WebKitCSSMatrix(curStyle.webkitTransform === 'none' ? '' : curStyle.webkitTransform);
                } else {
                    transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
                    matrix = transformMatrix.toString().split(',');
                }

                if (axis === 'x') {
                    //Latest Chrome and webkits Fix
                    if (window.WebKitCSSMatrix)
                        curTransform = transformMatrix.m41;
                    //Crazy IE10 Matrix
                    else if (matrix.length === 16)
                        curTransform = parseFloat(matrix[12]);
                    //Normal Browsers
                    else
                        curTransform = parseFloat(matrix[4]);
                }
                if (axis === 'y') {
                    //Latest Chrome and webkits Fix
                    if (window.WebKitCSSMatrix)
                        curTransform = transformMatrix.m42;
                    //Crazy IE10 Matrix
                    else if (matrix.length === 16)
                        curTransform = parseFloat(matrix[13]);
                    //Normal Browsers
                    else
                        curTransform = parseFloat(matrix[5]);
                }
            } else {
                if (axis === 'x') curTransform = parseFloat(el.style.left, 10) || 0;
                if (axis === 'y') curTransform = parseFloat(el.style.top, 10) || 0;
            }
            return curTransform || 0;
        },

        setWrapperTranslate: function(x, y, z) {
            'use strict';
            var es = this.wrapper.style,
                coords = {
                    x: 0,
                    y: 0,
                    z: 0
                },
                translate;

            // passed all coordinates
            if (arguments.length === 3) {
                coords.x = x;
                coords.y = y;
                coords.z = z;
            }

            // passed one coordinate and optional axis
            else {
                if (typeof y === 'undefined') {
                    y = this.params.mode === 'horizontal' ? 'x' : 'y';
                }
                coords[y] = x;
            }

            if (this.support.transforms && this.params.useCSS3Transforms) {
                translate = this.support.transforms3d ? 'translate3d(' + coords.x + 'px, ' + coords.y + 'px, ' + coords.z + 'px)' : 'translate(' + coords.x + 'px, ' + coords.y + 'px)';
                es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = translate;
            } else {
                es.left = coords.x + 'px';
                es.top = coords.y + 'px';
            }
            this.callPlugins('onSetWrapperTransform', coords);
            if (this.params.onSetWrapperTransform) this.fireCallback(this.params.onSetWrapperTransform, this, coords);
        },

        setWrapperTransition: function(duration) {
            'use strict';
            var es = this.wrapper.style;
            es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = (duration / 1000) + 's';
            this.callPlugins('onSetWrapperTransition', {
                duration: duration
            });
            if (this.params.onSetWrapperTransition) this.fireCallback(this.params.onSetWrapperTransition, this, duration);

        },

        /*==================================================
            Helpers
        ====================================================*/
        h: {
            getWidth: function(el, outer, round) {
                'use strict';
                var width = window.getComputedStyle(el, null).getPropertyValue('width');
                var returnWidth = parseFloat(width);
                //IE Fixes
                if (isNaN(returnWidth) || width.indexOf('%') > 0 || returnWidth < 0) {
                    returnWidth = el.offsetWidth - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right'));
                }
                if (outer) returnWidth += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-left')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-right'));
                if (round) return Math.ceil(returnWidth);
                else return returnWidth;
            },
            getHeight: function(el, outer, round) {
                'use strict';
                if (outer) return el.offsetHeight;

                var height = window.getComputedStyle(el, null).getPropertyValue('height');
                var returnHeight = parseFloat(height);
                //IE Fixes
                if (isNaN(returnHeight) || height.indexOf('%') > 0 || returnHeight < 0) {
                    returnHeight = el.offsetHeight - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) - parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom'));
                }
                if (outer) returnHeight += parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-top')) + parseFloat(window.getComputedStyle(el, null).getPropertyValue('padding-bottom'));
                if (round) return Math.ceil(returnHeight);
                else return returnHeight;
            },
            getOffset: function(el) {
                'use strict';
                var box = el.getBoundingClientRect();
                var body = document.body;
                var clientTop = el.clientTop || body.clientTop || 0;
                var clientLeft = el.clientLeft || body.clientLeft || 0;
                var scrollTop = window.pageYOffset || el.scrollTop;
                var scrollLeft = window.pageXOffset || el.scrollLeft;
                if (document.documentElement && !window.pageYOffset) {
                    //IE7-8
                    scrollTop = document.documentElement.scrollTop;
                    scrollLeft = document.documentElement.scrollLeft;
                }
                return {
                    top: box.top + scrollTop - clientTop,
                    left: box.left + scrollLeft - clientLeft
                };
            },
            windowWidth: function() {
                'use strict';
                if (window.innerWidth) return window.innerWidth;
                else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
            },
            windowHeight: function() {
                'use strict';
                if (window.innerHeight) return window.innerHeight;
                else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
            },
            windowScroll: function() {
                'use strict';
                if (typeof pageYOffset !== 'undefined') {
                    return {
                        left: window.pageXOffset,
                        top: window.pageYOffset
                    };
                } else if (document.documentElement) {
                    return {
                        left: document.documentElement.scrollLeft,
                        top: document.documentElement.scrollTop
                    };
                }
            },

            addEventListener: function(el, event, listener, useCapture) {
                'use strict';
                if (typeof useCapture === 'undefined') {
                    useCapture = false;
                }

                if (el.addEventListener) {
                    el.addEventListener(event, listener, useCapture);
                } else if (el.attachEvent) {
                    el.attachEvent('on' + event, listener);
                }
            },

            removeEventListener: function(el, event, listener, useCapture) {
                'use strict';
                if (typeof useCapture === 'undefined') {
                    useCapture = false;
                }

                if (el.removeEventListener) {
                    el.removeEventListener(event, listener, useCapture);
                } else if (el.detachEvent) {
                    el.detachEvent('on' + event, listener);
                }
            }
        },
        setTransform: function(el, transform) {
            'use strict';
            var es = el.style;
            es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transform;
        },
        setTranslate: function(el, translate) {
            'use strict';
            var es = el.style;
            var pos = {
                x: translate.x || 0,
                y: translate.y || 0,
                z: translate.z || 0
            };
            var transformString = this.support.transforms3d ? 'translate3d(' + (pos.x) + 'px,' + (pos.y) + 'px,' + (pos.z) + 'px)' : 'translate(' + (pos.x) + 'px,' + (pos.y) + 'px)';
            es.webkitTransform = es.MsTransform = es.msTransform = es.MozTransform = es.OTransform = es.transform = transformString;
            if (!this.support.transforms) {
                es.left = pos.x + 'px';
                es.top = pos.y + 'px';
            }
        },
        setTransition: function(el, duration) {
            'use strict';
            var es = el.style;
            es.webkitTransitionDuration = es.MsTransitionDuration = es.msTransitionDuration = es.MozTransitionDuration = es.OTransitionDuration = es.transitionDuration = duration + 'ms';
        },
        /*==================================================
            Feature Detection
        ====================================================*/
        support: {

            touch: (window.Modernizr && Modernizr.touch === true) || (function() {
                'use strict';
                return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
            })(),

            transforms3d: (window.Modernizr && Modernizr.csstransforms3d === true) || (function() {
                'use strict';
                var div = document.createElement('div').style;
                return ('webkitPerspective' in div || 'MozPerspective' in div || 'OPerspective' in div || 'MsPerspective' in div || 'perspective' in div);
            })(),

            transforms: (window.Modernizr && Modernizr.csstransforms === true) || (function() {
                'use strict';
                var div = document.createElement('div').style;
                return ('transform' in div || 'WebkitTransform' in div || 'MozTransform' in div || 'msTransform' in div || 'MsTransform' in div || 'OTransform' in div);
            })(),

            transitions: (window.Modernizr && Modernizr.csstransitions === true) || (function() {
                'use strict';
                var div = document.createElement('div').style;
                return ('transition' in div || 'WebkitTransition' in div || 'MozTransition' in div || 'msTransition' in div || 'MsTransition' in div || 'OTransition' in div);
            })(),

            classList: (function() {
                'use strict';
                var div = document.createElement('div');
                return 'classList' in div;
            })()
        },

        browser: {

            ie8: (function() {
                'use strict';
                var rv = -1; // Return value assumes failure.
                if (navigator.appName === 'Microsoft Internet Explorer') {
                    var ua = navigator.userAgent;
                    var re = new RegExp(/MSIE ([0-9]{1,}[\.0-9]{0,})/);
                    if (re.exec(ua) !== null)
                        rv = parseFloat(RegExp.$1);
                }
                return rv !== -1 && rv < 9;
            })(),

            ie10: window.navigator.msPointerEnabled,
            ie11: window.navigator.pointerEnabled
        }
    };

    /*=========================
      jQuery & Zepto Plugins
      ===========================*/
    if (window.jQuery || window.Zepto) {
        (function($) {
            'use strict';
            $.fn.swiper = function(params) {
                var firstInstance;
                this.each(function(i) {
                    var that = $(this);
                    var s = new Swiper(that[0], params);
                    if (!i) firstInstance = s;
                    that.data('swiper', s);
                });
                return firstInstance;
            };
        })(window.jQuery || window.Zepto);
    }

    // component
    if (typeof(module) !== 'undefined') {
        module.exports = Swiper;
    }

    // requirejs support
    if (typeof define === 'function' && define.amd) {
        define([], function() {
            'use strict';
            return Swiper;
        });
    }

});