// basic jQuery extensions
$.extend($,
{
	// for debugging purposes - caution - writes to global space
	log : function()
	{
		window.log = function(){
			try{
				if(!window.LOG_OFF) console.log.apply(console,arguments);
			} catch(error)
			{
				// .. IE
			}
		};
		return window.log;
	}(),
	
	// get a timer, pass old timer for time since then
	time : function(t)
	{
		var d = (new Date()).getTime();
		return ( t? d-t  : d );
	},
	
	// Original Author: Rafael Lima (http://rafael.adm.br)
	// updated with iPhone sniff
	cssBrowserSelect : (function()
	{
		var ua=navigator.userAgent.toLowerCase(),
			is=function(t){ return ua.indexOf(t) != -1; },
			h=document.getElementsByTagName('html')[0],
			b=( !(/opera|webtv/i.test(ua)) && /msie (\d)/.test(ua) )? ('ie ie'+RegExp.$1):
				is('gecko/')? 'gecko':
					is('applewebkit/')? 'webkit safari':
						is('mozilla/')? 'gecko':						
							is('opera/9')? 'opera opera9':
								/opera (\d)/.test(ua)? 'opera opera'+RegExp.$1:
									is('konqueror')? 'konqueror':
										'',
			d = is('iphone')? ' iphone' : '',
			os=( is('x11')||is('linux') )? ' linux':
				is('mac')? ' mac':
					is('win')? ' win':
						'',
			c=b+d+os+' js';
		
		h.className += h.className?' '+c:c;
		
		return true;
	})(),
	
	// helper for toggling an input field label
	inputToggle: function (selector,message)
	{
		$(selector).focus(function(){
			if($(this).val()==message) $(this).val('')
		}).blur(function(){
			if($(this).val()=='') $(this).val(message)
		});
	},
	
	// fading in group
	fadeGroup : function(group,selector){
		
		var group = $(group);

		group.mouseenter(function(e){

			$(this).stop(true).fadeTo(300,1);
			group.not($(this)).stop(true).fadeTo(300,0.5);

		}).mouseleave(function(e){

			group.filter(selector).stop(true).fadeTo(300,1);
			group.not(selector).stop(true).fadeTo(300,0.5);

		}).mouseleave();
		
	}
});



/*
Title:      jQuery.relativeDate
Description:Formats a date relative to current time (eg '3 mins ago')
Developer:  Antenna Logistics (http://theantenna.org)
Date:       May 2009
Version:    0.1
Usage:      
Notes:      
To Do:      
License:    Dual licensed under the MIT and GPL licenses:
            http://www.opensource.org/licenses/mit-license.php,
            http://www.gnu.org/licenses/gpl.html
*/

(function($) {
	
	var a_minute = 60 *1000,
		an_hour = a_minute*60,
		a_day = an_hour*24,
		a_month = a_day*30, // averaged
		a_year = a_day*365,
		years,months,days,hours,minutes,secs,
		_plural = "s",
		_seperator = " ",
		_now = new Date();
	
	$.relativeDate = function(date, now)
	{
		//years = months = days = hours = minutes = secs = 0;
		
		if(typeof date == "string") date = new Date(date);
		secs = (now || _now).getTime() - date.getTime();
	
		years = Math.floor(secs/a_year);
		secs = secs%a_year;
		months = Math.floor(secs/a_month);
		
		secs = secs%a_month;
		days = Math.floor(secs/a_day);
		secs = secs%a_day;
		hours = Math.floor(secs/an_hour);
		secs = secs%an_hour;
		minutes = Math.floor(secs/a_minute);
		
		return formattedDate();
	};
	
	formattedDate = function()
	{
		if(years > 0) return displayDate(years,' year');
		else if(months > 0) return displayDate(months + (days>15? 1 : 0),' month');
		else if(days > 0) return displayDate(days + (hours>12? 1 : 0),' day');
		else if(hours > 0) return displayDate(hours + (minutes>30? 1 : 0),' hour') ;
		else return displayDate(minutes ,' minute');
	}
	
	displayDate = function(num, string, seperator, plural)
	{
		plural = plural || _plural,
		seperator = seperator || _seperator;
		return (num? (num!=1? num+string+plural+seperator : num+string+seperator) : "");
	}
	
	
})(jQuery);


