
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


// place any jQuery/helper plugins in here, instead of separate, slower script files.

// l10n.js

function convertEntities(b){var d,a;d=function(c){if(/&[^;]+;/.test(c)){var f=document.createElement("div");f.innerHTML=c;return !f.firstChild?c:f.firstChild.nodeValue}return c};if(typeof b==="string"){return d(b)}else{if(typeof b==="object"){for(a in b){if(typeof b[a]==="string"){b[a]=d(b[a])}}}}return b};

// Easy Slider v1.7

/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="img/01.jpg" alt="" /></li>
 *			<li><img src="img/02.jpg" alt="" /></li>
 *			<li><img src="img/03.jpg" alt="" /></li>
 *			<li><img src="img/04.jpg" alt="" /></li>
 *			<li><img src="img/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls',
			project:		"project"			
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);
			
			// Make controls project specific
			var prevId = "prev-"+options.project;
			var nextId = "next-"+options.project;
			var numericId = "controls-"+options.project;
						
			
			if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};				
			
			if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				
					html += '<ol id="'+ numericId +'" class="clearfix"></ol>';
				
					if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					html += ' <div class="prevNextControls clearfix">';
					html += ' <span class="slideshowBtn prevBtn" id="'+ prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					html += ' <span class="slideshowBtn nextBtn" id="'+ nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					html += ' </div>';
					if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};			
			
												
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			
				$("a","#"+nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
		
			
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + numericId).removeClass("current");
				$("li#" + numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;													
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = parseInt(dir);							
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							$("a","#"+nextId).hide();
							$("a","#"+options.lastId).hide();
						} else {
							$("a","#"+nextId).show();
							$("a","#"+options.lastId).show();					
						};
						if(t==0){
							$("a","#"+prevId).hide();
							$("a","#"+options.firstId).hide();
						} else {
							$("a","#"+prevId).show();
							$("a","#"+options.firstId).show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);

// Flickr Feed

/*
* Copyright (C) 2009 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/jquery-flickr-plugin
*
* Available tags for templates:
* title, link, date_taken, description, published, author, author_id, tags, image*
*/
(function($) {
	$.fn.jflickrfeed = function(settings, callback) {
		settings = $.extend(true, {
			flickrbase: 'http://api.flickr.com/services/feeds/',
			feedapi: 'photos_public.gne',
			limit: 20,
			qstrings: {
				lang: 'en-us',
				format: 'json',
				jsoncallback: '?'
			},
			cleanDescription: true,
			useTemplate: true,
			itemTemplate: '',
			itemCallback: function(){}
		}, settings);

		var url = settings.flickrbase + settings.feedapi + '?';
		var first = true;

		for(var key in settings.qstrings){
			if(!first)
				url += '&';
			url += key + '=' + settings.qstrings[key];
			first = false;
		}

		return $(this).each(function(){
			var $container = $(this);
			var container = this;
			$.getJSON(url, function(data){
				$.each(data.items, function(i,item){
					if(i < settings.limit){
					
						// Clean out the Flickr Description
						if(settings.cleanDescription){
							var regex = /<p>(.*?)<\/p>/g;
							var input = item.description;
							if(regex.test(input)) {
								item.description = input.match(regex)[2]
								if(item.description!=undefined)
									item.description = item.description.replace('<p>','').replace('</p>','');
							}
						}
						
						// Add Image Sizes
						// http://www.flickr.com/services/api/misc.urls.html
						item['image_s'] = item.media.m.replace('_m', '_s');
						item['image_t'] = item.media.m.replace('_m', '_t');
						item['image_m'] = item.media.m.replace('_m', '_m');
						item['image'] = item.media.m.replace('_m', '');
						item['image_b'] = item.media.m.replace('_m', '_b');
						delete item.media;
						
						// Use Template
						if(settings.useTemplate){
							var template = settings.itemTemplate;
							for(var key in item){
								var rgx = new RegExp('{{' + key + '}}', 'g');
								template = template.replace(rgx, item[key]);
							}
							$container.append(template)
						}
						
						//itemCallback
						settings.itemCallback.call(container, item);
					}
				});
				if($.isFunction(callback)){
					callback.call(container, data);
				}
			});
		});
	}
})(jQuery);

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/*
 * visualNavigation (visualNav) v2.1.2 minified
 * http://wowmotty.blogspot.com/2010/07/visual-navigation.html
 *
 * Copyright (c) 2010 Rob Garrison (aka Mottie & Fudgey)
 * Dual licensed under the MIT and GPL licenses.
 *
 * Plugin base: http://starter.pixelgraphics.us/
 */

