/*
	Avoid conflict with Prototype by putting all
	code inside DOM ready area
*/ 

jQuery.noConflict();
jQuery(function($) { // Execute when DOM is ready

// Settings
// --------------------------------------------------------

// Overlay Expose (dimmed background effect)
$.tools.overlay.conf.expose = { 
	color: '#222', 
	loadSpeed: 200, 
	opacity: 0.6
};

// Scrollable
$.extend($.tools.scrollable.conf, {
	vertical: true,
	circular: true,
	speed: 600
});
$.tools.scrollable.autoscroll.conf.interval = 12000;

// DOM ready
// --------------------------------------------------------

// First text element
$('h4:first-child').addClass('first')

// Last text element
$('p:last-child, .box > :last-child').addClass('last')

// Textarea expand
$('.contact textarea').prettyComments({maxHeight: 350});

// Login column height
$('.login #body .column').equalizeHeight();

// Banner scroll
bannerScroll();

// Quote scroll
quoteScroll();

// Video Overlay
$('a[rel^="#video"]').overlay({fixed: false});

// Contact thank you
contactThank();


// Functions
// --------------------------------------------------------

// Banner scroll
function bannerScroll() {
	// Does element exist? If not, exit.
	if (!$('.home .scrollable').length) { return; }
	
	// Banner scrollable initialize
	var $banner = $(".scrollable")
		.scrollable()
		.autoscroll()
		.navigator();

	// Provide scrollable API for the action buttons
	window.api = $banner.data("scrollable");

	// Controller initialize
	$('.play').click(api.play);
	$('.stop').click(api.stop);

	// Hide controls
	$banner.hover(
		function() {
			$('.controller', this).fadeTo(200, 1);
		},
		function() {
			$('.controller', this).fadeTo(800, 0.6);
		}
	).mouseleave();
}

// Quote scroll
function quoteScroll() {
	// Does element exist? If not, exit.
	if (!$('.about .scrollable').length) { return; }
	
	// Banner scrollable initialize
	var $banner = $(".scrollable")
		.scrollable({speed: 1500})
		.autoscroll({interval: 9000, autopause: false});
}

// Make big clickable areas
function bigClicks() {
	$('body.products.category .column .head').hover(
		function() {
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	)
	.click(function() {
        goTo = $(this).find('a:first').attr('href');
        if (goTo != undefined) window.location = goTo;        
    });	
}

// Contact thank you
function contactThank() {
	// Are we on contact page? If not, exit.
	if (!$('.contact').length) { return; }
	
	if (location.hash == '#thankyou') {
		$('form').hide();
		$('.message').show();
	}
}

}); // End jQuery DOM execute

/*
	This has to stay outside DOM ready area
*/

// Height equalizer
(function($){
	$.fn.equalizeHeight = function() {
		var max = 0;
		this.each(function(){
			// remove any previously set heights
			$(this).css('height', 'auto');
			// compare heights
			if ($(this).height() > max)
				max = $(this).height();    
		});
		return this.height(max);	
	}
})(jQuery);