/*
 * 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);

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-14 23:57:10 -0600 (Fri, 14 Dec 2007) $
 * $Rev: 4163 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */
(function($){$.event.special.mousewheel={setup:function(){var handler=$.event.special.mousewheel.handler;if($.browser.mozilla)$(this).bind('mousemove.mousewheel',function(event){$.data(this,'mwcursorposdata',{pageX:event.pageX,pageY:event.pageY,clientX:event.clientX,clientY:event.clientY});});if(this.addEventListener)this.addEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=handler;},teardown:function(){var handler=$.event.special.mousewheel.handler;$(this).unbind('mousemove.mousewheel');if(this.removeEventListener)this.removeEventListener(($.browser.mozilla?'DOMMouseScroll':'mousewheel'),handler,false);else
this.onmousewheel=function(){};$.removeData(this,'mwcursorposdata');},handler:function(event){var args=Array.prototype.slice.call(arguments,1);event=$.event.fix(event||window.event);$.extend(event,$.data(this,'mwcursorposdata')||{});var delta=0,returnValue=true;if(event.wheelDelta)delta=event.wheelDelta/120;if(event.detail)delta=-event.detail/3;if($.browser.opera)delta=-event.wheelDelta;event.data=event.data||{};event.type="mousewheel";args.unshift(delta);args.unshift(event);return $.event.handle.apply(this,args);}};$.fn.extend({mousewheel:function(fn){return fn?this.bind("mousewheel",fn):this.trigger("mousewheel");},unmousewheel:function(fn){return this.unbind("mousewheel",fn);}});})(jQuery);





// ---------------------------------------------------------------------------
// ANTENNA UTILS

(function($){
	
	window.net = window.net || {theantenna:{}};
	
	var backBtIvl,
		oldHash = location.hash.toString();
	
	// UTILS
	net.theantenna.utils = {
		
		hashManager :
		{
			// If page hash, launch (via permalink)
			rebootFromHash:function()
			{
				var hash = location.hash.toString();
		
				if(hash.length){
					//log('rebooting from hash: ', hash);
					$('a[href='+hash+']').trigger('click',true).mouseleave();
				}
			},
			
			updateHash:function(hash)
			{
				oldHash = hash;
			},
			
			catchBackButton:function(){
				
				backBtIvl = setInterval(function(){
					
					var newHash = location.hash.toString();
					
					if( oldHash != newHash ) net.theantenna.utils.hashManager.rebootFromHash();
					
					oldHash = newHash;
					
				},500);
			},
			
			cancelCatchBackButton:function(){
				clearInterval(backBtIvl);
			}
		}
	};
	

/*
Title:      fsviewer
Description:
Developer:  Antenna Praxis (http://theantenna.org)
Released:   Mar 2010
Updated:    Mar 2010
Version:    0.0.1
License:    Not licensed for public or commercial use.
Usage:      
Notes:      			
To Do:      
*/
	
	var scrollTop = 0;
	
	// Called by Flash ExternalInterface
	net.theantenna.fsviewer = {
		
		id : '#fsviewer-wrapper',
		flash : $(document).ready(function(){
			// on ready event, set antenna.fsviewer.flash = actual flash object with ExternalInterface funcs
			// until then it returns $(window)
			$('#fsviewer-wrapper').one('ready.fsviewer',function(){
				net.theantenna.fsviewer.flash = $('#fsviewer')[0];
			});
		}), 
		
		events : {
			open: function()
			{
				$(net.theantenna.fsviewer.id).trigger('open.fsviewer');
				if( $('html').hasClass('safari') )
				{
					// weird bug in Safari - Flash FS wont load if scrollTop != 0
					scrollTop = $(window).scrollTop();
					window.scroll(0,0);
				}
			},

			exit: function()
			{
				$(net.theantenna.fsviewer.id).trigger('exit.fsviewer');
				// scroll back to previous position
				if($('html').hasClass('safari') && scrollTop) window.scroll(0,scrollTop);
			},

			ready: function()
			{
				$(net.theantenna.fsviewer.id).trigger('ready.fsviewer');
			},

			mouseover: function ()
			{
				$(net.theantenna.fsviewer.id).trigger('mouseenter.fsviewer');
			},

			mouseout: function()
			{
				$(net.theantenna.fsviewer.id).trigger('mouseleave.fsviewer');
			}
		}
		
		
	}


})(jQuery);



