Cufon.replace("body:not(.blog) h1", { hover: true });
Cufon.replace("p.tagline, body>.header h2, body>.header .two-columns h3, body:not(.blog)>.content-parent .three-columns h4, .projects h3, .cards h2");
Cufon.replace("body>.header ul.menu li, body:not(.blog)>.content-parent h3", { hover: true });

Cufon.replace("p.tagline, body>.navig h2, body>.navig .two-columns h3, body:not(.blog)>.content-parent .three-columns h4, .projects h3, .cards h2");
Cufon.replace("body>#about #foot #relativ .navig ul.menu li, body:not(.blog)>.content-parent h3", { hover: true });

$("a.contrast").click(function() { $("body").toggleClass("hc"); createCookie("style", $("body").hasClass("hc") ? "hc" : "", 365); return false; });
if (readCookie("style") == "hc" && !$("body").hasClass("hc"))
	$("a.contrast").click();


String.prototype.startsWith = function(start) {
	var str = this.substr(0, Math.min(this.length, start.length));
	return str == start;
};


var
	intro = null
,	introTimer = null
,	introAuto = true
,	introPos = 0
,	introItems = 8
,	introSlideInTime = 2000
,	introSlideOutTime = 1000
,	introItemTime = 13000
,	introRulerStep = Math.round(930 / introItems)
,	introNavH = 0
,	introContentH = 0
,	introW = 0
,	pl = $("body").hasClass("pl")
;


function introStop() { if (introTimer) { clearTimeout(introTimer); introTimer = null; } }


function introPause(dir)
{
	introStop();
	introAuto = !introAuto;
	if (introAuto)
		introPlay();
}


function introPlay() { introStop(); introTimer = setTimeout("introChange()", introItemTime); }


function introChange(dir, manual)
{
	if (!dir)
		dir = 1;

	if (manual)
		introStop();

	var next = intro.find("> .content.current").stop(true).animate({ left: (-dir * introW) + "px" }, introSlideOutTime).removeClass("current");
	next = (dir < 0) ? next.prev(".content") : next.next(".content");
	if (!next.length)
	{
		next = (dir < 0) ? intro.find("> .content:last") : intro.find("> .content:first");
		introPos = (dir < 0) ? introItems - 1 : 0;
	}
	else
		introPos += dir;

	var ruler = intro.find(".ruler > a");
	ruler.stop(true).animate({ left: (introPos * introRulerStep) + "px"}, introSlideInTime);
	if (!next.is(":animated"))
		next.css("left", (dir * introW) + "px");
	next.addClass("current").show().stop(true).animate({ left: "0px" }, introSlideInTime);
	ruler.find("span").text(next.find(".info > span:first").data("info"));
	if (introAuto)
		introPlay();
}


function introChangeTo(item)
{
	var current = intro.find("> .content.current");
	dir = (item > introPos) ? 1 : -1;
	if (introPos != item)
		current.stop(true).animate({ left: (-dir * introW) + "px" }, introSlideOutTime).removeClass("current");
	next = intro.find("> .content:eq(" + item + ")");
	var ruler = intro.find("> .ruler > a");
	ruler.stop(true).animate({ left: (item * introRulerStep) + "px"}, introSlideInTime);
	if (introPos != item)
		next.addClass("current").css("left", (dir * introW) + "px").show().stop(true).animate({ left: "0px" }, introSlideInTime);
	ruler.find("span").text(next.find(".info > span:first").data("info"));
	introPos = item;
}


var tooltip = null;


function tooltipShow(element, text)
{
	tooltip.find("span").text(text);

	var IEOffset = { left: 0 };
	if ($.browser.msie)
		IEOffset = $("body").offset();
	var offset = element.offset();

	tooltip.css({ left: (offset.left + element.width() - IEOffset.left - 10) + "px", top: (offset.top + (element.outerHeight() - tooltip.outerHeight()) / 2) + "px" }).show();
}


var tooltipAlt = null;


function tooltipAltShow(element, text)
{
	var i = text.indexOf(":");
	tooltipAlt.find("span").empty().append("<strong>" + text.substring(0, i + 1) + "</strong> " + text.substring(i + 1));

	var IEOffset = { left: 0 };
	if ($.browser.msie)
		IEOffset = $("body").offset();
	var offset = element.offset();

	tooltipAlt.css({ left: (offset.left + element.width() - IEOffset.left) + "px", top: (offset.top + (element.outerHeight() - tooltipAlt.outerHeight()) / 2) + "px" }).show();
}


/*
** site map magix
*/

$("#site-map:first").clone().prependTo("body");
$(".site-map:last").remove();
var sitemap = $("#site-map");
var sitemapH = -sitemap.outerHeight();
sitemap.css("margin-top", sitemapH + "px").hide();

$("a[href=#site-map]").click(function()
{
	if (sitemap.is(":animated"))
		return false;
	if (sitemap.is(":visible"))
		sitemap.stop(true).animate({ marginTop: sitemapH + "px" }, 750, "swing", function() { $(this).hide(); });
	else
		sitemap.show().stop(true).animate({ marginTop: "0px" }, 750, "swing");
	return false;
});


/*
** tooltip
*/
if ($(".tooltip-alt").length)
{
	$("body").append("<p id=\"tooltip-alt\"><span></span></p>");
	tooltipAlt = $("#tooltip-alt").hide();
	$(".work .work img").hover(function() { tooltipAltShow($(this), $(this).attr("alt")); }, function() { tooltipAlt.hide(); });
}


