﻿$(document).ready(function() {


    /* IMG Rollover */

    $('div.link').mouseover(function() {
        $(this).find('div.icon').css('background-position', 'right');
        $(this).find('.alter').css('color', '#68b11b;');
    });

    $('div.link').mouseout(function() {
        $(this).find('div.icon').css('background-position', 'left');
        $(this).find('.alter').css('color', '#000;');
    });


    /* Archive Section */

    $('#tab4 table tr').hide();
    $('#tab4 table tr.row-empty').show();

    

    $('#topic-archive').change(function() {
        var topic = $('#topic-archive').fieldValue();
        $('#tab4 table tr').hide();
        $('#tab4 table tr.row-header').show();
        $('#tab4 table tr.row-' + topic).show();
        $('#tab4 table tr').each(function() {
            var dldate = $(this).find('.date').text();
            $(this).find('.download a').attr('href', 'pdf/' + dldate + '.' + topic + '.pdf').attr('target','blank');
        });
    });

    $('select#topic-archive option:not(.selecttopic)').each(function() {
        var topicquant = $(this).val();
        var quantity = $('#tab4 table tr.row-' + topicquant).length;
        $(this).append(' (' + quantity + ')');
    });

    /* Calendar Sorting */

    $('#tab2 table tr').hide();
    $('#tab2 table tr.row-empty').show();
    $('#topic-calendar').change(function() {
        var topic = $('#topic-calendar').fieldValue();
        $('#tab2 table tr').hide();
        $('#tab2 table tr.row-header').show();
        $('#tab2 table tr.row-' + topic).show();
    });


    $("#tab2 table tr").each(function(i) {
        var issuedate = $(this).find('.issuedate').text();
        var topicname = $(this).find('.topic').text();
        $(this).find('.download span').html('<a href="mailto:nature@collegehill.com?subject=Article Submission - ' + topicname + ' - ' + issuedate + '">Submit Article &raquo;</a>');
    });




    /* Tab Sliding System */

    $('.tab .tabcontents').hide();

    $('div#0').click(function() {
        $('#tab1, #tab2, #tab3, #tab4').animate({ width: '0px' });
        $('.tab .tabcontents').hide();
    });

    $('div#1').click(function() {
        $('#tab2, #tab3, #tab4').animate({ width: '0px' });
        $('#tab2 .tabcontents,#tab3 .tabcontents,#tab4 .tabcontents').hide();
        $('#tab1').animate({ width: '615px' }, 500, function() {
            $('#tab1 .tabcontents').fadeIn('fast');
        });
    });

    $('div#2, .homepage').click(function() {
        $('#tab1, #tab3, #tab4').animate({ width: '0px' });
        $('#tab1 .tabcontents,#tab3 .tabcontents,#tab4 .tabcontents').hide();
        $('#tab2').animate({ width: '615px' }, 500, function() {
            $('#tab2 .tabcontents').fadeIn('fast');
        });
    });

    $('div#3').click(function() {
        $('#tab1, #tab2, #tab4').animate({ width: '0px' });
        $('#tab1 .tabcontents,#tab2 .tabcontents,#tab4 .tabcontents').hide();
        $('#tab3').animate({ width: '615px' }, 500, function() {
            $('#tab3 .tabcontents').fadeIn('fast');
        });
    });

    $('div#4').click(function() {
        $('#tab1,#tab2,#tab3').animate({ width: '0px' });
        $('#tab1 .tabcontents,#tab2 .tabcontents,#tab3 .tabcontents').hide();
        $('#tab4').animate({ width: '615px' }, 500, function() {
            $('#tab4 .tabcontents').fadeIn('fast');
        });
    });

});