var CALLAGHAN = CALLAGHAN || {}

CALLAGHAN = {
    
    init : function () {
        this.clouds.init();
        this.email.init();
        if ( !$.browser.msie || ( $.browser.msie && $.browser.version > 6 ) ) {
            this.share.init();
        }
        if ( $.browser.msie && $.browser.version < 9 ) {
            this.mediaQuerySupport.init();
        }
    },
    
    clouds : {
        el : '#clouds',
        width : 1160,
        speed : 95,
        init : function () {
            if ( !$.browser.webkit ) {
                var clouds      =   $( this.el );
                    background  =   0,
                    _this       =   this;
                setInterval( function () {
                    background -= 2;
                    if ( background == _this.width ) {
                        background = 0;
                    }
                    clouds.css( 'background-position', background )
                }, this.speed )
            }
        }
    },
    
    share : {
        el : 'aside#share',
        delay : 3000,
        speed : 'slow',
        init : function () {
            var _this = this;
            setTimeout( function () {
                $( _this.el ).fadeIn( _this.speed );
            }, this.delay );
        }
    },
    
    email : {
        init : function () {
            var spt     =   $( 'span#email' ),
                at      =   / at /,
                dot     =   / dot /g,
                addr    =   $( spt ).text().replace( at, "@" ).replace( dot, "." );
                $( spt ).after( '<a href="mailto:' + addr + '">' + addr + '</a>')
                        .remove()
                        .show();
                
        }
    },
    
    mediaQuerySupport : {
    
        lastSize    :   null,
    
        init : function () {
            var _this = this;
            this.lastSize = this.getViewportWidth();
            this.doDetect();
            $( window ).resize( function( e ) {
                _this.doDetect();
            } );
        },
        
        doDetect : function () {
            var s = this.getViewportWidth(),
            dir = s <= this.lastSize ? 'down' : 'up',
            sizes = [ 'xx-large', 'x-large', 'large', 'medium', 'small', 'x-small', 'xx-small' ];
            if ( s > 960 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass();
                }
            } else if ( s <= 960 && s > 800 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass();
                }
                $( 'html' ).addClass( sizes[ 1 ] );
            } else if ( s <= 800 && s > 760 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass( sizes[ 3 ] );
                }
                $( 'html' ).addClass( sizes[ 2 ] );
            } else if ( s <= 760 && s > 600 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass( sizes[ 4 ] );
                }
                $( 'html' ).addClass( sizes[ 3 ] );
            } else if ( s <= 680 && s > 600 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass( sizes[ 5 ] );
                }
                $( 'html' ).addClass( sizes[ 4 ] );
            } else if ( s <= 600 && s > 510 ) {
                if( dir === 'up' ){
                    $( 'html' ).removeClass( sizes[ 6 ] );
                }
                $( 'html' ).addClass( sizes[ 5 ] );
            } else if ( s <= 510 ) {
                $( 'html' ).addClass( sizes[ 6 ] );
            }
            this.lastSize = s;
        },
        
        getViewportWidth : function () {
    		var viewPortWidth;
    		if( typeof window.innerWidth != 'undefined' ){
    			viewPortWidth = window.innerWidth;
    		}else if(	typeof document.documentElement != 'undefined'
    					&& typeof document.documentElement.clientWidth != 'undefined'
    					&& document.documentElement.clientWidth != 0 ){
    			viewPortWidth = document.documentElement.clientWidth;
    		}else{
    			viewPortWidth = document.getElementsByTagName( 'body' )[ 0 ].clientWidth;
    		}
    		return viewPortWidth;
    	}
    
    }
    
}    
    

$( window ).load( function () {

    CALLAGHAN.init();
    
} );

/**
SidJS - JavaScript And CSS Lazy Loader 0.1
Copyright © Alexandru Marasteanu <alexaholic [at) gmail (dot] com>
All rights reserved.
*/
(function(){var win=window,doc=document,proto='prototype',head=doc.getElementsByTagName('head')[0],body=doc.getElementsByTagName('body')[0],sniff=/*@cc_on!@*/1+/(?:Gecko|AppleWebKit)\/(\S*)/.test(navigator.userAgent);var createNode=function(tag,attrs){var attr,node=doc.createElement(tag);for(attr in attrs){if(attrs.hasOwnProperty(attr)){node.setAttribute(attr,attrs[attr])}}return node};var load=function(type,urls,callback,scope){if(this==win){return new load(type,urls,callback,scope)}urls=(typeof urls=='string'?[urls]:urls);scope=(scope?(scope=='body'?body:head):(type=='js'?body:head));this.callback=callback||function(){};this.queue=[];var node,i=len=0,that=this;for(i=0,len=urls.length;i<len;i++){this.queue[i]=1;if(type=='css'){node=createNode('link',{type:'text/css',rel:'stylesheet',href:urls[i]})}else{node=createNode('script',{type:'text/javascript',src:urls[i]})}scope.appendChild(node);if(sniff){if(type=='css'&&sniff==2){var intervalID=setInterval(function(){try{node.sheet.cssRules;clearInterval(intervalID);that.__callback()}catch(ex){}},100)}else{node.onload=function(){that.__callback()}}}else{node.onreadystatechange=function(){if(/^loaded|complete$/.test(this.readyState)){this.onreadystatechange=null;that.__callback()}}}}return this};load[proto].__callback=function(){if(this.queue.pop()&&(this.queue==0)){this.callback()}};window.Sid={css:function(urls,callback,scope){return load('css',urls,callback,scope)},js:function(urls,callback,scope){return load('js',urls,callback,scope)},load:function(type,urls,callback,scope){return load(type,urls,callback,scope)}}})();

/*
 * jQuery resize event - v1.1 - 3/14/2010
 * http://benalman.com/projects/jquery-resize-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);


