"use strict";

/* =========================================
[Navigation Side Menu System] Start Here
==========================================*/
$(document).ready(function(){
    /* If User Click Navigation Button, Call Navigation Menu to Open*/
    $('.navi-menu-button').on('click', function(e){
		navMenuOpen();
	});

    /* If User Click Outside of Navigation Menu, Call Navigation Menu to Close*/
    $('.nav-menu').on('click', function(e){
        if ($(e.target).hasClass('nav-menu')){
			navMenuClose();
		}
    });

    /* [Company nav Open] */
    $('.profile-menu-company').on('click', function (e) {
        AznavCMenuOpen();
    });

    /* [Branch nav Open] */
    $('.profile-menu-branch').on('click', function (e) {
        AznavBMenuOpen();
    });

    /* [Delivery nav Open] */
    $('.profile-menu-xAxisP').on('click', function (e) {
        AznavDMenuOpen();
    });

    /* [Staff nav Open] */
    $('.profile-menu-xAxisM').on('click', function (e) {
        AznavSMenuOpen();
    });

    /* [Personal nav Open] */
    $('.profile-menu-personal').on('click', function (e) {
        AznavPMenuOpen();
    });

    $('.go-back-linkC').on('click', function (e) {
        AznavCMenuClose();
    });

    $('.go-back-linkB').on('click', function (e) {
        AznavBMenuClose();
    });

    $('.go-back-linkD').on('click', function (e) {
        AznavDMenuClose();
    });

    $('.go-back-linkS').on('click', function (e) {
        AznavSMenuClose();
    });

    $('.go-back-linkP').on('click', function (e) {
        AznavPMenuClose();
    });

    /* Dropdown List System for Unorderd List Function*/
    $('nav.menu ul.main-menu>li>a').on('click', function(e){
		var that = $(this);
		if (that.parent().find('ul:first').length)
		{
			e.preventDefault();
			if (!that.parent().hasClass('active'))
            {     
                /* If User Click Dropdown List Change Up Arrow to Down Arrow*/
                $('nav.menu ul.main-menu ul').slideUp('fast',function(){
                    $('nav.menu ul.main-menu > li').removeClass('active');
				});
				
                $('nav.menu ul li a span').removeClass('fa-angle-up').addClass('fa-angle-down');

				/* If User Click Other Dropdown List Change Down Arrow to Up Arrow*/
				that.parent().find('ul:first').slideDown('fast',function(){
					that.parent().addClass('active');
				});

				that.find('span').removeClass('fa-angle-down').addClass('fa-angle-up');
			}
			else
			{
				/* If User Click None Change Up Arrow to Down Arrow*/
				that.parent().find('ul:first').slideUp('fast',function(){
					$(this).parent().removeClass('active');
				});
				that.find('span').removeClass('fa-angle-up').addClass('fa-angle-down');
			}
		}
		else
		{
            $('nav.menu ul.main-menu ul').slideUp('fast');
            $('nav.menu ul.main-menu > li').removeClass('active');
			that.parent().addClass('active');
		}
	});


    $('.tab-item .fix-width .menu-item').css({ 'width': 100 / $('.tab-item .fix-width .menu-item').length+'%'});

	if ($('.wizard').length)
	{
		wizardFixHeight();
		$(window).resize();
	}



	if ($('.animated-text').length)
		animateText();

});
/* =========================================
[Navigation Side Menu System] End Here
==========================================*/

$(".wrapper-inline").on("scroll", function(e) {
	if (this.scrollTop > 150) {
		$('header.no-background').addClass("set-bg");
	} else {
		$('header.no-background').removeClass("set-bg");
	}
  
});

/* =========================================
[Open Navigation Menu Function] Don't touch
==========================================*/
//[Main Nav]
var navMenuOpen = function () {
    $('.navi-menu-button').addClass('focused');

    $('div.nav-menu').fadeIn(50, function (e) {
        $('nav.menu').addClass('opened');
    });
};
//[Company Nav]
var AznavCMenuOpen = function () {
    $('.profile-menu-company').addClass('focused');

    $('div.AznavC-menuC').fadeIn(50, function (e) {
        $('AznavC.menuC').addClass('opened');
    });
};
//[Branch Nav]
var AznavBMenuOpen = function () {
    $('.profile-menu-branch').addClass('focused');

    $('div.AznavB-menuB').fadeIn(50, function (e) {
        $('AznavB.menuB').addClass('opened');
    });
};
//[Delivery Nav]
var AznavDMenuOpen = function () {
    $('.profile-menu-xAxisP').addClass('focused');

    $('div.AznavD-menuD').fadeIn(50, function (e) {
        $('AznavD.menuD').addClass('opened');
    });
};
//[Staff Nav]
var AznavSMenuOpen = function () {
    $('.profile-menu-xAxisM').addClass('focused');

    $('div.AznavS-menuS').fadeIn(50, function (e) {
        $('AznavS.menuS').addClass('opened');
    });
};
//[Personal Nav]
var AznavPMenuOpen = function () {
    $('.profile-menu-personal').addClass('focused');

    $('div.AznavP-menuP').fadeIn(50, function (e) {
        $('AznavP.menuP').addClass('opened');
    });
};

