/*!
 * jQuery Taconite plugin - A port of the Taconite framework by Ryan Asleson and
 *     Nathaniel T. Schutta: http://taconite.sourceforge.net/
 *
 * Examples and documentation at: http://malsup.com/jquery/taconite/
 * Copyright (c) 2007-2011 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Thanks to Kenton Simpson for contributing many good ideas!
 *
 * @version: 3.59  18-MAR-2011
 * @requires jQuery v1.2.6 or later
 */
(function(f){var e="3.59";f.taconite=function(y){j(y)};f.taconite.debug=0;f.taconite.autodetect=true;f.taconite.defaults={cdataWrap:"div"};f.fn.replace=f.fn.replace||function(y){this.after(y);this.remove()};f.fn.replaceContent=f.fn.replaceContent||function(y){return this.empty().append(y)};f.expr[":"].taconiteTag=function(y){return y.taconiteTag===1};f.taconite.enableAutoDetection=function(y){f.taconite.autodetect=y;if(t){f.httpData=y?t:s}};var k=0;function h(){if(!f.taconite.debug||!window.console||!window.console.log){return}!k++&&h("Plugin Version: "+e);window.console.log("[taconite] "+[].join.call(arguments,""))}var b=f.parseJSON||function(y){return window["eval"]("("+y+")")};function a(D,B,A){var z=D.getResponseHeader("content-type")||"",y=B==="xml"||!B&&z.indexOf("xml")>=0,C=y?D.responseXML:D.responseText;if(y&&C.documentElement.nodeName==="parsererror"){f.error&&f.error("parsererror")}if(A&&A.dataFilter){C=A.dataFilter(C,B)}if(typeof C==="string"){if(B==="json"||!B&&z.indexOf("json")>=0){C=b(C)}else{if(B==="script"||!B&&z.indexOf("javascript")>=0){f.globalEval(C)}}}return C}function x(A,z,y){if(t){return t(A,z,y)}return A.responseXML||A.responseText}function s(C,A,z){var y=C.getResponseHeader("content-type");if(f.taconite.debug){h("[AJAX response] content-type: ",y,";  status: ",C.status," ",C.statusText,";  has responseXML: ",C.responseXML!=null);h("type arg: "+A)}var B=x(C,A,z);if((B&&B.documentElement&&B.documentElement.nodeName!="parsererror")||typeof B=="string"){f.taconite(B)}else{h("jQuery core httpData returned: "+B);h('httpData: response is not XML (or not "valid" XML)')}return B}f.ajaxPrefilter&&f.ajaxPrefilter(function(y,A,z){z.success(function(D,B,C){if(f.taconite.autodetect){s(C,y.dataType,y)}})});var t=f.httpData;if(f.httpData){f.httpData=s}var g={json:m};f.taconite.registerParser=function(z,y){g[z]=y};function l(y,z){var A=z,B=g[y];if(f.isFunction(B)){A=B(z)}f.event.trigger("taconite-rawdata-notify",[y,A,z]);return A}function m(y){return b(y)}function j(B){var z=true,C;try{if(typeof B=="string"){B=i(B)}if(!B){h("$.taconite invoked without valid document; nothing to process");return false}var y=B.documentElement.tagName;h("XML document root: ",y);var A=f("taconite",B)[0];if(!A){h("document does not contain <taconite> element; nothing to process");return false}f.event.trigger("taconite-begin-notify",[A]);z=p(A)}catch(D){z=C=D}f.event.trigger("taconite-complete-notify",[B,!!z,z===true?null:z]);if(C){throw C}}function i(z){var B;h("attempting string to document conversion");try{if(window.DOMParser){var C=new DOMParser();B=C.parseFromString(z,"text/xml")}else{B=f("<xml>")[0];B.async="false";B.loadXML(z)}}catch(A){if(window.console&&window.console.error){window.console.error("[taconite] ERROR parsing XML string for conversion: "+A)}throw A}var y=B&&B.documentElement&&B.documentElement.tagName!="parsererror";h("conversion ",y?"successful!":"FAILED");return B}function p(y){try{var z=new Date().getTime();n(y.childNodes);f.taconite.lastTime=(new Date().getTime())-z;h("time to process response: "+f.taconite.lastTime+"ms")}catch(A){if(window.console&&window.console.error){window.console.error("[taconite] ERROR processing document: "+A)}throw A}return true}function n(C){var J={wrap:1};var N=0;var L,E,O,I,H,B,G,M,K,z,D,A;for(I=0;I<C.length;I++){if(C[I].nodeType!=1){continue}var y=C[I],F=y.tagName;if(F=="eval"){B=(y.firstChild?y.firstChild.nodeValue:null);h('invoking "eval" command: ',B);if(B){f.globalEval(B)}continue}if(F=="rawData"){M=(y.firstChild?y.firstChild.nodeValue:null);K=y.getAttribute("type");h("rawData ("+K+"): ",M);l(K,M);continue}z=y.getAttribute("select");D=f(z);if(!D[0]){h("No matching targets for selector: ",z);continue}A=y.getAttribute("cdataWrap")||f.taconite.defaults.cdataWrap;L=[];if(y.childNodes.length>0){N=1;for(H=0,G=[];H<y.childNodes.length;H++){G[H]=w(y.childNodes[H],A)}L.push(J[F]?u(G):G)}E=y.getAttribute("name");O=y.getAttribute("value");if(E!==null){L.push(E)}if(O!==null){L.push(O)}for(var H=1;true;H++){O=y.getAttribute("arg"+H);if(O===null){break}var E=Number(O);if(O==E){O=E}L.push(O)}f.taconite.debug&&r(z,F,L,G);D[F].apply(D,L)}N&&q()}function r(D,C,y,B){var A="...";if(!B){A="";for(var z=0,E=y[0];z<y.length,E=y[z];z++){z>0&&(A+=",");typeof E=="string"?(A+=("'"+E+"'")):(A+=E)}}h("invoking command: $('",D,"').",C,"("+A+")")}function q(){if(f.browser.mozilla){return}f("select:taconiteTag").each(function(){var y=this;f("option:taconiteTag",this).each(function(){this.setAttribute("selected","selected");this.taconiteTag=null;if(y.type=="select-one"){var z=f("option",y).index(this);y.selectedIndex=z}});this.taconiteTag=null})}function u(A){for(var z=0,y=[];z<A.length;z++){if(A[z].nodeType==1){y.push(A[z])}}return y}function w(A,y){var z=A.nodeType;if(z==1){return o(A,y)}if(z==3){return v(A.nodeValue)}if(z==4){return c(A.nodeValue,y)}return null}function c(C,y){var B=document.createElement(y);var A=f(B),z=A.children();A[y=="script"?"text":"html"](C);if(z.size()==1){return z[0]}return B}function v(y){if(f.browser.msie){y=y.replace(/\n/g,"\r").replace(/\s+/g," ")}return document.createTextNode(y)}function o(B,y){var D,G=B.tagName.toLowerCase();if(f.browser.msie&&f.browser.version<9){var E=B.getAttribute("type");if(G=="table"||E=="radio"||E=="checkbox"||G=="button"||(G=="select"&&B.getAttribute("multiple"))){D=document.createElement("<"+G+" "+d(null,B,true)+">")}}if(!D){D=document.createElement(G);d(D,B)}if(f.browser.msie&&G=="td"){var A=B.getAttribute("colspan");if(A){D.colSpan=parseInt(A)}}if(f.browser.msie&&!D.canHaveChildren){if(B.childNodes.length>0){D.text=B.text}}else{for(var C=0,F=B.childNodes.length;C<F;C++){var z=w(B.childNodes[C],y);if(z){D.appendChild(z)}}}if(!f.browser.mozilla){if(G=="select"||(G=="option"&&B.getAttribute("selected"))){D.taconiteTag=1}}return D}function d(B,E,D){for(var C=0,y="";C<E.attributes.length;C++){var z=E.attributes[C],F=f.trim(z.name),A=f.trim(z.value);if(D){y+=(F+'="'+A+'" ')}else{if(F=="style"){B.style.cssText=A;B.setAttribute(F,A)}else{f.attr(B,F,A)}}}return y}})(jQuery);

