/* Gets IE version */
/* -------------------------------------------------------------------- */

function mk_detect_ie() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf('MSIE ');
    var trident = ua.indexOf('Trident/');
    if (msie > 0) {
        return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
    }
    if (trident > 0) {
        var rv = ua.indexOf('rv:');
        return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
    }
    return false;
};/* Page Loader */
/* -------------------------------------------------------------------- */

function mk_query_loader() {
    if (jQuery().queryLoader2 && mk_detect_ie() == false) {
        $("body").queryLoader2({
            showbar: "on",
            barColor: mk_accent_color,
            textColor: mk_preloader_txt_color,
            backgroundColor: mk_preloader_bg_color,
            barHeight: 1,
            logo: mk_preloader_logo,
            percentage: true,
            completeAnimation: "fade",
            minimumTime: 700,
            onComplete: function() {
                $(".mk-body-loader-overlay").fadeOut(600, "easeInOutExpo", function() {
                    $(this).remove();
                });
            }
        });
    }

    if (mk_detect_ie() > 7) {
        $('.mk-body-loader-overlay').hide();
    }
};/* Window Scroller */
/* -------------------------------------------------------------------- */

function mk_window_scroller() {
    if (!$.exists('.mk-window-scroller')) {
        return false;
    }

    $('.mk-window-scroller').each(function() {
        var $this = $(this),
            $container_h = $this.attr('data-height'),
            $image = $this.find('img'),
            $speed = parseInt($this.attr('data-speed'));

        $this.stop(true, true).hoverIntent(function() {
            $image.animate({
                'top': -($image.height() - $container_h)
            }, $speed);

        }, function() {
            $image.animate({
                'top': 0
            }, $speed / 3);
        });
    });

};/* Header Section Sticky function */
/* -------------------------------------------------------------------- */

function sticky_header() {
    if ($('#mk-header').hasClass('sticky-header') && $(window).width() > mk_nav_res_width) {
        var mk_window_y = parseInt($(window).scrollTop());
        var $mk_header_height = parseInt((mk_header_padding * 2) + mk_logo_height) + 30;

        if (mk_window_y > $mk_header_height) {

            $('#mk-header').addClass('sticky-trigger-header');

        } else {

            $('#mk-header').removeClass('sticky-trigger-header');
        }
        setTimeout(function() {
            mk_main_navigation();
        }, 200);

    }

}



function transparent_header_sticky() {
    if ($('#mk-header').hasClass('transparent-header') && $(window).width() > mk_nav_res_width) {
        var mk_window_y = parseInt($(window).scrollTop()),
            edge_active = $('.mk-edge-slider.first-el-true').find('.swiper-slide-active').attr('data-header-skin'),
            $mk_header_height = parseInt((mk_header_padding * 2) + mk_logo_height) + 30;
        mk_header_trans_offset = (mk_header_trans_offset == 0) ? $(window).height() : mk_header_trans_offset;
        if ($.exists("#wpadminbar")) {
            var $wp_admin_height = $("#wpadminbar").height();
        } else {
            var $wp_admin_height = 0;
        }

        if (mk_window_y > $mk_header_height) {
            $('#mk-header').addClass('header-offset-passed').css('top', -200);
        } else {
            $('#mk-header').removeClass('header-offset-passed').attr('top', '');
        }

        if (mk_window_y > mk_header_trans_offset) {
            $('#mk-header').addClass('transparent-header-sticky sticky-trigger-header').removeClass('light-header-skin dark-header-skin').css('top', $wp_admin_height);

        } else {
            if (edge_active != '' && typeof edge_active !== 'undefined') {
                $('#mk-header').removeClass('transparent-header-sticky sticky-trigger-header').addClass(edge_active + '-header-skin').css('top', '');
            } else {
                $('#mk-header').removeClass('transparent-header-sticky sticky-trigger-header').addClass($('#mk-header').attr('data-transparent-skin') + '-header-skin').css('top', '');
            }


        }

        setTimeout(function() {
            mk_main_navigation();
        }, 200);

    }

}
;/* Main Navigation Init */
/* -------------------------------------------------------------------- */

function mk_main_navigation_init() {

    $(".main-navigation-ul").dcMegaMenu({
        rowItems: '6',
        speed: 200,
        effect: 'fade',
        fullWidth: true
    });

}



/* Main Navigation desktop mode */
/* -------------------------------------------------------------------- */

function mk_main_navigation() {

    var $mk_header_height = (mk_header_padding * 2) + mk_logo_height;
    var $mk_sticky_header_height = parseInt((mk_header_padding * 2) / 2.4) + parseInt(mk_logo_height / 1.5);

    if ($('#mk-header').hasClass('sticky-header') || $.exists('.mk-secondary-header') || $('#mk-header').hasClass('transparent-header')) {

        if (($('#mk-header').hasClass('sticky-trigger-header') || $('.mk-secondary-header').hasClass('sticky-trigger-header')) && $(window).width() > mk_nav_res_width && mk_squeeze_header != 0) {
            $('.main-navigation-ul div.sub-container, .mk-shopping-box').css('top', $mk_sticky_header_height);

        } else {

            $('.main-navigation-ul div.sub-container, .mk-shopping-box').css('top', $mk_header_height);

        }
    } else {
        $('.main-navigation-ul div.sub-container, .mk-shopping-box').css('top', $mk_header_height);
    }
}



/* Main Navigation mobile mode */
/* -------------------------------------------------------------------- */

function mk_main_navigation_functions() {

    if ($(window).width() > mk_nav_res_width) {

        $('#mk-responsive-nav').hide();
        setTimeout(function() {
            mk_main_navigation_init();
            mk_main_navigation();
        }, 200);

        if ($('#mk-header').attr('data-header-style') == 'transparent') {
            $('#mk-header').addClass('transparent-header ' + $('#mk-header').attr('data-transparent-skin') + '-header-skin');
        }



    } else {
        if (!$.exists('#mk-responsive-nav')) {
            $('.main-navigation-ul').clone().attr({
                id: "mk-responsive-nav",
                "class": ""
            }).appendTo('.responsive-nav-container');

            $('#mk-responsive-nav > li > ul, #mk-responsive-nav > li > div').each(function() {
                $(this).siblings('a').append('<span class="mk-theme-icon-bottom-big mk-nav-arrow mk-nav-sub-closed"></span>');
            });

            $('#mk-responsive-nav').on('click', '.mk-nav-arrow', function(e) {

                if ($(this).hasClass('mk-nav-sub-closed')) {
                    $(this).parent().siblings('ul').slideDown(300);
                    $(this).parent().siblings('div').slideDown(300);
                    $(this).removeClass('mk-nav-sub-closed').addClass('mk-nav-sub-opened');
                } else {
                    $(this).parent().siblings('ul').slideUp(300);
                    $(this).parent().siblings('div').slideUp(300);
                    $(this).removeClass('mk-nav-sub-opened').addClass('mk-nav-sub-closed');
                }
                e.preventDefault();
            });

        }

        if ($('#mk-header').attr('data-header-style') == 'transparent') {
            $('#mk-header').removeClass('transparent-header ' + $('#mk-header').attr('data-transparent-skin') + '-header-skin');
        }

        $('#mk-responsive-nav li, #mk-responsive-nav li a, #mk-responsive-nav ul, #mk-responsive-nav div').removeAttr('style');

        $('.mk-header-inner').attr('style', '');


        $('#mk-responsive-nav').append($('.responsive-searchform'));

        $('#mk-responsive-nav').show();

    }


    if ($(window).width() < mk_grid_width) {
        $('.main-navigation-ul .sub-container.mega, .main-navigation-ul .sub-container.mega .row').each(function() {
            $(this).css('width', $(window).width() - 40);
        });
    }



};/* Secondary Header Scripts */
/* -------------------------------------------------------------------- */

var secondary_header_offset;

function mk_secondary_header_res() {
    if ($.exists('.mk-secondary-header')) {
        secondary_header_offset = $('.mk-secondary-header').position().top;
    }
}

function secondary_header() {
    if ($.exists('.mk-secondary-header')) {

        var wpadminbar = 0,
            mk_header = 0,
            $window_top = $(window).scrollTop();


        if ($.exists("#wpadminbar")) {
            var wpadminbar = $("#wpadminbar").height();
        }

        if ($.exists("#mk-header.sticky-header")) {
            var mk_header = parseInt($("#mk-header.sticky-header").attr('data-sticky-height'));
        }

        var dsitance_from_top = secondary_header_offset - mk_header;

        //console.log(secondary_header_offset);
        if ($window_top > dsitance_from_top) {
            $('.mk-secondary-header').addClass('secondary-header-sticky').css('top', (mk_header + wpadminbar));
            $('.secondary-header-space').addClass('secondary-space-sticky');
        } else {
            $('.mk-secondary-header').removeClass('secondary-header-sticky').css('top', 'auto');
            $('.secondary-header-space').removeClass('secondary-space-sticky');
        }

    }
}
;
/* Retina compatible images */
/* -------------------------------------------------------------------- */
var mk_retina = function() {
    return {
        init: function() {
            var pixelRatio = !!window.devicePixelRatio ? window.devicePixelRatio : 1;
            if (pixelRatio > 1) {
                $("img").each(function(idx, el) {
                    el = $(el);
                    if (el.attr("data-retina-src")) {
                        el.attr("data-src-orig", el.attr("src"));
                        el.attr("src", el.attr("data-retina-src"));
                    }
                });
            }
        }
    };
}();
mk_retina.init();

;
$(window).load(function() {

    /* Milestone Number Shortcode */
    /* -------------------------------------------------------------------- */
    $('.mk-milestone').one('inview', function(event, visible) {
        if (visible == true) {

            var el_this = $(this),
                stop_number = el_this.find('.milestone-number').attr('data-stop'),
                animation_speed = parseInt(el_this.find('.milestone-number').attr('data-speed'));

            $({
                countNum: el_this.find('.milestone-number').text()
            }).animate({
                countNum: stop_number
            }, {
                duration: animation_speed,
                step: function() {
                    el_this.find('.milestone-number').text(Math.floor(this.countNum));
                },
                complete: function() {
                    el_this.find('.milestone-number').text(this.countNum);
                }
            });
        }
    });



    /* Skill Meter and Charts */
    /* -------------------------------------------------------------------- */
    $('.mk-skill-meter .progress-outer').one('inview', function(event, visible) {
        if (visible == true) {
            var $this = $(this);
            $this.animate({
                width: $(this).attr("data-width") + '%'
            }, 2000);
        }
    });



    $('.mk-chart').one('inview', function(event, visible) {
        if (visible == true) {
            var $this = $(this),
                $parent_width = $(this).parent().width(),
                $chart_size = $this.attr('data-barSize');

            if ($parent_width < $chart_size) {
                $chart_size = $parent_width;
                $this.css('line-height', $chart_size);
                $this.find('i').css({
                    'line-height': $chart_size + 'px',
                    'font-size': ($chart_size / 3)
                });
            }
            $this.easyPieChart({
                animate: 1300,
                lineCap: 'square',
                lineWidth: $this.attr('data-lineWidth'),
                size: $chart_size,
                barColor: $this.attr('data-barColor'),
                trackColor: $this.attr('data-trackColor'),
                scaleColor: 'transparent',
                onStep: function(value) {
                    this.$el.find('.chart-percent span').text(Math.ceil(value));
                }
            });
        }
    });



    /* Animated Contents */
    /* -------------------------------------------------------------------- */
    if (is_touch_device() || $(window).width() < 800) {
        $('body').addClass('no-transform').find('.mk-animate-element').removeClass('mk-animate-element');
    }

    $('.mk-animate-element').one('inview', function(event, visible) {
        if (visible == true) {
            $(this).addClass('mk-in-viewport');
        }
    });


});
;/* Google Maps */
/* -------------------------------------------------------------------- */

function mk_google_maps() {


    "use strict";

    $('.mk-gmaps').each(function() {

        var $this = $(this),
            $id = $this.attr('id'),
            $zoom = parseInt($this.attr('data-zoom')),
            $latitude = $this.attr('data-latitude'),
            $longitude = $this.attr('data-longitude'),
            $address = $this.attr('data-address'),
            $latitude_2 = $this.attr('data-latitude2'),
            $longitude_2 = $this.attr('data-longitude2'),
            $address_2 = $this.attr('data-address2'),
            $latitude_3 = $this.attr('data-latitude3'),
            $longitude_3 = $this.attr('data-longitude3'),
            $address_3 = $this.attr('data-address3'),
            $pin_icon = $this.attr('data-pin-icon'),
            $pan_control = $this.attr('data-pan-control') === "true" ? true : false,
            $map_type_control = $this.attr('data-map-type-control') === "true" ? true : false,
            $scale_control = $this.attr('data-scale-control') === "true" ? true : false,
            $draggable = $this.attr('data-draggable') === "true" ? true : false,
            $zoom_control = $this.attr('data-zoom-control') === "true" ? true : false,
            $modify_coloring = $this.attr('data-modify-coloring') === "true" ? true : false,
            $saturation = $this.attr('data-saturation'),
            $hue = $this.attr('data-hue'),
            $lightness = $this.attr('data-lightness'),
            $styles;



        if ($modify_coloring == true) {
            var $styles = [{
                stylers: [{
                    hue: $hue
                }, {
                    saturation: $saturation
                }, {
                    lightness: $lightness
                }, {
                    featureType: "landscape.man_made",
                    stylers: [{
                        visibility: "on"
                    }]
                }]
            }];
        }


        var map;

        function initialize() {

            var bounds = new google.maps.LatLngBounds();

            var mapOptions = {
                zoom: $zoom,
                panControl: $pan_control,
                zoomControl: $zoom_control,
                mapTypeControl: $map_type_control,
                scaleControl: $scale_control,
                draggable: $draggable,
                scrollwheel: false,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                styles: $styles
            };

            map = new google.maps.Map(document.getElementById($id), mapOptions);
            map.setTilt(45);

            // Multiple Markers

            var markers = [];
            var infoWindowContent = [];

            if ($latitude != '' && $longitude != '') {
                markers[0] = [$address, $latitude, $longitude];
                infoWindowContent[0] = ['<div class="info_content"><p>' + $address + '</p></div>'];
            }

            if ($latitude_2 != '' && $longitude_2 != '') {
                markers[1] = [$address_2, $latitude_2, $longitude_2];
                infoWindowContent[1] = ['<div class="info_content"><p>' + $address_2 + '</p></div>'];
            }

            if ($latitude_3 != '' && $longitude_3 != '') {
                markers[2] = [$address_3, $latitude_3, $longitude_3];
                infoWindowContent[3] = ['<div class="info_content"><p>' + $address_3 + '</p></div>'];
            }



            var infoWindow = new google.maps.InfoWindow(),
                marker, i;


            for (i = 0; i < markers.length; i++) {
                var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
                bounds.extend(position);
                marker = new google.maps.Marker({
                    position: position,
                    map: map,
                    title: markers[i][0],
                    icon: $pin_icon
                });

                google.maps.event.addListener(marker, 'click', (function(marker, i) {
                    return function() {
                        infoWindow.setContent(infoWindowContent[i][0]);
                        infoWindow.open(map, marker);
                    }
                })(marker, i));

                map.fitBounds(bounds);

            }


            var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
                this.setZoom($zoom);
                google.maps.event.removeListener(boundsListener);
            });
        }

        google.maps.event.addDomListener(window, "load", initialize);



    });

    $(window).load(function() {
        if ($.exists('.mk-gmaps-parallax')) {
            var mk_skrollr = skrollr.init({
                forceHeight: false
            });
            mk_skrollr.refresh($('.mk-page-section'));
        }
    });

};/* Header Search, Header Dashboard scripts */
/* -------------------------------------------------------------------- */