(function(b){b.visualNav=function(d,g){var a=this;a.$el=b(d);a.el=d;a.$el.data("visualNav",a);a.w=window;a.win=b(a.w);a.doc=b(document);var k="html, body";b("html, body").each(function(){var c=b(this).attr("scrollTop");b(this).attr("scrollTop",c+1);if(b(this).attr("scrollTop")===c+1){k=this.nodeName.toLowerCase();b(this).attr("scrollTop",c);return false}});a.body=b(k);a.init=function(){a.options=b.extend({},b.visualNav.defaultOptions,g);a.body.bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(c){if(c.which>0||c.type==="mousedown"||c.type==="mousewheel")a.body.stop()});a.$el.find(a.options.link).add(b("."+a.options.contentLinks)).click(function(){var c=this.tagName==="A"?"href":a.options.targetAttr;a.animate(b(this).attr(c));return false});a.win.scroll(function(){a.findLocation()}).resize(function(){a.findLocation()})};a.animate=function(c){if(c!=="#"&&b(c).length){var f=Math.min(b(c).offset().top,a.doc.height()-a.win.height());a.body.stop().animate({scrollTop:f},a.options.animationTime, function(){a.w.location.hash=c})}};a.findLocation=function(){var c,f,e,l,h,m=a.win.scrollTop(),i=m+a.win.height(),n=a.doc.height(),j=a.$el.find(a.options.selectedAppliedTo).removeClass(a.options.inViewClass);a.$el.find(a.options.link).each(function(o){e=b(this).attr(a.options.targetAttr);if(e==="#"||e.length<=1)e="";c=b(e);if(c.length){f=c.offset().top;h=c.outerHeight();l=f+h+a.options.bottomMargin;if(f<i&&(f+h-a.options.bottomMargin>m||l>i))j.eq(o).addClass(a.options.inViewClass)}});e=i+a.options.bottomMargin>= n?":last":":first";j.removeClass(a.options.selectedClass);j.filter("."+a.options.inViewClass+e).addClass(a.options.selectedClass)};a.init();a.findLocation()};b.visualNav.defaultOptions={link:"a",targetAttr:"href",inViewClass:"inView",selectedClass:"selected",selectedAppliedTo:"li",contentClass:"content",contentLinks:"visualNav",bottomMargin:100,animationTime:1200};b.fn.visualNav=function(d){return this.each(function(){var g=b(this).data("visualNav");typeof d==="string"&&/^#/.test(d)&&g.animate(d); g||new b.visualNav(this,d)})};b.fn.getvisualNav=function(){this.data("visualNav")}})(jQuery);


// Slide show script

//////////////////////////////////////////////////////////////
// Set Variables
/////////////////////////////////////////////////////////////

var transitionSpeed = 500;
var scrollSpeed = 500;
var fadeDelay = 100;
var currentProject = "";
var nextProject = "";

//////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////

function getProject(project) {
	
	return jQuery("#project-"+project);
}

function getProjectLink(project) {
	return jQuery("#thumb-"+project+" a");
}

function showProject(project, animate) {
	if (jQuery("#projectThumbs a.selected").attr("href")) {
		currentProject = getProject(jQuery("#projectThumbs a.selected").attr("href").replace("\#",""));		
	}	
	
	nextProject = getProject(project);	

	if (!getProjectLink(project).hasClass("selected")) {
				
		// Fade out the current project
		if (currentProject) {currentProject.fadeOut(transitionSpeed);}
		
		// Fade in the next project
		nextProject.delay(fadeDelay).fadeIn(transitionSpeed);
		
		// Add the selected class to the thumbnail
		jQuery("#projectThumbs a.selected").removeClass("selected");
		getProjectLink(project).addClass("selected");
		
		// Adjust the height of project container
		jQuery("#projects").animate({
			height: nextProject.outerHeight()
		}, scrollSpeed );				
	}
	
	// Scroll to the top of the projects
	jQuery.scrollTo("#projects", scrollSpeed, { offset:-25 });
}

function hideProject() {
	currentProject = getProject(jQuery("#projectThumbs a.selected").attr("href").replace("\#",""));		
	
	// Fade out the current project
	currentProject.fadeOut(transitionSpeed);
	
	// Remove the selected class from thumbnail
	jQuery("#projectThumbs a.selected").removeClass("selected");
	
	// Close the project container
	jQuery("#projects").delay(fadeDelay).animate({
		height: 0
	}, transitionSpeed );	
}

function createProjectSlider() {
	jQuery("#projectThumbs a").each(function(){
		var project = jQuery(this).attr("href").replace("\#","");		
		jQuery(".slideshow", getProject(project)).easySlider({
			speed: transitionSpeed,
			project: project,
			continuous: true,
			numeric: true,
			controlsBefore: '<div class="slideshowControls clearfix">',
			controlsAfter: '</div>'				
		});
	});
}

function createCloseProjectButton() {	
	jQuery(".closeBtn").click(function() {
		hideProject();
	});
}


//////////////////////////////////////////////////////////////
// Initialize
/////////////////////////////////////////////////////////////


jQuery.noConflict();
jQuery(document).ready(function(){	
	
	// Rename project ids
	jQuery(".projectDetails").each(function(){
		jQuery(this).attr("id","project-"+jQuery(this).attr("id"));
	});

	// Add click events to project thumbnails
	jQuery("#projectThumbs a").click(function() {
		//alert(jQuery(this).attr("href").replace("\#",""));
		showProject(jQuery(this).attr("href").replace("\#",""));
	});
	
	// Call inititial functions
	createCloseProjectButton();	
	createProjectSlider();

	// Show project is there is a hash in the URL
	var project = location.hash.replace("\#","");
	if (getProject(project).length) {
		showProject(project, true);
	}
});


// Navigation

jQuery(window).load(function() {
// Setup the site navigation
	jQuery('#mainNav').visualNav({
      link              : 'a',         // add a link class, as necessary (e.g. 'a.menu')
      targetAttr        : 'href',      // added in case you have link = "div" and attribute something like
      inViewClass       : 'inView',    // css class added to items in the viewport
      selectedClass     : 'selected',  // css class applied to menu when a link is selected (highlighted)
      selectedAppliedTo : 'a',        // to only apply to the link, use the same value as is in the link option
      contentClass      : 'pqSection',   // content class to get height of the section
      contentLinks      : 'visualNav', // class name of links inside the content that act like the visualNav menu (smooth scroll)
      bottomMargin      : 200,         // margin from the end of the page where the last menu item is used (in case the target is short)
      animationTime     : 700  ///speed of scrolling in milliseconds      
 	});
});

jQuery(window).load(function() {
// Setup the site links
	jQuery('#aboutslide').visualNav({
      link              : 'a',         // add a link class, as necessary (e.g. 'a.menu')
      targetAttr        : 'href',      // added in case you have link = "div" and attribute something like
      inViewClass       : 'inView',    // css class added to items in the viewport
      selectedClass     : 'selected',  // css class applied to menu when a link is selected (highlighted)
      selectedAppliedTo : 'a',        // to only apply to the link, use the same value as is in the link option
      contentClass      : 'pqSection',   // content class to get height of the section
      contentLinks      : 'visualNav', // class name of links inside the content that act like the visualNav menu (smooth scroll)
      bottomMargin      : 200,         // margin from the end of the page where the last menu item is used (in case the target is short)
      animationTime     : 700  ///speed of scrolling in milliseconds      
 	});
});




