Cufon.replace("body>.header .two-columns h3,body>.content h1, .projects h3, body>.content h2, body>.content h3"); 
Cufon.replace("body>.header #tag_words2"); 
Cufon.replace("body>.header #tag_words3"); 
Cufon.replace("body>.header #tag_words");
Cufon.replace("h5");
Cufon.replace("body>.header .glarge", { hover: true  });
				
 
 
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;



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").text());
	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").text());
	introPos = item;
}

 

/*
** site map 
*/

$("#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;
});

 

/*
** intro stuff
*/
intro = $(".intro");
if (intro.length)
{
	$.getJSON("data/intro.js", function(json)
	{
		intro.addClass("intro-scripted");
		var introNav = intro.find("> .navigation > ul");

		// data loaded from JSON, now inject it to the HTML
		for (var i = 0; i < introItems; i++)
		{
			var item = intro.find("> .content:first").clone().insertBefore(intro.find("> .ruler"));
			item.find("> .photo img").attr("src", "data/intro/" + json.items[i].file + ".png").attr("alt", json.items[i].info);
			item.find("> h2").html(json.items[i].title);
			var info = item.find("> .info");
			info.find("> span").text(json.items[i].info);
			if (json.items[i].visit)
				info.find("> a").attr("href", json.items[i].visit).text(pl ? "Visit" : "Visit");
			else
				info.find("> a").attr("href", json.items[i].work).text(pl ? "See project" : "See project");
			info.find("~ p").remove();
			for (t in json.items[i].text)
				item.append("<p>" + json.items[i].text[t] + "</p>");
		}

		Cufon.replace(".intro h2");
		Cufon.replace(".intro p");

		intro.find("> .content:first").remove();

		// make navigation work
		introNav.find("> li:first").after("<li><a class=\"pause\" href=\"#\">|| / [&gt;</a></li>");
		introNavH = -introNav.outerHeight() - intro.find("> .navigation > p").outerHeight();
		introNav.css("margin-top", introNavH + "px").hide();
		intro.find("> .navigation")
			.bind("mouseenter", function() { introNav.show().stop(true).animate({ marginTop: "0px" }, 350, "swing"); })
			.bind("mouseleave", function() { introNav.stop(true).animate({ marginTop: introNavH + "px" }, 150, "swing", function() { $(this).hide(); }); });

		// content sliding
		introContentH = 0;
		introW = intro.find("> .content:first").addClass("current").outerWidth();
		intro.find("> .content").each(function() { introContentH = Math.max($(this).outerHeight(), introContentH); }).not(":first").hide();
		intro.height(introContentH + 30);

		//intro.append("<div class=\"fade-left\"></div><div class=\"fade-right\"></div>");
		//intro.find("> .fade-left, > .fade-right").height(intro.find("> .content").outerHeight());

		// handle clicking on previous and next buttons
		intro.find("> .navigation a.previous").click(function() { introChange(-1, true); return false; });
		intro.find("> .navigation a.next").click(function() { introChange(1, true); return false; });
		intro.find("> .navigation a.pause").click(function() { $(this).toggleClass("play"); introPause(); return false; });

		intro.find("> .ruler").css("padding-top", (introContentH + 10) + "px").find("a").css("left", (introPos * introRulerStep) + "px")
			.bind("dragstart dragend", function()
			{
				$(this).stop(true).toggleClass("drag");
				introStop();
			})
			.bind("drag", function(event)
			{
				var offset = $(this).parent().offset();
				var max_x = (introItems - 1) * introRulerStep;
				var x = Math.min(max_x, Math.max(0, event.offsetX - offset.left - 34));
				$(this).css("left", x + "px");
				x = Math.round(x / introRulerStep);
				$(this).find("span").text(intro.find("> .content:eq(" + x + ") .info > span:first").text());
			})
			.bind("dragend", function(event)
			{
				var offset = $(this).parent().offset();
				var max_x = (introItems - 1) * introRulerStep;
				var x = Math.round(Math.min(max_x, Math.max(0, event.offsetX - offset.left - 34)) / introRulerStep);
				introChangeTo(x);
				if (introAuto)
					setTimeout("introPlay()", introSlideInTime + 1000);
			});

		introPlay();

		if ($.browser.msie && $.browser.version < 7)
			intro.find("> .ruler > a").attr("href", "#").click(function() { return false; });
	});
}


 


