/**
 * functions.js
 *
 * jQuery functions file for Cohda Design Limited website.
 *
 * @author Martin Bean <martin@mcbwebdesign.co.uk>
 */

jQuery(document).ready(function($) {
    // $('a').externalLinks();
    $('a[rel="external"]').click(function() {
        window.open(this.href);
        return false;
    });
    $('a[rel*=popup]').facebox({
        opacity: 0.5,
        loadingImage: '/v2/tpl/cohda/images/facebox/loading.gif',
        closeImage: '/v2/tpl/cohda/images/facebox/closelabel.gif'
    });
    $('#images ul li a').imageGallery();
    $('#latest_tweet').tweet({
        loading_text: 'Loading&hellip;',
        username: 'cohda',
        count: 1,
        template: function(item) {
            return '<strong>Cohda&#39;s Latest News:</strong> ' + item.text;
        }
    });
});

/**
 * Finds external links and listens for clicks.
 */
jQuery.fn.externalLinks = function() {
    return this.each(function() {
        if (this.host != window.location.host) {
            $(this).addClass('external');
            $(this).click(function() {
                window.open(this.href);
                return false;
            });
        }
    });
};

jQuery.fn.imageGallery = function() {
    return this.each(function() {
        $(this).click(function() {
            $('li.selected').removeClass('selected');
            $('#main_image img').attr('src', $(this).attr('href'));
            $(this).parent().addClass('selected');
            return false;
        });
    });
};
