﻿var is_focused = false;
function go(){
	$("#s").focus(start_craze);
	$("#s").blur(stop_craze);
	$(".post object").each(fix_flash);
	$("h2 a, .random_bg, .comment-author").each(function(){
		var cls = "rand_col_"+Math.round(Math.random()*9);
		//alert(cls);
		$(this).addClass(cls);
	})
	$(".square_post, .gallery_post").each(function(){
		//alert("hi");
		$(this).find(".post-meta-key").remove();
		var img = $(this).find(".data .post-meta li").html();
		if(img != null){
			$(this).find(".image").html("<img src=\""+img+"\" />");
		}
	})
	$("h1").text($("h1").text().replace("Category Archives: ",""));
	if($("body").hasClass("single")){
		setup_form();
	}
	$("#content").removeClass("hide")
	$("a.subscribe").click(signUp);
}
//
function start_craze(){
	is_focused = true;	
	change_colour();
}
//
function change_colour(){
	if(is_focused){
		$("#search").css({
			'background-color':random_colour()
		});
		setInterval(change_colour, 500);
	}
}
//
function showFlashDiv(id)
 {
	 //#TODO: this is not working-check jquery syntax/ids exist etc
		$(id).css('bottom',"0px");
}

function hideFlashDiv(id)
 {
	//alert('hide div '+$(id));
	//#TODO: this is not working-check jquery syntax/ids exist etc
		$(id).css('bottom',"-600px");
}


function stop_craze(){
	is_focused = false;
}
//
function fix_flash(){
	$(this).width(450);
}
//
function random_colour(){
	colors = new Array(14)
	colors[0]="0"
	colors[1]="1"
	colors[2]="2"
	colors[3]="3"
	colors[4]="4"
	colors[5]="5"
	colors[5]="6"
	colors[6]="7"
	colors[7]="8"
	colors[8]="9"
	colors[9]="a"
	colors[10]="b"
	colors[11]="c"
	colors[12]="d"
	colors[13]="e"
	colors[14]="f"

	digit = new Array(5)
	color=""
	for (i=0;i<6;i++){
		digit[i]=colors[Math.round(Math.random()*14)]
		color = color+digit[i]
	}
	
	return "#"+color;
}
//
function setup_form(){
	var author_d = "name*";
	var email_d = "email*";
	var url_d = "website";
	var comments_d = "comment";
	$(".form-label").addClass("hide");
	if($("#author").val() == ""){
		$("#author").val(author_d);
	}
	if($("#email").val() == ""){
		$("#email").val(email_d);
	}
	if($("#url").val() == ""){
		$("#url").val(url_d);
	}
	if($("#comment").val() == ""){
		$("#comment").val(comments_d);
	}
	//
	$("#author").focus(function(){
		if($(this).val() == author_d){
			$(this).val("");
		}
	});
	$("#author").blur(function(){
		if($(this).val() == ""){
			$(this).val(author_d);
		}
	});
	//
	$("#email").focus(function(){
		if($(this).val() == email_d){
			$(this).val("");
		}
	});
	$("#email").blur(function(){
		if($(this).val() == ""){
			$(this).val(email_d);
		}
	});
	//
	$("#url").focus(function(){
		if($(this).val() == url_d){
			$(this).val("");
		}
	});
	$("#url").blur(function(){
		if($(this).val() == ""){
			$(this).val(url_d);
		}
	});
	//
	$("#comment").focus(function(){
		if($(this).val() == comments_d){
			$(this).val("");
		}
	});
	$("#comment").blur(function(){
		if($(this).val() == ""){
			$(this).val(comments_d);
		}
	});

}
//
/* <form action="http://resn.createsend.com/t/r/s/hlhtit/" method="post">
<div>
<label for="hlhtit-hlhtit">Email:</label><br /><input type="text" name="cm-hlhtit-hlhtit" id="hlhtit-hlhtit" /><br />

<input type="submit" value="Subscribe" />
</div>
</form>
*/
function signUp(){
	var ezizzle = prompt("Giz your email address!", "")
	if(ezizzle != "" && ezizzle != null & ezizzle != undefined){
		/*
		$.post("http://resn.createsend.com/t/r/s/hlhtit/", {"cm-hlhtit-hlhtit":String(ezizzle), something:true}, function(data){
			alert("????");
		});
		alert("Thanks bro!");
		*/
		$.ajax({
			type: 'POST',
			url: "http://resn.createsend.com/t/r/s/hlhtit/",
			data: {
				'cm-hlhtit-hlhtit':String(ezizzle)
			},
			success: function(D){
				alert(D);
			}
		});
	}
	return false;
}
//
$(document).ready(go);