/* =========================================
[Close Navigation Menu Function] Don't touch
==========================================*/
//[Main Nav]
var navMenuClose = function () {
    $('.navi-menu-button').removeClass('focused');

    $('nav.menu').removeClass('opened');
    $('div.nav-menu').fadeOut(200);
};
//[Company Nav]
var AznavCMenuClose = function () {
    $('.go-back-linkC').removeClass('focused');

    $('AznavC.menuC').removeClass('opened');
    $('div.AznavC-menuC').fadeOut(200);
};
//[Branch Nav]
var AznavBMenuClose = function () {
    $('.go-back-linkB').removeClass('focused');

    $('AznavB.menuB').removeClass('opened');
    $('div.AznavB-menuB').fadeOut(200);
};
//[Delivery Nav]
var AznavDMenuClose = function () {
    $('.go-back-linkD').removeClass('focused');

    $('AznavD.menuD').removeClass('opened');
    $('div.AznavD-menuD').fadeOut(200);
};
//[Staff Nav]
var AznavSMenuClose = function () {
    $('.go-back-linkS').removeClass('focused');

    $('AznavS.menuS').removeClass('opened');
    $('div.AznavS-menuS').fadeOut(200);
};
//[Personal Nav]
var AznavPMenuClose = function () {
    $('.go-back-linkP').removeClass('focused');

    $('AznavP.menuP').removeClass('opened');
    $('div.AznavP-menuP').fadeOut(200);
};

/* =========================================
[Navigation Button Animate] Don't touch
==========================================*/
var animateText = function () {
    $('.vertical-center').css({ 'margin-top': $(window).height() / 2 - $('.vertical-center').height() / 2 });
    $('.animated-text').removeClass('zero-opacity');
    $('[data-transation]').each(function (e, i) {
        var that = $(this);
        that.addClass('hide');

        var transation = that.attr('data-transation');
        if (transation == '')
            transation = 'fadeInDown';

        var startTime = parseInt(that.attr('data-start-time'));
        if (isNaN(startTime))
            startTime = 0;

        setTimeout(function () {
            that.addClass('animated ' + transation);
        }, startTime);
    });
};


/* =========================================
[Check Box] 
==========================================*/
$('.sweet-check :checkbox:checked').each(function(e,i){
	$(this).parent().addClass('checked');
});


$(document).on('click', '.sweet-check', function(){
	if ($(this).hasClass('checked'))
	{
		$(this).removeClass('checked');
		$(this).find('input').prop('checked', false);
	}
	else
	{
		$(this).addClass('checked');
		$(this).find('input').prop('checked', true);
	}

	//console.log($(this).find('input').prop('checked'));
});

$(document).on('click','[data-loader]', function(){
	$('.sweet-loader').show().addClass('show');
});


/* =========================================
[Accordion] 
==========================================*/
$(document).on('click', '.expandable-item .expandable-header', function(){
	if ($(this).parent().hasClass('accordion'))
	{
		if ($(this).parent().hasClass('active'))
		{
			$(this).parent().removeClass('active');
			$(this).parent().find('.expandable-content').attr('style','');
		}
		else
		{
			var accordionGroup = $(this).parent().attr('data-group');
			$('[data-group="'+accordionGroup+'"]').removeClass('active');
			$('[data-group="'+accordionGroup+'"]').find('.expandable-content').attr('style','');
			$(this).parent().find('.expandable-content').css({'max-height':$(this).parent().find('.expandable-content')[0].scrollHeight});
			$(this).parent().addClass('active');
		}
	}
	else
	{
		if ($(this).parent().hasClass('active'))
			$(this).parent().find('.expandable-content').attr('style','');
		else
			$(this).parent().find('.expandable-content').css({'max-height':$(this).parent().find('.expandable-content')[0].scrollHeight});

		$(this).parent().toggleClass('active');
	}
});


/* =========================================
[Tab Control] 
==========================================*/
$(document).on('click', '.tab-item .menu-item', function(e){
	e.preventDefault();
	var tabContentId = $(this).attr('data-content');

    $(this).parents('.tab-item').find('.menu-item').removeClass('active');
	$(this).addClass('active');

    $(this).parents('.tab-item').find('.content-item').removeClass('active');
    $('#' + tabContentId).addClass('active');
    window.location.hash = tabContentId;
});

/* =========================================
[Popup Action] 
==========================================*/
$(document).on('click', '[data-dismiss="true"]', function(){
	$(this).parents('.popup-overlay').fadeOut('fast');
});

$(document).on('click', '[data-popup]', function(){
	var modalId = $(this).attr('data-popup');
	$('#'+modalId).fadeIn('fast');
});

$(document).on('click', '.popup-overlay', function(e){
	if ($(e.target).hasClass('popup-overlay'))
	{
		$(this).fadeOut('fast');
	}
});


/* =========================================
[Search Popup Action] 
==========================================*/
var openSearchPopup = function () {
    $('.search-form').fadeIn('fast');
    $('.search-form input').focus();
};

var closeSearchPopup = function () {
    $('.search-form').fadeOut('fast');
};

$(document).on('click', '[data-search="open"]', function(){
	openSearchPopup();
});

$(document).on('click', '[data-search="close"]', function(){
	closeSearchPopup();
});

/* =========================================
[Personal Profile Upload] Start Here
==========================================*/
$("#PersonalProfile").click(function (e) {
    $("#PersonalUpload").click();
});

function fasterPreviewPersonal(uploader) {
    if (uploader.files && uploader.files[0]) {
        $('#PersonalProfile').attr('src',
            window.URL.createObjectURL(uploader.files[0]));
    }
}

$("#PersonalUpload").change(function () {
    fasterPreviewPersonal(this);
});

/* =========================================
[Company Profile Upload] Start Here
==========================================*/
$("#CompanyProfile").click(function (c) {
    $("#CompanyUpload").click();
});

function fasterPreviewCompany(uploader) {
    if (uploader.files && uploader.files[0]) {
        $('#CompanyProfile').attr('src',
            window.URL.createObjectURL(uploader.files[0]));
    }
}

$("#CompanyUpload").change(function (c) {
    fasterPreviewCompany(this);
});