var testimonials = $(".testimonials");
if (testimonials.length)
{
	testimonials.append("<ul class=\"numbers\"></ul>");
	var h = 0;
	testimonials.find("> ul:not(.numbers) > li").each(function(i)
	{
		h = Math.max(h, $(this).outerHeight());
		$(this).attr("id", "testimonial-" + i);
		testimonials.find(".numbers").append("<li><a href=\"#testimonial-" + i + "\">" + (i + 1) + "</a></li>");
	});
	testimonials.find("> ul:not(.numbers)").height(h);

	testimonials.find(".numbers a").click(function(event, fast)
	{
		if ($(this).hasClass("selected"))
			return false;

		$(this).parents(".numbers").find("a.selected").removeClass("selected");
		$(this).addClass("selected");

		if (fast)
		{
			$(this).parents(".testimonials").find("> ul:not(.numbers) > li:visible").hide();
			$($(this).hrefId()).show();
		}
		else
		{
			$(this).parents(".testimonials").find("> ul:not(.numbers) > li:visible").fadeOut(500);
			$($(this).hrefId()).animate({ opacity: "show" }, 500, "linear", function() { if ($.browser.msie && $.browser.version == 7) this.style.removeAttribute("filter"); });
		}

		return false;
	});

	testimonials.find(".numbers a:first").trigger("click", true);
}


 
if ($.isFunction($("input.date").DatePicker))
	$("input.date").DatePicker
	({
		eventName: "focus"
	,	date: ""
	,	onBeforeShow: function() { $("input.date").DatePickerSetDate($("input.date").val(), true); }
	,	onChange: function(formated, dates) { $("input.date").val(formated); }
	});








 jQuery(function($){ // JDOCKS setup
				 
				 
		$('div.demo').children().click(function(ev){
				var wrapper = $(this).parent().parent()
					, label = wrapper.find('.jqDockLabel').text() || ''
					, t = [
							'you clicked on'
						, '#' + wrapper.closest('.jqDocked').attr('id') + ', option ' + (wrapper.index()+1)
						];
				if(label){ t.push('"' + label + '"'); }
    		$('#showClicked').stop().hide().css({opacity:1}).html(t.join('<br />')).show().fadeOut(5000);
				this.blur();
				return false;
      });
		var changeSource = function(i){
				//use the 'alt' attribute if present, else construct a PNG path from the 'src'...
				return (this.alt) ? false : this.src.replace(/(jpg|gif)$/,'png');
			}
			//options are only set/shown where they differ from the defaults...
			, demoOpts = [
				// #menu1 : horizontal, labelled, with expanding image set by function...
		    {labels:true, source:changeSource}
		    // #menu2 : vertical, reduced distance, centered labels, 4 second inactivity...
		  , {align:'right', distance:60, labels:'mc', inactivity:4000}
		  	// #menu3 : horizontal, reduced distance, labelled...
		  , {align:'top', distance:60, labels:true,}
		  	// #menu4 : horizontal, linear coefficient, labelled at bottom-right...
		  , {align:'middle', coefficient:1, labels:true}
		  	// #menu5 : vertical, labelled...
		  , {align:'left', labels:true}
		  	// #menu6 : vertical, bigger 'at rest' size, increased distance...
		  , {align:'center', size:60, distance:80}
				// #menu7 : horizontal, smaller 'at rest' size, reduced distance, fading in over 1 second, with expanding image set by function...
		  , {size:50, distance:54, fadeIn:1000,labels:true}
		  ];
    //apply jqDock to each of the demo menus, setting the options (as specified above) for each one...
    $('div.demo').each(function(i){
    		$(this).jqDock(demoOpts[6]);
      });
  });