$(".mk-header-search, .mk-side-dashboard, .dashboard-trigger, .search-ajax-input").click(function(event) {
    if (event.stopPropagation) {
        event.stopPropagation();
    } else if (window.event) {
        window.event.cancelBubble = true;
    }
});


$("html").click(function() {
    $('.header-search-icon').removeClass('search-clicked');
    $('form.header-searchform-input').fadeOut(250);
    $('#mk-header').removeClass('header-search-triggered');
    $('.dashboard-trigger').removeClass('dashboard-active');
    $('.theme-main-wrapper, .mk-side-dashboard').removeClass('dashboard-opened');

});


$('.header-search-icon').on('click', function(e) {
    $('form.header-searchform-input').fadeIn(250);
    $('#mk-header').addClass('header-search-triggered');
    $('form.header-searchform-input input[type=text]').focus();
    e.preventDefault();
});

$('.header-search-close').on('click', function(e) {
    $('form.header-searchform-input').fadeOut(250);
    $('#mk-header').removeClass('header-search-triggered');
    e.preventDefault();
});



$('.dashboard-trigger').on('click', function(e) {

    var $this = $(this);

    if (!$this.hasClass('dashboard-active')) {

        $this.addClass('dashboard-active');
        $('.theme-main-wrapper, .mk-side-dashboard').addClass('dashboard-opened');

    } else {

        $this.removeClass('dashboard-active');
        $('.theme-main-wrapper, .mk-side-dashboard').removeClass('dashboard-opened');
    }
    e.preventDefault();
});


$('.responsive-nav-link').on('click', function(e) {
    var $this = $(this);

    if (!$this.hasClass('res-nav-opened')) {

        $this.addClass('res-nav-opened');
        $('.responsive-nav-container').slideDown(600);

    } else {

        $this.removeClass('res-nav-opened');
        $('.responsive-nav-container').slideUp(600);
    }
    e.preventDefault();
});;/* jQuery Colorbox lightbox */
/* -------------------------------------------------------------------- */

function mk_lightbox_init() {
    jQuery(".mk-lightbox").fancybox({ 
        padding: 15, 
        margin: 15,
 
        width: 800,
        height: 600,
        minWidth: 100,
        minHeight: 100,
        maxWidth: 9999,
        maxHeight: 9999,
        pixelRatio: 1, // Set to 2 for retina display support

        autoSize: true,
        autoHeight: false,
        autoWidth: false,

        autoResize: true,
        fitToView: true,
        aspectRatio: false,
        topRatio: 0.5,
        leftRatio: 0.5,

        scrolling: 'auto', // 'auto', 'yes' or 'no'
        wrapCSS: '',

        arrows: true,
        closeBtn: true,
        closeClick: false,
        nextClick: false,
        mouseWheel: true,
        autoPlay: false,
        playSpeed: 3000,
        preload: 3,
        modal: false,
        loop: true,
        // Properties for each animation type
        // Opening fancyBox
        openEffect: 'elastic', // 'elastic', 'fade' or 'none'
        openSpeed: 250,
        openEasing: 'swing',
        openOpacity: true,
        openMethod: 'zoomIn',

        // Closing fancyBox
        closeEffect: 'elastic', // 'elastic', 'fade' or 'none'
        closeSpeed: 250,
        closeEasing: 'swing',
        closeOpacity: true,
        closeMethod: 'zoomOut',
 
        // Changing next gallery item
        nextEffect: 'fade', // 'elastic', 'fade' or 'none'
        nextSpeed: 350,
        nextEasing: 'swing',
        nextMethod: 'changeIn',

        // Changing previous gallery item
        prevEffect: 'fade', // 'elastic', 'fade' or 'none'
        prevSpeed: 350,
        prevEasing: 'swing',
        prevMethod: 'changeOut',

        tpl: {
            wrap: '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
            image: '<img class="fancybox-image" src="{href}" alt="" />',
            error: '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
            closeBtn: '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"><i class="mk-theme-icon-cancel"></i></a>',
            next: '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span><i class="mk-theme-icon-next-small"></i></span></a>',
            prev: '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span><i class="mk-theme-icon-prev-small"></i></span></a>',
            loading: '<div id="fancybox-loading"><div></div></div>'
        },

    });

};/* Edge Slideshow */
/* -------------------------------------------------------------------- */

function mk_edge_slider_init() {

    $('.mk-edge-slider').each(function() {
        var $slider_wrapper = $(this),
            $next_arrow = $slider_wrapper.find('.mk-edge-next'),
            $prev_arrow = $slider_wrapper.find('.mk-edge-prev'),
            $pause = $slider_wrapper.attr('data-pause'),
            $first_el = $slider_wrapper.attr('data-first'),
            $speed = $slider_wrapper.attr('data-speed');

        // remove viewport animations from slider    
        $slider_wrapper.find('.mk-animate-element').removeClass('mk-animate-element fade-in scale-up right-to-left left-to-right bottom-to-top top-to-bottom forthy-five-rotate');

        var mk_swiper = $slider_wrapper.swiper({
            mode: 'horizontal',
            loop: true,
            grabCursor: true,
            useCSS3Transforms: true,
            mousewheelControl: false,
            // pagination : $pagination_class,
            freeModeFluid: true,
            speed: $speed,
            autoplay: $pause,
            autoplayDisableOnInteraction: true,
            onSwiperCreated: function(swiper) {
                if (mk_detect_ie() == false) {
                    var prev_active_slide = $slider_wrapper.find('.swiper-slide').eq(0).find('.edge-slide-content .mk-edge-title').text(),
                        next_active_slide = $slider_wrapper.find('.swiper-slide').eq(2).find('.edge-slide-content .mk-edge-title').text();
                    //console.log(prev_active_slide + "---" + next_active_slide);
                    if (prev_active_slide.length > 1) {
                        $prev_arrow.find('.prev-item-caption').show().text(prev_active_slide);
                    } else {
                        $prev_arrow.find('.prev-item-caption').css('display', 'none');
                    }
                    if (next_active_slide.length > 1) {
                        $next_arrow.find('.next-item-caption').show().text(next_active_slide);
                    } else {
                        $next_arrow.find('.next-item-caption').css('display', 'none');
                    }

                    if (!$('#mk-header').hasClass('transparent-header-sticky')) {
                        if ($first_el == 'true') {
                            $('#mk-header.transparent-header').removeClass('light-header-skin dark-header-skin').addClass($slider_wrapper.find('.swiper-slide').eq(1).attr('data-header-skin') + '-header-skin');
                        }
                    }

                } else {
                    $next_arrow.find('.next-item-caption').css('display', 'none');
                    $prev_arrow.find('.prev-item-caption').css('display', 'none');
                }

            },
            onSlideChangeEnd: function() {

                if (mk_detect_ie() == false) {
                    var prev_active_slide = $(mk_swiper.getSlide(mk_swiper.activeLoopIndex)).find('.edge-slide-content .mk-edge-title').text(),
                        next_active_slide = $(mk_swiper.getSlide(mk_swiper.activeLoopIndex + 2)).find('.edge-slide-content .mk-edge-title').text();

                    if (prev_active_slide.length > 1) {
                        $prev_arrow.find('.prev-item-caption').show().text(prev_active_slide);
                    } else {
                        $prev_arrow.find('.prev-item-caption').css('display', 'none');
                    }
                    if (next_active_slide.length > 1) {
                        $next_arrow.find('.next-item-caption').show().text(next_active_slide);
                    } else {
                        $next_arrow.find('.next-item-caption').css('display', 'none');
                    }

                    if (!$('#mk-header').hasClass('transparent-header-sticky')) {
                        if ($first_el == 'true') {
                            $('#mk-header.transparent-header').removeClass('light-header-skin dark-header-skin').addClass($(mk_swiper.getSlide(mk_swiper.activeLoopIndex + 1)).attr('data-header-skin') + '-header-skin');
                        }
                    }

                } else {
                    $next_arrow.find('.next-item-caption').css('display', 'none');
                    $prev_arrow.find('.prev-item-caption').css('display', 'none');
                }
            }



        });

        $prev_arrow.click(function(e) {
            mk_swiper.swipePrev();
            e.preventDefault();
        });

        $next_arrow.click(function(e) {
            mk_swiper.swipeNext();
            e.preventDefault();
        });

    });

}



function mk_edge_slider_resposnive() {


    $('.mk-edge-slider').each(function() {


        var $this = $(this),
            $containers = $this.find('.edge-slider-holder, .swiper-slide'),
            $height = $this.attr('data-height'),
            $fullHeight = $this.attr('data-fullHeight'),
            $wpadminbar = 0,
            $header_height = 0;

        var $window_height = $(window).outerHeight();


        if ($.exists('#wpadminbar')) {
            $wpadminbar = $('#wpadminbar').outerHeight();
        }

        if ($.exists('#mk-header.sticky-header') && !$('#mk-header').hasClass('transparent-header')) {
            var $header_height = parseInt($('#mk-header.sticky-header').attr('data-sticky-height'));
        }


        if ($fullHeight === 'true') {
            $window_height = $window_height - $header_height - $wpadminbar;
        } else {
            $window_height = $height;
        }


        $containers.css('height', $window_height);
        $this.css('height', $window_height);



        $this.find('.swiper-slide').each(function() {


            var $this = $(this),
                $content = $this.find('.edge-slide-content');

            if ($this.hasClass('left_center') || $this.hasClass('center_center') || $this.hasClass('right_center')) {

                var $this_height_half = $content.outerHeight() / 2,
                    $window_half = $window_height / 2;

                $content.css('marginTop', ($window_half - $this_height_half));
            }

            if ($this.hasClass('left_bottom') || $this.hasClass('center_bottom') || $this.hasClass('right_bottom')) {

                var $distance_from_top = $window_height - $content.outerHeight() - 90;

                $content.css('marginTop', ($distance_from_top));
            }

        });

        $this.find('.edge-slider-loading').fadeOut();
    });

}



$(window).on("debouncedresize", function(event) {
    setTimeout(function() {
        mk_edge_slider_resposnive();
    }, 500);
});
;
/* Swipe Slideshow */
/* -------------------------------------------------------------------- */


function mk_swipe_slider() {

    $('.mk-swiper-slider').each(function() {

        var $this = $(this),
            $thumbs = $this.parent().siblings('.gallery-thumbs-small'),
            $next_arrow = $this.find('.mk-swiper-next'),
            $prev_arrow = $this.find('.mk-swiper-prev'),
            $direction = $this.attr('data-direction'),
            $pagination = $this.attr('data-pagination') === "true" ? true : false,
            $slideshowSpeed = $this.attr('data-slideshowSpeed'),
            $animationSpeed = $this.attr('data-animationSpeed'),
            //$controlNav = $this.attr('data-controlNav') === "true" ? true : false,
            //$directionNav = $this.attr('data-directionNav') === "true" ? true : false,
            $freeModeFluid = $this.attr('data-freeModeFluid') === "true" ? true : false,
            $freeMode = $this.attr('data-freeMode') === "true" ? true : false,
            $mousewheelControl = $this.attr('data-mousewheelControl') === "true" ? true : false,
            $loop = $this.attr('data-loop') === "true" ? true : false,
            $slidesPerView = $this.attr('data-slidesPerView');

        if ($pagination === true) {
            var $pagination_class = '#' + $this.attr('id') + ' .swiper-pagination';
        } else {
            var $pagination_class = false;
        }


        var mk_swiper = $(this).swiper({
            mode: $direction,
            loop: $loop,
            freeMode: $freeMode,
            pagination: $pagination_class,
            freeModeFluid: $freeModeFluid,
            autoplay: $slideshowSpeed,
            speed: $animationSpeed,
            calculateHeight: true,
            grabCursor: true,
            //useCSS3Transforms: false,
            //mousewheelControl: $mousewheelControl,
            mousewheelControl: true,
            mousewheelControlForceToAxis: true,
            paginationClickable: true,
            slidesPerView: $slidesPerView,
            onSwiperCreated: function(swiper) {
                mk_lightbox_init();
            },
            onSlideChangeStart: function() {
                $thumbs.find('.active-item').removeClass('active-item');
                $thumbs.find('a').eq(mk_swiper.activeIndex).addClass('active-item');
            }
        });


        $prev_arrow.click(function(e) {
            mk_swiper.swipePrev();
            e.preventDefault();
        });

        $next_arrow.click(function(e) {
            mk_swiper.swipeNext();
            e.preventDefault();
        });



        $thumbs.find('a').on('touchstart mousedown', function(e) {
            e.preventDefault();
            $thumbs.find('.active-item').removeClass('active-item');
            $(this).addClass('active-item');
            mk_swiper.swipeTo($(this).index());
        });

        $thumbs.find('a').click(function(e) {
            e.preventDefault();
        });


    });

}


function mk_gallery_thumbs_width() {

    $('.mk-gallery.thumb-style .gallery-thumbs-small').each(function() {

        var $this = $(this),
            $thumbs_count = $this.children().length,
            $thumbs_width = $thumbs_count * $this.find('a').outerWidth(),
            $container_width = $this.siblings('.gallery-thumb-large').outerWidth();

        if ($thumbs_width > $container_width) {
            $this.find('a').css('width', 100 / $thumbs_count + '%');
        }
    });
}

;
/* Section Background Parallax Effects */
/* -------------------------------------------------------------------- */

