jQuery.ajaxSetup ({  
	cache: false  
});
var ajax_load = '<img src="/images/loading.gif" alt="Loading..." />';  
var loadUrl = '/ajax.asp';  

jQuery(document).ready(function() {
	// SETUP DIALOG DIVS
	jQuery('#dim').hide();
	jQuery('#dialog').hide();
	jQuery('#slider-stage').carousel('#previous', '#next');
	jQuery('#viewport').carousel('#simplePrevious', '#simpleNext');
	setInterval('jQuery("#simpleNext").click();', 2000);
	jQuery('.zebra TR:odd').addClass('odd');
	jQuery('.zebra TR:even').addClass('even');
	jQuery('.zebra LI:odd').addClass('odd');
	jQuery('.zebra LI:even').addClass('even');
	jQuery('.toggleBtn').click(function(){
		jQuery(this).removeAttr('href');
		if(jQuery('#slideMenu').hasClass('closed')){
			jQuery('#slideMenu').animate({left:0}, 100, function(){
				jQuery(this).removeClass('closed').addClass('opened');
			//	setTimeout('jQuery(".toggleBtn").trigger("click")', 1000);
			});
		}
		jQuery('#toggleLink').one('mousedown',function(){
			jQuery('#slideMenu').animate({left:-200}, 100, function(){
				jQuery(this).removeClass('opened').addClass('closed');
			});
		});
	});
	jQuery('a.anchorLink').click(function () {	
		elementClick = jQuery(this).attr('href');
		destination = jQuery(elementClick).offset().top;
		jQuery('html:not(:animated),body:not(:animated)').animate({ scrollTop: destination}, 1000 );
		return false;
	})
	jQuery('#buttonPhotos').click(function () { // Photos
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
		});
	});
	jQuery('#buttonTalent').click(function () { // Talent Search
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
			revealDialog('talent');
		});
		return false;
	});
	jQuery('#buttonVolunteer').click(function () { // Volunteer Form
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
			revealDialog('volunteer');
		});
		return false;
	});
	jQuery('#buttonVendor').click(function () { // Apply To Be A Vendor
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
			revealDialog('vendor');
		});
		return false;
	});
	jQuery('#buttonMap').click(function () { // Map
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
		});
	});
	jQuery('#buttonContact').click(function () { // Contact
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
			revealDialog('contact');
		});
		return false;
	});
	jQuery('#buttonPrivacy').click(function () { // Schedule
		jQuery('#slideMenu').animate({left:-200}, 500, function(){
			jQuery(this).removeClass('opened').addClass('closed');
			revealDialog('privacy');
		});
		return false;
	});
	jQuery('#dim').css('height', jQuery(document).height());
	jQuery('#dim').click(function() {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').toggle();
		jQuery('#dialog').hide();
	});
	var dialogToShow = unescape(self.document.location.hash.substring(1));
	if (dialogToShow != '') {
		if ((dialogToShow != 'photos') && (dialogToShow != 'map')){
			revealDialog(dialogToShow);
		}
	}
	/* GALLERIFFIC SETUP */
	// We only want these styles applied when javascript is enabled
	$('div.navigation').css({'width' : '190px', 'float' : 'left'});
	$('div.content').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').opacityrollover({
		mouseOutOpacity:   onMouseOutOpacity,
		mouseOverOpacity:  1.0,
		fadeSpeed:         'fast',
		exemptionSelector: '.selected'
	});
	
	// Initialize Advanced Galleriffic Gallery
	var gallery = $('#thumbs').galleriffic({
		delay:                     2500,
		numThumbs:                 10,
		preloadAhead:              0,
		enableTopPager:            true,
		enableBottomPager:         true,
		maxPagesToShow:            7,
		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',
		enableKeyboardNavigation:	false,
		enableHistory:             false,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#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);
		}
	});

});

function revealDialog(element){ // Support function of CLICK event of slideshow buttons
	jQuery('BODY').css('overflow','hidden');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		// VALIDATE FORM THEN AJAX SUBMIT
		var v1 = jQuery('#formContact').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						//$('#dialog').animate({borderWidth:'10px', width:'760px', height:'450px'},400);
						}  
				});
			}
		});
		var v2 = jQuery('#formVendor').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						//$('#dialog').animate({borderWidth:'10px', width:'760px', height:'450px'},400);
						}  
				});
			}
		});
		var v3 = jQuery('#formVolunteer').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						//$('#dialog').animate({borderWidth:'10px', width:'760px', height:'450px'},400);
						}  
				});
			}
		});
		jQuery('INPUT[type="text"]').css('padding','3px');
	});
	jQuery('#close').click(function () {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').hide();
		jQuery('#dialog').hide();
	});
	jQuery('#dialog').css('top', (jQuery(window).scrollTop() + 50) + 'px');
	jQuery('#dim').toggle();
	jQuery('#dialog').toggle();
}

// RESIZE DIM ON WINDOW CHANGE
jQuery(window).bind('resize', function(){
   jQuery('#dim').css('height', jQuery(window).height());
});

