jQuery(document).ready(function(){
    imagetour.init();
});

//***********************
// Class imagetour
//***********************
imagetour = {
    indexActive: null,

    init: function() {
        //click event for bullets
        jQuery('.tx-abimagetour-pi1-bullet').click(function() {
            imagetour.imageActive(this);
        });

        //click event for captions
        jQuery('.tx-abimagetour-pi1-captions a').click(function() {
            imagetour.imageActive(this);
        });


        //hover event for bullets
        jQuery('.tx-abimagetour-pi1-bullet').hover(function() {
            imagetour.highlight(this);
        },
        function() {
            imagetour.highlight(this, 'out');
        });

        //hover event for captions
        jQuery('.tx-abimagetour-pi1-captions a').hover(function() {
            imagetour.highlight(this);
        },
        function() {
            imagetour.highlight(this, 'out');
        });
    },


    //display active image
    imageActive: function(obj) {
        this.indexActive = jQuery(obj).index();

        //Display selected image, hide the rest
        jQuery('.tx-abimagetour-pi1-imageset img').hide();
        jQuery('#tx-abimagetour-pi1-image-'+jQuery(obj).index()).show();

        imagetour.highlight(obj);

        jQuery('.tx-abimagetour-pi1-captions a').removeClass('hover');
    },


    // hightligt bullets and captions
    highlight: function(obj, hoverAction) {
        jQuery('.tx-abimagetour-pi1-bullet').removeClass('tx-abimagetour-pi1-bullet-selected');
        if('out' == hoverAction && this.indexActive != jQuery(obj).index()) {
            if(this.indexActive != null) {
                jQuery('#tx-abimagetour-pi1-bullet-'+this.indexActive).addClass('tx-abimagetour-pi1-bullet-selected');
            }
        }
        else {
            jQuery('#tx-abimagetour-pi1-bullet-'+this.indexActive).addClass('tx-abimagetour-pi1-bullet-selected');
            jQuery('#tx-abimagetour-pi1-bullet-'+jQuery(obj).index()).addClass('tx-abimagetour-pi1-bullet-selected');
        }

        jQuery('.tx-abimagetour-pi1-captions a').removeClass('hover');
        jQuery('.tx-abimagetour-pi1-captions a').removeClass('selected');
        if('out' == hoverAction && this.indexActive != jQuery(obj).index()) {
            if(this.indexActive != null) {
                jQuery('#tx-abimagetour-pi1-caption-'+this.indexActive).addClass('selected');
            }
        }
        else {
            jQuery('#tx-abimagetour-pi1-caption-'+this.indexActive).addClass('selected');
            if(hoverAction != '') {
                jQuery('#tx-abimagetour-pi1-caption-'+jQuery(obj).index()).addClass('hover');
            }
            else {
                jQuery('#tx-abimagetour-pi1-caption-'+jQuery(obj).index()).addClass('selected');
            }
        }
    }
};

