var Suitcase = { ready : function() { Suitcase.hideInfoBox(); Suitcase.detectBrowser(); Suitcase.startGA(); Suitcase.replaceFonts(); Suitcase.startHeroSlideshow(); Suitcase.addBlogPosts(); Suitcase.addTweets(); Suitcase.addNewsletter(); Suitcase.addContact(); Suitcase.addCallMeBack(); Suitcase.addClientBlock(); Suitcase.addServicesBlock(); Suitcase.startLinks(); 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 } }); }, startGA : function() { $.ga.load( 'UA-480296-2' ); }, startLinks : function() { var target = ( arguments[ 0 ] || $( 'a' ) ); target.each( function() { var link = $( this ); if ( !link.attr( 'onclick' ) && link.attr( 'href' ).indexOf( 'javascript:;' ) === -1 && !link.hasClass( 'notracking' ) ) { 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) { if ( $.inArray( Suitcase.queuedEvents, arr ) === -1 ) { Suitcase.queuedEvents.push( arr ); } if ( Suitcase.queuedEvents.length > 0 ) { 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() { var target = $( '#heroshow'); if ( target.length > 0 ) { var slides = $( 'li', target ); slides.each( function(i) { $( 'a:first', this ).attr( 'href', 'javascript:;' ); $( this ).css( 'background', 'url(/assets/image/hero_sprite.jpg) 0px -' + ( i * 230 ) + 'px no-repeat' ); $( this ).click( function() { var content = $( '.more', this ).html(); content = content.replace( /h5/gim, 'h3' ); Suitcase.showInfoBox( content ); }); $( this ).hide(); }); Suitcase.showHeroSlide( slides.get( 0 ) ); } }, showHeroSlide : function(slide) { var li = $( slide ); var next = ( li.next().length ? li.next() : li.siblings().get( 0 ) ); li.siblings().fadeOut(); li.fadeIn(); setTimeout( function() { Suitcase.showHeroSlide( next ) }, 5000 ); }, addBlogPosts : function() { var target = $( '#blogposts .content' ); if ( target.length > 0 ) { $.ajax({ url : '/proxy.php?file=http://www.themediacube.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, 30 ) + ' ... </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 .content' ); if ( target.length > 0 ) { target.tweet({ username : 'themediacube', 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() { $.jGrowl( 'Sending, please wait...' ); $.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() ); }); } }, addContact : function() { var target = $( '#contactform' ); if ( target.length > 0 ) { target.submit( function() { $.jGrowl( 'Sending, please wait...' ); $.postJSON( target.attr( 'action' ), target.serialize(), function(d) { $.jGrowl( d.message ); }); return false; }); $( 'a', target ).click( function() { target.submit(); }); } }, addCallMeBack : function() { var target = $( '#callmebackform' ); if ( target.length > 0 ) { target.submit( function() { $.jGrowl( 'Sending, please wait...' ); $.postJSON( target.attr( 'action' ), target.serialize(), function(d) { $.jGrowl( d.message ); }); return false; }); $( 'a', target ).click( function() { target.submit(); }); $( 'input[name=name]', target ).focus( function() { $( this ).val( $( this ).val() == 'Enter your name' ? '' : $( this ).val() ); }); $( 'input[name=name]', target ).blur( function() { $( this ).val( $( this ).val() == '' ? 'Enter your name' : $( this ).val() ); }); $( 'input[name=number]', target ).focus( function() { $( this ).val( $( this ).val() == 'Enter your phone number' ? '' : $( this ).val() ); }); $( 'input[name=number]', target ).blur( function() { $( this ).val( $( this ).val() == '' ? 'Enter your phone number' : $( this ).val() ); }); } }, addClientBlock : function() { var target = $( '.clientblock' ); if ( target.length > 0 ) { $( 'div', target ).each( function() { $( this ).click( function() { var content = $( '.content', this ).html(); content = content.replace( /h5/gim, 'h3' ); Suitcase.showInfoBox( content ); }); }); } }, addServicesBlock : function() { var target = $( '#services .cols' ); if ( target.length > 0 ) { $( target ).each( function() { var content = $( '.more', this ).html(); content = content.replace( /h5/gim, 'h3' ); $( 'a.buttonsmall', this ).click( function() { Suitcase.showInfoBox( content ); }); }); } }, hideInfoBox : function() { $( '#infobox' ).hide(); $( 'body' ).css( 'overflow', 'auto' ); $( window ).unbind( 'resize' ); }, showInfoBox : function(html) { $( 'body' ).css( 'overflow', 'hidden' ); $( '#infobox' ).fadeIn( 'def', function() { Cufon.refresh( 'h3' ); }); $( '#infoboxcontent' ).html( html + '<p>If you\'d like to find out more about how The Media Cube can help your company, <a href="contact.html">please contact us</a>.</p>' ); $( '#infoboxclose' ).click( function() { Suitcase.hideInfoBox(); }); $( window ).resize( function() { $( '#infobox' ).css( 'top', $( window ).scrollTop() ); $( '#infoboxbg' ).css( 'height', $( window ).height() ); $( '#infoboxbg' ).css( 'width', $( window ).width() ); $( '#infoboxcontainer' ).css( 'top', ( $( window ).height() / 2 ) - ( $( '#infoboxcontainer' ).height() / 2 ) ); $( '#infoboxcontainer' ).css( 'left', ( $( window ).width() / 2 ) - ( $( '#infoboxcontainer' ).width() / 2 ) ); }); $( window ).trigger( 'resize' ); } }; $( document ).ready( Suitcase.ready );
