// Common site functions and variables

/**********************************************************************/
//! Variables

// Options passed into modal windows
var modalOptions = {
	'opacity':80,
	'overlayCss':{backgroundColor:'#000'},
	'autoResize':true
}

// Options passed into the lightbox
var lightboxOptions = {
	'overlayOpacity':0.4,

	// Set up image paths, as it doesn't seem to find these outherwise
	'imageBtnClose':'http://jbwebresources.com/js/lightbox/images/lightbox-btn-close.gif',
	'imageBtnPrev':'http://jbwebresources.com/js/lightbox/images/lightbox-btn-prev.gif',
	'imageBtnNext':'http://jbwebresources.com/js/lightbox/images/lightbox-btn-next.gif',
	'imageLoading':'http://jbwebresources.com/js/lightbox/images/lightbox-ico-loading.gif'
};


/**********************************************************************/
//! AJAX modal window

// Set up AJAX
function modal(url, data, width) {
	if (data==null) data={};
	$('#modal').css('width',(width)? width+'px':''); // Set / reset width
	$.post(url, data, modalResponse);
} // End function modal()

// Process response
function modalResponse(data) {
	if (data) {
		// Close existing modal, if any
		$.modal.close();

		// Set up new modal
		$('#modal-content').html(data);
		$('#modal').modal(modalOptions);
	}
} // End function modalResponse()

// Close modal window
function closeModal() {
	$.modal.close();
} // End function closeModal()



/**********************************************************************/
//! Products slider

var sliderFunc = function() {
	// Get selected item
	var curSlide = $('.feature-slider .sel');
	var prev = $(this).hasClass('prev');

	// Which direction (backward or forward)?
	if (prev) {
		// Get the preceding element, or wrap around to the final one if none
		var slide = curSlide.prev('li');
		if (!slide.length) slide = $('.feature-slider li:last-child');
	}
	else {
		// Get the next element, or wrap around to the first one if none, and remove the selected class
		var slide = curSlide.next('li');
		if (!slide.length) slide = $('.feature-slider li:first-child');
	}

	// Disable nav clicking to prevent goofy behavior
	$('.feature-slider .slider-nav a').unbind('click');
	$('.feature-slider .slider-nav a').click(function() { return false; }); // Prevents href from firing

	// Move to the prev/next slide
	slide.addClass('sel').css('left',(prev)? '-100%':'100%').animate({'left':'0'}, 500);
	curSlide.animate({'left':(prev)? '100%':'-100%'}, 500, null, function() {
		$(this).removeClass('sel');

		// Reactivate nav clicking
		$('.feature-slider .slider-nav a').click(sliderFunc);
	});

	return false;
} // End function sliderFunc()


$(function() {
	//Login stuff
	$('.modal_login').click(function() {
	
		modal('/login/get_frame');
			
	});
	
	// FAQ Answer Hide/show
	$('.faq dd').hide();
	$('.faq dt').click(function() {
		$('.faq dd').hide(); // Hide others
 		$(this).next('dd').toggle(); // Show this one
	});
 
});

