$(document).ready(function() {
	// force #main to height of window
	function resizeWindow() {
		$('#main').height($(window).height());
	}
	
	resizeWindow();
	$(window).bind('resize', resizeWindow);
	
	// load the carousel on the home page
	$('#homefeatures.carousel').jCarouselLite({
		btnNext: '#homefeatures_next',
		btnPrev: '#homefeatures_prev',
		visible: 1,
		speed: 300,
		easing: 'easeinout',
		circular: false
	});
	
	// take the carousel and kick it in the pants
	//$('#homefeatures.carousel ul').css('left', '-500px');
	
	// press image viewer
	$('#ptable .lightbox, a[rel=t]').colorbox({transition:"elastic", contentCurrent:"{current} / {total}"});
	
	// press video viewer
	//$('#videoplayer_box .video h3 a').colorbox({fixedWidth:360, fixedHeight:280, iframe:true});
	
	// photo browsing on product page
	$('#product_photo_standard').css('background-image', 'url(/site/images.products/' + $('.product_photo_bucket.selected .thumbnail').attr('id') + '.standard.jpg)');
	$('.product_photo.thumbnail').click(function() {
		$('.product_photo_bucket').removeClass('selected');
		$(this).parent().addClass('selected');
		$('#product_photo_standard').css('background-image', 'url(/site/images.products/' + $(this).attr('id') + '.standard.jpg)');
	});
	
	// news, read more
	$('#press_table .read_more').click(function(e) {
		e.preventDefault();
		
		id = this.id;
		$.get('/press/news.php', { read_more: 'true', news_id: this.id }, function(data) {
			$('#' + id).parent().siblings('p.summary').html(data);
			$('#' + id).parent().remove();
		});
	});
	
	// product "tooltip"
/*	$('#product_grid .product').tooltip({
		track: true, 
		delay: 0, 
		showURL: false, 
		fade: 250,
		bodyHandler: function() { 
			//return $('<img/>').attr('src', '/site/images.products/' + this.id + '.standard.jpg');
			return '<div class="smancytooltip" style="background-image: url(\'/site/images.products/' + this.id + '.standard.jpg\')"><div class="title">' + $(this).find('.data .title').text() + '</div><div class="status ' + $(this).find('.data .extinct').text() + '">' + $(this).find('.data .extinct').text() + '</div></div>';
		} 
	});*/
	
	
	/*
	 * ABOUT US accordion
	 */
	
	// activate first
	/*
	$('#aboutus_box p:first').show();
	$('#aboutus_box h2:first').addClass('active');
	
	// trigger
	$('#aboutus_box h2').click(function() {
		// close everything down
		$('#aboutus_box p').hide('fast');
		$('#aboutus_box h2').removeClass('active');
		
		// activate this
		$(this).next().show('fast');
		$(this).addClass('active');
	});
	*/
	
	// US retailers order form: tally
	$('#order_products .quantity input').keyup(function() {
		var sub = $(this).val() * $(this).parent().siblings('.price').text();
		$(this).parent().siblings('.extended_amount').html(formatNumber(sub, 2, ',', '.', '', '', '', ''));
		
		var total = 0;
		$('#order_products .extended_amount').each(function() {
			total += parseFloat($(this).text().replace(/,/g, ''));
		});
		$('#order_products #total').html(formatNumber(total, 2, ',', '.', '', '', '', ''));
	});
	
	
	/*
	 * press video quote rotator
	 */
	
	setInterval(change_quote, 5000);
	var quotes = $('#testimonials_box.small blockquote');
	var index = 0;
	
	$('#testimonials_box.small blockquote:eq(' + index + ')').fadeIn();
	
	function change_quote() {
		$('#testimonials_box.small blockquote:eq(' + index + ')').fadeOut();
		index == quotes.length - 1 ? index = 0 : index++;
		$('#testimonials_box.small blockquote:eq(' + index + ')').fadeIn();
	}
});