/*global $topValue,$,window,$popContact,$contactButton,jQuery */

var $topValue, $popContact, $contactButton;

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

    // Instantiate Tabs

    $('#tabs').tabs({
        fx  : {
            'opacity'   :   'toggle',
            'duration'  :   500
        }
    });

    $popContact = $('#popContact');
    $contactButton = $('#contactButton');
    $topValue = $popContact.outerHeight();

    // Pop Contact

    var $topPos = 0;
    $popContact.css('top', -$topValue);
    $contactButton.hover(
        function () {
            if ($topPos === 0) {
                setTimeout(function () {
                    $popContact.animate({
                        top: '+=10px'
                    }, 200, function () {
                        $popContact.css('top', '-' + ($topValue - 10) + 'px');
                    });
                }, 40);
            }
        },
        function () {
            if ($topPos === 0) {
                setTimeout(function () {
                    $popContact.animate({
                        top: '-=10px'
                    }, 200, function () {
                        $popContact.css('top', '-' + $topValue + 'px');
                    });
                }, 40);
            }
        }
        );
    $contactButton.click(function () {
        $topValue = $popContact.outerHeight();
        if ($topPos === 0) {
            $popContact.animate({
                top: '+=' + ($topValue - 10) + 'px'
            }, 1000, 'easeInOutExpo');
            $topPos = 1;
        } else {
            $popContact.animate({
                top: '-=' + ($topValue - 10) + 'px'
            }, 1000, 'easeInOutExpo');
            $topPos = 0;
        }
    });
    $('.closeButton', $popContact).click(function () {
        $topValue = $popContact.outerHeight();
        if ($topPos === 1) {
            $popContact.animate({
                top: '-=' + $topValue + 'px'
            }, 1000, 'easeInOutExpo');
        }
        $topPos = 0;
    });

    ////////////////////////////
    // Pretty Checkbox Script //
    ////////////////////////////

    var pageCheckboxes = $('input[type="checkbox"]');

    $(pageCheckboxes).hide();
    $(pageCheckboxes).each(function () {
        $(this).before('<span class="prettyCheck"></span>');
        // Look for already checked values
        if ($(this).is(':checked')) {
            $(this).prev().addClass('activeCheck');
        }
    });

    $('.prettyCheck').click(function () {
        $(this).toggleClass('activeCheck');
        var inputCheck = $(this).next();
        if (inputCheck.is(':checked')) {
            inputCheck.attr('checked', false);
        } else {
            inputCheck.attr('checked', true);
        }
    });

    $(window).load(function () {
        $popContact.fadeIn(1300);
    });

});
