$(document).ready(function() {

	var myTimer;
	var msie6 = $.browser == 'msie' && $.browser.version < 7;
	
	if (msie6) {
		$('#main_content').prepend($('<div class="error_message">This aint no time machine sucka! We don\'t support Internet Explorer 6. <br /> Please upgrade to the newest version or try a new browser like <a href="http://getfirefox.com" target="_blank">Firefox</a>.</div>'));
	}
	if ($.browser.msie) {
		$('#main_content').prepend($('<div class="error_message">We haven\'t added support for Internet Explorer yet (coming soon). <br /> Try a different browser like <a href="http://getfirefox.com" target="_blank">Firefox</a>.</div>'));
	}

	$('.delete').click(function(e){
		return confirm('Are you sure you want to delete this?');
	});

	var origNumOfLayers = $('#board_theme_layers img').size();
	var themeBaseFilename = $('#board_theme_layers img').attr('src');
	if(origNumOfLayers > 0){
		themeBaseFilename = themeBaseFilename.split('/');
		themeBaseFilename = themeBaseFilename[2];
		themeBaseFilename = themeBaseFilename.split('_layer');
		themeBaseFilename = themeBaseFilename[0];
		$('#artlab_canvas div[unselectable=on]').remove();
		initAsset();
	} else {
		themeBaseFilename = 'blank';
	}

	$('.tooltip').qtip({
		style: {
			width: 200,
			padding: 5,
			background: '#000000',
			color: '#bed52f',
			textAlign: 'center',
			border: {
				width: 2,
				radius: 2,
				color: '#FFFFFF'
			},
			tip:true,
			name: 'light'
		},
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			}
		}
	});

	$("#login_form :text").toggleVal({
		focusClass: "hasFocus",
		changedClass: "isChanged"
	});

	$('.next_button').click(function(e){
		marginTop = marginTop - 559;
		$('#artlab_steps').animate({
			marginTop: marginTop + 'px'
		}, 1000);
		e.preventDefault();
	});

	$('.back_button').click(function(e){
		marginTop = marginTop + 559;
		$('#artlab_steps').animate({
			marginTop: marginTop + 'px'
		}, 1000);
		e.preventDefault();
	});

	$('#draft_view').click(function(e){
		if ( $('#board_overlay').attr('src') == "images/layout/polished.png" ) {
			setDraftView();
		} else if ($('#board_overlay').attr('src') == "images/layout/polished2.png") {
			setDraftView2();
		}
		e.preventDefault();
	});

	$('#polished_view').click(function(e){
		if ( $('#board_overlay').attr('src') == "images/layout/wireframe.png" ) {
			setPolishedView();
		} else if ($('#board_overlay').attr('src') == "images/layout/wireframe2.png"){
			setPolishedView2();
		}
		e.preventDefault();
	});

	$('#review_top_view').click(function(e){
		setReviewTopView();
		e.preventDefault();
	});

	$('#review_bottom_view').click(function(e){
		setReviewBottomView();
		e.preventDefault();
	});

	$('#choose_a_board_form input').click(function(){
		if(! $.browser.msie){
			$('#step_2_link').slideDown();
			var boardChosen = $('#choose_a_board_form input[name=boards]:checked').val();
			boardChosen = boardChosen.split('||');
			$('.board_chosen, #review_board_model').text(boardChosen[0]);
			baseBoardPrice = boardChosen[1];
			calcTotalPrice();
		}
	});

	$('#board_themes_list').html(themesHTML);

	$('#step_2_link').click(function(e){
		if(step2Completed == 'no'){
			$('#board_rack').addClass('hidden');
			$('#board_orders').addClass('hidden');
			$('#board_overlay').removeClass('hidden');
			$('#view_modes').removeClass('hidden');
			if( origNumOfLayers < 1 ){
				$('#board_theme_layers').removeClass('hidden');
				$('#board_theme_layers').html('<img id="theme_layer_1" src="' + themePath + 'blank_layer1_00000.png" />');
			}
			
			$('ul#board_themes_list li img').click(function(){
				$('#review_graphic_theme').text($(this).attr('alt'));
				var filenameLayers = $(this).attr('rel');
				filenameLayers = filenameLayers.split('||');
				var numOfLayers = filenameLayers[1];
				var filename = filenameLayers[0];
				filename = filename.split('.');
				themeBaseFilename = filename[0];
				var i = 0;
				var html = "";
				$('#artlab_step_3 .swatch_groups').html('');
				for (i = numOfLayers; i > 0; i--){
					html += '<img id="theme_layer_' + i + '" src="' + themePath + themeBaseFilename + '_layer' + i + '_00000.png" /> ';
					$('#theme_swatch_groups').prepend(
						'<h4 id="swatch_title_' + i + '">COLOR #' + i + ': <span>DEFAULT</span></h4><ul id="swatch_list_' + i + '" class="swatch_list">' + swatchesHTML + '</ul><div class="divider"></div>'
					);
				}
				$('#board_theme_layers').html(html);
				createSwatches();
				$('#theme_swatch_groups').jScrollPane();
			});
			if (origNumOfLayers > 0){
				var i = 0;
				var html = "";
				$('#artlab_step_3 .swatch_groups').html('');
				for (i = origNumOfLayers; i > 0; i--){
					html += '<img id="theme_layer_' + i + '" src="' + themePath + themeBaseFilename + '_layer' + i + '_00000.png" /> ';
					$('#theme_swatch_groups').prepend(
						'<h4 id="swatch_title_' + i + '">COLOR #' + i + ': <span>SAVED COLOR</span></h4><ul id="swatch_list_' + i + '" class="swatch_list">' + swatchesHTML + '</ul><div class="divider"></div>'
					);
				}
				createSwatches();
				$('#theme_swatch_groups').jScrollPane();
			} else {
				$('#theme_swatch_groups').html(
					'<h4 id="swatch_title_1">COLOR #1: <span>DEFAULT</span></h4><ul id="swatch_list_1" class="swatch_list">' + swatchesHTML + '</ul><div class="divider"></div>'
				);
			}

			createSwatches();
			$('.board_list').jScrollPane();
			$('.assets_list').jScrollPane();
			step2Completed = 'yes';
		}
		e.preventDefault();
	});

	$('.set_draft').click(function(e){
		setDraftView();
		e.preventDefault();
	});

	$('.set_polished').click(function(e){
		setPolishedView();
		e.preventDefault();
	});

	$('.set_draft2').click(function(e){
		setDraftView2();
		e.preventDefault();
	});

	$('.set_polished2').click(function(e){
		setPolishedView2();
		e.preventDefault();
	});

	$('.set_draft3').click(function(e){
		setDraftView3();
		e.preventDefault();
	});

	$('.set_polished3').click(function(e){
		setPolishedView3();
		e.preventDefault();
	});

	$('.set_review').click(function(e){
		setReviewTopView();
		e.preventDefault();
	});

	$("a.overlay_button, a.overlay_button2").overlay({
		effect: 'apple',
		expose: {
			color: '#000',
			loadSpeed: 200,
			opacity: 0.7
		}
	});

	$("#upload_asset_input").uploadify({
		'uploader'       : '../scripts/jquery-uploadify/example/scripts/uploadify.swf',
		'script'         : '../scripts/jquery-uploadify/example/scripts/uploadify.php',
		'checkScript'    : '../scripts/jquery-uploadify/example/scripts/check.php',
		'cancelImg'      : '../scripts/jquery-uploadify/example/cancel.png',
		'folder'         : 'images/user',
		'auto'           : true,
		'fileExt'        : '*.jpg;*.jpeg;*.png;*.JPG;*.JPEG;*.PNG',
		'fileDesc'       : 'Image (.jpg or .png)',
		'buttonText'     : 'UPLOAD',
		//'buttonImg'      : '../scripts/jquery-uploadify/example/button.png',
		'onComplete'     : 	function(event,queueId,fileData,response,data){
								// Send filename to AJAX rename script
								$.ajax({
								   type: "POST",
								   url: "scripts/image_rename.php",
								   data: "filename=" + fileData['name'],
								   success: function(response){
										$('div#board_top').append( $('<div class="asset top" rel="custom_asset" style="z-index:200;"><div class="resizer"><span class="resize_handle hidden"></span><img src="images/user/' +  response + '" style="height:100px" /></div></div>') );
										initAsset();
										zDecline();
										topCustomGraphicsUsed++;
										calcTotalPrice();
								   }
								});
								$('.close').click();
		                   	}
	});

	$("#base_upload_asset_input").uploadify({
		'uploader'       : '../scripts/jquery-uploadify/example/scripts/uploadify.swf',
		'script'         : '../scripts/jquery-uploadify/example/scripts/uploadify.php',
		'checkScript'    : '../scripts/jquery-uploadify/example/scripts/check.php',
		'cancelImg'      : '../scripts/jquery-uploadify/example/cancel.png',
		'folder'         : 'images/user',
		'auto'           : true,
		'fileExt'        : '*.jpg;*.jpeg;*.png;*.JPG;*.JPEG;*.PNG',
		'fileDesc'       : 'Image (.jpg or .png)',
		'buttonText'     : 'UPLOAD',
		//'buttonImg'      : '../scripts/jquery-uploadify/example/button.png',
		'onComplete'     : 	function(event,queueId,fileData,response,data){
								// Send filename to AJAX rename script
								$.ajax({
								   type: "POST",
								   url: "scripts/image_rename.php",
								   data: "filename=" + fileData['name'],
								   success: function(response){
										$('div#board_bottom').append( $('<div class="asset" rel="custom_asset" style="z-index:200;"><div class="resizer"><span class="resize_handle hidden"></span><img src="images/user/' +  response + '" style="height:100px" /></div></div>') );
										initAsset();
										zDecline();
										bottomCustomGraphicsUsed++;
										calcTotalPrice();
								   }
								});
								$('.close').click();
		                   	}
	});

	$('#artlab_step_4 .asset_link').click(function(e){
		$('div#board_top').append( $('<div id="loading"></div>') );
		var img = new Image();
		var imgSrc = 'images/assets/' +  $(this).attr('rel') + '_00000.png';
		$(img)
			.load(function(){
				$('div#board_top').append( $('<div class="asset top" rel="humanoid_asset" style="z-index:200;"><div class="resizer"><span class="resize_handle hidden"></span><img src="' + imgSrc + '" style="height:100px" /></div><div class="rotator hidden"><div class="slider"></div></div></div>') );
				initAsset();
				zDecline();
				topGraphicsUsed++;
				calcTotalPrice();
				$('div#loading').remove();
			})
			.attr('src',imgSrc);
		e.preventDefault();
	});

	$('#artlab_step_7 .asset_link').click(function(e){
		$('div#board_bottom').append( $('<div id="loading"></div>') );
		var img = new Image();
		var imgSrc = 'images/assets/' +  $(this).attr('rel') + '_00000.png';
		$(img)
			.load(function(){
				$('div#board_bottom').append( $('<div class="asset" rel="humanoid_asset" style="z-index:200;"><div class="resizer"><span class="resize_handle hidden"></span><img src="' + imgSrc + '" style="height:100px" /></div><div class="rotator hidden"><div class="slider"></div></div></div>') );
				initAsset();
				zDecline();
				bottomGraphicsUsed++;
				calcTotalPrice();
				$('div#loading').remove();
			})
			.attr('src',imgSrc);
		e.preventDefault();
	});

	$("#trashcan").droppable({
		hoverClass: 'trashcan_hover',
		drop: function(event, ui) {
			var assetType = $(ui.draggable).attr('rel');
			var trashable = 1;
			if ($(ui.draggable).hasClass('custom_text')){ trashable = 0; }
			if ($(ui.draggable).hasClass('badge')){ trashable = 0; }
			if ($(ui.draggable).hasClass('top')){
				if (assetType == "custom_asset"){ topCustomGraphicsUsed--; }
				if (assetType == "humanoid_asset"){ topGraphicsUsed--;  }
			} else {
				if (assetType == "custom_asset"){ bottomCustomGraphicsUsed--; }
				if (assetType == "humanoid_asset"){ bottomGraphicsUsed--;  }
			}
			calcTotalPrice();
			if(trashable == 1){
				$(ui.draggable).remove();
			}
		}
	});

	$('#logo_only_link').click(function(){
		$('#base_text').html('<img src="'+ basePath + 'logo_only.png" />');
		$('#text_options').addClass('hidden');
		$('#custom_text_options').addClass('hidden');
		customBaseText = 0;
		$('#review_base_option').text('Logo Only');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		baseTextOrCombo = "logo";
		$('#base_options').jScrollPane();
		calcTotalPrice();
	});

	$('#text_only_link').click(function(){
		$('#base_text').html('<img src="'+ basePath + baseFont + '_text_' + zeroPad(baseFontColor,5) + '.png" />');
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').addClass('hidden');
		customBaseText = 0;
		$('#review_base_option').text('Text Only');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		baseTextOrCombo = "text";
		$('#base_options').jScrollPane();
		calcTotalPrice();
	});

	$('#logo_and_text_link').click(function(){
		$('#base_text').html('<img src="'+ basePath + baseFont + '_combo_' + zeroPad(baseFontColor,5) + '.png" />');
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').addClass('hidden');
		customBaseText = 0;
		$('#review_base_option').text('Logo + Text');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		baseTextOrCombo = "combo";
		$('#base_options').jScrollPane();
		calcTotalPrice();
	});

	$('#custom_text_link').click(function(){
		$('#base_text').html('<img src="images/base/custom_text_message.png" />');
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').removeClass('hidden');
		customBaseText = 1;
		$('#review_base_option').text('Custom Text');
		$('#custom_text_review').removeClass('hidden');
		$('#base_custom_text').addClass('hidden');
		baseTextOrCombo = "custom";
		$('#base_options').jScrollPane();
		calcTotalPrice();
	});

	$('#blank_base_link').click(function(){
		$('#base_text').html('');
		$('#text_options').addClass('hidden');
		$('#custom_text_options').addClass('hidden');
		customBaseText = 0;
		$('#review_base_option').text('Blank');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		baseTextOrCombo = "blank";
		$('#base_options').jScrollPane();
		calcTotalPrice();
	});

	if(baseTextOrCombo == 'logo'){
		$('#text_options').addClass('hidden');
		$('#custom_text_options').addClass('hidden');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		myTimer = setTimeout(function(){
			$('#base_options').jScrollPane();
		}, 2000);
	} else if (baseTextOrCombo == 'text'){
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').addClass('hidden');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		$('#base_options').jScrollPane();
		myTimer = setTimeout(function(){
			$('#base_options').jScrollPane();
		}, 2000);
	} else if (baseTextOrCombo == 'combo'){
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').addClass('hidden');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		myTimer = setTimeout(function(){
			$('#base_options').jScrollPane();
		}, 2000);
	} else if (baseTextOrCombo == 'custom'){
		$('#text_options').removeClass('hidden');
		$('#custom_text_options').removeClass('hidden');
		$('#custom_text_review').removeClass('hidden');
		$('#base_custom_text').addClass('hidden');
		myTimer = setTimeout(function(){
			$('#base_options').jScrollPane();
		}, 2000);
	} else if (baseTextOrCombo == 'blank'){
		$('#text_options').addClass('hidden');
		$('#custom_text_options').addClass('hidden');
		$('#custom_text_review').addClass('hidden');
		$('#base_custom_text').addClass('hidden');
		myTimer = setTimeout(function(){
			$('#base_options').jScrollPane();
		}, 2000);
	}

	$('#step_6_link').click(function(){
		if (customBaseText == 1) {
			updateCustomText();
		}
	});

	$('.font_radio').click(function(){
		baseFont = $(this).val();
		var imgSource =  basePath + baseFont + '_' + baseTextOrCombo + '_' + zeroPad(baseFontColor,5) + '.png';
		$('#base_text img').attr('src',imgSource);
		baseFontFilename = $(this).attr('rel');
		if (customBaseText == 1) { updateCustomText(); }
	});

	$('#update_text_button').click(function(e){
		customTextString = $('#custom_text_input').val();
		updateCustomText();
		e.preventDefault();
	});

	$('#artlab_step_6 .orientation_button').click(function(e){
		customBaseTextRotation = $(this).attr('rel');
		$('#artlab_step_6 .orientation_button').removeClass('current');
		$(this).addClass('current');
		updateCustomText();
		e.preventDefault();
	});

	$('#step_8_link').click(function(){
		$('#base_badge').removeClass('hidden');
	});

	$('div#base_badge').draggable();

	$('#artlab_step_8 .orientation_button').click(function(e){
		var badgeOrientation = $(this).attr('rel');
		$('#artlab_step_8 .orientation_button').removeClass('current');
		$(this).addClass('current');
		$('#base_badge img').attr('src','images/layout/badge_'+badgeOrientation+'.png')
		e.preventDefault();
	});

	$('#badge_text').keyup(function(){
		badgeText = $(this).val();
		$('#review_badge_text').text(badgeText);
		if (badgeText.length > 25) {
			$(this).addClass('small');
			$(this).removeClass('medium');
			$(this).removeClass('large');
		} else if (badgeText.length > 15) {
			$(this).removeClass('small');
			$(this).addClass('medium');
			$(this).removeClass('large');
		} else {
			$(this).removeClass('small');
			$(this).removeClass('medium');
			$(this).addClass('large');
		}
	});

	$('#sidewall_color_radio_list input').click(function(){
		$('#review_sidewall_color').text($(this).val());
		$('#base_sidewall img').attr('src','images/layout/sidewall_'+$(this).attr('rel')+'.png');
	});

	$('#fin_style_radio_list input').click(function(){
		$('#review_fin_style').text($(this).val());		
	});

	$('#fin_color_radio_list input').click(function(){
		$('#review_fin_color').text($(this).val());
		$('#base_fins img').attr('src','images/layout/fins_'+$(this).attr('rel')+'.png');
	});

	function updateCustomText(){
		$('#base_text').html('');
		$('#base_custom_text').removeClass('hidden');
		$('#review_custom_text').text($('#custom_text_input').val());
		$.ajax({
			type: "POST",
			url: "scripts/text_to_image.php",
			data: "font=" + baseFontFilename + "&color=" + baseFontHex +  "&bg_color=" + baseHex +  "&rotation=" + customBaseTextRotation +  "&text=" + customTextString,
			success: function(filename){
				$('div#base_custom_text img').attr( "src", "images/text/" + filename);
				initAsset();
				zDecline();
			}
		});
	}

	initBaseColorSwatches();

	initFontColorSwatches();

	function initAsset() {
		$('div.asset').draggable({
			start: function(e,ui){
				$(this).css('zIndex','200');
				zDecline();
			},
			stop: function(e,ui){
				//$('span.pos').html( $(this).css('left') +' X '+ $(this).css('top') );
			}
		});

		$('div#artlab_canvas div.asset').click(function(){
			$(this).css('zIndex','200');
			zDecline();
		});

		$('div.asset div.resizer').hover(function(){
			$(this).resizable({
				handles :	'se',
				resize  :	function(event, ui){
								$(this).find('*').not('div').not('span').css('width',$(this).parent().css('width')).css('height',$(this).parent().css('height'));
							}
			});

		});

		$('div.resizer').hover(function(){
			$(this).find('span.resize_handle').removeClass('hidden');
		},function(){
			$(this).find('span.resize_handle').addClass('hidden');
		});

		$("div.asset div.rotator div.slider").slider({
			//range: "min",
			//value: 0,
			min: 0,
			max: 359,
			slide: function(event, ui) {
				//var imgSrc = 'images/assets/asset_placeholder_' + zeroPad(ui.value,5) + '.png';
				var origSrc = $(this).parent().parent().find('img').attr('src');
				var strLen = origSrc.length;
				var imgSrc = origSrc.substring(0,strLen - 9) + zeroPad(ui.value,5) + '.png';
				$(this).parent().parent().find('img').attr('src',imgSrc);
			},
			stop: function(event, ui) {
				var origSrc = $(this).parent().parent().find('img').attr('src');
				var strLen = origSrc.length;
				var imgSrc = origSrc.substring(0,strLen - 9) + zeroPad(ui.value,5) + '.png';
				$(this).parent().parent().find('img').attr('src',imgSrc);
			}
		});


		$('div.asset').hover(function(){
			$(this).find('div.rotator').removeClass('hidden');
		},function(){
			$(this).find('div.rotator').addClass('hidden');
		});
	}

	function setDraftView(){
		$('#draft_view').addClass('hidden');
		$('#polished_view').removeClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/wireframe.png').css('zIndex',10);
		$('#trashcan').removeClass('hidden');
		$('#board_top').removeClass('hidden');
		$('#board_bottom').addClass('hidden');
		$('#view_modes').removeClass('hidden');
	}

	function setPolishedView(){
		$('#polished_view').addClass('hidden');
		$('#draft_view').removeClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/polished.png').css('zIndex',1000);
		$('#trashcan').addClass('hidden');
		$('#board_top').removeClass('hidden');
		$('#board_bottom').addClass('hidden');
		$('#view_modes').removeClass('hidden');
	}

	function setDraftView2(){
		$('#draft_view').addClass('hidden');
		$('#polished_view').removeClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/wireframe2.png').css('zIndex',10);
		$('#trashcan').removeClass('hidden');
		$('#board_top').addClass('hidden');
		$('#board_bottom').removeClass('hidden');
		$('#view_modes').removeClass('hidden');
		$('#base_fins').addClass('hidden');
		$('#base_sidewall').addClass('hidden');
	}

	function setPolishedView2(){
		$('#polished_view').addClass('hidden');
		$('#draft_view').removeClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/polished2.png').css('zIndex',1000);
		$('#trashcan').removeClass('hidden');
		$('#board_top').addClass('hidden');
		$('#board_bottom').removeClass('hidden');
		$('#view_modes').removeClass('hidden');
		$('#base_fins').addClass('hidden');
		$('#base_sidewall').addClass('hidden');
	}

	function setPolishedView3(){
		$('#polished_view').addClass('hidden');
		$('#draft_view').removeClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/polished2.png').css('zIndex',1000);
		$('#trashcan').removeClass('hidden');
		$('#board_top').addClass('hidden');
		$('#view_modes').addClass('hidden');
		$('#board_bottom').removeClass('hidden');
		$('#base_fins').removeClass('hidden');
		$('#base_sidewall').removeClass('hidden');
	}

	function setReviewTopView(){
		$('#draft_view').addClass('hidden');
		$('#polished_view').addClass('hidden');
		$('#review_top_view').addClass('hidden');
		$('#review_bottom_view').removeClass('hidden');
		$('#board_overlay').attr('src','images/layout/polished.png').css('zIndex',1000);
		$('#trashcan').addClass('hidden');
		$('#board_top').removeClass('hidden');
		$('#board_bottom').addClass('hidden');
		$('#view_modes').removeClass('hidden');
	}

	function setReviewBottomView(){
		$('#draft_view').addClass('hidden');
		$('#polished_view').addClass('hidden');
		$('#review_top_view').removeClass('hidden');
		$('#review_bottom_view').addClass('hidden');
		$('#board_overlay').attr('src','images/layout/polished2.png').css('zIndex',1000);
		$('#trashcan').addClass('hidden');
		$('#board_top').addClass('hidden');
		$('#board_bottom').removeClass('hidden');
		$('#view_modes').removeClass('hidden');
	}

	function zDecline() {
		$('div#artlab_canvas div.asset').each(function(){
			var zVal = $(this).css('zIndex');
			$(this).css('zIndex',zVal-1);
		});
	}

	function createSwatches() {
		$('#theme_swatch_groups a.swatch').each(function(){
			var hexCode = $(this).attr('rel');
			if(hexCode == "DEFAULT"){
				$(this).css('background', 'url(images/layout/default_swatch.png) 50% 50%');
			} else {
				$(this).css('background', '#' + hexCode);
			}
		});
		initSwatches();
	}

	function initSwatches() {
		$('#theme_swatch_groups a.swatch').click(function(e){
			var swatchColorName = $(this).attr('rel');
			if(swatchColorName != "DEFAULT"){ swatchColorName = "HEX CODE #" + swatchColorName; }
			var groupID = $(this).parent().parent().attr('id');
			groupID = groupID.split('_');
			groupID = groupID[2];
			var imgSource =  themePath + themeBaseFilename + '_layer' + groupID + '_' + zeroPad($(this).attr('href'),5) + '.png';
			$('#theme_layer_' + groupID).attr('src',imgSource);
			$('#swatch_title_' + groupID + ' span').text(swatchColorName);
			e.preventDefault();
		});

	}

	function initBaseColorSwatches() {
		$('#base_color_swatches').html('<h4 id="swatch_title_base">BASE COLOR: <span>DEFAULT</span></h4><ul id="swatch_list_base" class="swatch_list">' + swatchesHTML + '</ul>');
		$('#base_color_swatches a.swatch').each(function(){
			var hexCode = $(this).attr('rel');
			if(hexCode == "DEFAULT"){
				$(this).css('background', 'url(images/layout/default_swatch.png) 50% 50%');
			} else {
				$(this).css('background', '#' + hexCode);
			}
		});
		$('#base_color_swatches a.swatch').click(function(e){
			baseHex = $(this).attr('rel');
			var swatchColorName = "DEFAULT";
			if(baseHex != "DEFAULT"){ swatchColorName = "HEX CODE #" + baseHex; } else { baseHex = "FFFFFF"; }
			var imgSource =  themePath + 'blank_layer1_' + zeroPad($(this).attr('href'),5) + '.png';
			$('#base_color img').attr('src',imgSource);
			$('#swatch_title_base span').text(swatchColorName);
			if (customBaseText == 1) { updateCustomText(); }
			e.preventDefault();
		});
	}

	function initFontColorSwatches() {
		$('#font_color_swatches').html('<h4 id="swatch_title_font">FONT COLOR: <span>DEFAULT</span></h4><ul id="swatch_list_font" class="swatch_list">' + swatchesHTML + '</ul>');
		$('#font_color_swatches a.swatch').each(function(){
			var hexCode = $(this).attr('rel');
			if(hexCode == "DEFAULT"){
				$(this).css('background', 'url(images/layout/default_swatch.png) 50% 50%');
			} else {
				$(this).css('background', '#' + hexCode);
			}
		});
		$('#font_color_swatches a.swatch').click(function(e){
			baseFontHex = $(this).attr('rel');
			var swatchColorName = "DEFAULT";
			if(baseFontHex != "DEFAULT"){ swatchColorName = "HEX CODE #" + baseFontHex; } else { baseFontHex = "000000"; }
			var imgSource =  basePath + baseFont + '_' + baseTextOrCombo + '_' + zeroPad($(this).attr('href'),5) + '.png';
			$('#base_text img').attr('src',imgSource);
			$('#swatch_title_font span').text(swatchColorName);
			baseFontColor = zeroPad($(this).attr('href'),5);
			if (customBaseText == 1) { updateCustomText(); }
			e.preventDefault();
		});
	}

	function calcTotalPrice(){
		totalPrice = parseInt(baseBoardPrice) + parseInt(graphicsPrice * topGraphicsUsed) + parseInt(customGraphicsPrice * topCustomGraphicsUsed) + parseInt(graphicsPrice * bottomGraphicsUsed) + parseInt(customGraphicsPrice * bottomCustomGraphicsUsed) + parseInt(customBaseTextPrice * customBaseText);
		$('.total_price, #review_total_price').text('$' + totalPrice);
		$('#review_theme_uploads').text(topCustomGraphicsUsed);
		$('#review_theme_assets').text(topGraphicsUsed);
		$('#review_base_uploads').text(bottomCustomGraphicsUsed);
		$('#review_base_assets').text(bottomGraphicsUsed);
	}

	function zeroPad(num,count){
		var numZeropad = num + '';
		while(numZeropad.length < count) {
			numZeropad = "0" + numZeropad;
		}
		return numZeropad;
	}

});