var aitools = {
		extensions: {
			projectsfilter: {
				ajaxGet: function(url) {
					var $ajaxloader = $("#projects .ajaxloader");					

					$ajaxloader.height($("#projects .entries").height()+26).css("left", "0");

					$.get(url, function() {
						$ajaxloader.css("left", "-9999px");
					});
				},
				init: function() {
					$("#projects").append("<div class=\"ajaxloader\" />");

					//$("#projectsfilter .filter > a").click(function() { return false; });

					//$('#projectsfilter a.dropdown-label').click(function(){ return false;});
					$("#projectsfilter a:not(.dropdown-label), #allprojects_link").click(function() {
					
						var rel = $(this).attr('rel');
						var label;
						var show_all_link = true;
						
						switch (rel){
							case 'projecttype':
							case 'projectrole':
							case 'projectlocation':
								label = [ 'Featured ', $(this).text() , ' Properties'].join('');
							break;
							case 'all':
								label ='All Featured Properties';
								show_all_link = false;
							break;
							default:
								label = $(this).text();
							break;
						}
						$('#projects-viewing').text( label);
						aitools.extensions.projectsfilter.ajaxGet($(this).attr("href"));
						if(show_all_link){
							$('#allprojects_link_wrap').fadeIn();
						}else{
							$('#allprojects_link_wrap').fadeOut('fast');
						}
						
						return false;
					});

					$("#projectsfilter form").submit(function() {
						$('#projects-viewing').text('Search results for "'+$('#project_text_search').val()+'"');
						$('#allprojects_link_wrap').fadeIn();
						nibbi.extensions.projectsfilter.ajaxGet($(this).attr("action")+"?"+$(this).serialize());
						return false;
					});
				}
			}
		}
	}

