var d = new Date();
var foldername = d.getTime();
// ------------------------------------------
// GENERAL FUNCTIONS ------------------------
// ------------------------------------------
function changeHeaderBackground(pos){
	$(".iphone_header").css("background","#000 url(images/iphone_build/headers/iphone_header_"+pos+".png) no-repeat top left");
	alert(foldername);
}
function changeHeaderText(pos){
	$(".iphone_header_copy").css("color","#"+pos+"");
}
function changeTitleText(pos){
	$(".iphone_cell_title_copy").css("color","#"+pos+"");
}
function changeDiscriptionText(pos){
	$(".iphone_cell_discription_copy").css("color","#"+pos+"");
	alert(foldername);
	
}
function changeTableColor(pos){
	var selectedusr = $("#table_type option:selected");		
	if(selectedusr.val() == 'plain'){
	}else if(selectedusr.val() == 'shadow'){
		$(".iphone_table").css("background","#000 url(images/iphone_build/table_shadow/iphone_table_"+pos+".png) no-repeat top left");
	}else if(selectedusr.val() == 'solid'){
		$(".iphone_table").css("background","#000 url(images/iphone_build/table_solid/iphone_table_"+pos+".png) no-repeat top left");
	}
}

function cellColorToggle(pos){
	var selectedusr = $("#table_type option:selected");		
	if(selectedusr.val() == 'plain'){
		$(".iphone_table").css("background","#FF8000 url(images/iphone_table_white.png) no-repeat top left");
		
		$("#table_color").fadeOut(500);
	}else if(selectedusr.val() == 'shadow'){
		$(".iphone_table").css("background-image","url(images/iphone_build/table_shadow.png)");
		
		$("#table_color").fadeIn(500);
	}else if(selectedusr.val() == 'solid'){
		$(".iphone_table").css("background-image","url(images/iphone_build/table_solid.png)");
		
		$("#table_color").fadeIn(500);
		
	}
}
function callback(color) {

	//var color = $("#color1").val()
	var current_id = $('.onFocus').attr('id');
	$('#'+current_id).css("background-color",color);
    if(current_id == "iphone_header"){	
		$('#'+current_id).val(color);
		$(".iphone_header, .color_box_1, .iphone_shell_background").css("background-color",color);

		
	}else if(current_id == "iphone_artical_title"){
		$('#'+current_id).val(color);
		$(".iphone_artical_headline, .iphone_cell_title_copy").css("color",color);
		$(".color_box_2").css("background-color",color);
		
		
	}else if(current_id == "iphone_artical_description"){
		$('#'+current_id).val(color);
		$(".iphone_cell_discription_copy, .iphone_artical_copy, .iphone_artical_date, .iphone_about_copy, .iphone_about_phone, .iphone_about_email").css("color",color);
		$(".color_box_3").css("background-color",color);
		
		
	}else if(current_id == "iphone_background"){
		$('#'+current_id).val(color);
		$(".iphone_background").css("background-color",color);
		$(".color_box_4").css("background-color",color);
		
	}	
	//$(".iphone_header_copy").css("color",color);
}



// ------------------------------------------
// DOCUMENT READY ---------------------------
// ------------------------------------------
$(document).ready(function(){
	$("#table_type").change(cellColorToggle);
	$('.formsection-designphones').css('opacity', 1);
	
	$('#picker1').farbtastic(callback);
	$('#picker2').farbtastic(callback);
	$('#picker3').farbtastic(callback);
	$('#picker4').farbtastic(callback);
	
	$('input.colorwell').focus(function() {
		$('input').removeClass('onFocus');
		$(this).addClass('onFocus');
		var current_id = $('.onFocus').attr('id');
		
	    if(current_id == "iphone_header"){
			$("#colorpickercontainer1").show();
		$("#colorpickercontainer2").hide();
		$("#colorpickercontainer3").hide();
		$("#colorpickercontainer4").hide();
		
		}else if(current_id == "iphone_artical_title"){
				$("#colorpickercontainer2").show();
			$("#colorpickercontainer1").hide();
			$("#colorpickercontainer3").hide();
			$("#colorpickercontainer4").hide();
		}else if(current_id == "iphone_artical_description"){
				$("#colorpickercontainer3").show();
			$("#colorpickercontainer1").hide();
			$("#colorpickercontainer2").hide();
			$("#colorpickercontainer4").hide();
		}else if(current_id == "iphone_background"){
				$("#colorpickercontainer4").show();
			$("#colorpickercontainer1").hide();
			$("#colorpickercontainer2").hide();
			$("#colorpickercontainer3").hide();
		}		
		
		$(document).keyup(function(event){
			var current_id = $('.onFocus').attr('id');
			var newcolor = $('#'+current_id).val();
			$('#'+current_id).css("background-color",newcolor);
			
	        callback(newcolor);
		});		
	});
	
	$('#message').focus(function() {
		$(document).keyup(function(event){
			var newmessage = $('#message').val();
			if(newmessage.length < 241){
	    		$(".iphone_about_copy").text(newmessage);
			}
		});		
	});
	$('#about_phone').focus(function() {
		$(document).keyup(function(event){
			var newmessage = $('#about_phone').val();
			if(newmessage.length < 30){
		    	$(".iphone_about_button_phone").text(newmessage);
			}
			if(newmessage.length == 0){
	    		$(".button_phone_blocks").hide();
			}else{
				$(".button_phone_blocks").show();
			}
		});	
	
	});
	
	$('#about_email').focus(function() {
		$(document).keyup(function(event){
			var newmessage = $('#about_email').val();
			if(newmessage.length < 30){
		    	$(".iphone_about_button_email").text(newmessage);
			}
			if(newmessage.length == 0){
    			$(".button_email_blocks").hide();
			}else{
				$(".button_email_blocks").show();
			}
		});		
	});

/*
	$('.formsection-normalleft input').focus(function() {
		var p = $('#iphonebuilderwrap').css('opacity', 1);
		$('input').removeClass('onFocus');
	});
	$('.formsection-normalleft input').focus(function() {
		var p = $('#iphonebuilderwrap').css('opacity', 1);
		$('input').removeClass('onFocus');
	});
	$('.formsection-normalleft input').focus(function() {
		var p = $('#iphonebuilderwrap').css('opacity', 1);
		$('input').removeClass('onFocus');
	});
	*/
	$("#build_form").validate();
    
	
});