jQuery(document).ready(function($) {
	if ($('#slider1').length > 0) {
        $('#slider1').s3Slider({
            timeOut: 10000 
        });
	}
    
    $('.entry').jScrollPane({reinitialiseOnImageLoad : true});

    // GALLERY
	// We only want these styles applied when javascript is enabled 
    $('div.navigation').css({'width' : '100px', 'float' : 'left'});
    $('div.gcontent').css('display', 'block');
    // Initially set opacity on thumbs and add
    // additional styling for hover effect on thumbs
    var onMouseOutOpacity = 0.67;
    $('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
        .hover(
            function () {
                $(this).not('.selected').fadeTo('fast', 1.0);
            }, 
            function () {
                $(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
            }
        );

        // Initialize Advanced Galleriffic Gallery
        var galleryAdv = $('#gallery').galleriffic('#thumbs', {
            delay:                  2000,
            numThumbs:              12,
            preloadAhead:           10,
            enableTopPager:         true,
            enableBottomPager:      true,
            imageContainerSel:      '#slideshow',
            controlsContainerSel:   '#controls',
            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:          true,
            autoStart:              false,
            onChange:               function(prevIndex, nextIndex) {
                $('#thumbs ul.thumbs').children()
                    .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                    .eq(nextIndex).fadeTo('fast', 1.0);
            },
            onTransitionOut:        function(callback) {
                $('#slideshow').fadeTo('fast', 0.0, callback);
            },
            onTransitionIn:         function() {
                $('#slideshow').fadeTo('fast', 1.0);
            },
            onPageTransitionOut:    function(callback) {
                $('#thumbs ul.thumbs').fadeTo('fast', 0.0, callback);
            },
            onPageTransitionIn:     function() {
                $('#thumbs ul.thumbs').fadeTo('fast', 1.0);
            }
        });

		//END GALLERY

		// ** BEGIN - Custom Pop Up for Reservations Page **
		
		// determine if it is the Reservations page, install click handlers 
		if ( $('#do_custom_pop_up').length != 0 ) {
			
			// set boolean
			IS_DO_POP_UP = true;
			
			if ( $('.wpcf7-mail-sent-ok').length != 0 ) {
				IS_DO_POP_UP = false;
			}
			
			// set email link to disable pop up
			$("a[href^=mailto:]").click( function(e) {
  			// alert(e.target.href);
				IS_DO_POP_UP = false;
			});
			
			// set form submit button to disable pop up
			$("input[type=submit][value=Send]").click( function(e) {
				// nada at moment
				// alert("submit button pressed");
				IS_DO_POP_UP = false;
			});
			
			// When attempting to navigate from page ...
			window.onunload = function() {
				if (IS_DO_POP_UP) {
					// display contact form 
					IS_DO_POP_UP = false;
					// alert("pop up trigger here!");
					window.open("http://casadelasirena.net/?page_id=582", "popup", "status=0,toolbar=0,location=0,scrollbars=0,menubar=0,resizable=0,height=500,width=630");
				}
			}

		}
		
		// ** END Custom Pop up for reservations page
		
		// GIVEAWAY PROMO BUTTON
		if ( $('#giveaway_promo_button').length != 0 ) {
			$('#giveaway_promo_button').click( function (e) {
					window.open("http://casadelasirena.net/?page_id=582", "popup", "status=0,toolbar=0,location=0,scrollbars=0,menubar=0,resizable=0,height=500,width=630");
					return false;
				});
		}
		
		// Top menu option opens pop-up window
		$('a[class=enter-contest-link]').click( function(e) {
				window.open("http://casadelasirena.net/?page_id=582", "popup", "status=0,toolbar=0,location=0,scrollbars=0,menubar=0,resizable=0,height=500,width=630");
				IS_DO_POP_UP = false;
				return false;
		});		
		
});