/* Author: Roi Kingon | Active Ingredients 

*/
$(function() {
	//Homepage Hero
	var isHovered = false;
	function setHero(a) {
		if(isHovered){
			$(a).filter("li:eq(1)").css("cursor", "pointer").find('div').fadeIn();
		}
		$(a).filter("li:eq(1)").data("allowHover", "yes").find('img').stop(true, true).animate({
			opacity: 1
		},'fast');
	}
	function resetHero(a) {
		$(a).data("allowHover", "no").siblings().find('img').stop(true, true).animate({
			opacity: .7
		});
		$(a).css("cursor", "default");
	}
	
	$("#hero").jCarouselLite({
		start: 0,
		circular: true,
		visible: 3,
		btnGo: [".hero1",".hero2",".hero3",".hero4"],
		speed: 500,
		auto: 7000,
		afterEnd: function(a) {
			resetHero(a);
			var slide = $(a).attr('rel');
       		$(".hero-controller").find("a").removeClass("activeSlide").parent().find("."+slide).addClass("activeSlide");
			setHero(a);
    	},
		beforeStart: function(a){
			resetHero(a);
		}
    }).find('li').hover(function() {
		isHovered = true;
	}, function() {
		isHovered = false;
	}).data('allowHover', 'no').filter(".activeSlide").data('allowHover', 'yes');
	
	//Investment Map
	$("area", "#investmap").each(function() {
		var overlay = $(".investment_overlays");
		$(this).hover(function() {
			var city = $(this).attr('alt');
			overlay.find("."+city).show();
		},function() {
			overlay.children().hide();
		});
	});
	
	//Generic Overlay
	$(".hasOverlay").each(function() {
		$(this).hover(function() {
			if($(this).data('allowHover') != "no") {
			$(this).find(".overlay").stop(true,true).fadeIn();}
		}, function() {
			$(this).find(".overlay").stop(true,true).fadeOut('fast');
			isHovered = false;
		});
	});
	
	//Image Trans
	$(".img-trans").parent().hover(function() {
		$(this).find('.img-trans').stop(true,true).animate({
			opacity: 1
		}, 'fast');
	},function() {
		$(this).find('.img-trans').stop(true,true).animate({
			opacity: .8
		});
	}, 'fast');
	
	//Promo Slider
	$(".imagepromo").each(function() {
		timeout = ($(this).hasClass('auto')) ? 8000 : false;
		pager = $(this).parent().find('.promo-pager');
		$(this).cycle({
			fx:     'fade',
			sync: true,
			speed:  1000,
			timeout: timeout,
			pause: true,
			pager:  pager,
			pauseOnPagerHover: 1
		});
	});
	
	//Directions
	$(".directions").directions(); // See plugins.js
	//Case Study
	$(".casestudy").casestudy(); // See plugins.js
	//Graph
	$(".graph").investGraph(); // See plugins.js
	//Timeline Table
	$('.historical-timeline').timelineTable(); // See plugins.js
	//More News
	$('.morenews').morenews(); // See plugins.js
	//Linkable
	$('.linkable').linkable();
	
	$("span.dropdown").bind('click mouseenter', function() {
		if($(this).data("status") != "open"){
			$(this).children("ul").inView({effect:'show'});
			$(this).data("status","open");
			$(document).bind('touchend.dd', function(e) {
				if (!$(e.target).parents().is(".dropdown") ) {
					$("span.dropdown").data("status","closed").children("ul").hide();
					$(document).unbind('.dd');
				}
			});
		}
	});
	$("span.dropdown").bind('mouseleave', function() {
		$("span.dropdown").data("status","closed").children("ul").hide();
		$(document).unbind('.dd');
	});
	
	//Timeline
	$(".timeline").setScrollWidth();
	$(".scroller").jScrollPane({
		horizontalDragMinWidth: 46,
		horizontalDragMaxWidth: 46		
	});
	
	var direction;
	$("div.tabnav>a.next").click(function() { direction = "next"; return false; });
	$("div.tabnav>a.prev").click(function() { direction = "prev"; return false; });
	
	//Performance Tabs
	$('div.panes').tabs();
	$("#performance").jCarouselLite({
		start: 0,
		circular: true,
		visible: 3,
		scroll: 3,
		btnNext: ".next",
        btnPrev: ".prev",
		speed: 500,
		beforeStart: function(a){
			//$('div.panes').tabs(direction);
		}
    });
	
	aitools.extensions.projectsfilter.init();

});






















