var specRate = 600;
var currentColor = '';
var previewColor = '';
var colorTimer = null;
var colorSpeed = 'fast';
var current_display = 'visual';
var colorResetText = '';

$(document).ready( 
	function (){ 
		$('#ModelSpec table tr:odd td').addClass('altbg'); 
		$('#ModelSpec').hide();
		if ( $('#ColorName').length > 0 ) colorResetText = $('#ColorName').text();
		if ( $('img.C5_ColorButton').length > 0 ) {
			$('img.C5_ColorButton.Black')
				.click( function () { c5_showColor('Black'); } )
				.hover( function () { showColorName('Black'); }, function () { setColorTimer(); } )
			$('img.C5_ColorButton.Red')
				.click( function () { c5_showColor('Red'); } )
				.hover( function () { showColorName('Royal Maroon'); }, function () { setColorTimer(); } )
				.addClass('Current');
			$('img.C5_ColorButton.Teal')
				.click( function () { c5_showColor('Teal'); } )
				.hover( function () { showColorName('Classic Green'); }, function () { setColorTimer(); } );
		}
	}
);
$(window).load(
	function (){ 
		$('#ModelVisual').fadeIn( 
			specRate, 
			function () { 
				$('#ModelActions').show('drop', {direction: 'up'}, specRate); 
			}
		);
		if ( $('#C5_ColorPhoto').length > 0 && window.c5_lazyLoadColors ) c5_lazyLoadColors();
	}
);

function showSpecs() {
	if (current_display != 'spec') {
		$('#ModelActions').hide('drop', {direction: 'up'}, specRate, function() {
			$('#ModelVisual').fadeOut(specRate, 
				function() { $('#ModelSpec').fadeIn(specRate); }
			);
		});
		current_display = 'spec';
	} 
	else hideSpecs();
}

function hideSpecs() {
	if (current_display != 'visual') {
		$('#ModelSpec').fadeOut(specRate, 
			function() { $('#ModelVisual').show('drop', {direction: 'left'}, specRate,
				function () { 
					$('#ModelActions').show('drop', {direction: 'up'}, specRate); 
				}								  
			);}
		);
		current_display = 'visual';
	}
}

function showColorName( colorName ) {
	if (colorTimer) clearTimeout(colorTimer);
	if (colorName != currentColor) {
		$('#ColorName').text(colorName);
		currentColor = colorName;
	}
}

function c5_showColor( colorName ) {
	if (previewColor != colorName) {
		var colorDiv = false;
		switch (colorName) {
			case 'Red':
				colorDiv = '#C5_Red';
				colorButton  = 'img.C5_ColorButton.Red';
				break;
			case 'Teal':
				colorDiv = '#C5_Teal';
				colorButton  = 'img.C5_ColorButton.Teal';
				break;
			case 'Black':
				colorDiv = '#C5_Black';
				colorButton  = 'img.C5_ColorButton.Black';
				break;
		}
		if (colorDiv != false) {
			$('#C5_ColorPhoto').fadeOut(colorSpeed, function(){ previewColor = colorName; $('#C5_ColorPhoto div').hide(0); $(colorDiv).show(0); $('#C5_ColorPhoto').fadeIn(colorSpeed); });
			$('img.C5_ColorButton').removeClass('Current');
			$(colorButton).addClass('Current');
		}
	}
}

function setColorTimer() { 
	colorTimer = setTimeout('resetColorName()', 500); 
}

function resetColorName() {
	if (colorTimer) clearTimeout(colorTimer);
	$('#ColorName').text(colorResetText);
	currentColor = '';
}

function c5_lazyLoadColors () {
	$("#C5_Black img").attr('src','/models/img/classic-c5/c5-right-black.jpg');
	$("#C5_Teal img").attr('src','/models/img/classic-c5/c5-right-teal.jpg');
}