jQuery(document).ready(function() {

    /* on page load - show first colour */
    if (jQuery('ul.colours')) {
        if (jQuery('#coordinating-styles')) {
            var currentColour = jQuery('ul.colours li:eq(0) a').attr('colourid');
            changeRelatedColours();

            // change all error messages
            jQuery('#coordinating-styles .right-col-item div.no-styles-available').html('<p>There are no co-ordinating colours available for this colour.</p>');
        }
    }

    /* rotate the images on the homepage */
    if (jQuery("#home-hero").imgRotate) {
        jQuery("#home-hero").imgRotate({ rotateImgSpeed: 8000 });
    }

    /* swatch swapper */
    jQuery('.change-swatch').click(function(e) {
        e.preventDefault();

        // make sure the url we're using is not blank AND not the base url
        if (this.href != '' &&
            this.href != jQuery('base').attr('href')) {

            // swap images
            jQuery('#main-image img:eq(0)').attr('src', this.href);
            //jQuery('#main-image').attr('href', this.rel);
            jQuery('#main-image img:eq(0)').attr('height', '600');

            /* change the colour */
            currentColour = jQuery(this).attr('colourid');
            changeRelatedColours();
        }
    });

    /* change the related colours */
    function changeRelatedColours() {
        if (jQuery('ul.colours')) {
            // make sure we have coordinating styles to play with
            if (jQuery('#coordinating-styles')) {
                // hide all of em
                jQuery('#coordinating-styles .right-col-item div.image-text').hide();
                // now check if we have any to show
                if (jQuery('#coordinating-styles .right-col-item div[colourid=' + currentColour + ']').length > 0) {
                    // if we have coordinating items, show them
                    jQuery('#coordinating-styles .right-col-item div[colourid=' + currentColour + ']').show();
                    jQuery('#coordinating-styles .right-col-item p.styles-available').show();
                    jQuery('#coordinating-styles .right-col-item div.no-styles-available').hide();
                }
                else {
                    // if we don't have any, show error
                    jQuery('#coordinating-styles .right-col-item p.styles-available').hide();
                    jQuery('#coordinating-styles .right-col-item div.no-styles-available').show();
                }
            }
        }
    }

});	