function pageDimensions() {var x,y;if (self.innerHeight) {x = self.innerWidth;y = self.innerHeight;} else if (document.documentElement && document.documentElement.clientHeight) {x = document.documentElement.clientWidth;y = document.documentElement.clientHeight;} else if (document.body) {x = document.body.clientWidth;y = document.body.clientHeight;}return [x,y];}
function scrollOffset() {var x,y;if (self.pageYOffset) {x = self.pageXOffset;y = self.pageYOffset;} else if (document.documentElement && document.documentElement.scrollTop) {x = document.documentElement.scrollLeft;y = document.documentElement.scrollTop;} else if (document.body) {x = document.body.scrollLeft;y = document.body.scrollTop;}return [x, y]}

var embed = '<object type="application/x-shockwave-flash" allowScriptAccess="never" allowNetworking="internal" height="200" width="350" data="http://www.joombly.com/flv/countdown.swf"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="http://www.joombly.com/flv/countdown.swf" /><param name="quality" value="high" />';

var alerta = 0;
var change = 0;

$(document).ready(function() {
	// color de los colores :P
	$("#t").css("background-color","#"+ $("#ct").val());
	$("#b").css("background-color","#"+ $("#cb").val());
	$("#f").css("background-color","#"+ $("#cf").val());
						   
	$(".color_picker").click(function() {
		if ($(this).attr("id") == "f") {
			if ($("#image-move").css("display") == "none")
				change = 1;
			mypickcolor("#cf", "#f", 'f',this);	
		}
		else
			mypickcolor("#c" + $(this).attr("id"), "#" + $(this).attr("id"), '',this);
	});
	
	$("#msg").blur(function() {
		reloadFlash();						
	});
	$("#fx").change(function() {
		reloadFlash();						 
	});
	
	$(".time").change(function() {
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth() + 1;
		var day = now.getDate();
		var hh = now.getHours();
		var mm = now.getMinutes();
		
		if ($("#year").val() < year) {
			if (alerta == 0)
				alert("La fecha debe ser mayor a la fecha actual");
			alerta = 1;
			return false;
		}
		else if ($("#year").val() == year) {
			if ($("#month").val() < month) {
				if (alerta == 0)
					alert("La fecha debe ser mayor a la fecha actual");
				alerta = 1;
				return false;
			}
			else if ($("#month").val() == month) {
				if ($("#day").val() < day) {
					if (alerta == 0)
						alert("La fecha debe ser mayor a la fecha actual");
					alerta = 1;
					return false;
				}
				else if ($("#day").val() == day) {
					if ($("#timezone").val() == "AM")
						mul = 1;
					else
						mul = 2;
					if ($("#hour").val() * mul < hh) {
						if (alerta == 0)
							alert("La fecha debe ser mayor a la fecha actual");
						alerta = 1;
						return false;
					}
					else if ($("#hour").val() * mul == hh) {
						if ($("#minutes").val() <= mm) {
							if (alerta == 0)
								alert("La fecha debe ser mayor a la fecha actual");
							alerta = 1;
							return false;
						}
					}
				}
			}
		}
		
		var result = '';
		$(".time").each(function() {
			var str = $(this).val();
			if ($(this).attr("id") == "hour")
				result += "-";
			if ($(this).attr("id") == "minutes")
				result += ":";
			if ($(this).attr("id") == "timezone")
				result += "-";
			if (str.length == 1)
				result += "0" + str;
			else
				result += str;
		});
		$("#dt").val(result);
		reloadFlash();
	});
	
	$("#result").click(function() {
		$(this).focus();				
		$(this).select();							
	});
	
	$("#cmCloseButton").click(function() {
		$("#ColourMod").hide();
		if (change == 0)
			reloadFlash();
		else
			$("#submit").click();
		return false;
	});
});

function reloadFlash() {
	var result = embed + '<param name="flashvars" value="';
	$(".option").each(function() {
		result += "&" + $(this).attr("id") + "=" + $(this).attr("value");					   
	});
	result += '" /></object><br/><a href="http://www.joombly.com/flash-countdown" target="_blank" title="Flash Countdowns para Myspace">Flash Countdowns</a>';
	$("#flash-content").html(result);
	$("#result").val(result);
}