/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		aqua:[0,255,255],
		azure:[240,255,255],
		beige:[245,245,220],
		black:[0,0,0],
		blue:[0,0,255],
		brown:[165,42,42],
		cyan:[0,255,255],
		darkblue:[0,0,139],
		darkcyan:[0,139,139],
		darkgrey:[169,169,169],
		darkgreen:[0,100,0],
		darkkhaki:[189,183,107],
		darkmagenta:[139,0,139],
		darkolivegreen:[85,107,47],
		darkorange:[255,140,0],
		darkorchid:[153,50,204],
		darkred:[139,0,0],
		darksalmon:[233,150,122],
		darkviolet:[148,0,211],
		fuchsia:[255,0,255],
		gold:[255,215,0],
		green:[0,128,0],
		indigo:[75,0,130],
		khaki:[240,230,140],
		lightblue:[173,216,230],
		lightcyan:[224,255,255],
		lightgreen:[144,238,144],
		lightgrey:[211,211,211],
		lightpink:[255,182,193],
		lightyellow:[255,255,224],
		lime:[0,255,0],
		magenta:[255,0,255],
		maroon:[128,0,0],
		navy:[0,0,128],
		olive:[128,128,0],
		orange:[255,165,0],
		pink:[255,192,203],
		purple:[128,0,128],
		violet:[128,0,128],
		red:[255,0,0],
		silver:[192,192,192],
		white:[255,255,255],
		yellow:[255,255,0]
	};
	
})(jQuery);

/*
	Rotates content by fading.
*/
var rotator = {
	elements : Array(),
	current : 0,
	seconds : 5,
	interval : null,
	
	init : function(selector, seconds) {
		rotator.elements = $(selector);
		rotator.seconds = seconds*1000;
	},
	
	start : function() {
		rotator.stop(); /* stop it just in case already playing */
		rotator.interval = setInterval("rotator.next()", rotator.seconds);
	},
	
	stop : function() {
		clearInterval(rotator.interval);
	},
	
	next : function() {		
		var show = (rotator.current < rotator.elements.length-1) ? rotator.current+1 : 0;
		rotator.swap(show);
	},	

	prev : function() {
		var show = (rotator.current == 0) ? rotator.elements.length-1 : rotator.current-1;
		rotator.swap(show);		
	},	
	
	swap : function(indexToShow, anchor) {
		if(rotator.interval){ rotator.start();}
		$(rotator.elements[rotator.current]).fadeOut(200, function(){
			$(rotator.elements[indexToShow]).fadeIn();
			rotator.current = indexToShow;
		});
		if(anchor){
			$(anchor).siblings('a').each(function(){
				$(this).removeClass('active');
			})
			$(anchor).addClass('active');
		}
	}
}

var anchor = {
	get : function() {
		var url = document.location.toString();
		if (url.match('#')) { 
			return url.split('#')[1];
		} else {
			return false;
		}		
	},
	set : function(val) {
		//redirect.go('#'+val);
	}
}

var d = document;
var dsS = d.styleSheets;
if (dsS[0].insertRule) dsS[0].insertRule("html { overflow-x: hidden; }", dsS[0].cssRules.length); // W3C DOM2 Style
else if (dsS[0].addRule) dsS[0].addRule("html", "overflow-x: hidden"); // Microsoft


var gallery = {
	items : Array(),
	currentIndex : 0,
	holder : null,
	step : 1,
	indicator : null,
	init : function() {
		var startIndex = parseInt(anchor.get());
		gallery.holder=$('div#gallery');
		gallery.indicator=$('div#gallery-header .h2-label strong');
		var itemsArray = gallery.holder.find('div.work');
		for(var i=0;i<itemsArray.length;i++){
			$(itemsArray[i]).bind('mouseover', i, function(e){
				for(var j=0;j<itemsArray.length;j++){
					if(j != e.data){
						$(itemsArray[j]).find('img.workimg').stop().fadeTo(200, 0.50);
					}else{
						$(itemsArray[j]).find('h1.work-header').show();
					}
				}
			});
			$(itemsArray[i]).bind('mouseout', i, function(e){
				for(var j=0;j<itemsArray.length;j++){
					$(itemsArray[j]).find('img.workimg').stop().fadeTo(200, 1);
					$(itemsArray[j]).find('h1.work-header').hide();
				}
			});
			gallery.items.push({div:itemsArray[i], pos:($(itemsArray[i]).find("a").attr('rel')*-1)})
		}
		if(startIndex){ gallery.goToIndex(startIndex, true) }
	},
	next : function() {
		if(!gallery.items[gallery.currentIndex+gallery.step]){ gallery.goToIndex(0); return false;}
		gallery.goToIndex(gallery.currentIndex+gallery.step);
		
	},
	prev : function() {
		if(!gallery.items[gallery.currentIndex-gallery.step]){ gallery.goToIndex(0); return false; }
		gallery.goToIndex(gallery.currentIndex-gallery.step);

	},
	goToIndex : function(newIndex, jump) {	    
		var newPos = gallery.items[newIndex].pos;
		gallery.currentIndex = newIndex;
		
		var remainingGalleryWidth = (gallery.items.length)*505 + newPos;
		if(remainingGalleryWidth<$('body').width())
		    newPos = newPos+($('body').width()-remainingGalleryWidth);
		
		var indicatorStart = gallery.currentIndex+1;
		var indicatorEnd = indicatorStart+2;
		while(indicatorEnd > gallery.items.length){ indicatorEnd--; }
		gallery.indicator.text(indicatorStart+' - '+indicatorEnd);
		
		
		if(jump){ gallery.jump(newPos); }
		else{    gallery.slide(newPos); }
		
		anchor.set(newIndex);

		if(gallery.currentIndex==0){ 
			$('a#gallery-prev').removeClass('active');
		}else{
			$('a#gallery-prev').addClass('active');
		}
		
		if(!gallery.items[gallery.currentIndex+gallery.step]){ 
			$('a#gallery-next').removeClass('active');
		}else{
			$('a#gallery-next').addClass('active');
		}
	},
	slide : function (pos) {
		gallery.holder.animate({ left: pos }, 1000 );
	},
	jump : function (pos) {
		gallery.holder.css('left', pos);
	}
	
}

