$(document).ready(function() {
	$('#mahogany').click(function() {
		$("a.oak, #sidelites .oak a").removeAttr("rel");
		$("a.mahogany, #sidelites .mahogany a").attr("rel", "sidelitesAndTransoms")
		$(".oak").hide();
		$(".mahogany").fadeIn("fast");
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
	});
	$('#oak').click(function() {
		$("a.mahogany, #sidelites .mahogany a").removeAttr("rel");
		$("a.oak, #sidelites .oak a").attr("rel", "sidelitesAndTransoms")
		$(".mahogany").hide();
		$(".oak").fadeIn("fast");
		$('div.tabs ul.tabNavigation a').removeClass('selected');
		$(this).addClass('selected');
	});
	
	var fPrint = function(){window.print()};
    var fWarn  = function(){alert("You must select some door options before you can print.")};
 	$('.print').html('<img src="/i/bullet3.png" /> Print Selections and Take to Lowe&rsquo;s').bind("click",fWarn);
	$('.print2').html('<img src="/i/btn-printableVersion-grey2.gif" />').bind("click",fWarn);

	var $layoutOptions = $('.layout .option');
	var $doorOptions = $('#doors .option');
	var $finishOptions = $('#paint .option');
	var $stainOptions = $('#stains .option');
	var $sideliteOptions = $('#sidelites .option');
	var $transomOptions = $('#transoms .option');
	var $jambOptions = $('#jambs .option');

	$layoutOptions.click(function() {
		if( $(this).hasClass('highlight') ){
			$(this).removeClass('highlight');
		}else if( $layoutOptions.hasClass('highlight') ){
			$layoutOptions.removeClass('highlight');
			$(this).addClass('highlight');
		}else{
			$(this).toggleClass('highlight');
		}
		
	 	updatePrintButtons();
	});

	$doorOptions.click(function() {
	 	if( $(this).hasClass('highlight') ){
			$(this).removeClass('highlight');
		}else if( $doorOptions.hasClass('highlight') ){
			$doorOptions.removeClass('highlight');
			$(this).addClass('highlight');
		}else{
			$(this).toggleClass('highlight');
		}
	 	updatePrintButtons();
	});
	
	$sideliteOptions.click(function() {
	 	if( $(this).hasClass('highlight') ){
			$(this).removeClass('highlight');
		}else if( $sideliteOptions.hasClass('highlight') ){
			$sideliteOptions.removeClass('highlight');
			$(this).addClass('highlight');
		}else{
			$(this).toggleClass('highlight');
		}

	 	updatePrintButtons();
	});
	
	$transomOptions.click(function() {
	 	if( $(this).hasClass('highlight') ){
			$(this).removeClass('highlight');
		}else if( $transomOptions.hasClass('highlight') ){
			$transomOptions.removeClass('highlight');
			$(this).addClass('highlight');
		}else{
			$(this).toggleClass('highlight');
		}

	 	updatePrintButtons();
	});
	
	$finishOptions.click(function() {
	 	if($finishOptions.siblings('.highlight').length > 1){
			$(this).removeClass("highlight");
	 	}else{
	  		//Select clicked option
	  		$(this).toggleClass("highlight");
	 	}
		updatePrintButtons();
	});
	
	$stainOptions.click(function() {
	 	if($stainOptions.siblings('.highlight').length > 1){
			$(this).removeClass("highlight");
	 	}else{
	  		//Select clicked option
	  		$(this).toggleClass("highlight");
	 	}
		updatePrintButtons();
	});
	
	$jambOptions.click(function() {
	 	$(this).toggleClass('highlight');

	 	updatePrintButtons();
	});

	function updatePrintButtons() {
		//Makes printable button printable if something is selected
		$(".highlight").size()>0 ?
				$('.print').html('<img src="/i/bullet3.png" /> <a href="#">Print Selections and Take to Lowe&rsquo;s</a>').unbind("click",fWarn).bind("click",fPrint)
			: 	$('.print').html('<img src="/i/bullet3.png" /> Print Selections and Take to Lowe&rsquo;s').unbind("click",fPrint).bind("click",fWarn);
		$(".highlight").size()>0 ?
				$('.print2').html('<img src="/i/btn-printableVersion2.gif" />').unbind("click",fWarn).bind("click",fPrint)
			: 	$('.print2').html('<img src="/i/btn-printableVersion-grey2.gif" />').unbind("click",fPrint).bind("click",fWarn);

	}

});