(function ($) {
    "use strict";

    //Home fit screen	

    /*global $:false */
    $(function () {
        "use strict";
        if ($(window).width() >= 1366) {
            $('#home').css({
                'height': ($(window).height()) + 'px'
            });
        } else {
            $('#home').css({
                'height': "70vw"
            });
        }
        $(window).resize(function () {
            if ($(window).width() >= 1366) {
                $('#home').css({
                    'height': ($(window).height()) + 'px'
                });
            } else {
                $('#home').css({
                    'height': "70vw"
                });
            }
        });
    });


    //Home text fade on scroll	

    $(window).scroll(function (e) {
        e.preventDefault();
        var $Fade = $('#sync3 .item .line, #sync3 .item .home-big-text, #sync3 .item .home-small-text, #sync3 .item .line1, #sync4');
        //Get scroll position of window 
        var windowScroll = $(this).scrollTop();
        //Slow scroll and fade it out 
        $Fade.css({
            'margin-top': -(windowScroll / 0) + "px",
            'opacity': 1 - (windowScroll / 400)
        });
    });



    //Navigation	

    $('ul.slimmenu').on('click', function () {
        var width = $(window).width();
        if ((width <= 800)) {
            $(this).slideToggle();
        }
    });
    $('ul.slimmenu').slimmenu({
        resizeWidth: '800',
        collapserTitle: '',
        easingEffect: 'easeInOutQuint',
        animSpeed: 'medium',
        indentChildren: true,
        childrenIndenter: '&raquo;'
    });
    /*global $:false */
    $(document).ready(function () {
        "use strict";
        $(".scroll").click(function (event) {

            event.preventDefault();

            var full_url = this.href;
            var parts = full_url.split("#");
            var trgt = parts[1];
            var target_offset = $("#" + trgt).offset();
            var target_top = target_offset.top - 60;

            $('html, body').animate({
                scrollTop: target_top
            }, 800);
        });
    });








    //Parallax effects 


    $(document).ready(function () {
        $('.parallax-home').parallax("50%", 0.3);
        $('.parallax1').parallax("50%", 0.3);
        $('.parallax2').parallax("50%", 0.2);
        $('.parallax3').parallax("50%", 0.2);
    });






    //Portfolio filter 

    /*global $:false */
    $(window).load(function () {
        var $container = $('.portfolio-wrap');
        var $filter = $('#filter');
        // Initialize isotope 
        $container.isotope({
            filter: '*',
            layoutMode: 'fitRows',
            animationOptions: {
                duration: 750,
                easing: 'linear'
            }
        });
        // Filter items when filter link is clicked
        $filter.find('a').click(function () {
            var selector = $(this).attr('data-filter');
            $filter.find('a').removeClass('current');
            $(this).addClass('current');
            $container.isotope({
                filter: selector,
                animationOptions: {
                    animationDuration: 750,
                    easing: 'linear',
                    queue: false,
                }
            });
            return false;
        });
    });


    // Portfolio Isotope

    jQuery(document).ready(function ($) {

        var container = $('.portfolio-wrap');

        function splitColumns() {
            var winWidth = $(window).width(),
                columnNumb = 1;


            if (winWidth > 1200) {
                columnNumb = 4;
            } else if (winWidth > 700) {
                columnNumb = 2;
            } else if (winWidth > 479) {
                columnNumb = 2;
            } else if (winWidth < 479) {
                columnNumb = 1;
            }

            return columnNumb;
        }

        function setColumns() {
            var winWidth = $(window).width(),
                columnNumb = splitColumns(),
                postWidth = Math.floor(winWidth / columnNumb);

            container.find('.portfolio-box').each(function () {
                $(this).css({
                    width: postWidth + 'px'
                });
            });
        }

        function setProjects() {
            setColumns();
            container.isotope('reLayout');
        }

        container.imagesLoaded(function () {
            setColumns();
        });


        $(window).bind('resize', function () {
            setProjects();
        });

    });


    // Portfolio Ajax


    $(window).load(function () {
        'use strict';
        var loader = $('.expander-wrap');
        if (typeof loader.html() == 'undefined') {
            $('<div class="expander-wrap"><div id="expander-wrap" class="container clearfix relative"><p class="cls-btn"><a class="close">X</a></p><div/></div></div>').css({
                opacity: 0
            }).hide().insertAfter('.portfolio');
            loader = $('.expander-wrap');
        }
        $('.expander').on('click', function (e) {
            e.preventDefault();
            e.stopPropagation();
            var url = $(this).attr('href');



            loader.slideUp(function () {
                $.get(url, function (data) {
                    var portfolioContainer = $('.portfolio');
                    var topPosition = portfolioContainer.offset().top;
                    var bottomPosition = topPosition + portfolioContainer.height();
                    $('html,body').delay(600).animate({
                        scrollTop: bottomPosition - -10
                    }, 800);
                    var container = $('#expander-wrap>div', loader);

                    container.html(data);
                    $(".video").fitVids();
                    $('.project').flexslider({
                        animation: "fade",
                        selector: ".project-slides .slide",
                        controlNav: false,
                        directionNav: true,
                        slideshowSpeed: 5000,
                    });


                    loader.slideDown(function () {
                        if (typeof keepVideoRatio == 'function') {
                            keepVideoRatio('.video > iframe');
                        }
                    }).delay(1000).animate({
                        opacity: 1
                    }, 200);
                });
            });
        });

        $('.close', loader).on('click', function () {
            loader.delay(300).slideUp(function () {
                var container = $('#expander-wrap>div', loader);
                container.html('');
                $(this).css({
                    opacity: 0
                });

            });
            var portfolioContainer = $('.portfolio');
            var topPosition = portfolioContainer.offset().top;
            $('html,body').delay(0).animate({
                scrollTop: topPosition - 70
            }, 500);
        });

    });




    //Counter 

    jQuery(document).ready(function ($) {
        $('.counter').counterUp({
            delay: 100,
            time: 2000
        });
    });






    //Google map	

    /*global $:false */
    var map;
    $(document).ready(function () {
        "use strict";
        map = new GMaps({
            disableDefaultUI: true,
            scrollwheel: false,
            el: '#map',
            lat: 44.789511,
            lng: 20.43633
        });
        map.drawOverlay({
            lat: map.getCenter().lat(),
            lng: map.getCenter().lng(),
            layer: 'overlayLayer',
            content: '<div class="overlay"></div>',
            verticalAlign: 'center',
            horizontalAlign: 'center'
        });
        var styles = [
            {
                "featureType": "poi",
                "stylers": [
                    {
                        "visibility": "on"
                    },
                    {
                        "weight": 0.9
                    },
                    {
                        "lightness": 37
                    },
                    {
                        "gamma": 0.62
                    },
                    {
                        "hue": "#ff0000"
                    },
                    {
                        "saturation": -93
                    }
    ]
  }, {
                "featureType": "poi",
                "stylers": [
                    {
                        "hue": "#ff0000"
                    },
                    {
                        "saturation": -1
                    },
                    {
                        "color": "#ffffff"
                    },
                    {
                        "weight": 0.2
                    }
    ]
  }, {
                "featureType": "road",
                "stylers": [
                    {
                        "hue": "#ff0000"
                    },
                    {
                        "saturation": -98
                    }
    ]
  }, {
                "featureType": "landscape",
                "stylers": [
                    {
                        "hue": "#ff0000"
                    },
                    {
                        "saturation": -89
                    }
    ]
  }, {
                "featureType": "water",
                "stylers": [
                    {
                        "hue": "#cfa144"
                    },
                    {
                        "weight": 0.4
                    },
                    {
                        "saturation": -38
                    }
    ]
  }
];

        map.addStyle({
            styledMapName: "Styled Map",
            styles: styles,
            mapTypeId: "map_style"
        });

        map.setStyle("map_style");
    });

})(jQuery);



var $item = $('.carousel .item');
var $wHeight = $(window).height();
$item.eq(0).addClass('active');
$item.addClass('full-screen');
if ($(window).width() >= 1366) {
    $item.height($wHeight);
} else {
    $item.css('height', '70vw');

}


$('.carousel img').each(function () {
    var $src = $(this).attr('src');
    var $color = $(this).attr('data-color');
    $(this).parent().css({
        'background-image': 'url(' + $src + ')',
        'background-color': $color,
        'background-position': 'top center',
        'background-size': 'cover',
    });
    $(this).remove();
});

$(window).on('resize', function () {
    $wHeight = $(window).height();
    if ($(window).width() >= 1366) {
        $item.height($wHeight);
    } else {
        $item.css('height', '70vw');

    }
});