function mk_section_parallax() {
    if (is_touch_device() || $(window).width() < 800) {
        return false;
    }

    $('.mk-page-section.parallax-true').each(function() {

        var $this = $(this),
            $direction = $this.attr('data-direction'),
            $speedFactor = $this.attr('data-speedFactor');

        if ($direction === 'horizontal_mouse' || $direction === 'vertical_mouse' || $direction === 'both_axis_mouse') {

            var $yparallax = $this.attr('data-direction') === "vertical_mouse" ? true : false,
                $xparallax = $this.attr('data-direction') === "horizontal_mouse" ? true : false,
                $xyparallax = $this.attr('data-direction') === "both_axis_mouse" ? true : false;

            if ($xyparallax === true) {
                $xparallax = true;
                $yparallax = true;
            }


            $(this).find('.parallax-layer').parallax({
                mouseport: $this,
                yparallax: $yparallax,
                xparallax: $xparallax,
                decay: 0.8,
                frameDuration: 50
            });

        } else {

            var mk_skrollr = skrollr.init({
                forceHeight: false,
                mobileCheck: function() {
                    return false;
                }
            });
            mk_skrollr.refresh($('.mk-page-section'));

        }

    });


}



function mk_image() {

    $('.mk-image').each(function() {
        var $this = $(this),
            width = $this.outerWidth(),
            caption_h = $this.find('.mk-image-hover').outerHeight(),
            caption_w = width - 40;

        $this.find('.mk-image-hover').css({
            'width': caption_w,
            'margin-top': -(caption_h / 2),
            'margin-left': -(caption_w / 2)
        });
    });
}


function mk_center_caption() {
    $('.mk-parent-element').each(function() {
        var $this = $(this),
            width = $this.outerWidth(),
            caption_h = $this.find('.mk-caption-item').outerHeight(),
            caption_w = width - 120;

        $this.find('.mk-caption-item').css({
            'width': caption_w,
            'margin-top': -(caption_h / 2),
            'margin-left': -(caption_w / 2)
        });
    });
}



function mk_portfolio_image() {

    $('.mk-portfolio-item, .widget_recent_portfolio .item-holder').each(function() {
        var $this = $(this),
            width = $this.outerWidth(),
            caption_h = $this.find('.portfolio-meta').outerHeight(),
            caption_w = (width > 300) ? (width - 100) : (width - 20);



        /*$this.find('.portfolio-meta').css({
            'width': caption_w,
            'margin-top': -(caption_h / 2),
            'margin-left': -(caption_w / 2)
        });*/ 

        var logo = $(this).find('.portfolio-entry-logo'),
            logo_width = logo.width(),
            logo_height = logo.height();

        logo.css({
            'margin-left': -logo_width / 2,
            'margin-top': -logo_height / 2
        });


    });

}


function mk_employees() {

    $('.mk-employees.grid-style .mk-employee-item').each(function() {
        var $this = $(this),
            height = $this.outerHeight();
        $this.find('.team-info-wrapper').css({
            'height': height
        });
    });

}


function mk_gallery_image() {

    $('.mk-gallery-item').each(function() {
        var $this = $(this),
            width = $this.outerWidth(),
            caption_h = $this.find('.gallery-meta').outerHeight(),
            caption_w;

        if (width < 200) {
            caption_w = width;
        } else {
            caption_w = width - 100;
        }
        $this.find('.gallery-meta').css({
            'width': caption_w,
            'margin-top': -(caption_h / 2),
            'margin-left': -(caption_w / 2)
        });


    });

}

function mk_portfolio_masonry() {

    $('.masonry-portfolio-item').each(function() {

        var $this = $(this),
            item_height = $this.parent().find('.regular-entry').outerHeight();

        if ($this.hasClass('tall-entry') || $this.hasClass('wide-tall-entry')) {

            $this.css('height', item_height * 2 + 'px');
            $this.find('.featured-image').css('height', item_height * 2 + 'px');

        } else if ($this.hasClass('wide-entry')) {

            $this.css('height', item_height + 'px');
            $this.find('.featured-image').css('height', item_height + 'px');

        }

    });

}


function mk_portfolio_hovers() {

    $('.masonry-portfolio-item, .grid-portfolio-item, .portfolio-scroller').each(function() {
        var $this = $(this);

        $this.hover(function() {

            $this.find('.border-tb').stop(true, true).animate({
                'height': 100 + '%'
            }, 1200, 'easeInOutQuint');
            $this.find('.border-bt').stop(true, true).animate({
                'height': 100 + '%'
            }, 1200, 'easeInOutQuint');
            $this.find('.border-bl').stop(true, true).animate({
                'width': 100 + '%'
            }, 1200, 'easeInOutQuint');
            $this.find('.border-tr').stop(true, true).animate({
                'width': 100 + '%'
            }, 1200, 'easeInOutQuint');

        }, function() {
            $this.find('.border-tb').stop(true, true).animate({
                'height': 0
            }, 800, 'easeInOutQuint');
            $this.find('.border-bt').stop(true, true).animate({
                'height': 0
            }, 800, 'easeInOutQuint');
            $this.find('.border-bl').stop(true, true).animate({
                'width': 0
            }, 800, 'easeInOutQuint');
            $this.find('.border-tr').stop(true, true).animate({
                'width': 0
            }, 800, 'easeInOutQuint');
        });

    });


}
;

/* Tabs */
/* -------------------------------------------------------------------- */

function mk_tabs() {
    if ($.exists('.mk-tabs')) {
        $(".mk-tabs").tabs();

        $('.mk-tabs.vertical-style').each(function() {
            var $this = $(this),
                inner_pane = $this.find('.inner-box'),
                tabs_height = $(this).find('.mk-tabs-tabs').height() + 80;
            inner_pane.css('minHeight', tabs_height);
        });
    }
} ;/* Blog, Portfolio Audio */
/* -------------------------------------------------------------------- */

function loop_audio_init() {
    if ($.exists('.jp-jplayer')) {
        $('.jp-jplayer.mk-blog-audio').each(function() {
            var css_selector_ancestor = "#" + $(this).siblings('.jp-audio').attr('id');
            var ogg_file, mp3_file, mk_theme_js_path;
            ogg_file = $(this).attr('data-ogg');
            mp3_file = $(this).attr('data-mp3');
            $(this).jPlayer({
                ready: function() {
                    $(this).jPlayer("setMedia", {
                        mp3: mp3_file,
                        ogg: ogg_file
                    });
                },
                play: function() { // To avoid both jPlayers playing together.
                    $(this).jPlayer("pauseOthers");
                },
                swfPath: mk_theme_js_path,
                supplied: "mp3, ogg",
                cssSelectorAncestor: css_selector_ancestor,
                wmode: "window"
            });
        });
    }
}


/* Ajax portfolio */
/* -------------------------------------------------------------------- */
function mk_portfolio_ajax() {

    $('.portfolio-grid.portfolio-ajax-enabled').ajaxPortfolio();
};/* Initialize isiotop  */
/* -------------------------------------------------------------------- */

function loops_iosotop_init() {

    $('.loop-main-wrapper').each(function() {
        var $this = $(this),
            $mk_container = $this.find('.mk-theme-loop'),
            $mk_container_item = '.mk-isotop-item',
            $load_button = $this.find('.mk-loadmore-button'),
            $pagination_items = $this.find('.mk-pagination');

        if ($mk_container.hasClass('isotop-enabled')) {

            $mk_container.isotope({
                itemSelector: $mk_container_item,
                animationEngine: "best-available",
                masonry: {
                    columnWidth: 1
                }

            });
        }


        $('.mk-isotop-filter').on('click', 'a', function() {
            var $this;
            $this = $(this);

            /* Removes ajax container when filter items get triggered */
            $this.parents('.portfolio-grid').find('.ajax-container').animate({
                'height': 0,
                opacity: 0
            }, 500);

            if ($this.hasClass('.current')) {
                return false;
            }
            var $optionSet = $this.parents('.mk-isotop-filter ul');
            $optionSet.find('.current').removeClass('current');
            $this.addClass('current');

            var selector = $(this).attr('data-filter');

            $mk_container.isotope({
                filter: ''
            });
            $mk_container.isotope({
                filter: selector
            });


            return false;
        });



        $load_button.hide();

        if ($this.find('.mk-theme-loop').hasClass('scroll-load-style') || $this.find('.mk-theme-loop').hasClass('load-button-style')) {
            if ($pagination_items.length > 0) {
                $load_button.css('display', 'block');
            }
            $pagination_items.hide();


            $load_button.on('click', function() {
                if (!$(this).hasClass('pagination-loading')) {
                    $(this).addClass('pagination-loading');
                }

            });

            $mk_container.infinitescroll({
                    navSelector: $pagination_items,
                    nextSelector: $this.find('.mk-pagination a:first'),
                    itemSelector: $mk_container_item,
                    bufferPx: 70,
                    loading: {
                        finishedMsg: "",
                        msg: null,
                        msgText: "",
                        selector: $load_button,
                        speed: 300,
                        start: undefined
                    },
                    errorCallback: function() {

                        $load_button.html(mk_no_more_posts).addClass('disable-pagination');

                    },

                },

                function(newElements) {

                    var $newElems = $(newElements);
                    $newElems.imagesLoaded(function() {
                        $load_button.removeClass('pagination-loading');

                        $mk_container.isotope('appended', $newElems);
                        $mk_container.isotope({
                            filter: ''
                        });
                        var selected_item = $('.mk-isotop-filter ul').find('.current').attr('data-filter');
                        $mk_container.isotope({
                            filter: selected_item
                        });

                        $mk_container.isotope('reLayout');
                        loop_audio_init();
                        mk_lightbox_init();
                        mk_portfolio_image();
                        mk_gallery_image();
                        mk_swipe_slider();
                        mk_portfolio_ajax();
                    });
                }

            );



            /* Loading elements based on scroll window */
            if ($this.find('.mk-theme-loop').hasClass('load-button-style')) {
                $(window).unbind('.infscr');
                $load_button.click(function() {

                    $mk_container.infinitescroll('retrieve');

                    return false;

                });
            }

        } else {
            $load_button.hide();
        }
    });
}
;
/* Fix isotop layout */
/* -------------------------------------------------------------------- */

function isotop_load_fix() {
    if ($.exists('.mk-blog-container') || $.exists('.mk-portfolio-container')) {
        $('.mk-blog-container>article, .mk-portfolio-container>article').each(function(i) {
            $(this).delay(i * 100).animate({
                'opacity': 1
            }, 100);

        }).promise().done(function() {
            $('.mk-theme-loop').isotope('reLayout');
        });
    }

}
;
/* Event Count Down */
/* -------------------------------------------------------------------- */

function mk_event_countdown() {
    if ($.exists('.mk-event-countdown')) {
        $('.mk-event-countdown').each(function() {
            var $this = $(this),
                $date = $this.attr('data-date'),
                $offset = $this.attr('data-offset');

            $this.downCount({
                date: $date,
                offset: $offset
            });
        });
    }
};
/* Instagram Feed */
/* -------------------------------------------------------------------- */

function mk_instagram() {
    if ($.exists('.mk-instagram-feeds')) {

        $('.mk-instagram-feeds').each(function() {
            var $this = $(this),
                $size = $this.attr('data-size'),
                $sort_by = $this.attr('data-sort'),
                $count = $this.attr('data-count'),
                $userid = parseInt($this.attr('data-userid')),
                $access_token = $this.attr('data-accesstoken'),
                $column = $this.attr('data-column'),
                $id = $this.attr('id');

            console.log($userid);


            var feed = new Instafeed({
                get: "user",
                target: $id,
                resolution: $size,
                sortBy: $sort_by,
                limit: $count,
                userId: $userid,
                accessToken: $access_token,
                template: '<a class="featured-image ' + $column + '-columns" href="{{link}}"><div class="item-holder"><img src="{{image}}" /><div class="hover-overlay"></div></div></a>'
            });
            feed.run();
        });
    }
};/* Accordions */

function mk_accordion() {

    if ($.exists('.mk-accordion')) {
        $(".mk-accordion").each(function() {
            var $this = $(this),
                accordion_section = $this.find('.mk-accordion-single'),
                all_panes = $this.find('.mk-accordion-pane').hide();

            accordion_section.first().addClass('current-item').find('.mk-accordion-pane').slideDown(300);


            $this.find('.mk-accordion-tab').click(function() {
                var $this = $(this),
                    $this_item = $this.parent();
                if (!($this_item.hasClass('current-item'))) {
                    $this_item.siblings().removeClass('current-item').end().addClass('current-item');
                    all_panes.slideUp(300);
                    $this.parent().children('.mk-accordion-pane').slideDown(300);
                }
                return false;
            });
        });
    }

    /* Toggles */

    if ($.exists('.mk-toggle-title')) {
        $(".mk-toggle-title").toggle(

            function() {
                $(this).addClass('active-toggle');
                $(this).siblings('.mk-toggle-pane').slideDown("fast");
            },

            function() {
                $(this).removeClass('active-toggle');
                $(this).siblings('.mk-toggle-pane').slideUp("fast");
            });
    }
}
;/* Social Share */
/* -------------------------------------------------------------------- */

function mk_social_share() {


    $('.twitter-share').on('click', function() {
        var $url = $(this).attr('data-url'),
            $title = $(this).attr('data-title');

        window.open('http://twitter.com/intent/tweet?text=' + $title + ' ' + $url, "twitterWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0");
        return false;
    });

    $('.pinterest-share').on('click', function() {
        var $url = $(this).attr('data-url'),
            $title = $(this).attr('data-title'),
            $image = $(this).attr('data-image');
        window.open('http://pinterest.com/pin/create/button/?url=' + $url + '&media=' + $image + '&description=' + $title, "twitterWindow", "height=320,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0");
        return false;
    });

    $('.facebook-share').on('click', function() {
        var $url = $(this).attr('data-url');
        window.open('https://www.facebook.com/sharer/sharer.php?u=' + $url, "facebookWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0");
        return false;
    });

    $('.googleplus-share').on('click', function() {
        var $url = $(this).attr('data-url');
        window.open('https://plus.google.com/share?url=' + $url, "googlePlusWindow", "height=380,width=660,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0");
        return false;
    });
};/* Typer */
/* -------------------------------------------------------------------- */
function mk_text_typer() {
    $('[data-typer-targets]').each(function() {
        var $this = $(this),
            $first_string = [$this.text()],
            $rest_strings = $this.attr('data-typer-targets').split(','),
            $strings = $first_string.concat($rest_strings);

        $this.text('');

        $this.typed({
            strings: $strings,
            typeSpeed: 30, // typing speed
            backDelay: 1200, // pause before backspacing
            loop: true, // loop on or off (true or false)
            loopCount: false, // number of loops, false = infinite
        });
    });
}

;/* Process Steps */
/* -------------------------------------------------------------------- */