/*
 * jQuery Easing v1.1 - http://gsgd.co.uk/sandbox/jquery.easing.php
 *
 * Uses the built in easing capabilities added in jQuery 1.1
 * to offer multiple easing options
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
jQuery.easing={easein:function(x,t,b,c,d){return c*(t/=d)*t+b},easeinout:function(x,t,b,c,d){if(t<d/2)return 2*c*t*t/(d*d)+b;var a=t-d/2;return-2*c*a*a/(d*d)+2*c*a/d+c/2+b},easeout:function(x,t,b,c,d){return-c*t*t/(d*d)+2*c*t/d+b},expoin:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(Math.exp(Math.log(c)/d*t))+b},expoout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}return a*(-Math.exp(-Math.log(c)/d*(t-d))+c+1)+b},expoinout:function(x,t,b,c,d){var a=1;if(c<0){a*=-1;c*=-1}if(t<d/2)return a*(Math.exp(Math.log(c/2)/(d/2)*t))+b;return a*(-Math.exp(-2*Math.log(c/2)/d*(t-d))+c+1)+b},bouncein:function(x,t,b,c,d){return c-jQuery.easing['bounceout'](x,d-t,0,c,d)+b},bounceout:function(x,t,b,c,d){if((t/=d)<(1/2.75)){return c*(7.5625*t*t)+b}else if(t<(2/2.75)){return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b}else if(t<(2.5/2.75)){return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b}else{return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b}},bounceinout:function(x,t,b,c,d){if(t<d/2)return jQuery.easing['bouncein'](x,t*2,0,c,d)*.5+b;return jQuery.easing['bounceout'](x,t*2-d,0,c,d)*.5+c*.5+b},elasin:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return-(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b},elasout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d)==1)return b+c;if(!p)p=d*.3;if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);return a*Math.pow(2,-10*t)*Math.sin((t*d-s)*(2*Math.PI)/p)+c+b},elasinout:function(x,t,b,c,d){var s=1.70158;var p=0;var a=c;if(t==0)return b;if((t/=d/2)==2)return b+c;if(!p)p=d*(.3*1.5);if(a<Math.abs(c)){a=c;var s=p/4}else var s=p/(2*Math.PI)*Math.asin(c/a);if(t<1)return-.5*(a*Math.pow(2,10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p))+b;return a*Math.pow(2,-10*(t-=1))*Math.sin((t*d-s)*(2*Math.PI)/p)*.5+c+b},backin:function(x,t,b,c,d){var s=1.70158;return c*(t/=d)*t*((s+1)*t-s)+b},backout:function(x,t,b,c,d){var s=1.70158;return c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},backinout:function(x,t,b,c,d){var s=1.70158;if((t/=d/2)<1)return c/2*(t*t*(((s*=(1.525))+1)*t-s))+b;return c/2*((t-=2)*t*(((s*=(1.525))+1)*t+s)+2)+b},linear:function(x,t,b,c,d){return c*t/d+b}};


$(document).ready(function(){
	$("html").keypress(function (e) { if(e.which==37){ gallery.prev(); }else if(e.which==39){ gallery.next(); } });
	gallery.init();

});	

/* idTabs ~ Sean Catchpole - Version 2.2 - MIT/GPL */ 
(function(){ 
var dep = {"jQuery":"http://code.jquery.com/jquery-latest.min.js"}; 
var init = function(){  
 
/* Options (in any order): 
 
 start (number|string) 
    Index number of default tab. ex: $(...).idTabs(0) 
    String of id of default tab. ex: $(...).idTabs("tab1") 
    default: class "selected" or index 0 
    Passing null will force it to not select a default tab 
 
 change (boolean) 
    True - Url will change. ex: $(...).idTabs(true) 
    False - Url will not change. ex: $(...).idTabs(false) 
    default: false 
 
 click (function) 
    Function will be called when a tab is clicked. ex: $(...).idTabs(foo) 
    If the function returns true, idTabs will show/hide content (as usual). 
    If the function returns false, idTabs will not take any action. 
    The function is passed four variables: 
      The id of the element to be shown 
      an array of all id's that can be shown 
      the element containing the tabs 
      and the current settings 
 
 selected (string) 
    Class to use for selected. ex: $(...).idTabs(".current") 
    default: ".selected" 
 
 event (string) 
    Event to trigger idTabs on. ex: $(...).idTabs("!mouseover") 
    default: "!click" 
    To bind multiple event, call idTabs multiple times 
      ex: $(...).idTabs("!click").idTabs("!focus") 
 
*/ 
(function($){ 
 
  $.fn.idTabs = function(){ 
    //Loop Arguments matching options 
    var s = {}; 
    for(var i=0; i<arguments.length; ++i) { 
      var a=arguments[i]; 
      switch(a.constructor){ 
        case Object: $.extend(s,a); break; 
        case Boolean: s.change = a; break; 
        case Number: s.start = a; break; 
        case Function: s.click = a; break; 
        case String: 
          if(a.charAt(0)=='.') s.selected = a; 
          else if(a.charAt(0)=='!') s.event = a; 
          else s.start = a; 
        break; 
      } 
    } 
 
    if(typeof s['return'] == "function") //backwards compatible 
      s.change = s['return']; 
     
    return this.each(function(){ $.idTabs(this,s); }); //Chainable 
  } 
 
  $.idTabs = function(tabs,options) { 
    //Settings 
    var meta = ($.metadata)?$(tabs).metadata():{}; 
    var s = $.extend({},$.idTabs.settings,meta,options); 
 
    //Play nice 
    if(s.selected.charAt(0)=='.') s.selected=s.selected.substr(1); 
    if(s.event.charAt(0)=='!') s.event=s.event.substr(1); 
    if(s.start==null) s.start=-1; //no tab selected 
     
    //Setup Tabs 
    var showId = function(){ 
      if($(this).is('.'+s.selected)) 
        return s.change; //return if already selected 
      var id = "#"+this.href.split('#')[1]; 
      var aList = []; //save tabs 
      var idList = []; //save possible elements 
      $("a",tabs).each(function(){ 
        if(this.href.match(/#/)) { 
          aList.push(this); 
          idList.push("#"+this.href.split('#')[1]); 
        } 
      }); 
      if(s.click && !s.click.apply(this,[id,idList,tabs,s])) return s.change; 
      //Clear tabs, and hide all 
      for(i in aList) $(aList[i]).removeClass(s.selected); 
      for(i in idList) $(idList[i]).hide(); 
      //Select clicked tab and show content 
      $(this).addClass(s.selected); 
      $(id).fadeIn("slow"); 
      return s.change; //Option for changing url 
    } 
 
    //Bind idTabs 
    var list = $("a[href*='#']",tabs).unbind(s.event,showId).bind(s.event,showId); 
    list.each(function(){ $("#"+this.href.split('#')[1]).hide(); }); 
 
    //Select default tab 
    var test=false; 
    if((test=list.filter('.'+s.selected)).length); //Select tab with selected class 
    else if(typeof s.start == "number" &&(test=list.eq(s.start)).length); //Select num tab 
    else if(typeof s.start == "string" //Select tab linking to id 
         &&(test=list.filter("[href*='#"+s.start+"']")).length); 
    if(test) { test.removeClass(s.selected); test.trigger(s.event); } //Select tab 
 
    return s; //return current settings (be creative) 
  } 
 
  //Defaults 
  $.idTabs.settings = { 
    start:0, 
    change:false, 
    click:null, 
    selected:".selected", 
    event:"!click" 
  }; 
 
  //Version 
  $.idTabs.version = "2.2"; 
 
  //Auto-run 
  $(function(){ $(".idTabs").idTabs(); }); 
 
})(jQuery); 
 
 
 
} //init 
 
// Check Dependencies 
var check = function(o,s){ 
  s = s.split('.'); 
  while(o && s.length) o = o[s.shift()]; 
  return o; 
} 
 
// Add Script 
var head = document.getElementsByTagName("head")[0]; 
var add = function(url){ 
  var s = document.createElement("script"); 
  s.type = "text/javascript"; s.src = url; 
  head.appendChild(s); 
} 
 
// Save Self 
var s = document.getElementsByTagName('script'); 
var src = s[s.length-1].src; 
 
// Load Dependencies 
var ok=true; 
for(d in dep) { 
  if(check(this,d)) continue; 
  ok=false; 
  add(dep[d]); 
} if(ok) return init(); 
 
// Reload Self 
add(src); 
 
})(); 