// JavaScript Document


$j = jQuery.noConflict();

$j(function() {

    $j('a[rel*="external"], a[rel*="download"]').attr('target', '_blank');
    
    //footer / sharethis
    $j('a[rel*="sharethis"]').each(function() {
        var shareThis =
            SHARETHIS.addEntry({
            title: document.title,
            summary: $j('meta[http-equiv*="description"]').attr('content')},
            {button:false});
        shareThis.attachButton(this);
    });
    
    $j('input[rel*="screenInfo"]').attr("value", screen.width + "x" + screen.height);
    
    $j('.sidebar li h3').hover(function() {
        //mouseover
        if (!$j(this).parent().hasClass('open')) {
            $j(this).css({ textDecoration: 'underline' });
        }
    }, function() {
        //mouseout
        $j(this).css({ textDecoration: 'none' });
    }).click(function() {
        if ($j(this).hasClass('open')) {
            //do nothing, close?
        } else {
            //reset all open, slideup ul's
            $j(this).parent().parent().children().removeClass('open'); //.children('ul').slideUp('fast');
            //set this to open *could be in chain with .end() methods
            $j(this).parent().addClass('open'); //.children('ul').slideDown('fast');
            //slidedown sibling ul

        }
        return false;
    });

    //
    $j(':text').each(function() {
        $j(this).focus(function() {
            $j(this).addClass('focus');
            if ($j(this).val() == $j(this).attr('alt')) {
                $j(this).val('');
            }
        }).blur(function() {
            $j(this).removeClass('focus');
            if ($j(this).val() == '' || $j(this).val() == ' ') {
                $j(this).val($j(this).attr('alt'));
            }
        });
    });

    //site search basic validation
    $j('#site_search').submit(function() {
        return $j('#key_word').val() != $j('#key_word').attr('alt')
    });
    
        //Secretary and Staff -- adjust height of profiles for long content 
    
    var maxProfileHeight = 0;
    $j(".portrait_wrap").each(function() {
        
        if ($j(this).height() > maxProfileHeight) {
            maxProfileHeight = $j(this).height();
        }
    });
    $j(".portrait_wrap").each(function() {
        
        var heightDiff = maxProfileHeight - $j(this).height();
        var caption = $j(this).find(".caption");
        caption.height(caption.height() + heightDiff);
    });
   
   
    //tab navigation
    var tabCount = 0;
    $j('.tab_system').each(function() {
        $j(this).children('.tab_panel').hide().eq(0).show().before('<ul id="tabNav">').end()
        .each(function() {
            var tmpID = $j(this).attr('id');
            $j('<li rel="Panel_' + tmpID + '" id="' + tmpID + '_Tab">').appendTo('#tabNav').text($j(this).children('h2').text())
            .click(function() {
                $j('#tabNav li').removeClass('selected');
                $j('.tab_panel').hide();
                $j(this).addClass('selected');
                $j('#' + ($j(this).attr('rel').split('_')[1])).show();
                return false;
            }).hover(function() {
                $j(this).addClass('hover');
            }, function() {
                $j(this).removeClass('hover');
            });
            tabCount++;
        }).children('h2').hide();
        $j('.tab_system #tabNav li:first').addClass('selected');
    });

        
        $j('#ShowHideButton').click(function() {
            $j('#RegisterForm').toggle();
            $j('#ShowHideButton').toggle();
        }); 
});