function mk_process_steps() {
    if ($.exists('.mk-process-steps.horizontal')) {

        $('.mk-process-steps.horizontal').each(function() {

            var $this = $(this),
                $tabs = $this.find('.step-items'),
                $panes = $this.find('.step-panes');

            $tabs.find('li').first().addClass('active-step-item');

            $panes.css('height', $panes.find('.mk-step').first().outerHeight() + 30);
            $panes.find('.mk-step').first().addClass('active-step');


            $tabs.find('span').hoverIntent(function() {
                var $this_id = $(this).attr('data-id'),
                    $this_pane = $panes.find('div[id^="' + $this_id + '"]'),
                    $pane_height = $this_pane.outerHeight() + 30;

                $(this).parent().siblings('li').removeClass('active-step-item').end().addClass('active-step-item');

                $panes.css('height', $pane_height);
                $panes.find('.mk-step').removeClass('active-step');
                $this_pane.addClass('active-step');
            });


        });

    }
}
;/* Page Section full height feature */
/* -------------------------------------------------------------------- */

function section_to_full_height() {

    $('.full-height-true.mk-page-section').each(function() {
        var $this = $(this),
            $content_height = $this.find('.page-section-content').outerHeight(),
            $window_height = $(window).outerHeight();

        if ($.exists("#wpadminbar")) {
            var $wp_admin_height = $("#wpadminbar").outerHeight();
        } else {
            var $wp_admin_height = 0;
        }


        if ($.exists("#mk-header.sticky-header")) {
            if ($('#mk-header').hasClass('sticky-trigger-header')) {
                var mk_header = parseInt($("#mk-header.sticky-header").attr('data-sticky-height'));
            } else {
                var mk_header = parseInt($("#mk-header.sticky-header").attr('data-height'));
            }

        } else {
            var mk_header = 0;
        }
        //console.log($wp_admin_height + " " + mk_header);

        $window_height = $window_height - $wp_admin_height - mk_header;

        if ($content_height > $window_height) {
            $this.css('height', 'auto');
            $this.find('.page-section-content').css({
                'padding-top': 30,
                'padding-bottom': 30
            });
        } else {
            $this.css('height', $window_height);

            var $this_height_half = $this.find('.page-section-content').outerHeight() / 2,
                $window_half = $window_height / 2;

            $this.find('.page-section-content').css('marginTop', ($window_half - $this_height_half));
        }

        $this.find('.mk-page-section-loader').fadeOut();

    });

};
/* Expandable Page Sections */
/* -------------------------------------------------------------------- */

function mk_expandable_page_section() {



    $('.section-expandable-true').each(function() {

        var $container = $(this).find('.mk-padding-wrapper').hide();

        $(this).find('.expandable-section-trigger').on('click', function() {
            var $this = $(this);
            if ($this.hasClass('active-toggle')) {
                $this.removeClass('active-toggle');
                $container.slideUp(400);
            } else {
                $this.addClass('active-toggle');
                $container.slideDown(400);
            }

        });

    });

}
;

/* Flickr Feeds */
/* -------------------------------------------------------------------- */

function mk_flickr_feeds() {

    $('.mk-flickr-feeds').each(function() {
        var $this = $(this),
            apiKey = $this.attr('data-key'),
            userId = $this.attr('data-userid'),
            perPage = $this.attr('data-count');

        jQuery.getJSON('http://api.flickr.com/services/rest/?format=json&method=' + 'flickr.photos.search&api_key=' + apiKey + '&user_id=' + userId + '&&per_page=' + perPage + '&jsoncallback=?', function(data) {

            jQuery.each(data.photos.photo, function(i, rPhoto) {
                var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/' + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret;

                var thumbPhotoURL = basePhotoURL + '_q.jpg';
                var mediumPhotoURL = basePhotoURL + '.jpg';

                var photoStringStart = '<a ';
                var photoStringEnd = 'title="' + rPhoto.title + '" rel="flickr-feeds" class="mk-lightbox featured-image" href="' + mediumPhotoURL + '"><img src="' + thumbPhotoURL + '" alt="' + rPhoto.title + '"/><div class="hover-overlay"></div></a>;';
                var photoString = (i < perPage) ? photoStringStart + photoStringEnd : photoStringStart + photoStringEnd;

                jQuery(photoString).appendTo($this);
            });
        });
    });

}
mk_flickr_feeds();
;
/* Flexslider init */
/* -------------------------------------------------------------------- */

function mk_flexslider_init() {


    $('.mk-flexslider.mk-script-call').each(function() {

        if ($(this).parents('.mk-tabs').length || $(this).parents('.mk-accordion').length) {
            $(this).removeData("flexslider");
        }


        var $this = $(this),
            $selector = $this.attr('data-selector'),
            $animation = $this.attr('data-animation'),
            $easing = $this.attr('data-easing'),
            $direction = $this.attr('data-direction'),
            $smoothHeight = $this.attr('data-smoothHeight') == "true" ? true : false,
            $slideshowSpeed = $this.attr('data-slideshowSpeed'),
            $animationSpeed = $this.attr('data-animationSpeed'),
            $controlNav = $this.attr('data-controlNav') == "true" ? true : false,
            $directionNav = $this.attr('data-directionNav') == "true" ? true : false,
            $pauseOnHover = $this.attr('data-pauseOnHover') == "true" ? true : false,
            $isCarousel = $this.attr('data-isCarousel') == "true" ? true : false;

        if ($selector != undefined) {
            var $selector_class = $selector;
        } else {
            var $selector_class = ".mk-flex-slides > li";
        }

        if ($isCarousel == true) {
            var $itemWidth = parseInt($this.attr('data-itemWidth')),
                $itemMargin = parseInt($this.attr('data-itemMargin')),
                $minItems = parseInt($this.attr('data-minItems')),
                $maxItems = parseInt($this.attr('data-maxItems')),
                $move = parseInt($this.attr('data-move'));
        } else {
            var $itemWidth = $itemMargin = $minItems = $maxItems = $move = 0;
        }

        $this.flexslider({
            selector: $selector_class,
            animation: $animation,
            easing: $easing,
            direction: $direction,
            smoothHeight: $smoothHeight,
            slideshow: true,
            slideshowSpeed: $slideshowSpeed,
            animationSpeed: $animationSpeed,
            controlNav: $controlNav,
            directionNav: $directionNav,
            pauseOnHover: $pauseOnHover,
            prevText: "",
            nextText: "",

            itemWidth: $itemWidth,
            itemMargin: $itemMargin,
            minItems: $minItems,
            maxItems: $maxItems,
            move: $move,
        });

    });

}

function mk_fade_onload() {

    $(".mk-mobile-image").fadeIn();
    $(".mk-tablet-image").fadeIn();
}
;/* Edge One Pager */
/* -------------------------------------------------------------------- */
function mk_one_page_scroller() {
    $('.mk-edge-one-pager').each(function() {

        var $this = $(this),
            $tooltip_txt = [];

        $this.find('.section').each(function() {
            $tooltip_txt.push($(this).attr('data-title'));
        });

        $this.fullpage({
            verticalCentered: false,
            resize: true,
            slidesColor: ['#ccc', '#fff'],
            anchors: $tooltip_txt,
            scrollingSpeed: 600,
            easing: 'easeInQuart',
            menu: false,
            navigation: true,
            navigationPosition: 'right',
            navigationTooltips: false,
            slidesNavigation: true,
            slidesNavPosition: 'bottom',
            loopBottom: false,
            loopTop: false,
            loopHorizontal: true,
            autoScrolling: true,
            scrollOverflow: false,
            css3: true,
            paddingTop: 0,
            paddingBottom: 0,
            fixedElements: '#element1, .element2',
            normalScrollElements: '#element1, .element2',
            normalScrollElementTouchThreshold: 5,
            keyboardScrolling: true,
            touchSensitivity: 15,
            continuousVertical: false,
            animateAnchor: true,

            //events
            onLeave: function(index, nextIndex, direction) {
                //console.log(nextIndex - 1);
                //console.log($this.find('.one-pager-slide').eq(nextIndex - 1).attr('data-header-skin'));

                if (!$('#mk-header').hasClass('transparent-header-sticky')) {
                    $('#mk-header.transparent-header').removeClass('light-header-skin dark-header-skin').addClass($this.find('.one-pager-slide').eq(nextIndex - 1).attr('data-header-skin') + '-header-skin');

                    $('#fullPage-nav').removeClass('light-skin dark-skin').addClass($this.find('.one-pager-slide').eq(nextIndex - 1).attr('data-header-skin') + '-skin');
                }

            },
            afterLoad: function(anchorLink, index) {

            },
            afterRender: function() {
                if (!$('#mk-header').hasClass('transparent-header-sticky')) {
                    setTimeout(function() {
                        $('#mk-header.transparent-header').removeClass('light-header-skin dark-header-skin').addClass($this.find('.one-pager-slide').eq(0).attr('data-header-skin') + '-header-skin');
                        $('#fullPage-nav').removeClass('light-skin dark-skin').addClass($this.find('.one-pager-slide').eq(nextIndex - 1).attr('data-header-skin') + '-skin');
                    }, 300);
                }

            },
            afterResize: function() {},
            afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex) {



            },
            onSlideLeave: function(anchorLink, index, slideIndex, direction) {

            } // You can now define the direction of the One Page Scroll animation. Options available are "vertical" and "horizontal". The default value is "vertical".  
        });
    });
}


function mk_one_pager_resposnive() {


    $('.mk-edge-one-pager').each(function() {
        var $this = $(this),
            $wpadminbar = 0,
            $header_height = 0;

        var $window_height = $(window).outerHeight();


        if ($.exists('#wpadminbar')) {
            $wpadminbar = $('#wpadminbar').outerHeight();
        }

        if ($.exists('#mk-header.sticky-header') && !$('#mk-header').hasClass('transparent-header')) {
            var $header_height = parseInt($('#mk-header.sticky-header').attr('data-sticky-height'));
        }

        $window_height = $window_height - $header_height - $wpadminbar;



        $this.find('.one-pager-slide').each(function() {


            var $this = $(this),
                $content = $this.find('.edge-slide-content');

            if ($this.hasClass('left_center') || $this.hasClass('center_center') || $this.hasClass('right_center')) {

                var $this_height_half = $content.outerHeight() / 2,
                    $window_half = $window_height / 2;

                $content.css('marginTop', ($window_half - $this_height_half));
            }

            if ($this.hasClass('left_bottom') || $this.hasClass('center_bottom') || $this.hasClass('right_bottom')) {

                var $distance_from_top = $window_height - $content.outerHeight() - 90;

                $content.css('marginTop', ($distance_from_top));
            }

        });
    });

}
;/* Animated Columns */
/* -------------------------------------------------------------------- */
function mk_animated_columns() {

    $('.mk-animated-columns').each(function() {
        var $this = $(this);

        if ($this.hasClass('full-style')) {
            $this.find('.animated-column-item').each(function() {
                var $this = $(this),
                    $box_height = $this.outerHeight(true),
                    $icon_height = $this.find('.animated-column-icon').outerHeight(true);

                $this.find('.animated-column-holder').css({
                    'paddingTop': $box_height / 2 - ($icon_height)
                });
            });
        } else {
            $this.find('.animated-column-item').each(function() {
                var $this = $(this),
                    $half_box_height = $this.outerHeight(true) / 2,
                    $icon_height = $this.find('.animated-column-icon').outerHeight(true),
                    $title_height = $this.find('.animated-column-simple-title').outerHeight(true);

                $this.find('.animated-column-holder').css({
                    'paddingTop': $half_box_height - $icon_height
                });
                $this.find('.animated-column-title').css({
                    'paddingTop': $half_box_height - $title_height
                });

                //console.log($half_box_height - $title_height);

            });
        }

    });

    $(".mk-animated-columns.full-style .animated-column-item").hover(
        function() {
            TweenLite.to($(this).find(".animated-column-holder"), 0.5, {
                top: '-15%',
                ease: Back.easeOut
            });
            TweenLite.to($(this).find(".animated-column-desc"), 0.5, {
                top: '50%',
                ease: Expo.easeOut
            }, 0.4);
            TweenLite.to($(this).find(".animated-column-btn"), 0.5, {
                top: '80%',
                ease: Expo.easeOut
            }, 0.6);
        },
        function() {
            TweenLite.to($(this).find(".animated-column-holder"), 0.5, {
                top: '0%',
                ease: Back.easeOut
            });
            TweenLite.to($(this).find(".animated-column-desc"), 0.5, {
                top: '100%',
                ease: Back.easeOut
            }, 0.4);
            TweenLite.to($(this).find(".animated-column-btn"), 0.5, {
                top: '100%',
                ease: Back.easeOut
            }, 0.2);
        }
    );

    $(".mk-animated-columns.simple-style .animated-column-item").hover(
        function() {
            TweenLite.to($(this).find(".animated-column-holder"), 0.7, {
                top: '100%',
                ease: Expo.easeOut
            });
            TweenLite.to($(this).find(".animated-column-title"), 0.7, {
                top: '0%',
                ease: Back.easeOut
            }, 0.2);
        },
        function() {
            TweenLite.to($(this).find(".animated-column-holder"), 0.7, {
                top: '0%',
                ease: Expo.easeOut
            });
            TweenLite.to($(this).find(".animated-column-title"), 0.7, {
                top: '-100%',
                ease: Back.easeOut
            }, 0.2);
        }
    );

};


/* Adds Smooth scroll to page native scroll */
/* -------------------------------------------------------------------- */
function mk_smooth_scroll() {

    /*$("html").niceScroll({
        scrollspeed: 65,
        mousescrollstep: 40,
        cursorwidth: 10,
        cursorborder: 0,
        cursorcolor: '#434343',
        cursorborderradius: 6,
        autohidemode: false,
        zindex: 9999,
        horizrailenabled: false
    });*/
   var wheel = false, 
            $docH = $(document).height() - $(window).height(),
            $scrollTop = $(window).scrollTop();

        $(window).bind('scroll', function() {
            if (wheel === false) {
                $scrollTop = $(this).scrollTop();
            }
        });

        $(document).bind('DOMMouseScroll mousewheel', function(e, delta) {
            delta = delta || -e.originalEvent.detail / 3 || e.originalEvent.wheelDelta / 120;
            wheel = true;
            
            $scrollTop = Math.min($docH, Math.max(0, parseInt($scrollTop - delta * 120)));

            $($.browser.webkit ? 'body' : 'html').stop().animate({
                scrollTop: $scrollTop + 'px'
            }, 500, 'easeOutQuint', function() {
                wheel = false;
            });

            return false;
        }); 
}



