/**
 * Created by Tejas on 10/04/18.
 */
$(function () {

    if (mobile == "") {
        $('#myshow').cycle({
            swipe: "true",
            slides: "> div.slide",
            easing: "easeOutCubic",
            fx: 'scrollHorz', //'scrollVert',
            timeout: 26000,
            speed: 1200,
            allowWrap: true,
            log: false
        });
        var wh = window.innerHeight;
        var navH = $(".navbar").height();
        wh-=navH;
        //console.log(navH);
        $(".slide").height(wh);
        //$(".slide").height(wh*0.85);
    } else {
        console.log("mobile");
    }

    //$(".slide").height(wh);
    $(".slide").each(function () {
        var img = $(this).attr("data-slide-image");
        var me = $(this);
        if (mobile) {
            img = "assets/images/" + img;
        } else {
            img = "assets/images/" + img;
        }
        me.css('background', 'url("' + img + '")');
        me.css('background-repeat', 'no-repeat');
        me.css('background-position', 'center');
        me.css('background-size', 'cover');
    });

    $('#myshow').on('cycle-before', function (e, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
        var active = $(incomingSlideEl);
        //console.log(forwardFlag);
        //NEXT SLIDE
        $(incomingSlideEl).children().find(".slide_content").addClass("fadeInRight animated");
        $(incomingSlideEl).find(".img1").addClass("fadeInLeft animated");

        //CURRENT SLIDE
        //$(outgoingSlideEl).children().find(".slide_content").addClass("fadeOutLeft animated");

        //$(incomingSlideEl).children().find(".slide_head1").velocity("transition:slideUpIn");
        //$(incomingSlideEl).find(".slide_content").addClass("fadeInUp animated");
        if (active.is('#slide1')) {
//                $(incomingSlideEl).find(".slide_content").addClass("fadeInDown animated");
            //$(incomingSlideEl).find(".slide_content").addClass("fadeInUp animated");
        } else {
            //$(incomingSlideEl).find(".slide_content").addClass("fadeInUp animated");
        }
    });
    $('#myshow').on('cycle-after', function (e, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag) {
        var active = $(incomingSlideEl);
        $(outgoingSlideEl).children().find(".slide_content").removeClass("fadeInRight fadeOutLeft animated");
        $(outgoingSlideEl).find(".slide_content, .img1").removeClass("fadeInUp fadeInDown zoomIn  fadeInLeft fadeInRight bounce animated");

        if (active.is('#slide2')) {
            //
        }
    });

    var scroll = new SmoothScroll('a[href*="#"]');

//        var preload = ["<?php //if(is_array($img_main)){echo $img_path.$img_main[0]; }else{ echo $img_path.$img_main;} ?>//"];
//        var promises = [];
//        for (var i = 0; i < preload.length; i++) {
//            (function (url, promise) {
//                var img = new Image();
//                img.onload = function () {
//                    promise.resolve();
//                };
//                img.src = url;
//            })(preload[i], promises[i] = $.Deferred());
//        }
//        $.when.apply($, promises).done(function () {
//            //alert("All images ready sir!");
//            $(".preloader_div").hide();
//            var $cat_head = $(".product_name"),
//                $cat_tag = $(".product_tagline"),
//                $img_main = $(".img_main"),
//            //$icon = $(".icon"),
//                $element3 = $(".img_0");
//            var animationSequence =
//                [
//                    {e: $img_main, p: {scale: 0.9}, o: {easing: "easeOutCubic"}},
//                    {
//                        e: $img_main,
//                        p: {opacity: 1, scale: 1},
//                        o: {easing: "easeOutCubic", stagger: 800, delay: 500, duration: 2000}
//                    },
////                            { e: $element1,  p: { translateY: 10, opacity: 1}, o: {easing:"easeInCubic", stagger:800, delay:200 }},
//                {e: $cat_head, p: {translateY: 10, opacity: 1}, o: {easing: "easeOutElastic", duration: 600}},
//                {e: $cat_tag, p: {translateY: 10, opacity: 1}, o: {easing: "easeOutElastic", duration: 600}},
//            ];
//
//            $.Velocity.RunSequence(animationSequence);
//        });

});