$(document).ready(function($) {
	
	if($.browser.mozilla){
		$(".bc .rightcol ul li div.content").css("padding-bottom","8px");
		$(".bc .rightcol ul li.style div.content").css("padding-bottom","14px");
		$("#content.bc.logo .rightcol ul li.design div.content").css("padding-bottom","18px");
	}

	$('ul.options li div.content').hide();

	var firstTab = $("ul.options li:first");
	
	firstTab.find("div.content").show();
	firstTab.find("a.title").css("background-position","Center Bottom");
	
	
	$('ul.options li a.title').click(function(){
		
		if($(this).parent() == $('ul.options li:first')){
			
		} else {

			$("ul.options li a.title").css("background-position","");
			$(this).css("background-position","Center Bottom");
		}
		
		
		
		if($(this).parent().find("div.content").is(":visible")){
			
		} else {
			
			$("ul.options li div.content").slideUp();
			$(this).parent().find("div.content").slideDown();
			
		}
		
		
		return false;
	});
	//if any tab is clicked all others content will be hidden and its will be revealed
	
	$("input[type!='submit'][type!='checkbox']").change(function() {
			
			if($(this).hasClass("donttab")){
				
				/*if($(this).parents('body').attr("class") == 'bconly'){
								
					if($(this + "#contact-01, " + this + "#contact-02")){
					
						

						$("ul.options li.card-type a.title").click();
						
					
					}
				
				}*/
				
			} else {
				nextTab($(this));
			}
		
	});
	//if 3 checkboxes are checked go to next tab
	
	$("li.style input[type='checkbox']").change(function() {

		if($("li.style input[type='checkbox']:checked").length == 3){
					
			$("ul.options li a.title").css("background-position","");
			$("ul.options li div.content").slideUp();
			$(this).parents("li").next().find("div.content").slideDown();
			$(this).parents("li").next().find("a.title").css("background-position","center bottom");
		
		}
		
	});
	
		
	function nextTab(thisTab){
		
		var nextTab = thisTab.parents("li").next();
		nextTab.find("a").click();
		
	}
	
	$("li.projects h4").hide();
	$("li.projects h4.5projects").show();
	
	$("ul.options li.design div.content input[type='radio']").change(function() {
		
		if($("ul.options li.design div.content input[type='radio']:checked").attr("id") == 'design-01'){
			
			$("li.projects h4").hide();
			$("ul.options li.projects div.content h4.3projects").show();
			projectSelect(3);
			
		} else if ($("ul.options li.design div.content input[type='radio']:checked").attr("id") == 'design-02'){
			
			$("li.projects h4").hide();
			$("ul.options li.projects div.content h4.4projects").show();
			projectSelect(4);
			
		} else if ($("ul.options li.design div.content input[type='radio']:checked").attr("id") == 'design-03'){
			
			$("li.projects h4").hide();
			$("ul.options li.projects div.content h4.5projects").show();
			projectSelect(5);
			
		}
		
	});
	
	function projectSelect(num){
		
		$("li.projects input[type='checkbox']").change(function() {

			if($("li.projects input[type='checkbox']:checked").length == num){

				$("ul.options li a.title").css("background-position","");
				$("ul.options li div.content").slideUp();
				$(this).parents("li").next().find("div.content").slideDown();
				$(this).parents("li").next().find("a.title").css("background-position","center bottom");

			}

		});
		
	}
	
	//samples section
	$("#samples ul li a:last").css("paddingRight","0px");
	
	var imgWidth = $("#samples ul li a img").width() + parseInt($("#samples ul li a").css("paddingRight"));
	
	var totalWidth = ($("#samples ul li").length - 4) * -imgWidth;
	var totalWidthRight = (totalWidth + 10);
	totalWidth = totalWidth + "px";
	var imgWidthLeft = "+=" + imgWidth * 4 + "px";
	var imgWidthRight = "-=" + imgWidth * 4 + "px";
	
	$("#samples a.prev").click(function() {
		
		var marginL = parseInt($("#samples ul").css("marginLeft"));

		if(marginL >= -135){
			
			$("#samples ul").animate({ "marginLeft": totalWidth }, { queue:true, duration: 1000});
			
		} else {
		
			$("#samples ul").animate({ "marginLeft": imgWidthLeft }, { queue:true, duration: 500});
			
		}
		
		return false;
		
	});
	
	$("#samples a.next").click(function() {
		
		var marginL = parseInt($("#samples ul").css("marginLeft"));
		
		if(marginL <= totalWidthRight){
			
			$("#samples ul").animate({ "marginLeft": "0px" }, { queue:true, duration: 1000});
			
		} else {
		
			$("#samples ul").animate({ "marginLeft": imgWidthRight }, { queue:true, duration: 500});
			
		}
		
		return false;
		
	});
	
	var uploadClick = 0;
	
	$("ul li.upload a.upload-button").click(function() {
		
		uploadClick++;
		
		if(uploadClick == 1 && $("input[type='radio'][name='design']:checked").length == 1){
			$(this).after("<input type='hidden' name='uploaded file(s)' value='yes' />");
		}
		
	});
	
	if($("p.total").length != 0){
		var price = 0;
		$("input, select").change(function() {
			
			
			if($("input:checked")){
				$(this).toggleClass("checked");
				if($(this).attr("alt") != ""){
					
					if($(this).hasClass("checked")){
					
						price += parseInt($(this).attr("alt"));
						$("p.total span").text(price);
						
					} else {
						
						price -= parseInt($(this).attr("alt"));
						$("p.total span").text(price);
						
					}
					
				}
				
			}
			
		});
		
	}	
	
});