$(document).ready(function() {

    if (mk_smooth_scroll_option == 1 && $(window).width() > 960 && $('body').outerHeight(true) > $(window).height() && Modernizr.csstransforms3d && !navigator.userAgent.match(/(Android|iPod|iPhone|iPad|IEMobile|Opera Mini)/)) {
        mk_smooth_scroll();
    }
     
    mk_instagram();
    mk_main_navigation_functions();
    mk_main_navigation();
    mk_swipe_slider();
    sticky_header();
    transparent_header_sticky();
    loop_audio_init();
    mk_social_share();
    mk_google_maps();
    mk_event_countdown();
    mk_edge_slider_init();
    mk_portfolio_ajax();
    mk_text_typer();
    mk_flexslider_init();
    mk_one_page_scroller();
    mk_one_pager_resposnive();
    mk_animated_columns();
    


    $(window).load(function() {
        mk_fade_onload();
        mk_lightbox_init();
        mk_portfolio_masonry();
        mk_image();
        mk_portfolio_image();
        mk_gallery_image();
        mk_window_scroller();
        section_to_full_height();
        mk_expandable_page_section();
        mk_accordion();
        mk_employees();
        mk_process_steps();
        mk_gallery_thumbs_width();
        mk_edge_slider_resposnive();
        mk_center_caption();
        loops_iosotop_init();
        isotop_load_fix();
        mk_section_parallax();
        mk_secondary_header_res();
        mk_tabs();
        secondary_header();
        mk_portfolio_hovers();
        mk_query_loader();
    });



    $(window).on("debouncedresize", function() {
        mk_portfolio_image();
        mk_portfolio_masonry();
        mk_image();
        section_to_full_height();
        mk_main_navigation_functions();
        mk_employees();
        mk_window_scroller();
        mk_section_parallax();
        mk_secondary_header_res();
        secondary_header();
        mk_center_caption();
        mk_one_pager_resposnive();
    });



    new ChopScroll(function() {
        sticky_header();
        secondary_header();
        transparent_header_sticky();

        /* Floating Go to top Link */
        /* -------------------------------------------------------------------- */
        if ($(this).scrollTop() > 700) {
            $('.mk-go-top').removeClass('off').addClass('on');
        } else {
            $('.mk-go-top').removeClass('on').addClass('off');
        }
    }, 100);



    /* Floating Go to top Link */
    /* -------------------------------------------------------------------- */
    $('.mk-go-top, .mk-back-top-link').click(function() {
        $("html, body").animate({
            scrollTop: 0
        }, 800, "easeInOutExpo");
        return false;
    });



    /* Love This */
    /* -------------------------------------------------------------------- */

    function mk_love_post() {

        $('body').on('click', '.mk-love-this', function() {
            var $this = $(this),
                $id = $this.attr('id');

            if ($this.hasClass('item-loved')) {
                return false;
            }

            if ($this.hasClass('item-inactive')) {
                return false;
            }

            var $sentdata = {
                action: 'mk_love_post',
                post_id: $id
            };

            $.post(ajaxurl, $sentdata, function(data) {
                $this.find('span').html(data);
                $this.addClass('item-loved');
            });

            $this.addClass('item-inactive');
            return false;
        });


    }

    mk_love_post();








    /* Woocmmerce Header Checkout */
    /* -------------------------------------------------------------------- */

    function mk_header_checkout() {
        $('.mk-shopping-cart').hoverIntent(function() {
            $('.mk-shopping-box').fadeIn(200);
        }, function() {
            $('.mk-shopping-box').delay(500).fadeOut(200);
        });
    }


    setTimeout(function() {
        mk_header_checkout();
    }, 500);



    /* Woocommerce Scripts */
    /* -------------------------------------------------------------------- */

    function product_loop_add_cart() {
        var $body = $('body');

        $body.on('click', '.add_to_cart_button', function() {
            var product = $(this).parents('.product:eq(0)').addClass('adding-to-cart').removeClass('added-to-cart');
        });

        $body.bind('added_to_cart', function() {
            $('.adding-to-cart').removeClass('adding-to-cart').addClass('added-to-cart');
            mk_header_checkout();
        });
    }
    product_loop_add_cart();


    /* Table Responsive */
    /* -------------------------------------------------------------------- */
    var switched = false;
    var updateTables = function() {
        if (($(window).width() < 767) && !switched) {
            switched = true;
            $("table.shop_table").each(function(i, element) {
                splitTable($(element));
            });
            return true;
        } else if (switched && ($(window).width() > 767)) {
            switched = false;
            $("table.shop_table").each(function(i, element) {
                unsplitTable($(element));
            });
        }
    };

    $(window).load(updateTables);
    $(window).on("redraw", function() {
        switched = false;
        updateTables();
    }); // An event to listen for
    $(window).on("resize", updateTables);


    function splitTable(original) {
        original.wrap("<div class='table-wrapper' />");

        var copy = original.clone();
        copy.find("td:not(:first-child), th:not(:first-child)").css("display", "none");
        copy.removeClass("shop_table");

        original.closest(".table-wrapper").append(copy);
        copy.wrap("<div class='pinned' />");
        original.wrap("<div class='scrollable' />");

        setCellHeights(original, copy);
    }

    function unsplitTable(original) {
        original.closest(".table-wrapper").find(".pinned").remove();
        original.unwrap();
        original.unwrap();
    }

    function setCellHeights(original, copy) {
        var tr = original.find('tr'),
            tr_copy = copy.find('tr'),
            heights = [];

        tr.each(function(index) {
            var self = $(this),
                tx = self.find('th, td');

            tx.each(function() {
                var height = $(this).outerHeight(true);
                heights[index] = heights[index] || 0;
                if (height > heights[index]) heights[index] = height;
            });

        });

        tr_copy.each(function(index) {
            $(this).height(heights[index]);
        });
    }



    /* Fixing side dashboard and responsive navigation top padding */
    /* -------------------------------------------------------------------- */
    if ($.exists("#wpadminbar")) {
        $('.mk-side-dashboard').addClass('wpadminbar-exists');
    }



    /* Ajax Search */
    /* -------------------------------------------------------------------- */

    function mk_ajax_search() {
        if ($.exists('.search-ajax-input')) {
            $(".search-ajax-input").autocomplete({
                delay: 50,
                minLength: 2,
                messages: {
                    noResults: '',
                    results: function() {}
                },
                appendTo: $(".header-searchform-input"),
                source: function(req, response) {
                    $.getJSON(ajaxurl + '?callback=?&action=mk_ajax_search', req, response);
                },
                select: function(event, ui) {
                    window.location.href = ui.item.link;
                }

            }).data("ui-autocomplete")._renderItem = function(ul, item) {


                return $("<li>").append("<a>" + item.image + "<span class='search-title'>" + item.label + "</span><span class='search-date'>" + item.date + "</span></a>").appendTo(ul);

            };
        }
    }

    mk_ajax_search();



    /* Contact Form */
    /* -------------------------------------------------------------------- */

    function mk_contact_form() {

        if ($.tools.validator != undefined) {
            $.tools.validator.addEffect("contact_form", function(errors) {
                $.each(errors, function(index, error) {
                    var input = error.input;

                    input.addClass('mk-invalid');
                });
            }, function(inputs) {
                inputs.removeClass('mk-invalid');
            });


            $('.mk-contact-form').validator({
                effect: 'contact_form'
            }).submit(function(e) {
                var form = $(this);
                if (!e.isDefaultPrevented()) {
                    $(this).find('.mk-contact-loading').fadeIn('slow');

                    var data = {
                        action: 'mk_contact_form',
                        to: $(this).find('input[name="contact_to"]').val().replace("*", "@"),
                        name: $(this).find('input[name="contact_name"]').val(),
                        phone: $(this).find('input[name="contact_phone"]').val(),
                        email: $(this).find('input[name="contact_email"]').val(),
                        content: $(this).find('textarea[name="contact_content"]').val()
                    };

                    $.post(ajaxurl, data, function(response) {
                        form.find('.mk-contact-loading').fadeOut('slow');
                        form.find('.mk-contact-success').delay(2000).fadeIn('slow').delay(8000).fadeOut();
                        form.find('input#contact_email, input#contact_name, textarea').val("");

                    });
                    e.preventDefault();
                }
            });

        }
    }

    mk_contact_form();


    $(this).find('.mk-form-row input, .comment-form-row input, .mk-login-form input').each(function() {

        $(this).focusin(function() {
            $(this).siblings('i').addClass('input-focused');
        });
        $(this).focusout(function() {
            $(this).siblings('i').removeClass('input-focused');
        });

    });



    /* Ajax Login Form */
    /* -------------------------------------------------------------------- */

    function mk_login_form() {

        $('form.mk-login-form').each(function() {
            var $this = $(this);
            $this.on('submit', function(e) {
                $('p.mk-login-status', $this).show().text(ajax_login_object.loadingmessage);
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    url: ajax_login_object.ajaxurl,
                    data: {
                        'action': 'ajaxlogin',
                        //calls wp_ajax_nopriv_ajaxlogin
                        'username': $('#username', $this).val(),
                        'password': $('#password', $this).val(),
                        'security': $('#security', $this).val()
                    },
                    success: function(data) {
                        $('p.mk-login-status', $this).text(data.message);
                        if (data.loggedin === true) {
                            document.location.href = ajax_login_object.redirecturl;
                        }
                    }
                });
                e.preventDefault();
            });
        });
    }

    mk_login_form();



    /* Smooth scroll using hash */
    /* -------------------------------------------------------------------- */
    $(".mk-smooth, .blog-comments").bind('click', function(e) {
        var secondary_header_height = 0,
            header_height = 0,
            wp_admin_height = 0;


        if ($.exists("#wpadminbar")) {
            var wp_admin_height = $("#wpadminbar").height();
        }
        if ($.exists('#mk-header') && !$('#mk-header').hasClass('transparent-header')) {
            var header_height = parseInt($('#mk-header').attr('data-sticky-height'));
        }

        if ($.exists('.mk-secondary-header')) {
            var secondary_header_height = parseInt($('.mk-secondary-header').attr('data-sticky-height'));
        }
        $("body, html").animate({
            scrollTop: $($(this).attr("href")).offset().top - (wp_admin_height + header_height + secondary_header_height - 2) + "px"
        }, {
            duration: 1200,
            easing: "easeInOutExpo"
        });

        e.preventDefault();
    });


    /* Scroll function for main navigation on one page concept */
    /* -------------------------------------------------------------------- */



    function mk_main_nav_scroll() {

        var lastId, topMenu = $(".main-navigation-ul"),
            menuItems = topMenu.find(".menu-item a"),
            secondary_header_height = 0,
            header_height = 0,
            wp_admin_height = 0;



        menuItems.each(function() {
            if ($(this).hasAttr('href')) {
                var href = $(this).attr("href").split('#')[0];
            } else {
                href = "";
            }


            if (href === window.location.href.split('#')[0] && (typeof $(this).attr("href").split('#')[1] !== 'undefined') && href !== "") {

                $(this).attr("href", "#" + $(this).attr("href").split('#')[1]);
                $(this).parent().removeClass("current-menu-item");
            }


        });



        var scrollItems = menuItems.map(function() {
            var item = $(this).attr("href");

            if (/^#\w/.test(item) && $(item).length) {
                return $(item);
            }

        });


        if ($.exists("#wpadminbar")) {
            var wp_admin_height = $("#wpadminbar").height();
        }
        if ($.exists('#mk-header')) {
            header_height = parseInt($('#mk-header').attr('data-sticky-height'));
        }

        if ($.exists('.mk-secondary-header')) {
            secondary_header_height = parseInt($('.mk-secondary-header').attr('data-sticky-height'));
        }


        menuItems.click(function(e) {
            var href = $(this).attr("href");
            if (typeof $(href).offset() !== 'undefined') {
                var href_top = $(href).offset().top;
            } else {
                var href_top = 0;
            }
            //console.log(href_top);
            var offsetTop = href === "#" ? 0 : href_top - (wp_admin_height + header_height + secondary_header_height - 2) + "px";

            $('html, body').stop().animate({
                scrollTop: offsetTop
            }, {
                duration: 800,
                easing: "easeInOutExpo"
            });
            e.preventDefault();
        });


        $(window).scroll(function() {

            if (!scrollItems.length) {
                return false;
            }

            var fromTop = $(this).scrollTop() + (wp_admin_height + header_height + secondary_header_height - 1);

            var cur = scrollItems.map(function() {

                if ($(this).offset().top < fromTop) {
                    return this;
                }
            });
            //console.log(cur);
            cur = cur[cur.length - 1];
            var id = cur && cur.length ? cur[0].id : "";

            if (lastId !== id) {
                lastId = id;

                menuItems.parent().removeClass("current-menu-item");
                //console.log(id);
                if (id.length) {
                    menuItems.filter("[href=#" + id + "]").parent().addClass("current-menu-item");
                    //console.log(id);
                }
            }
        });
    }

    mk_main_nav_scroll();
});


function mk_ajax_portfolio() {
    var pluginName = "ajaxPortfolio",
        defaults = {
            propertyName: "value"
        };

    function Plugin(element, options) {
        this.element = $(element);
        this.settings = $.extend({}, defaults, options);
        this.init();

    }
    Plugin.prototype = {
        init: function() {
            var obj = this;
            this.grid = this.element.find('.mk-portfolio-container'), this.items = this.grid.children();

            if (this.items.length < 1) {
                return false;
            } //If no items was found then exit
            this.ajaxDiv = this.element.find('div.ajax-container'), this.filter = this.element.find('#mk-filter-portfolio'), this.loader = this.element.find('.portfolio-loader'), this.triggers = this.items.find('.project-load'), this.closeBtn = this.ajaxDiv.find('.close-ajax'), this.nextBtn = this.ajaxDiv.find('.next-ajax'), this.prevBtn = this.ajaxDiv.find('.prev-ajax'), this.api = {}, this.id = null, this.win = $(window), this.current = 0, this.breakpointT = 989, this.breakpointP = 767, this.columns = this.grid.data('columns'), this.real_col = this.columns;
            this.loader.fadeIn();
            if (this.items.length === 1) {
                this.nextBtn.remove();
                this.prevBtn.remove();
            }
            this.grid.waitForImages(function() {
                obj.loader.fadeOut();
                obj.bind_handler();
            });

        },

        bind_handler: function() {
            var obj = this; // Temp instance of this object
            // Bind the filters with isotope
            obj.filter.find('a').click(function() {
                obj.triggers.removeClass('active');
                obj.grid.removeClass('grid-open');
                obj.close_project();
                obj.filter.find('a').removeClass('active_sort');
                $(this).addClass('active_sort');
                var selector = $(this).attr('data-filter');
                obj.grid.isotope({
                    filter: selector
                });
                return false;
            });

            obj.triggers.on('click', function() {

                var clicked = $(this),
                    clickedParent = clicked.parents('.portfolio-ajax-item');

                obj.current = clickedParent.index();

                if (clicked.hasClass('active')) {
                    return false;
                }

                obj.close_project();

                obj.triggers.removeClass('active');
                clicked.addClass('active');
                obj.grid.addClass('grid-open');
                obj.loader.fadeIn();

                obj.id = clicked.data('post-id');

                obj.load_project();

                return false;

            });

            obj.nextBtn.on('click', function() {
                if (obj.current === obj.triggers.length - 1) {
                    obj.triggers.eq(0).trigger('click');
                    return false;
                } else {
                    obj.triggers.eq(obj.current + 1).trigger('click');
                    return false;
                }

            });

            obj.prevBtn.on('click', function() {
                if (obj.current === 0) {
                    obj.triggers.eq(obj.triggers.length - 1).trigger('click');
                    return false;
                } else {
                    obj.triggers.eq(obj.current - 1).trigger('click');
                    return false;
                }

            });

            // Bind close button
            obj.closeBtn.on('click', function() {
                obj.close_project();
                obj.triggers.removeClass('active');
                obj.grid.removeClass('grid-open');
                return false;
            });


        },
        // Function to close the ajax container div
        close_project: function() {
            var obj = this,
                // Temp instance of this object
                project = obj.ajaxDiv.find('.ajax_project'),
                newH = project.actual('outerHeight');



            if (obj.ajaxDiv.height() > 0) {
                obj.ajaxDiv.css('height', newH + 'px').transition({
                    height: 0,
                    opacity: 0
                }, 600);
            } else {
                obj.ajaxDiv.transition({
                    height: 0,
                    opacity: 0
                }, 600);
            }
        },
        load_project: function() {
            var obj = this;
            $.post(ajaxurl, {
                action: 'mk_ajax_portfolio',
                id: obj.id
            }, function(response) {
                obj.ajaxDiv.find('.ajax_project').remove();
                obj.ajaxDiv.find('.portfolio-ajax-holder').append(response);
                obj.project_factory();
                mk_lightbox_init();
                mk_tabs();
                mk_swipe_slider();
                mk_portfolio_image();
                mk_gallery_image();
                mk_accordion();
                mk_social_share();

            });
        },
        project_factory: function() {
            var obj = this,
                project = this.ajaxDiv.find('.ajax_project');



            project.waitForImages(function() {
                $('html:not(:animated),body:not(:animated)').animate({
                    scrollTop: obj.ajaxDiv.offset().top - 160
                }, 700);
                obj.loader.fadeOut(function() {
                    var newH = project.actual('outerHeight');
                    obj.ajaxDiv.transition({
                        opacity: 1,
                        height: newH
                    }, 400, function() {
                        obj.ajaxDiv.css({
                            height: 'auto'
                        });
                    });
                });

            });

        },

    };
    $.fn[pluginName] = function(options) {
        return this.each(function() {
            $.data(this, "plugin_" + pluginName, new Plugin(this, options));
        });
    };

}

