var isTest=true;
$(function(){
	var showStep=function(stepId){
		$("#content .step").hide();
		$("#"+stepId).fadeIn();

    if(stepId != "step1")
    {
      $('#init').hide();
    }else
    {
      $('#init').show();
    }
	}

	var setFlow=function(stepId){
			$("#flow li").attr("id","");
			$("#flow").find("."+stepId).attr("id","selected");
	}
	$(".step").each(function(){
    if($(this).attr('id') == 'step1')
    {
      // do nothing
      return;
    }

		$(this).find(".submit button").click(function(){
			
			var nextStep = $(this).next().attr("value");
			var stepNum = parseInt(nextStep.split("step")[1])-1;

			$("#twitterwindWindow #init").hide();
			$("#twitterwindWindow #twitterWindIframe").fadeIn();
			showStep(nextStep);
			
			//$("#flow .step"+stepNum).attr("id","");
			setFlow(nextStep);
			
			var nextURL = location.href.split("#")[0]+"#_"+nextStep;
			location.replace(nextURL);
			return false;
		});
		
		var href = location.href;
		if(href.indexOf("#")!=-1 &&isTest){
			var targetStep = href.split("#_")[1];//step3
			if(targetStep!=""){
				$("#step1").hide();
				showStep(targetStep);
			}else{
				$("#step1").show();
			}
		}
	});
	
	$(".step .content_body").corner("round 15px");
	
	$("p.back a").click(function(){
		var href = $(this).attr("href");//#_step1
		var stepId = href.split("#_")[1];
		showStep(stepId);
		if(stepId=="step1") {
			$("#twitterwindWindow #init").fadeIn();
			//$("#twitterwindWindow #twitterWindIframe").hide();
		}
		setFlow(stepId);
	});
	
	$('button.colorbox').each(function(){
		var $button=$(this);
		var $input = $button.parent().find("input");
		$button.css({'backgroundColor':'#'+$input[0].value});
		//log($button);
		
		$button.ColorPicker({
			flat: false,
			color: '#0000ff',
			livePreview:true,
			onShow: function (colpkr) {
				$(colpkr).fadeIn(300);
			},
			onHide: function (colpkr) {
				$(colpkr).fadeOut(100);
			},
			onBeforeShow: function () {
				$(this).ColorPickerSetColor($input.val());
			},
			onChange: function (hsb, hex, rgb) {
				$button.css('backgroundColor', '#' + hex);
				$input.attr({value:hex.toUpperCase()});
				$input.change(); /* */
			},
			onSubmit: function (hsb, hex, rgb,el) {
				//$(el).val(hex.toUpperCase());
				$(el).ColorPickerHide();
			}
		});
		$button.click(function(){
	  	 return false;
	   });
	});
	
	$("#step3 .detail").hide();
	$(".detailBtn a").click(function(){
		$detail = $(this).parent().parent().find(".detail");
		$("#step3 .detail").not($detail[0]).slideUp("slow");
		$detail.slideToggle("slow");
		return false;
	});
	
	$("#step4 textarea").click(function(){
		this.focus();
		this.select();

	});

  function initialize_page()
  {
    if( location.href.indexOf("#_") == -1)
    {
      showStep('step1');
      setFlow('step1');
    }else
    {
      var step = location.href.split("#_")[1]; 
      showStep(step);
      setFlow(step);
    }
  };
  initialize_page();

});

function log(o){
	if (window.console) console.log(o);
}

function setColorBtns(){
	
}

