(function ($) {
    
    var TIMER = 500;
    
    $(function() {


        // Kill links to self
        $('a').each(function(i, item) {
            if (item.href == ('' + window.location).replace(/#.*$/, '')) {
                $(item).addClass('current');
            }
        });
        
        // nav links
        $('#nav li').each(function(i, item) {
            //console.log(('' + window.location).replace(/#.*$/, ''), $(item).find('a').attr('href'));
            //console.log(('' + window.location).indexOf($(item).find('a').attr('href')));
            if (
                ('' + window.location).replace(/#.*$/, '') == $(item).find('a')[0].href ||
                ('' + window.location).indexOf($(item).find('a')[0].href) === 0 &&
                $(item).find('a').attr('href') != '/'
            ) {
                $(item).addClass('current');
            }
        });
        
        
        
        /*
        // Add stars to required form fields
        $(function() {
            $('input.required, select.required, textarea.required').parent('li, tr').find('label, th').append("*").addClass('required');
        });
    
    
        // add prompts to form elements
        $('form.titleprompt input, form input.titleprompt').formPrompt();
        
        $('input.datepicker').datepicker({dateFormat: 'yy-mm-dd'});
        
        
        // facilitate zebra striping in uls and tables
        $('ul li:even, table tr:even').addClass('alt');
        
        // fix checkboxes
        $('input[type=checkbox]').addClass('checkbox');
        */
        
        
        // home page
        $('.home h2').each(function(i, item) {
            var me = $(item);
            var toggle = function() {
                var current = me.hasClass('current');
                $('.home .content').slideUp(TIMER);
                $('.home .blurb').slideDown(TIMER);
                $('.home h2').removeClass('current');
    
                if (!current) {
                    me.nextAll('.content').eq(0).slideDown(TIMER, function() {
                        $.scrollTo(me,TIMER);
                    });
                    me.nextAll('.blurb').eq(0).slideUp(TIMER);
                    me.addClass('current');
                    //$.scrollTo(me,TIMER);
                }
    
            };
    
            $(item).addClass('clickable').click(toggle);
    
        });
        
        
        // ul on faq page
        $('.normalise-height').each(function() {
            var height = Math.max($(this).height(), $(this).next('li').height());
            $(this).css({'min-height': height + 'px'});
            $(this).next('li').css({'min-height': height + 'px'});
        });
        
        
        /* banner height - viewport height minus 530px, (min 250px, max 490px) */
        var resizeBanner = function() {
            if ($(window).height() > 800) {
                $('#banner').addClass('large');
            }
            else {
                $('#banner').removeClass('large');
            }
        };
        
        $(window).resize(resizeBanner);
        $(resizeBanner);
        
    });
    

// END
}) ($);