mk_ajax_portfolio();;
/*! fancyBox v2.1.5 fancyapps.com | fancyapps.com/fancybox/#license */
(function(s, H, f, w) {
    var K = f("html"),
        q = f(s),
        p = f(H),
        b = f.fancybox = function() {
            b.open.apply(this, arguments)
        },
        J = navigator.userAgent.match(/msie/i),
        C = null,
        t = H.createTouch !== w,
        u = function(a) {
            return a && a.hasOwnProperty && a instanceof f
        },
        r = function(a) {
            return a && "string" === f.type(a)
        },
        F = function(a) {
            return r(a) && 0 < a.indexOf("%")
        },
        m = function(a, d) {
            var e = parseInt(a, 10) || 0;
            d && F(a) && (e *= b.getViewport()[d] / 100);
            return Math.ceil(e)
        },
        x = function(a, b) {
            return m(a, b) + "px"
        };
    f.extend(b, {
        version: "2.1.5",
        defaults: {
            padding: 15,
            margin: 20,
            width: 800,
            height: 600,
            minWidth: 100,
            minHeight: 100,
            maxWidth: 9999,
            maxHeight: 9999,
            pixelRatio: 1,
            autoSize: !0,
            autoHeight: !1,
            autoWidth: !1,
            autoResize: !0,
            autoCenter: !t,
            fitToView: !0,
            aspectRatio: !1,
            topRatio: 0.5,
            leftRatio: 0.5,
            scrolling: "auto",
            wrapCSS: "",
            arrows: !0,
            closeBtn: !0,
            closeClick: !1,
            nextClick: !1,
            mouseWheel: !0,
            autoPlay: !1,
            playSpeed: 3E3,
            preload: 3,
            modal: !1,
            loop: !0,
            ajax: {
                dataType: "html",
                headers: {
                    "X-fancyBox": !0
                }
            },
            iframe: {
                scrolling: "auto",
                preload: !0
            },
            swf: {
                wmode: "transparent",
                allowfullscreen: "true",
                allowscriptaccess: "always"
            },
            keys: {
                next: {
                    13: "left",
                    34: "up",
                    39: "left",
                    40: "up"
                },
                prev: {
                    8: "right",
                    33: "down",
                    37: "right",
                    38: "down"
                },
                close: [27],
                play: [32],
                toggle: [70]
            },
            direction: {
                next: "left",
                prev: "right"
            },
            scrollOutside: !0,
            index: 0,
            type: null,
            href: null,
            content: null,
            title: null,
            tpl: {
                wrap: '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
                image: '<img class="fancybox-image" src="{href}" alt="" />',
                iframe: '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen' +
                    (J ? ' allowtransparency="true"' : "") + "></iframe>",
                error: '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
                closeBtn: '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
                next: '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
                prev: '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
            },
            openEffect: "fade",
            openSpeed: 250,
            openEasing: "swing",
            openOpacity: !0,
            openMethod: "zoomIn",
            closeEffect: "fade",
            closeSpeed: 250,
            closeEasing: "swing",
            closeOpacity: !0,
            closeMethod: "zoomOut",
            nextEffect: "elastic",
            nextSpeed: 250,
            nextEasing: "swing",
            nextMethod: "changeIn",
            prevEffect: "elastic",
            prevSpeed: 250,
            prevEasing: "swing",
            prevMethod: "changeOut",
            helpers: {
                overlay: !0,
                title: !0
            },
            onCancel: f.noop,
            beforeLoad: f.noop,
            afterLoad: f.noop,
            beforeShow: f.noop,
            afterShow: f.noop,
            beforeChange: f.noop,
            beforeClose: f.noop,
            afterClose: f.noop
        },
        group: {},
        opts: {},
        previous: null,
        coming: null,
        current: null,
        isActive: !1,
        isOpen: !1,
        isOpened: !1,
        wrap: null,
        skin: null,
        outer: null,
        inner: null,
        player: {
            timer: null,
            isActive: !1
        },
        ajaxLoad: null,
        imgPreload: null,
        transitions: {},
        helpers: {},
        open: function(a, d) {
            if (a && (f.isPlainObject(d) || (d = {}), !1 !== b.close(!0))) return f.isArray(a) || (a = u(a) ? f(a).get() : [a]), f.each(a, function(e, c) {
                var l = {},
                    g, h, k, n, m;
                "object" === f.type(c) && (c.nodeType && (c = f(c)), u(c) ? (l = {
                        href: c.data("fancybox-href") || c.attr("href"),
                        title: f("<div/>").text(c.data("fancybox-title") || c.attr("title")).html(),
                        isDom: !0,
                        element: c
                    },
                    f.metadata && f.extend(!0, l, c.metadata())) : l = c);
                g = d.href || l.href || (r(c) ? c : null);
                h = d.title !== w ? d.title : l.title || "";
                n = (k = d.content || l.content) ? "html" : d.type || l.type;
                !n && l.isDom && (n = c.data("fancybox-type"), n || (n = (n = c.prop("class").match(/fancybox\.(\w+)/)) ? n[1] : null));
                r(g) && (n || (b.isImage(g) ? n = "image" : b.isSWF(g) ? n = "swf" : "#" === g.charAt(0) ? n = "inline" : r(c) && (n = "html", k = c)), "ajax" === n && (m = g.split(/\s+/, 2), g = m.shift(), m = m.shift()));
                k || ("inline" === n ? g ? k = f(r(g) ? g.replace(/.*(?=#[^\s]+$)/, "") : g) : l.isDom && (k = c) :
                    "html" === n ? k = g : n || g || !l.isDom || (n = "inline", k = c));
                f.extend(l, {
                    href: g,
                    type: n,
                    content: k,
                    title: h,
                    selector: m
                });
                a[e] = l
            }), b.opts = f.extend(!0, {}, b.defaults, d), d.keys !== w && (b.opts.keys = d.keys ? f.extend({}, b.defaults.keys, d.keys) : !1), b.group = a, b._start(b.opts.index)
        },
        cancel: function() {
            var a = b.coming;
            a && !1 === b.trigger("onCancel") || (b.hideLoading(), a && (b.ajaxLoad && b.ajaxLoad.abort(), b.ajaxLoad = null, b.imgPreload && (b.imgPreload.onload = b.imgPreload.onerror = null), a.wrap && a.wrap.stop(!0, !0).trigger("onReset").remove(),
                b.coming = null, b.current || b._afterZoomOut(a)))
        },
        close: function(a) {
            b.cancel();
            !1 !== b.trigger("beforeClose") && (b.unbindEvents(), b.isActive && (b.isOpen && !0 !== a ? (b.isOpen = b.isOpened = !1, b.isClosing = !0, f(".fancybox-item, .fancybox-nav").remove(), b.wrap.stop(!0, !0).removeClass("fancybox-opened"), b.transitions[b.current.closeMethod]()) : (f(".fancybox-wrap").stop(!0).trigger("onReset").remove(), b._afterZoomOut())))
        },
        play: function(a) {
            var d = function() {
                    clearTimeout(b.player.timer)
                },
                e = function() {
                    d();
                    b.current && b.player.isActive &&
                        (b.player.timer = setTimeout(b.next, b.current.playSpeed))
                },
                c = function() {
                    d();
                    p.unbind(".player");
                    b.player.isActive = !1;
                    b.trigger("onPlayEnd")
                };
            !0 === a || !b.player.isActive && !1 !== a ? b.current && (b.current.loop || b.current.index < b.group.length - 1) && (b.player.isActive = !0, p.bind({
                "onCancel.player beforeClose.player": c,
                "onUpdate.player": e,
                "beforeLoad.player": d
            }), e(), b.trigger("onPlayStart")) : c()
        },
        next: function(a) {
            var d = b.current;
            d && (r(a) || (a = d.direction.next), b.jumpto(d.index + 1, a, "next"))
        },
        prev: function(a) {
            var d =
                b.current;
            d && (r(a) || (a = d.direction.prev), b.jumpto(d.index - 1, a, "prev"))
        },
        jumpto: function(a, d, e) {
            var c = b.current;
            c && (a = m(a), b.direction = d || c.direction[a >= c.index ? "next" : "prev"], b.router = e || "jumpto", c.loop && (0 > a && (a = c.group.length + a % c.group.length), a %= c.group.length), c.group[a] !== w && (b.cancel(), b._start(a)))
        },
        reposition: function(a, d) {
            var e = b.current,
                c = e ? e.wrap : null,
                l;
            c && (l = b._getPosition(d), a && "scroll" === a.type ? (delete l.position, c.stop(!0, !0).animate(l, 200)) : (c.css(l), e.pos = f.extend({}, e.dim, l)))
        },
        update: function(a) {
            var d = a && a.originalEvent && a.originalEvent.type,
                e = !d || "orientationchange" === d;
            e && (clearTimeout(C), C = null);
            b.isOpen && !C && (C = setTimeout(function() {
                var c = b.current;
                c && !b.isClosing && (b.wrap.removeClass("fancybox-tmp"), (e || "load" === d || "resize" === d && c.autoResize) && b._setDimension(), "scroll" === d && c.canShrink || b.reposition(a), b.trigger("onUpdate"), C = null)
            }, e && !t ? 0 : 300))
        },
        toggle: function(a) {
            b.isOpen && (b.current.fitToView = "boolean" === f.type(a) ? a : !b.current.fitToView, t && (b.wrap.removeAttr("style").addClass("fancybox-tmp"),
                b.trigger("onUpdate")), b.update())
        },
        hideLoading: function() {
            p.unbind(".loading");
            f("#fancybox-loading").remove()
        },
        showLoading: function() {
            var a, d;
            b.hideLoading();
            a = f('<div id="fancybox-loading"><div></div></div>').click(b.cancel).appendTo("body");
            p.bind("keydown.loading", function(a) {
                27 === (a.which || a.keyCode) && (a.preventDefault(), b.cancel())
            });
            b.defaults.fixed || (d = b.getViewport(), a.css({
                position: "absolute",
                top: 0.5 * d.h + d.y,
                left: 0.5 * d.w + d.x
            }));
            b.trigger("onLoading")
        },
        getViewport: function() {
            var a = b.current &&
                b.current.locked || !1,
                d = {
                    x: q.scrollLeft(),
                    y: q.scrollTop()
                };
            a && a.length ? (d.w = a[0].clientWidth, d.h = a[0].clientHeight) : (d.w = t && s.innerWidth ? s.innerWidth : q.width(), d.h = t && s.innerHeight ? s.innerHeight : q.height());
            return d
        },
        unbindEvents: function() {
            b.wrap && u(b.wrap) && b.wrap.unbind(".fb");
            p.unbind(".fb");
            q.unbind(".fb")
        },
        bindEvents: function() {
            var a = b.current,
                d;
            a && (q.bind("orientationchange.fb" + (t ? "" : " resize.fb") + (a.autoCenter && !a.locked ? " scroll.fb" : ""), b.update), (d = a.keys) && p.bind("keydown.fb", function(e) {
                var c =
                    e.which || e.keyCode,
                    l = e.target || e.srcElement;
                if (27 === c && b.coming) return !1;
                e.ctrlKey || e.altKey || e.shiftKey || e.metaKey || l && (l.type || f(l).is("[contenteditable]")) || f.each(d, function(d, l) {
                    if (1 < a.group.length && l[c] !== w) return b[d](l[c]), e.preventDefault(), !1;
                    if (-1 < f.inArray(c, l)) return b[d](), e.preventDefault(), !1
                })
            }), f.fn.mousewheel && a.mouseWheel && b.wrap.bind("mousewheel.fb", function(d, c, l, g) {
                for (var h = f(d.target || null), k = !1; h.length && !(k || h.is(".fancybox-skin") || h.is(".fancybox-wrap"));) k = h[0] && !(h[0].style.overflow &&
                    "hidden" === h[0].style.overflow) && (h[0].clientWidth && h[0].scrollWidth > h[0].clientWidth || h[0].clientHeight && h[0].scrollHeight > h[0].clientHeight), h = f(h).parent();
                0 !== c && !k && 1 < b.group.length && !a.canShrink && (0 < g || 0 < l ? b.prev(0 < g ? "down" : "left") : (0 > g || 0 > l) && b.next(0 > g ? "up" : "right"), d.preventDefault())
            }))
        },
        trigger: function(a, d) {
            var e, c = d || b.coming || b.current;
            if (c) {
                f.isFunction(c[a]) && (e = c[a].apply(c, Array.prototype.slice.call(arguments, 1)));
                if (!1 === e) return !1;
                c.helpers && f.each(c.helpers, function(d, e) {
                    if (e &&
                        b.helpers[d] && f.isFunction(b.helpers[d][a])) b.helpers[d][a](f.extend(!0, {}, b.helpers[d].defaults, e), c)
                })
            }
            p.trigger(a)
        },
        isImage: function(a) {
            return r(a) && a.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i)
        },
        isSWF: function(a) {
            return r(a) && a.match(/\.(swf)((\?|#).*)?$/i)
        },
        _start: function(a) {
            var d = {},
                e, c;
            a = m(a);
            e = b.group[a] || null;
            if (!e) return !1;
            d = f.extend(!0, {}, b.opts, e);
            e = d.margin;
            c = d.padding;
            "number" === f.type(e) && (d.margin = [e, e, e, e]);
            "number" === f.type(c) && (d.padding = [c, c,
                c, c
            ]);
            d.modal && f.extend(!0, d, {
                closeBtn: !1,
                closeClick: !1,
                nextClick: !1,
                arrows: !1,
                mouseWheel: !1,
                keys: null,
                helpers: {
                    overlay: {
                        closeClick: !1
                    }
                }
            });
            d.autoSize && (d.autoWidth = d.autoHeight = !0);
            "auto" === d.width && (d.autoWidth = !0);
            "auto" === d.height && (d.autoHeight = !0);
            d.group = b.group;
            d.index = a;
            b.coming = d;
            if (!1 === b.trigger("beforeLoad")) b.coming = null;
            else {
                c = d.type;
                e = d.href;
                if (!c) return b.coming = null, b.current && b.router && "jumpto" !== b.router ? (b.current.index = a, b[b.router](b.direction)) : !1;
                b.isActive = !0;
                if ("image" ===
                    c || "swf" === c) d.autoHeight = d.autoWidth = !1, d.scrolling = "visible";
                "image" === c && (d.aspectRatio = !0);
                "iframe" === c && t && (d.scrolling = "scroll");
                d.wrap = f(d.tpl.wrap).addClass("fancybox-" + (t ? "mobile" : "desktop") + " fancybox-type-" + c + " fancybox-tmp " + d.wrapCSS).appendTo(d.parent || "body");
                f.extend(d, {
                    skin: f(".fancybox-skin", d.wrap),
                    outer: f(".fancybox-outer", d.wrap),
                    inner: f(".fancybox-inner", d.wrap)
                });
                f.each(["Top", "Right", "Bottom", "Left"], function(a, b) {
                    d.skin.css("padding" + b, x(d.padding[a]))
                });
                b.trigger("onReady");
                if ("inline" === c || "html" === c) {
                    if (!d.content || !d.content.length) return b._error("content")
                } else if (!e) return b._error("href");
                "image" === c ? b._loadImage() : "ajax" === c ? b._loadAjax() : "iframe" === c ? b._loadIframe() : b._afterLoad()
            }
        },
        _error: function(a) {
            f.extend(b.coming, {
                type: "html",
                autoWidth: !0,
                autoHeight: !0,
                minWidth: 0,
                minHeight: 0,
                scrolling: "no",
                hasError: a,
                content: b.coming.tpl.error
            });
            b._afterLoad()
        },
        _loadImage: function() {
            var a = b.imgPreload = new Image;
            a.onload = function() {
                this.onload = this.onerror = null;
                b.coming.width =
                    this.width / b.opts.pixelRatio;
                b.coming.height = this.height / b.opts.pixelRatio;
                b._afterLoad()
            };
            a.onerror = function() {
                this.onload = this.onerror = null;
                b._error("image")
            };
            a.src = b.coming.href;
            !0 !== a.complete && b.showLoading()
        },
        _loadAjax: function() {
            var a = b.coming;
            b.showLoading();
            b.ajaxLoad = f.ajax(f.extend({}, a.ajax, {
                url: a.href,
                error: function(a, e) {
                    b.coming && "abort" !== e ? b._error("ajax", a) : b.hideLoading()
                },
                success: function(d, e) {
                    "success" === e && (a.content = d, b._afterLoad())
                }
            }))
        },
        _loadIframe: function() {
            var a = b.coming,
                d = f(a.tpl.iframe.replace(/\{rnd\}/g, (new Date).getTime())).attr("scrolling", t ? "auto" : a.iframe.scrolling).attr("src", a.href);
            f(a.wrap).bind("onReset", function() {
                try {
                    f(this).find("iframe").hide().attr("src", "//about:blank").end().empty()
                } catch (a) {}
            });
            a.iframe.preload && (b.showLoading(), d.one("load", function() {
                f(this).data("ready", 1);
                t || f(this).bind("load.fb", b.update);
                f(this).parents(".fancybox-wrap").width("100%").removeClass("fancybox-tmp").show();
                b._afterLoad()
            }));
            a.content = d.appendTo(a.inner);
            a.iframe.preload ||
                b._afterLoad()
        },
        _preloadImages: function() {
            var a = b.group,
                d = b.current,
                e = a.length,
                c = d.preload ? Math.min(d.preload, e - 1) : 0,
                f, g;
            for (g = 1; g <= c; g += 1) f = a[(d.index + g) % e], "image" === f.type && f.href && ((new Image).src = f.href)
        },
        _afterLoad: function() {
            var a = b.coming,
                d = b.current,
                e, c, l, g, h;
            b.hideLoading();
            if (a && !1 !== b.isActive)
                if (!1 === b.trigger("afterLoad", a, d)) a.wrap.stop(!0).trigger("onReset").remove(), b.coming = null;
                else {
                    d && (b.trigger("beforeChange", d), d.wrap.stop(!0).removeClass("fancybox-opened").find(".fancybox-item, .fancybox-nav").remove());
                    b.unbindEvents();
                    e = a.content;
                    c = a.type;
                    l = a.scrolling;
                    f.extend(b, {
                        wrap: a.wrap,
                        skin: a.skin,
                        outer: a.outer,
                        inner: a.inner,
                        current: a,
                        previous: d
                    });
                    g = a.href;
                    switch (c) {
                        case "inline":
                        case "ajax":
                        case "html":
                            a.selector ? e = f("<div>").html(e).find(a.selector) : u(e) && (e.data("fancybox-placeholder") || e.data("fancybox-placeholder", f('<div class="fancybox-placeholder"></div>').insertAfter(e).hide()), e = e.show().detach(), a.wrap.bind("onReset", function() {
                                f(this).find(e).length && e.hide().replaceAll(e.data("fancybox-placeholder")).data("fancybox-placeholder", !1)
                            }));
                            break;
                        case "image":
                            e = a.tpl.image.replace(/\{href\}/g, g);
                            break;
                        case "swf":
                            e = '<object id="fancybox-swf" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%"><param name="movie" value="' + g + '"></param>', h = "", f.each(a.swf, function(a, b) {
                                e += '<param name="' + a + '" value="' + b + '"></param>';
                                h += " " + a + '="' + b + '"'
                            }), e += '<embed src="' + g + '" type="application/x-shockwave-flash" width="100%" height="100%"' + h + "></embed></object>"
                    }
                    u(e) && e.parent().is(a.inner) || a.inner.append(e);
                    b.trigger("beforeShow");
                    a.inner.css("overflow", "yes" === l ? "scroll" : "no" === l ? "hidden" : l);
                    b._setDimension();
                    b.reposition();
                    b.isOpen = !1;
                    b.coming = null;
                    b.bindEvents();
                    if (!b.isOpened) f(".fancybox-wrap").not(a.wrap).stop(!0).trigger("onReset").remove();
                    else if (d.prevMethod) b.transitions[d.prevMethod]();
                    b.transitions[b.isOpened ? a.nextMethod : a.openMethod]();
                    b._preloadImages()
                }
        },
        _setDimension: function() {
            var a = b.getViewport(),
                d = 0,
                e = !1,
                c = !1,
                e = b.wrap,
                l = b.skin,
                g = b.inner,
                h = b.current,
                c = h.width,
                k = h.height,
                n = h.minWidth,
                v = h.minHeight,
                p = h.maxWidth,
                q = h.maxHeight,
                t = h.scrolling,
                r = h.scrollOutside ? h.scrollbarWidth : 0,
                y = h.margin,
                z = m(y[1] + y[3]),
                s = m(y[0] + y[2]),
                w, A, u, D, B, G, C, E, I;
            e.add(l).add(g).width("auto").height("auto").removeClass("fancybox-tmp");
            y = m(l.outerWidth(!0) - l.width());
            w = m(l.outerHeight(!0) - l.height());
            A = z + y;
            u = s + w;
            D = F(c) ? (a.w - A) * m(c) / 100 : c;
            B = F(k) ? (a.h - u) * m(k) / 100 : k;
            if ("iframe" === h.type) {
                if (I = h.content, h.autoHeight && 1 === I.data("ready")) try {
                    I[0].contentWindow.document.location && (g.width(D).height(9999), G = I.contents().find("body"), r && G.css("overflow-x",
                        "hidden"), B = G.outerHeight(!0))
                } catch (H) {}
            } else if (h.autoWidth || h.autoHeight) g.addClass("fancybox-tmp"), h.autoWidth || g.width(D), h.autoHeight || g.height(B), h.autoWidth && (D = g.width()), h.autoHeight && (B = g.height()), g.removeClass("fancybox-tmp");
            c = m(D);
            k = m(B);
            E = D / B;
            n = m(F(n) ? m(n, "w") - A : n);
            p = m(F(p) ? m(p, "w") - A : p);
            v = m(F(v) ? m(v, "h") - u : v);
            q = m(F(q) ? m(q, "h") - u : q);
            G = p;
            C = q;
            h.fitToView && (p = Math.min(a.w - A, p), q = Math.min(a.h - u, q));
            A = a.w - z;
            s = a.h - s;
            h.aspectRatio ? (c > p && (c = p, k = m(c / E)), k > q && (k = q, c = m(k * E)), c < n && (c = n, k = m(c /
                E)), k < v && (k = v, c = m(k * E))) : (c = Math.max(n, Math.min(c, p)), h.autoHeight && "iframe" !== h.type && (g.width(c), k = g.height()), k = Math.max(v, Math.min(k, q)));
            if (h.fitToView)
                if (g.width(c).height(k), e.width(c + y), a = e.width(), z = e.height(), h.aspectRatio)
                    for (;
                        (a > A || z > s) && c > n && k > v && !(19 < d++);) k = Math.max(v, Math.min(q, k - 10)), c = m(k * E), c < n && (c = n, k = m(c / E)), c > p && (c = p, k = m(c / E)), g.width(c).height(k), e.width(c + y), a = e.width(), z = e.height();
                else c = Math.max(n, Math.min(c, c - (a - A))), k = Math.max(v, Math.min(k, k - (z - s)));
            r && "auto" === t && k < B &&
                c + y + r < A && (c += r);
            g.width(c).height(k);
            e.width(c + y);
            a = e.width();
            z = e.height();
            e = (a > A || z > s) && c > n && k > v;
            c = h.aspectRatio ? c < G && k < C && c < D && k < B : (c < G || k < C) && (c < D || k < B);
            f.extend(h, {
                dim: {
                    width: x(a),
                    height: x(z)
                },
                origWidth: D,
                origHeight: B,
                canShrink: e,
                canExpand: c,
                wPadding: y,
                hPadding: w,
                wrapSpace: z - l.outerHeight(!0),
                skinSpace: l.height() - k
            });
            !I && h.autoHeight && k > v && k < q && !c && g.height("auto")
        },
        _getPosition: function(a) {
            var d = b.current,
                e = b.getViewport(),
                c = d.margin,
                f = b.wrap.width() + c[1] + c[3],
                g = b.wrap.height() + c[0] + c[2],
                c = {
                    position: "absolute",
                    top: c[0],
                    left: c[3]
                };
            d.autoCenter && d.fixed && !a && g <= e.h && f <= e.w ? c.position = "fixed" : d.locked || (c.top += e.y, c.left += e.x);
            c.top = x(Math.max(c.top, c.top + (e.h - g) * d.topRatio));
            c.left = x(Math.max(c.left, c.left + (e.w - f) * d.leftRatio));
            return c
        },
        _afterZoomIn: function() {
            var a = b.current;
            a && ((b.isOpen = b.isOpened = !0, b.wrap.css("overflow", "visible").addClass("fancybox-opened"), b.update(), (a.closeClick || a.nextClick && 1 < b.group.length) && b.inner.css("cursor", "pointer").bind("click.fb", function(d) {
                f(d.target).is("a") || f(d.target).parent().is("a") ||
                    (d.preventDefault(), b[a.closeClick ? "close" : "next"]())
            }), a.closeBtn && f(a.tpl.closeBtn).appendTo(b.skin).bind("click.fb", function(a) {
                a.preventDefault();
                b.close()
            }), a.arrows && 1 < b.group.length && ((a.loop || 0 < a.index) && f(a.tpl.prev).appendTo(b.outer).bind("click.fb", b.prev), (a.loop || a.index < b.group.length - 1) && f(a.tpl.next).appendTo(b.outer).bind("click.fb", b.next)), b.trigger("afterShow"), a.loop || a.index !== a.group.length - 1) ? b.opts.autoPlay && !b.player.isActive && (b.opts.autoPlay = !1, b.play(!0)) : b.play(!1))
        },
        _afterZoomOut: function(a) {
            a = a || b.current;
            f(".fancybox-wrap").trigger("onReset").remove();
            f.extend(b, {
                group: {},
                opts: {},
                router: !1,
                current: null,
                isActive: !1,
                isOpened: !1,
                isOpen: !1,
                isClosing: !1,
                wrap: null,
                skin: null,
                outer: null,
                inner: null
            });
            b.trigger("afterClose", a)
        }
    });
    b.transitions = {
        getOrigPosition: function() {
            var a = b.current,
                d = a.element,
                e = a.orig,
                c = {},
                f = 50,
                g = 50,
                h = a.hPadding,
                k = a.wPadding,
                n = b.getViewport();
            !e && a.isDom && d.is(":visible") && (e = d.find("img:first"), e.length || (e = d));
            u(e) ? (c = e.offset(), e.is("img") &&
                (f = e.outerWidth(), g = e.outerHeight())) : (c.top = n.y + (n.h - g) * a.topRatio, c.left = n.x + (n.w - f) * a.leftRatio);
            if ("fixed" === b.wrap.css("position") || a.locked) c.top -= n.y, c.left -= n.x;
            return c = {
                top: x(c.top - h * a.topRatio),
                left: x(c.left - k * a.leftRatio),
                width: x(f + k),
                height: x(g + h)
            }
        },
        step: function(a, d) {
            var e, c, f = d.prop;
            c = b.current;
            var g = c.wrapSpace,
                h = c.skinSpace;
            if ("width" === f || "height" === f) e = d.end === d.start ? 1 : (a - d.start) / (d.end - d.start), b.isClosing && (e = 1 - e), c = "width" === f ? c.wPadding : c.hPadding, c = a - c, b.skin[f](m("width" ===
                f ? c : c - g * e)), b.inner[f](m("width" === f ? c : c - g * e - h * e))
        },
        zoomIn: function() {
            var a = b.current,
                d = a.pos,
                e = a.openEffect,
                c = "elastic" === e,
                l = f.extend({
                    opacity: 1
                }, d);
            delete l.position;
            c ? (d = this.getOrigPosition(), a.openOpacity && (d.opacity = 0.1)) : "fade" === e && (d.opacity = 0.1);
            b.wrap.css(d).animate(l, {
                duration: "none" === e ? 0 : a.openSpeed,
                easing: a.openEasing,
                step: c ? this.step : null,
                complete: b._afterZoomIn
            })
        },
        zoomOut: function() {
            var a = b.current,
                d = a.closeEffect,
                e = "elastic" === d,
                c = {
                    opacity: 0.1
                };
            e && (c = this.getOrigPosition(), a.closeOpacity &&
                (c.opacity = 0.1));
            b.wrap.animate(c, {
                duration: "none" === d ? 0 : a.closeSpeed,
                easing: a.closeEasing,
                step: e ? this.step : null,
                complete: b._afterZoomOut
            })
        },
        changeIn: function() {
            var a = b.current,
                d = a.nextEffect,
                e = a.pos,
                c = {
                    opacity: 1
                },
                f = b.direction,
                g;
            e.opacity = 0.1;
            "elastic" === d && (g = "down" === f || "up" === f ? "top" : "left", "down" === f || "right" === f ? (e[g] = x(m(e[g]) - 200), c[g] = "+=200px") : (e[g] = x(m(e[g]) + 200), c[g] = "-=200px"));
            "none" === d ? b._afterZoomIn() : b.wrap.css(e).animate(c, {
                duration: a.nextSpeed,
                easing: a.nextEasing,
                complete: b._afterZoomIn
            })
        },
        changeOut: function() {
            var a = b.previous,
                d = a.prevEffect,
                e = {
                    opacity: 0.1
                },
                c = b.direction;
            "elastic" === d && (e["down" === c || "up" === c ? "top" : "left"] = ("up" === c || "left" === c ? "-" : "+") + "=200px");
            a.wrap.animate(e, {
                duration: "none" === d ? 0 : a.prevSpeed,
                easing: a.prevEasing,
                complete: function() {
                    f(this).trigger("onReset").remove()
                }
            })
        }
    };
    b.helpers.overlay = {
        defaults: {
            closeClick: !0,
            speedOut: 200,
            showEarly: !0,
            css: {},
            locked: !t,
            fixed: !0
        },
        overlay: null,
        fixed: !1,
        el: f("html"),
        create: function(a) {
            var d;
            a = f.extend({}, this.defaults, a);
            this.overlay &&
                this.close();
            d = b.coming ? b.coming.parent : a.parent;
            this.overlay = f('<div class="fancybox-overlay"></div>').appendTo(d && d.lenth ? d : "body");
            this.fixed = !1;
            a.fixed && b.defaults.fixed && (this.overlay.addClass("fancybox-overlay-fixed"), this.fixed = !0)
        },
        open: function(a) {
            var d = this;
            a = f.extend({}, this.defaults, a);
            this.overlay ? this.overlay.unbind(".overlay").width("auto").height("auto") : this.create(a);
            this.fixed || (q.bind("resize.overlay", f.proxy(this.update, this)), this.update());
            a.closeClick && this.overlay.bind("click.overlay",
                function(a) {
                    if (f(a.target).hasClass("fancybox-overlay")) return b.isActive ? b.close() : d.close(), !1
                });
            this.overlay.css(a.css).show()
        },
        close: function() {
            q.unbind("resize.overlay");
            this.el.hasClass("fancybox-lock") && (f(".fancybox-margin").removeClass("fancybox-margin"), this.el.removeClass("fancybox-lock"), q.scrollTop(this.scrollV).scrollLeft(this.scrollH));
            f(".fancybox-overlay").remove().hide();
            f.extend(this, {
                overlay: null,
                fixed: !1
            })
        },
        update: function() {
            var a = "100%",
                b;
            this.overlay.width(a).height("100%");
            J ? (b = Math.max(H.documentElement.offsetWidth, H.body.offsetWidth), p.width() > b && (a = p.width())) : p.width() > q.width() && (a = p.width());
            this.overlay.width(a).height(p.height())
        },
        onReady: function(a, b) {
            var e = this.overlay;
            f(".fancybox-overlay").stop(!0, !0);
            e || this.create(a);
            a.locked && this.fixed && b.fixed && (b.locked = this.overlay.append(b.wrap), b.fixed = !1);
            !0 === a.showEarly && this.beforeShow.apply(this, arguments)
        },
        beforeShow: function(a, b) {
            b.locked && !this.el.hasClass("fancybox-lock") && (!1 !== this.fixPosition && f("*").filter(function() {
                return "fixed" ===
                    f(this).css("position") && !f(this).hasClass("fancybox-overlay") && !f(this).hasClass("fancybox-wrap")
            }).addClass("fancybox-margin"), this.el.addClass("fancybox-margin"), this.scrollV = q.scrollTop(), this.scrollH = q.scrollLeft(), this.el.addClass("fancybox-lock"), q.scrollTop(this.scrollV).scrollLeft(this.scrollH));
            this.open(a)
        },
        onUpdate: function() {
            this.fixed || this.update()
        },
        afterClose: function(a) {
            this.overlay && !b.coming && this.overlay.fadeOut(a.speedOut, f.proxy(this.close, this))
        }
    };
    b.helpers.title = {
        defaults: {
            type: "float",
            position: "bottom"
        },
        beforeShow: function(a) {
            var d = b.current,
                e = d.title,
                c = a.type;
            f.isFunction(e) && (e = e.call(d.element, d));
            if (r(e) && "" !== f.trim(e)) {
                d = f('<div class="fancybox-title fancybox-title-' + c + '-wrap">' + e + "</div>");
                switch (c) {
                    case "inside":
                        c = b.skin;
                        break;
                    case "outside":
                        c = b.wrap;
                        break;
                    case "over":
                        c = b.inner;
                        break;
                    default:
                        c = b.skin, d.appendTo("body"), J && d.width(d.width()), d.wrapInner('<span class="child"></span>'), b.current.margin[2] += Math.abs(m(d.css("margin-bottom")))
                }
                d["top" === a.position ? "prependTo" :
                    "appendTo"](c)
            }
        }
    };
    f.fn.fancybox = function(a) {
        var d, e = f(this),
            c = this.selector || "",
            l = function(g) {
                var h = f(this).blur(),
                    k = d,
                    l, m;
                g.ctrlKey || g.altKey || g.shiftKey || g.metaKey || h.is(".fancybox-wrap") || (l = a.groupAttr || "data-fancybox-group", m = h.attr(l), m || (l = "rel", m = h.get(0)[l]), m && "" !== m && "nofollow" !== m && (h = c.length ? f(c) : e, h = h.filter("[" + l + '="' + m + '"]'), k = h.index(this)), a.index = k, !1 !== b.open(h, a) && g.preventDefault())
            };
        a = a || {};
        d = a.index || 0;
        c && !1 !== a.live ? p.undelegate(c, "click.fb-start").delegate(c + ":not('.fancybox-item, .fancybox-nav')",
            "click.fb-start", l) : e.unbind("click.fb-start").bind("click.fb-start", l);
        this.filter("[data-fancybox-start=1]").trigger("click");
        return this
    };
    p.ready(function() {
        var a, d;
        f.scrollbarWidth === w && (f.scrollbarWidth = function() {
            var a = f('<div style="width:50px;height:50px;overflow:auto"><div/></div>').appendTo("body"),
                b = a.children(),
                b = b.innerWidth() - b.height(99).innerWidth();
            a.remove();
            return b
        });
        f.support.fixedPosition === w && (f.support.fixedPosition = function() {
            var a = f('<div style="position:fixed;top:20px;"></div>').appendTo("body"),
                b = 20 === a[0].offsetTop || 15 === a[0].offsetTop;
            a.remove();
            return b
        }());
        f.extend(b.defaults, {
            scrollbarWidth: f.scrollbarWidth(),
            fixed: f.support.fixedPosition,
            parent: f("body")
        });
        a = f(s).width();
        K.addClass("fancybox-lock-test");
        d = f(s).width();
        K.removeClass("fancybox-lock-test");
        f("<style type='text/css'>.fancybox-margin{margin-right:" + (d - a) + "px;}</style>").appendTo("head")
    })
})(window, document, jQuery);






/*!
 * Media helper for fancyBox
 * version: 1.0.6 (Fri, 14 Jun 2013)
 * @requires fancyBox v2.0 or later
 *
 * Usage:
 *     $(".fancybox").fancybox({
 *         helpers : {
 *             media: true
 *         }
 *     });
 *
 * Set custom URL parameters:
 *     $(".fancybox").fancybox({
 *         helpers : {
 *             media: {
 *                 youtube : {
 *                     params : {
 *                         autoplay : 0
 *                     }
 *                 }
 *             }
 *         }
 *     });
 *
 * Or:
 *     $(".fancybox").fancybox({,
 *         helpers : {
 *             media: true
 *         },
 *         youtube : {
 *             autoplay: 0
 *         }
 *     });
 *
 *  Supports:
 *
 *      Youtube
 *          http://www.youtube.com/watch?v=opj24KnzrWo
 *          http://www.youtube.com/embed/opj24KnzrWo
 *          http://youtu.be/opj24KnzrWo
 *          http://www.youtube-nocookie.com/embed/opj24KnzrWo
 *      Vimeo
 *          http://vimeo.com/40648169
 *          http://vimeo.com/channels/staffpicks/38843628
 *          http://vimeo.com/groups/surrealism/videos/36516384
 *          http://player.vimeo.com/video/45074303
 *      Metacafe
 *          http://www.metacafe.com/watch/7635964/dr_seuss_the_lorax_movie_trailer/
 *          http://www.metacafe.com/watch/7635964/
 *      Dailymotion
 *          http://www.dailymotion.com/video/xoytqh_dr-seuss-the-lorax-premiere_people
 *      Twitvid
 *          http://twitvid.com/QY7MD
 *      Twitpic
 *          http://twitpic.com/7p93st
 *      Instagram
 *          http://instagr.am/p/IejkuUGxQn/
 *          http://instagram.com/p/IejkuUGxQn/
 *      Google maps
 *          http://maps.google.com/maps?q=Eiffel+Tower,+Avenue+Gustave+Eiffel,+Paris,+France&t=h&z=17
 *          http://maps.google.com/?ll=48.857995,2.294297&spn=0.007666,0.021136&t=m&z=16
 *          http://maps.google.com/?ll=48.859463,2.292626&spn=0.000965,0.002642&t=m&z=19&layer=c&cbll=48.859524,2.292532&panoid=YJ0lq28OOy3VT2IqIuVY0g&cbp=12,151.58,,0,-15.56
 */
(function ($) {
    "use strict";

    //Shortcut for fancyBox object
    var F = $.fancybox,
        format = function( url, rez, params ) {
            params = params || '';

            if ( $.type( params ) === "object" ) {
                params = $.param(params, true);
            }

            $.each(rez, function(key, value) {
                url = url.replace( '$' + key, value || '' );
            });

            if (params.length) {
                url += ( url.indexOf('?') > 0 ? '&' : '?' ) + params;
            }

            return url;
        };

    //Add helper object
    F.helpers.media = {
        defaults : {
            youtube : {
                matcher : /(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(watch\?v=|v\/|u\/|embed\/?)?(videoseries\?list=(.*)|[\w-]{11}|\?listType=(.*)&list=(.*)).*/i,
                params  : {
                    autoplay    : 1,
                    autohide    : 1,
                    fs          : 1,
                    rel         : 0,
                    hd          : 1,
                    wmode       : 'opaque',
                    enablejsapi : 1
                },
                type : 'iframe',
                url  : '//www.youtube.com/embed/$3'
            },
            vimeo : {
                matcher : /(?:vimeo(?:pro)?.com)\/(?:[^\d]+)?(\d+)(?:.*)/,
                params  : {
                    autoplay      : 1,
                    hd            : 1,
                    show_title    : 1,
                    show_byline   : 1,
                    show_portrait : 0,
                    fullscreen    : 1
                },
                type : 'iframe',
                url  : '//player.vimeo.com/video/$1'
            },
            metacafe : {
                matcher : /metacafe.com\/(?:watch|fplayer)\/([\w\-]{1,10})/,
                params  : {
                    autoPlay : 'yes'
                },
                type : 'swf',
                url  : function( rez, params, obj ) {
                    obj.swf.flashVars = 'playerVars=' + $.param( params, true );

                    return '//www.metacafe.com/fplayer/' + rez[1] + '/.swf';
                }
            },
            dailymotion : {
                matcher : /dailymotion.com\/video\/(.*)\/?(.*)/,
                params  : {
                    additionalInfos : 0,
                    autoStart : 1
                },
                type : 'swf',
                url  : '//www.dailymotion.com/swf/video/$1'
            },
            twitvid : {
                matcher : /twitvid\.com\/([a-zA-Z0-9_\-\?\=]+)/i,
                params  : {
                    autoplay : 0
                },
                type : 'iframe',
                url  : '//www.twitvid.com/embed.php?guid=$1'
            },
            twitpic : {
                matcher : /twitpic\.com\/(?!(?:place|photos|events)\/)([a-zA-Z0-9\?\=\-]+)/i,
                type : 'image',
                url  : '//twitpic.com/show/full/$1/'
            },
            instagram : {
                matcher : /(instagr\.am|instagram\.com)\/p\/([a-zA-Z0-9_\-]+)\/?/i,
                type : 'image',
                url  : '//$1/p/$2/media/?size=l'
            },
            google_maps : {
                matcher : /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
                type : 'iframe',
                url  : function( rez ) {
                    return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
                }
            } 
        },

        beforeLoad : function(opts, obj) {
            var url   = obj.href || '',
                type  = false,
                what,
                item,
                rez,
                params;

            for (what in opts) {
                if (opts.hasOwnProperty(what)) {
                    item = opts[ what ];
                    rez  = url.match( item.matcher );

                    if (rez) {
                        type   = item.type;
                        params = $.extend(true, {}, item.params, obj[ what ] || ($.isPlainObject(opts[ what ]) ? opts[ what ].params : null));

                        url = $.type( item.url ) === "function" ? item.url.call( this, rez, params, obj ) : format( item.url, rez, params );

                        break;
                    }
                }
            }

            if (type) {
                obj.href = url;
                obj.type = type;

                obj.autoHeight = false;
            }
        }
    };

}(jQuery));