/* Declare a namespace for the site */
var SITE = window.SITE || {};

/* Create a closure to maintain scope of the '$'
   and remain compatible with other frameworks.  */
(function($) {
	
    /**
     * Public: Stop users from trying to save images.
     */
    SITE.disableImageStealing = function () {
        // Disable image dragging.
        $('img').mousedown(function (e) {
            e.preventDefault(); // prevents the default action which is the drag and drop.
        });

        $('img').bind("contextmenu", function (e) {
            alert('Copyright 2010 Mirara Development Ltd.');
            return false;
        });
    }

    /**
     * Public: Is this page a Gallery page?
     * Checks the markup of the page for a '#thumbs' container. If it is found,
     * we want to create a Gallery on this page.
     */
    SITE.isGalleryPage = function () {
        return ($('#nav-thumbs').length > 0);
    }

    /**
     * Public: Checks if there are images to rotate on the home page. 
     */
    SITE.hasImagesOnHomePage = function () {
        return ($('#home-leadimage img').length > 0);
    }

    SITE.rotateImagesOnHomePage = function () {
        $('#home-leadimage').cycle();
    }

    /**
     * Public: Create a gallery using the jQuery Gallerific plugin. 
     */
    SITE.createGallery = function () {
        // Initially set opacity on thumbs and add
        // additional styling for hover effect on thumbs
        var onMouseOutOpacity = 0.67;
        $('#nav-thumbs ul.thumbs li').opacityrollover({
            mouseOutOpacity:   onMouseOutOpacity,
            mouseOverOpacity:  1.0,
            fadeSpeed:         'fast',
            exemptionSelector: '.selected'
        });

        // Initialize Advanced Galleriffic Gallery
        var gallery = $('#nav-thumbs').galleriffic({
            delay: 2500,
            numThumbs: 12,
            preloadAhead: 10,
            enableTopPager: true,
            enableBottomPager: true,
            maxPagesToShow: 3,
            imageContainerSel: '#slideshow',
            controlsContainerSel: '#controls',
            captionContainerSel: '#caption',
            loadingContainerSel: '#loading',
            renderSSControls: true,
            renderNavControls: true,
            playLinkText: 'Play Slideshow',
            pauseLinkText: 'Pause Slideshow',
            prevLinkText: '&lsaquo; Previous Photo',
            nextLinkText: 'Next Photo &rsaquo;',
            nextPageLinkText: 'Next &rsaquo;',
            prevPageLinkText: '&lsaquo; Prev',
            enableHistory: false,
            autoStart: false,
            syncTransitions: true,
            defaultTransitionDuration: 900,
            onSlideChange: function(prevIndex, nextIndex) {
                // 'this' refers to the gallery, which is an extension of $('#nav-thumbs')
                this.find('ul.thumbs').children()
                    .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                    .eq(nextIndex).fadeTo('fast', 1.0);
            },
            onPageTransitionOut: function(callback) {
                this.fadeTo('fast', 0.0, callback);
            },
            onPageTransitionIn: function() {
                this.fadeTo('fast', 1.0);
            }
        });
    };

	//same as $(document).ready();
	$(function() {

        SITE.disableImageStealing();

        if (SITE.isGalleryPage()) {
            SITE.createGallery();
        }

        if (SITE.hasImagesOnHomePage()) {
            SITE.rotateImagesOnHomePage();
        }

		
	});


	$(window).bind("load", function() {
		
		
	
	});
	
})(jQuery);

