(function($) {
    'use strict';
    $(document).ready(function() {
        "use strict";
        // Anchor Smooth Scroll
        $('body').on('click', '.page-scroll', function(event) {
            var $anchor = $(this);
            $('html, body').stop().animate({
                scrollTop: ($($anchor.attr('href')).offset().top - 80)
            }, 1500, 'easeInOutExpo');
            event.preventDefault();
        });
        // custom extra
        var $w_offset = $(window).width();
        var $w_container = $('.container');
        $.each($('.fix_pading_right'), function(i, item) {
            if ($w_container.length > 0) {
                $(item).css({
                    'padding-right': parseInt($w_offset - $w_container.width() + 30) / 2 + 'px'
                });
            }
        });
        $.each($('.video_box_fix'), function(i, item) {
            if ($('.testimonial-wrap').length > 0) {
                $(item).find('.vc_column-inner').css({
                    'padding-bottom': $('.testimonial-wrap').parents('.wpb_wrapper').height() + 'px'
                });
            }
        });
        // accordion fix
        $.each($('.panel-group'), function(i, item) {
            var currentId = $(item).attr('id');
            if (currentId != '') {
                var date = new Date();
                var newID = currentId + date.getTime() + i;
                $(item).attr('id', newID);
                $.each($(item).find('h4.panel-title a'), function(j, jtem) {
                    $(jtem).attr('data-parent', '#' + newID);
                    var targetId=$(jtem).attr('href');
                    if(j==0)
                    {
                        $(''+targetId+'').addClass('in');
                    }
                });
            }
        });
        //End accordion fix
        $(window).resize(function() {
            var $w_offset = $(window).width();
            var $w_container = $('.container');
            $.each($('.fix_pading_right'), function(i, item) {
                if ($w_container.length > 0) {
                    $(item).css({
                        'padding-right': parseInt($w_offset - $w_container.width() + 30) / 2 + 'px'
                    });
                }
            });
            $.each($('.video_box_fix'), function(i, item) {
                if ($('.testimonial-wrap').length > 0) {
                    $(item).find('.vc_column-inner').css({
                        'padding-bottom': $('.testimonial-wrap').parents('.wpb_wrapper').height() + 'px'
                    });
                }
            });
        });
        handleMapContact();
        if ($('.nav-default-fix').length > 0) {
            var fix = '-20px';
            if ($('.admin-bar').length > 0) {
                fix = '-52px'
            }
            if ($('.page-head').length > 0) {
                $('.page-head').css({
                    'margin-top': fix
                });
            }
            //blog-thumb
            if ($('.blog-thumb').length > 0) {
                $('.blog-thumb').css({
                    'margin-top': fix
                });
            }
        }
    });

    function handleMapContact() {
        if ($('.google-map').length > 0 && typeof(google) != "undefined") {
            var long = $('.google-map >div').attr('data-lon');
            var lat = $('.google-map >div').attr('data-lat');
            var Id = $('.google-map >div').attr('id');
            var zoom = $('.google-map >div').attr('data-zoom');
            var city = $('.google-map >div').attr('data-city');
            var address = $('.google-map >div').attr('data-address');
            var title = $('.google-map >div').attr('data-title');
            var iconMarker = $('.google-map >div').attr('data-icon')
            if (typeof(long) == "undefined") long = '40.9807648';
            if (typeof(lat) == "undefined") lat = '28.9866516';
            if (typeof(zoom) == "undefined") zoom = '12';
            if (typeof(city) == "undefined") city = 'Hello';
            if (typeof(address) == "undefined") address = 'ovatheme.com';
            var map;
            var stylez = [{
                featureType: "all",
                elementType: "all",
                stylers: [{
                    saturation: -100
                }]
            }];
            var mapOptions = {
                zoom: parseInt(zoom),
                center: new google.maps.LatLng(lat, long),
                streetViewControl: true,
                scrollwheel: true,
                panControl: true,
                zoomControl: true,
                mapTypeControl: false,
                overviewMapControl: true,
                mapTypeControlOptions: {
                    mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'TouxtMapStyle']
                }
            };
            map = new google.maps.Map(document.getElementById(Id), mapOptions);
            // var mapType = new google.maps.StyledMapType(stylez, {
            //     name: "Grayscale"
            // });
            // map.mapTypes.set('TouxtMapStyle', mapType);
            // map.setMapTypeId('TouxtMapStyle');
            var myLatLng = new google.maps.LatLng(lat, long);
            if (iconMarker == '') {
                var beachMarker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    title: title
                });
            } else {
                var beachMarker = new google.maps.Marker({
                    position: myLatLng,
                    map: map,
                    icon: iconMarker
                });
            }
            var infowindow = new google.maps.InfoWindow({
                content: "<div class='noScroll'><b>" + city + "</b>" + address + "</div>"
            });
            google.maps.event.addListener(beachMarker, "click", function() {
                infowindow.open(map, beachMarker);
            });
            infowindow.open(map, beachMarker);
        }
    }
    $.stellar({
        horizontalOffset: 50,
        verticalOffset: 50,
        responsive: true
    });
    // Fullwidth Slider
    setTimeout(function() {
        $('#intro6-slider').flexslider({
            animation: "slide",
            slideshowSpeed: 5000,
            animationSpeed: 1000,
            controlNav: false,
            directionNav: true
        });
    }, 500)
    $('.is-prev').on('click', function() {
        $('#intro6-slider').flexslider('prev')
        return false;
    })
    $('.is-next').on('click', function() {
        $('#intro6-slider').flexslider('next')
        return false;
    });
    // Countdown Timer
    $.each($('.intro-countdown'), function(i, item) {
        var end_day = $(this).data('end_day');
        var end_month = $(this).data('end_month') - 1;
        var end_year = $(this).data('end_year');
        var label_years = $(this).data('years');
        var label_months = $(this).data('months');
        var label_weeks = $(this).data('weeks');
        var label_days = $(this).data('days');
        var label_hours = $(this).data('hours');
        var label_minutes = $(this).data('minutes');
        var label_seconds = $(this).data('seconds');
        var label_years1 = $(this).data('years1');
        var label_months1 = $(this).data('months1');
        var label_weeks1 = $(this).data('week1s');
        var label_days1 = $(this).data('days1');
        var label_hours1 = $(this).data('hours1');
        var label_minutes1 = $(this).data('minutes1');
        var label_seconds1 = $(this).data('seconds1');
        var timezone = '0';
        var display_format = $(this).data('time_zone');
        $(this).find('.countdown.styled').countdown({
            labels: [label_years, label_months, label_weeks, label_days, label_hours, label_minutes, label_seconds],
            labels1: [label_years1, label_months1, label_weeks1, label_days1, label_hours1, label_minutes1, label_seconds1],
            until: new Date(end_year, end_month, end_day),
            timezone: timezone,
            format: display_format
        });
    });
    // Quote
    $.each($('.quote'), function(i, item) {
        var is_dot = $(item).attr('data-isdot');
        $(item).slick({
            arrows: false,
            dots: is_dot === 'true'
        });
    });
    $('.facts-wrap').appear(function() {
        $.each($('.facts-wrap'), function(i, item) {
            var number = $(item).find('.counter').attr('data-number');
            var time = $(item).find('.counter').attr('data-time');
            $(item).find('.counter').animateNumber({
                number: parseInt(number)
            }, parseInt(time));
        });
    }, {
        accX: 0,
        accY: -200
    });
    // Prettyphoto
    $("a[class^='prettyPhoto']").prettyPhoto({
        theme: 'pp_default'
    });
    // Scrollspy
    $('body').scrollspy({
            target: ".navbar",
            offset: 105
        })
        // Fixed Header
    $(window).scroll(function() {
        var value = $(this).scrollTop();
        if (value > 100) $(".navbar-default").css("background", "#111").css("padding", "15px 0");
        else $(".navbar-default").css("background", "transparent").css("padding", "25px 0");
    });
    $('.shots').slick({
        centerMode: true,
        arrows: true,
        dots: false,
        slidesToShow: 5,
        prevArrow: "<div class='slick-prev'><i class='fa fa-angle-left'></div>",
        nextArrow: "<div class='slick-next'><i class='fa fa-angle-right'></div>",
        responsive: [{
            breakpoint: 769,
            settings: {
                slidesToShow: 3
            }
        }, {
            breakpoint: 480,
            settings: {
                slidesToShow: 1
            }
        }]
    });
    // Product Filter
    $(window).load(function() {
        "use strict";
        var $container = $('.portfolio-grid');
        $container.isotope({
            layoutMode: "masonry",
            masonry: {
                columnWidth: 5
            },
            itemSelector: '.portfolio-item',
            transitionDuration: '0.8s'
        });
        var $optionSets = $('.portfolio-filter'),
            $optionLinks = $optionSets.find('a');
        $optionLinks.click(function() {
            var $this = $(this);
            // don't proceed if already selected
            if ($this.hasClass('active')) {
                return false;
            }
            var $optionSet = $this.parents('.portfolio-filter');
            $optionSet.find('.active').removeClass('active');
            $this.addClass('active');
            // make option object dynamically, i.e. { filter: '.my-filter-class' }
            var options = {},
                key = $optionSet.attr('data-option-key'),
                value = $this.attr('data-option-value');
            // parse 'false' as false boolean
            value = value === 'false' ? false : value;
            options[key] = value;
            if (key === 'layoutMode' && typeof changeLayoutMode === 'function') {
                changeLayoutMode($this, options);
            } else {
                // otherwise, apply new options
                $container.isotope(options);
            }
            return false;
        });
    });
    // Product Filter
    $(window).load(function() {
        "use strict";
        var $container = $('.blog-masonry');
        $container.isotope({
            layoutMode: "masonry",
            masonry: {
                columnWidth: 5
            },
            itemSelector: '.item',
            transitionDuration: '0.8s'
        });
        var $optionSets = $('.bm-filter'),
            $optionLinks = $optionSets.find('a');
        $optionLinks.click(function() {
            var $this = $(this);
            // don't proceed if already selected
            if ($this.hasClass('active')) {
                return false;
            }
            var $optionSet = $this.parents('.bm-filter');
            $optionSet.find('.active').removeClass('active');
            $this.addClass('active');
            // make option object dynamically, i.e. { filter: '.my-filter-class' }
            var options = {},
                key = $optionSet.attr('data-option-key'),
                value = $this.attr('data-option-value');
            // parse 'false' as false boolean
            value = value === 'false' ? false : value;
            options[key] = value;
            if (key === 'layoutMode' && typeof changeLayoutMode === 'function') {
                changeLayoutMode($this, options);
            } else {
                // otherwise, apply new options
                $container.isotope(options);
            }
            return false;
        });
    });
})(jQuery);