/*
Title:      jQuery.slidescroll
Description:Move content in scrolling slideshow.
Developer:  Antenna Praxis (http://theantenna.net)
Released:   Feb 2010
Updated:    Feb 2010
Version:    0.0.1
Usage:      
Notes:      Based on jquery Widget architecture.
			
To Do:      Scroll image to centre
License:    Not licensed for public or commercial use.
            
*/
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(4($){7 j={A:0,r:B,s:B,u:0,v:18,n:0,19:4(){7 a=3,C=0;$(3.6.x,3.5).1a(4(i){C+=$(3).q(l)});8(C>3.5.D())3.r=l;8(3.6.N)3.5.1b($.E(3.O,3));3.v=$.E(3.P,3);$(y).Q(\'F.m\',3.v).1c(\'F.m\');8(3.6.G)3.5.Q(\'R\',$.E(3.S,3))},S:4(a,b){8($(1d).T()!=$(y).T())9;3.n=3.6.G*(b>0?-1:1);3.H()},P:4(e){3.u=o.U(0,$(y).D()/2-3.6.V)},1e:4(){7 a=3;8(!3.r)9;3.I();3.s=l;3.A=1f(4(){a.H()},3.6.W)},I:4(){3.s=B;1g(3.A)},H:4(){7 b=3.6.J,k=3.6.K*b,X=(k-3.n)*3.6.Y;3.n=3.n+X;k=o.Z(3.n);8(!k)9;3.5.z(\'p\',4(i,a){9 L(a)-k});8(k>0){7 c=$(3.6.x,3.5).1h();8(c.11().p<-c.q(l)){3.5.z(\'p\',4(i,a){9 L(a)+c.q(l)});c.1i(3.5)}}1j{7 c=$(3.6.x,3.5).1k();8(c.11().p>3.5.q(l)){3.5.z(\'p\',4(i,a){9 L(a)-c.q(l)});c.1l(3.5)}}},O:4(e){7 a=e.1m,w=3.5.D(),12=a>w/2?1:-1,k=o.1n(o.1o(a-(w/2)));k=o.U(0,k-3.u);3.6.K=3.13(k,0,(w/2)-3.u,0,3.6.14);3.6.J=12},13:4(a,e,f,g,h){8(e==f)9 e;7 t=(a-e)/(f-e);7 b=g;7 c=h-g;7 d=1;9 o.Z(c*t/d+b)},15:4(){9 3.r},16:4(){9 3.s},1p:4(){3.I();3.5.z({p:0});3.5.1q("m");3.5.17(\'R\');$(y).17(\'F.m\',3.v)}};$.1r("M.m",j);$.M.m.1s="15 16";$.M.m.1t={x:\'1u\',N:1,G:1v,Y:0.1w,V:1x,J:1,K:1,14:10,W:1y}})(1z);',62,98,'|||this|function|element|options|var|if|return|||||||||||spd|true|slidescroll|iSpeed|Math|left|outerWidth|_hasContent|_isStarted||deadzone|resizeEvent||selector|window|css|scrollIntvl|false|contentW|width|proxy|resize|mouseWheel|setScroll|stop|direction|speed|parseInt|ui|mouseScroll|onMouseScroll|onWindowResize|bind|mousewheel|onMouseWheel|height|max|hotspotW|hertz|change|inertia|round||offset|dir|_mapRange|maxSpeed|hasContent|isStarted|unbind|null|_init|each|mousemove|trigger|document|start|setInterval|clearInterval|first|appendTo|else|last|prependTo|pageX|floor|abs|destroy|removeData|widget|getter|defaults|img|100|25|250|30|jQuery'.split('|'),0,{}))
