$(document).ready(function(){
    function addPlaceholderSupport(placeholderColor, normalColor) {
        var placeholderColor = placeholderColor || 'gray';
        var normalColor = normalColor || 'black';

        if (!('placeholder' in document.createElement('input'))) {
            function restorePlaceholderText(elem) {
                if (elem.attr('value') == '') {
                    elem.attr('value', elem.attr('placeholder'))
                        .css('color', placeholderColor);
                }
            }

            function clearPlaceholderText(elem) {
                elem.attr('value', '')
                    .css('color', normalColor);
            }

            restorePlaceholderText($('input[placeholder]'));

            $('input[placeholder]').focus(function(){
                if ($(this).attr('value') == $(this).attr('placeholder')) {
                    clearPlaceholderText($(this));
                }
            });

            $('input[placeholder]').blur(function(){
                if($(this).attr('value') == '') {
                    restorePlaceholderText($(this));
                }
            });
        }
    }

    addPlaceholderSupport('#959592','#000');

    function equalizeHeights(elem1, elem2) {
        while (elem1.height() !== elem2.height()) {
            if (elem1.height() < elem2.height()) {
                elem1.height(elem2.height());
            } else {
                elem2.height(elem1.height());
            }
        }
    }

    if ($('#subnav').length) {
        equalizeHeights($('#subnav'), $('#content'));
    }

    function wrapElement(elem, wrapper) {
        elem.wrap(wrapper);
    }

    function adjustSlideIndicator() {
        if (!$('#slide-indicators img.current').hasClass('last')) {
            $('#slide-indicators img.current')
                .removeClass('current').next().addClass('current');
        }
        else {
            $('#slide-indicators img.current').removeClass('current');
            $('#slide-indicators img').eq(0)
                .addClass('current');
        }
    }

    wrapElement($('.info-box img'), '<div class="image-wrapper"></div>');

    $('#slides').cycle({
        before: adjustSlideIndicator,
        next: '#prev-slide',
        prev: '#next-slide',
        speed: 2100, 
        timeout: 6000
    });
});

