// micro plugin that disables text selection on elements
$.fn.disableSelection = function() {
	$(this).attr('unselectable', 'on')
		.css('-moz-user-select', 'none')
		.each(function() {
			this.onselectstart = function() { return false; };
		});
};

var windowReSize = function() {
	// must reposition the background when the window size changes
	var screenWidth = $(window).width();
	
	var offset = ( ( (screenWidth / 2) - (1950 / 2) )  );
	$('#carousel-container').css( { 'left': (offset + 'px') });
}

$(function() {
	$('.drop-down').hoverIntent(
		function() { // in
			$(this).addClass('hover');
		},
		function() { // out
			$(this).removeClass('hover');
		}
	);
	
	$(window).resize(function() {
		windowReSize();
	});
	windowReSize();
	
	$('.service-info table .col').mouseenter(function( e ) {
		var self = $(this);
		var col = self.data('col');
		if( col !== undefined ) {
			$( self.parents('table')[0] ).find('.col').removeClass('on');
			$( '.' + col ).addClass('on');
		}
	});
	
	// highlight the current item
	var body = $('body');
	if( body.data('page') !== undefined ) {
		$( '.page-item-' + body.data('page') ).addClass('active');
	}
	
	$('.sub-row .sr-title').click(function() {
		var self = $(this).parent();
		if( self.hasClass('active') )
			self.removeClass('active');
		else
			self.addClass('active');
	});
	$('.sub-row').each(function() {
		var $this = $(this);
		var count = $this.find('> .sr-content > .question');
		$this.children('.sr-title').append('<div class="count">(' + count.size() + ' entries)</div>');
	});

	// faq page hash detection and auto-open
	if( location.hash != '' ) {
		$(location.hash).addClass('active');
	}
});

$(window).load(function() {
	$('#carousel').infiniteCarousel({
		displayTime: 5000,
		transitionSpeed: 800,
		textholderHeight : .25,
		displayThumbnailBackground: 0,
		displayProgressBar : 0
	});
	
	$('[placeholder]').placeholder();
});
