var Suitcase = { ready : function() { Suitcase.detectBrowser(); Suitcase.startGA(); Suitcase.replaceFonts(); Suitcase.startHeroSlideshow(); Suitcase.addBlogPosts(); Suitcase.addTweets(); Suitcase.startLinks(); Suitcase.addNewsletter(); Suitcase.addMap(); Suitcase.addContact(); Suitcase.addAccodrion(); Suitcase.checkForHash(); }, detectBrowser : function() { if ( $.browser.msie ) { $( 'body' ).addClass( 'ie' ); if ( $.browser.version == '8.0' ) { $( 'body' ).addClass( 'ie8' ); } else if ( $.browser.version == '7.0' ) { $( 'body' ).addClass( 'ie7' ); } else { $( 'body' ).addClass( 'ie6' ); } } if ( $.browser.safari ) { if ( navigator.userAgent.indexOf( 'Safari' ) != -1 ) { $( 'body' ).addClass( 'safari' ); } else { $( 'body' ).addClass( 'chrome' ); } } if ( $.browser.mozilla ) { $( 'body' ).addClass( 'ff' ); if ( $.browser.version.substr( 0, 3 ) == '1.9' ) { $( 'body' ).addClass( 'ff3' ); } else { $( 'body' ).addClass( 'ff2' ); } } if ( navigator.userAgent.indexOf( 'Windows' ) != -1 ) { $( 'body' ).addClass( 'windows' ); } else if ( navigator.userAgent.indexOf( 'Mac' ) != -1 ) { $( 'body' ).addClass( 'mac' ); } }, currentHash : '', checkForHash : function() { var hash = document.location.hash; var target; if ( hash && Suitcase.currentHash != hash ) { Suitcase.currentHash = hash; hash = hash.replace( '#', '' ); target = $( '#' + hash ); if ( target.length > 0 ) { if ( target.click ) { target.click(); } setTimeout( function() { Suitcase.scrollTo( target ) }, 500 ); } } setTimeout( 'Suitcase.checkForHash()', 500 ); }, scrollTo : function(t) { $.scrollTo( t, { duration : 1000, offset : { top: -100 }, onAfter : function() { t.effect( 'pulsate', { times: 1 }, 1000 ); } }); }, startGA : function() { $.ga.load( 'UA-6722795-1' ); }, startLinks : function() { var target = ( arguments[ 0 ] || $( 'a' ) ); target.each( function() { var link = $( this ); if ( !link.attr( 'onclick' ) && link.attr( 'href' ).indexOf( 'javascript:;' ) === -1 ) { link.unbind( 'click' ); link.click( function() { Suitcase.visitLink( this ); return false; }); } }); }, visitLink : function(t) { var link = ( $( t ).length > 0 ? $( t ).attr( 'href' ) : t ); var external = ( link.indexOf( 'http://' + document.domain ) === 0 || link.indexOf( 'http://' ) === -1 ? false : true ); Suitcase.trackEvent( [ 'LinkClick', ( external ? 'External' : 'Internal' ), 'URL', link ] ); window.open( link, ( external ? '_blank' : '_self' ) ); }, queuedEvents : [ ], queuedEventsInt : '', trackEvent : function(arr) { Suitcase.queuedEvents.push( arr ); if ( Suitcase.queuedEventsInt ) { clearInterval( Suitcase.queuedEventsInt ); } Suitcase.queuedEventsInt = setInterval( Suitcase.runEventsQueue, 1000 ); }, runEventsQueue : function() { var func = $.ga.trackEvent; if ( func ) { clearInterval( Suitcase.queuedEventsInt ); $.each( Suitcase.queuedEvents, function(i) { func.apply( null, Suitcase.queuedEvents[ i ] ); }); Suitcase.queuedEvents = [ ]; } }, replaceFonts : function() { var targets = [ 'h1', 'h2', 'h3', 'h4', '.replace' ]; $.each( targets, function() { Cufon.replace( this.toString() ); }); }, startHeroSlideshow : function() { if ( $( '#hero #slideshow').length > 0 ) { var slides = $( '#hero #slideshow li a' ); slides.each( function(i) { $( this ).addClass( 'corners' ); $( this ).css( 'background', 'url(/assets/image/hero_sprite.png) -' + ( i * 380 ) + 'px 0px no-repeat' ); $( this ).css( 'z-index', 100 - i ); $( this ).hide(); }); Suitcase.showHeroSlide( slides.get( 0 ) ); } }, showHeroSlide : function(slide) { var li = $( slide ).parent(); var next = $( 'a', ( li.next().length ? li.next() : li.siblings().get( 0 ) ) ); $( li ).siblings().find( 'a' ).fadeOut(); $( slide ).fadeIn(); setTimeout( function() { Suitcase.showHeroSlide( next ) }, 5000 ); }, addBlogPosts : function() { var target = $( '#blogposts' ); if ( target.length > 0 ) { $.ajax({ url : 'proxy.php?file=http://futureblogging.co.uk/blog/feed&type=xml', dataType : 'xml', success : function (d) { var entries = $( 'item', d ); if ( entries.length > 0 ) { target.html( '<ul>' ); for ( var i = 0; i < 3; i++ ) { target.append( '<li><strong>' + Suitcase.parseDate( $( 'pubDate', entries[ i ] ).text() ) + '</strong> &mdash; <a href="' + $( 'link', entries[ i ] ).text() + '">' + $( 'title', entries[ i ] ).text().substr( 0, 40 ) + ' ... </a></li>' ); } target.append( '</ul>'); } } }); } }, parseDate : function(stamp) { var date = new Date(); var days = [ 'Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat' ]; var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec' ]; date.setTime( Date.parse( stamp ) ); return days[ date.getDay() ] + ' ' + date.getDate() + ' ' + months[ date.getMonth() ]; }, addTweets : function() { var target = $( '#tweets' ); if ( target.length > 0 ) { target.tweet({ username : 'futureblogging', join_text : 'auto', avatar_size : 28, count : 3, auto_join_text_default : 'we said,', auto_join_text_ed : 'we', auto_join_text_ing : 'we were', auto_join_text_reply : 'we replied to', auto_join_text_url : 'we were checking out', loading_text : 'Loading tweets...', callback : Suitcase.startLinks }); } }, addNewsletter : function() { var target = $( '#newsletterform' ); if ( target.length > 0 ) { target.submit( function() { $.postJSON( target.attr( 'action' ), target.serialize(), function(d) { $.jGrowl( d.message ); if ( d.status ) { $( 'input[type=text]', target ).val( 'Enter your email address' ); } }); return false; }); $( 'a', target ).click( function() { target.submit(); }); $( 'input[type=text]', target ).focus( function() { $( this ).val( $( this ).val() == 'Enter your email address' ? '' : $( this ).val() ); }); $( 'input[type=text]', target ).blur( function() { $( this ).val( $( this ).val() == '' ? 'Enter your email address' : $( this ).val() ); }); } }, addMap : function() { var target = $( '.googlemap' ); if ( target.length > 0 && GBrowserIsCompatible() ) { var info = target.html(); var fbIcon = new GIcon( G_DEFAULT_ICON ); fbIcon.iconSize = new GSize( 30, 40 ); fbIcon.image = '/assets/image/gicon.png'; fbIcon.shadow = ''; target.html( '' ); target.css( 'width', '100%' ); target.css( 'height', '300px' ); target.each( function() { var map = new GMap2( this ); var marker; map.addControl( new GSmallMapControl() ); map.addControl( new GMapTypeControl() ); map.setCenter( new GLatLng( 51.26598, 0.48388 ), 15 ); marker = new GMarker( map.getCenter(), { icon: fbIcon } ); GEvent.addListener( marker, 'click', function() { marker.openInfoWindowHtml( info ); }); marker.openInfoWindowHtml( info ); map.addOverlay( marker ); }); } }, addContact : function() { var target = $( '#contactform' ); if ( target.length > 0 ) { target.submit( function() { $.postJSON( target.attr( 'action' ), target.serialize(), function(d) { $.jGrowl( d.message ); }); return false; }); $( 'a', target ).click( function() { target.submit(); }); } }, addAccodrion : function() { var target = $( '.accordion' ); if ( target.length > 0 ) { target.accordion(); } } }; $( document ).ready( Suitcase.ready );