$(document).ready(function() {
	//$('img').hide(1000);
	$('.trans').css('opacity', '0.90');
//_________ sets trans level _________\\
	$('#main_nav li:first-child a.primary').css('padding-left', 0);
	$('#main_nav li:last-child a.primary').css('padding-right', 0);
//_________ end main nav padding _________\\
	$("#main_nav li").hoverIntent(config);
//________ end sub nav hover _________\\
	$('#join_btn').click(function(){
		$('#join').animate({
		    opacity: 'toggle'
		  }, 600, function(){
			
		});
		return false;
	});
//_________ /join for slider _________\\
	
	var formOptions = { 
        //target:        '#output1',   // target element(s) to be updated with server response 
        //beforeSubmit:  validate,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };
	$('#join_form').ajaxForm(formOptions);
//_________ / form submit calback _________\\

/*
	$('#features').cycle({ 
	    fx:    'fade', 
		containerResize: 0,
		slideExpr: 'div.feature',
	    delay: 6000 
	});
*/
//_________ end home feature cycle _________\\

	$('#features').cjFlashySlideShow({
		preset: 'transport',
		delay: 50000 // does not seem to work, still defaults to 3000
	});
//_________ end home feature flashy transition _________\\

	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'facebook',
		deeplinking: false
	});
//_________ /prettyPhoto _________\\
	Cufon.replace('h1, h2, h3, h4, h5, label, a.event-name, #event-download, div.venue-name, a.venue-widget-header, .property-widget-header, a.event-name, a.venue-link, div.venue-blurb, div.property-hours, span.event-date', { hover: true });
	Cufon.replace('#main_nav a, a.media-link', { hover: true });
//_________ /cufon _________\\

	$('#property-slideshow').cjFlashySlideShow({
		preset: 'transport'
	});
//_________ end properties slideshow _________\\

	$('#property_list #event_widgets div.widget-header-right, #property_list #event_widgets a.venue-widget-header').hover(
		function(){
			$(this).css('cursor','pointer');
			$(this).parent().find('.venue-widget-header').css('background','url(/accelsite/themes/temp999/images/widget-header-on.png) no-repeat left center');
			$(this).parent().find('.venue-widget-header').css('color','#fff');
		},
		function(){
			$(this).parent().find('.venue-widget-header').css('background','url(/accelsite/themes/temp999/images/widget-header-off.png) no-repeat left center');
			$(this).parent().find('.venue-widget-header').css('color','#666');
		}
	);
//_________ end highlight property headers _________\\

	$('a#venue-hours').bind('click',function(e){
		e.preventDefault();
		var blurb = $(this).parents('.venue-box').find('.venue-blurb');
		var hours = $(this).parents('.venue-box').find('.property-hours');
		if ( $(blurb).is(':visible') ) {
			blurb.hide();
			hours.fadeIn();
			$(this).hide();
			$(this).html('DESCRIPTION');
			Cufon.refresh();
			$(this).fadeIn();
		} else {
			hours.hide();
			blurb.fadeIn();
			$(this).hide();
			$(this).html('HOURS');
			Cufon.refresh();
			$(this).fadeIn();
		}
	});
//_________ end property hours/description toggling _________\\

	$('a.property-widget-header').bind("click",function(e) {
		e.preventDefault();
	});
//_________ end disable property header anchors for properties that are not venues _________\\
	// setting the tabs in the sidebar hide and show, setting the current tab
	
		//$('div.tabbed div').hide();// in css
		$('#galleries').show().addClass('active');
		$('#media_tabs a#photos').addClass('tab-current');

		// SIDEBAR TABS
		$('#media_tabs a').click(function(){
			var tabID = $(this).attr('href');
			//$('.videoPlayer-1').pauseVideo();
			$('div.media-tab').hide().removeClass('active');
			$('div#' + tabID).show().addClass('active');
			$('#media_tabs a').removeClass('tab-current');
			$(this).addClass('tab-current');
			return false;
		});
//_________ media tabs _________\\

	image1 = $('#galleries div.gallery-1 a.image-1 img');
	image1Height = image1.height();
	gallery1Height = $('#galleries .gallery.gallery-1').height();
	if ( image1Height > gallery1Height) {
		image1YOffset = (image1Height - gallery1Height)/2;
	} else {
		image1YOffset = 0;
	}
	image1.css('margin-top','-'+image1YOffset+'px')
//_________ end photo gallery - main image offset _________\\
	

	$('a.product-link').click(function(){
		$(this).parent().next('div.product-info').slideToggle(400);
		return false;
	});
	$('a.product-closer').click(function(){
		$(this).parent('div.product-info').slideToggle(400);
		return false;
	});
	
	$("li.tab a").click(function () {
		
		if($(this).hasClass('active')){
			return false;
		}
		// switch all tabs off
		$(".active").removeClass("active");

		// switch this tab on
		$(this).addClass("active");

		// slide all content up
		$(".file").slideUp();

		// slide this content up
		var content_show = $(this).attr("rel");
		$("div.file."+content_show).slideDown();
		
		return false;
	});
//_________ /tabs _________\\
});
//_________ end doc ready _________\\

var config = {
	sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
	interval: 30, // number = milliseconds for onMouseOver polling interval
	over: hoverOn, // function = onMouseOver callback (REQUIRED)
	timeout: 250, // number = milliseconds delay before onMouseOut
	out: hoverOff // function = onMouseOut callback (REQUIRED)
};
function hoverOn(){
	$(this).find('ul').slideDown(300);
}
function hoverOff(){
	$(this).find('ul').slideUp(300);
}

//_________ end main nav hover _________\\
function validate(formData, jqForm, options) { 
	// fieldValue is a Form Plugin method that can be invoked to find the 
    // current value of a field 
    // 
    // To validate, we can capture the values of both the username and password 
    // fields and return true only if both evaluate to true 

    var emailValue = $('input[name=cc_email]').fieldValue(); 

    // usernameValue and passwordValue are arrays but we can do simple 
    // "not" tests to see if the arrays are empty 
    if (!emailValue[0]) { 
        alert('Please enter a valid email address'); 
        return false;
   	}
	else{
		//$(div#join).html("<div id='join_thanks'>Thanks for Signing Up!</div>");
	}
    
}
function showResponse(responseText, statusText, xhr, $form)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 	if(responseText == 'success') {
 		$('div#join').html("<div id='join_thanks'>Thanks for Signing Up!</div>");
 		return false;
 	}
 	else {
 		alert(responseText);
 		return false;
 	}
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
} 

function downloadTab(dlFile){
	tab = $('.tab.item-'+dlFile + ' a');
	file  = $('div.file.item-'+dlFile);
	
	// switch all tabs off
	$(".active").removeClass("active");

	// switch this tab on
	tab.addClass("active");
	//alert(dlFile + ':' + tab.attr('class'));
	
	// slide all content up
	$(".file").slideUp();
	
	// slide this content up
	file.slideDown();
	
	return false;
}
