var tracer;
var blogURL = "svc/getBlogPosts.php?url=http://daleyjem.com/wp/?feed=atom&count=1";
var isIE = navigator.userAgent.indexOf("MSIE") > -1;
var browserBuilds = new Array(
	{name: "Chrome",	version: 5,		icon: "chrome.png",		download: ""},
	{name: "Firefox",	version: 3.6,	icon: "firefox.png",	download: ""},
	{name: "Opera", 	version: 10.5,	icon: "opera.png",		download: ""},
	{name: "Safari",	version: 4,		icon: "safari.png",		download: ""}
);

window.onload = function(){
	showBlogRss();
	if (!cookieBrowser && isIE)
	{
		//showBrowserAlert();
	}
}

function closeHeaderAlert()
{
	$("alert_header").style.display = "none";
}

function showBrowserAlert()
{
	var tween = new Tween($("alert_header"));
	tween.position("marginTop", -32, 0, .25);
}

function showTwitter(data){
	data = data[0];
	var postDate = new Date(data.created_at.replace(/^\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)$/, "$1 $2 $4 $3 UTC"));
	var bubble = buildQuoteBubble("quote_bubble_twitter", data.text, "Twitter", postDate.toDateString(), "http://twitter.com/daleyjem", "_blank");
	$("_quote_bubble_twitter").style.display = "block";
	if (isIE)
	{
		bubble.style.visibility = "visible";
		return;
	}
	var tween = new Tween(bubble);
	tween.fadeIn(.5);
}

function showBlogRss(){
	var urlLoader = new URLLoader();
	urlLoader.addEventListener("complete", onBlogLoaded);
	urlLoader.load(new URLRequest(blogURL));
}

function onBlogLoaded(urlLoader)
{
	var data = jsonParse(urlLoader.data);
	data = data[0];
	var postDate = new Date(data.date);
	var bubble = buildQuoteBubble("quote_bubble_blog", data.title, "Blog", postDate.toDateString(), data.link, "_self");
	$("_quote_bubble_blog").style.display = "block";
	if (isIE)
	{
		bubble.style.visibility = "visible";
		return;
	}
	var tween = new Tween(bubble);
	tween.fadeIn(.5);
}

function popEmail(){

}

function buildQuoteBubble(id, quote, source, date, link, target)
{
	var bubble = $(id);
	var containerLink = document.createElement("a");
	containerLink.href = link;
	containerLink.target = target;
	var containerQuote = document.createElement("div");
	containerQuote.className = "quote_bubble_text";
	containerLink.appendChild(document.createTextNode(quote));
	containerQuote.appendChild(containerLink);
	bubble.appendChild(containerQuote);
	var containerFooter = document.createElement("div");
	containerFooter.className = "quote_bubble_footer";
	var sourceSpan = document.createElement("span");
	sourceSpan.className = "quote_bubble_source";
	sourceSpan.appendChild(document.createTextNode(source));
	containerFooter.appendChild(sourceSpan);
	var dateSpan = document.createElement("span");
	dateSpan.className = "quote_bubble_date";
	dateSpan.appendChild(document.createTextNode(date));
	containerFooter.appendChild(dateSpan);
	bubble.appendChild(containerFooter);
	
	if (bubble.className.indexOf("quote_bubble_right") > -1)
	{
		var img = new Image();
		img.src = "images/quote_right.png";
		img.width = 30;
		img.height = 30;
		img.style.position = "absolute";
		!isIE ? img.style.right = "-30px" : img.style.left = bubble.offsetLeft + bubble.offsetWidth - 6 + "px";
		!isIE ? img.style.top = ((bubble.offsetHeight / 2) - 15) + "px" : img.style.top = (((bubble.offsetHeight / 2) - 15) + bubble.offsetTop) + "px";
	}
	else if (bubble.className.indexOf("quote_bubble_left") > -1)
	{
		var img = new Image();
		img.src = "images/quote_left.png";
		img.width = 30;
		img.height = 30;
		img.style.position = "absolute";
		!isIE ? img.style.left = "-30px" : img.style.left = bubble.offsetLeft - img.width + 1 + "px";
		!isIE ? img.style.top = ((bubble.offsetHeight / 2) - 15) + "px" : img.style.top = (((bubble.offsetHeight / 2) - 15) + bubble.offsetTop) + "px";
	}
	
	img.style.display = "none";
	img.id = "_" + id;
	isIE ? bubble.parentNode.appendChild(img) : bubble.appendChild(img);
	
	//var settings = {tl: {radius: 10}, tr: {radius: 10}, bl: {radius: 10}, br: {radius: 10}, antiAlias: true};
    //if (isIE) curvyCorners(settings, bubble);
	
	return bubble;
}

function $(theID)
{
	return document.getElementById(theID);	
}
