$(document).ready(function(){
	
	// fix PNGs for IE6
	$(document).pngFix();
	
	// fix "external" links to open in new window									 
	$('a[rel="external"]').click(function(){
		window.open(this.href);
		return false;
	}).attr('title', 'Opens in New Window or Tab');

	
	// submenu builder
	$('ul.sf-menu').superfish();

	// clear text fields of default values on focus
    $('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('input[type="text"]').blur(function() {
        if ($.trim(this.value == '')){
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });

	// interactions for FAQ list
	$(".faq-list dd").hide();
	$(".faq-list dt").click(function(){
		$(this).toggleClass("faq-active");
		$(this).next("dd").toggle("fast");
    });
			
	// interactions for history timeline
/*			
	$(".history-timeline dd").hide();
	$(".history-timeline dt").hover(function(){
		$(this).toggleClass("time-active");
		$(this).next("dd").show("fast");
    },function(){
		$(this).toggleClass("time-active");
		$(this).next("dd").hide("fast");
	});
	*/
	
	
	// interactive timeline
	var minPos = 0;
	var maxPos = 1000;
	var currPos = 0;
	var increment = 334; // pixel shift left or right
	$("a.history-left").fadeOut("fast");
	
	$("a.history-left").click(function(){
		currPos = parseInt($(".timeline-top").css("margin-left").replace("px",""));
		if ( currPos < minPos ) {
			$(".timeline-top").animate({
					marginLeft: "+="+increment+"px"
				},500);
			$(".timeline-bottom").animate({
					marginLeft: "+="+increment+"px"
				},500);
			$("a.history-right").fadeIn("fast");
		} else {
			$("a.history-left").fadeOut("fast");
		}
		return false;
	});
	$("a.history-right").click(function(){
		currPos = parseInt($(".timeline-top").css("margin-left").replace("px",""));
		if ( currPos > -maxPos ) {
			$(".timeline-top").animate({
					marginLeft: "-="+increment+"px"
				},500);
			$(".timeline-bottom").animate({
					marginLeft: "-="+increment+"px"
				},500);
			$("a.history-left").fadeIn("fast");
		} else {
			$("a.history-right").fadeOut("fast");
		}
		return false;
	});
	
	
	
	// notable project slideshow
	$("#slideshow").cycle({
		fx:		'fade',
		pause:	1,
    	pager:  '#slideshow-nav', 
		// callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        	return '#slideshow-nav li:eq(' + idx + ') a'; 
		} 
	});
	
	// interactions for location map
	$("map.locations").append("<div id='locationTipContent'></div>");
	$("area.locationTip").hover(function(){
		$("#locationTipContent").text($(this).attr('alt')).fadeIn("fast");
	},function(){
		$("#locationTipContent").fadeOut("fast");
	});
	
	$(".tooltip-only").click(function(){ return false; });

	// interactions for country flag map
   $('area.tooltip').each(function()
   {
      $(this).qtip(
      {
         content: $(this).attr('alt'), // Use the ALT attribute of the area map
		 position: { corner: 'topMiddle', adjust: { x: 0, y: 25 } },
         style: {
            name: 'light',
			color: '#F00',
            border: {
               width: 0, 
               radius: 0
            }, 
            tip: false // Apply a tip at the default tooltip corner
         }
      });
   });
	
});

