﻿
$(function () {

    // Navigation hover effect
    $('#nav li:not("current")').hover(function () {

        $(this).find('span').stop(true, true).fadeOut();

    }, function () { $(this).find('span').stop(true, true).fadeIn(); });


    // Homepage Thumbnails
    $('.thumbnails a').hover(function () {

        $(this).stop(true, true).fadeTo('fast', 1);

    }, function () { $(this).stop(true, true).fadeTo('fast', 0.3); });


    // Narrow column hover effect
    $('.narrowcolumn a').hover(function () {

        $(this).stop(true, true).animate({ paddingLeft: 22 }, 100);

    }, function () { $(this).stop(true, true).animate({ paddingLeft: 8 }); });

    $('.largecolumn').fadeIn('slow');
    $('.slide').fadeIn('slow');

    // Social networking links

    var currentAddress = document.location

    $('#facebook a').attr('href', 'http://www.facebook.com/share.php?u=' + currentAddress);
    $('#digg a').attr('href', 'http://digg.com/submit?phrase=2&url=' + currentAddress);
    $('#twit a').attr('href', 'http://twitter.com/home?status=Currently reading: ' + currentAddress);
    $('#delicious a').attr('href', 'http://del.icio.us/post?url=' + currentAddress);

    // Stripy tables

    $('tr:odd').css({ backgroundColor: '#282828' });
    $('tr:even').css({ backgroundColor: '#333333' });

    // rotating commerce messages

    function shouldDisplay() {

        if ($('.commercemsg').size() > 0) { return true; }
        else { return false; }
    }

    function displayMsgs() {


        $('.commercemsg p').fadeOut('fast', function () {

            // Ajax request to XML

            $.ajax({

                type: "GET",
                url: "_assets/xml/commercemsg.xml",
                dataType: "xml",
                success: function (xml) {

                    var msgNums = $(xml).find('message').size();
                    var randMsgNum = Math.round(Math.random() * msgNums - 1);

                    $('.commercemsg p').text($(xml).find('message').eq(randMsgNum).text());
                    $('.commercemsg p').fadeIn('slow');

                } // end of sucess

            }); // end of ajax


        }); // end of fadeout call back


    }

    if (shouldDisplay()) {

        displayMsgs();

        var t = setInterval(function () {
            displayMsgs();
        }, 7000);
    }


    //Skype functionality
    $('#footer').find('#social').after('<div id="skype"><script type="text/javascript" src="http://download.skype.com/share/skypebuttons/js/skypeCheck.js"></script><a href="skype:splashoflondon?call"><img src="http://mystatus.skype.com/smallclassic/splashoflondon" style="border: none;" width="114" height="20" alt="My status" /></a></div>');

});

