//Var
var sliderTime;

//JQUERY PRIMARY SCRIPTS
//****************************************************
$(document).ready(function () {

    //Scroll Menu
    $(window).scroll(function () {
        var currentPos = $(window).scrollTop();

        if (currentPos > 75) {
            $('.menuFull').css('position', 'fixed');
            $('.menuFull').css('top', '0px');
            $('.menuFull').css('borderBottom', '1px solid #c6c6c6');
            $('.headerLogo_sm').fadeIn(800);
        } else {
            $('.menuFull').css('position', 'static');
            $('.menuFull').css('borderBottom', 'none');
            $('.headerLogo_sm').fadeOut(800);
        }
    });

    //Drop Down Menu
    $(".menu_drop").hover(
        function () {
            $(this).children("ul").css("display", "block");
        },
        function () {
            $(this).children("ul").css("display", "none");
        }
    );

    //Arrow Link
    $(".arrowLink").hover(
        function () {
            $(this).animate({ backgroundPosition:'90px 2px'}, 200,
                function () {
                    $(this).animate({ backgroundPosition:'87px 2px'}, 100,
                        function () {
                            $(this).animate({ backgroundPosition:'89px 2px'}, 100,
                                function () {
                                    $(this).animate({ backgroundPosition:'88px 2px'}, 100)
                                }
                            )
                        }
                    )
                }
            )
        },
        function () {
            $(this).stop().animate({ backgroundPosition:'85px 2px'}, 200)
        }
    );

    //Register Button
    $(".arrowRegister").hover(
        function () {
            $(this).animate({ backgroundPosition:'0px 0px'}, 200,
                function () {
                    $(this).animate({ backgroundPosition:'-3px 0px'}, 100,
                        function () {
                            $(this).animate({ backgroundPosition:'-1px 0px'}, 100,
                                function () {
                                    $(this).animate({ backgroundPosition:'-2px 0px'}, 100)
                                }
                            )
                        }
                    )
                }
            )
        },
        function () {
            $(this).stop().animate({ backgroundPosition:'-6px 0px'}, 200)
        }
    );

    //SLIDER SCRIPTS
    //****************************************************

    //Slider Nav
    var sliderButtons = $('.slider_nav a').size();
    var sliderNav_size = 1000 - (147 * sliderButtons); //Total Size - (Each Button with Margin * Total Buttons)

    $('.filler').css('width', sliderNav_size + 'px');

    $('.slider_nav a').hover(
        function () {
            sliderNav('up', $(this));
        },
        function () {
            if ($(this).hasClass('active')) null;
            else sliderNav('down', $(this));
        }
    );

    //Start
    sliderGo(0);

    $('.slide').hover(
        function () {
            clearTimeout(sliderTime);
        }, function () {
            //Get Active
            var slideActive = $('.slider_nav li').children('.active').attr('id');
            slideActive = parseInt(slideActive.replace('slideBtn_', '')) - 1;

            sliderGo(slideActive);
        }
    );

    $('.slider_nav a').click(function () {

        clearTimeout(sliderTime);

        //This Id
        var slideGo = $(this).attr('id');
        slideGo = parseInt(slideGo.replace('slideBtn_', ''));
        slideGo_pass = slideGo - 1;

        //Deactivate
        var slideActive = $('.slider_nav li').children('.active').attr('id');
        slideActive = parseInt(slideActive.replace('slideBtn_', ''));

        //Switch
        $('#slide_' + slideGo).fadeIn(300, function () {
            $('#slide_' + slideActive).fadeOut(300);
        });

        sliderNav('active', $(this));
        sliderNav('deactive', $('.slider_nav li').children('.active'));

        sliderGo(slideGo_pass);
    });

});


//Slider Functions
//****************************************************
function sliderNav(action, obj) {
    if (action == 'up') obj.animate({ marginTop:'0px', paddingTop:'7px', height:'23px' }, 100);
    else if (action == 'down') obj.animate({ marginTop:'5px', paddingTop:'5px', height:'20px' }, 100);
    else if (action == 'active') obj.animate({ marginTop:'0px', paddingTop:'7px', height:'23px' }, 100, function () {
        obj.addClass('active');
    });
    else if (action == 'deactive') obj.animate({ marginTop:'5px', paddingTop:'5px', height:'20px' }, 100, function () {
        obj.removeClass('active');
    });
}

function sliderGo(currentSlide) {
    //Total
    var slideTotal = $('.slider_nav a').size();

    //Next Slide
    var slideNext = currentSlide + 1;

    if (slideNext > slideTotal) slideNext = 1;

    //Go
    $('#slide_' + slideNext).fadeIn(300, function () {
        $('#slide_' + currentSlide).fadeOut(300);
    });

    //Buttons
    sliderNav('active', $('#slideBtn_' + slideNext));
    sliderNav('deactive', $('#slideBtn_' + currentSlide));

    //Timer
    sliderTime = setTimeout(function () {
        sliderGo(slideNext);
    }, 9000);
}


//NIVO SLDIER
//****************************************************
$(window).load(function () {
    $('#slider').nivoSlider({
        effect:'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices:30, // For slice animations
        boxCols:8, // For box animations
        boxRows:4, // For box animations
        animSpeed:500, // Slide transition speed
        pauseTime:8000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:true, // 1,2,3... navigation
        controlNavThumbs:false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, // Use image rel for thumbs
        keyboardNav:false, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
        manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity

    });
});


$(function () {
    $('#gallery a').lightBox();
});


//CONFERENCE REGISTRATION
function regPrimary(state) {
    $('#regHowmany').slideDown(200);
    regAttendee();
}

function regEvent(id) {
    if ($('#' + id).length != 0) {
        //Current State
        if ($('#' + id).css('display') == 'block') $('#' + id).slideUp(100);
        else if ($('#' + id).css('display') == 'none') $('#' + id).slideDown(100);
    }
}

function regAttendee() {
    //Is Primary Attending
    var attendingPrimary = $('input:radio[name=primary_attending]:checked').val();

    //Total Count
    var attendingTotal = $('#attendee_num').val();

    //Attending or Not
    if (attendingPrimary == 'yes') {
        $('#firstname_1').val($('#primary_firstname').html());
        $('#lastname_1').val($('#primary_lastname').html());
        $('#position_1').val($('#primary_position').html());
        $('#company_1').val($('#primary_company').html());
        $('#email_1').val($('#primary_email').html());
    } else {
        $('#firstname_1').val('');
        $('#lastname_1').val('');
        $('#position_1').val('');
        $('#company_1').val('');
        $('#email_1').val('');
    }

    //Hide All
    for (i = 1; i <= 5; i++) {
        $('#secondary_attendee_' + i).css('display', 'none');
    }

    //Show Form
    for (i = 1; i <= attendingTotal; i++) {
        $('#secondary_attendee_' + i).slideDown(300);
    }

}


