    function capitaliseFirstLetter(string){
        return string.charAt(0).toUpperCase() + string.slice(1);
    }
    var isMobile = false;
    if( navigator.userAgent.match(/Android/i) ||
     navigator.userAgent.match(/webOS/i) ||
     navigator.userAgent.match(/iPhone/i) ||
     navigator.userAgent.match(/iPod/i) ||
     navigator.userAgent.match(/iPad/i)
     ){
        isMobile = true;
    }
    $(function(){

        $("a[rel='oc_work'], a[rel='fishy_work'], a[rel='relavid_work'], a[rel='ipt_work'], a[rel='lenick_work'], a[rel='xterra_work'], a[rel='sups_work'], a[rel='equifax_work']").colorbox();
        $("a.main_work_img").click(function(){
            $(this).next().trigger('click');
            return false;
        });
        $('#contact_form').submit(function(){
            if($('#id_name').val() == "Name")$('#id_name').val("");
            if($('#id_website').val() == "Website")$('#id_website').val("");
            if($('#id_timeframe').val() == "Timeframe")$('#id_timeframe').val("");
            if($('#id_email').val() == "Email")$('#id_email').val("");
            if($('#id_message').val() == "Tell us more about your project.")$('#id_message').val("").html("");
            $.post("/contact/ajax/", $(this).serialize(), function(data){
                if(data["form_success"]){
                   alert('Thank you! Someone will contact you shortly.');
                   $('#contact_form input, #contact_form select, #contact_form textarea').val(''); 
                   $('#contact_form textarea').html(''); 
                }else{
                    var err_msg = 'Please fix the following form errors:\n\n';
                    for(error in data["form_errors"]){
                        err_msg += ( capitaliseFirstLetter(error) + ": " )
                        err_msg += data.form_errors[error];
                        err_msg += "\n" 
                        $('#contact_form #id_'+error).addClass('error');
                    }   
                    alert(err_msg);
                }   
                $('#contact_form input, #contact_form textarea').blur();
            }, "json");
            return false; 
        }); 

        $('.reset').click(function(){
            $('#contact_form input, #contact_form textarea').each(function(index){
                $(this).val($(this).attr("title"))
            });
            return false;
        });


        if(isMobile){
            $('#footer').css({'position':'static'});
            $('#foot_pad').css({'height':0});
        }
        $('input, textarea').live('focus', function(){
            var $theinput = $(this);
            var $value = $(this).attr('title');
            $theinput.removeClass('error');
            if($theinput.val() == $value){  
                $theinput.val('');
            }
        }).live('blur', function(){
            var $theinput = $(this);
            var $value = $(this).attr('title');
            if($theinput.val() == ''){  
                $theinput.val($value);
            }
        });
        $('nav a').hover(function(){
            if(!$(this).hasClass('active')){
                $(this).css({backgroundPosition:"0 -50px"}).animate({'height':'50px', 'line-height':'60px', backgroundPosition:"0 -35px"}, 100);
            }
        }, function(){
            if(!$(this).hasClass('active')){
                $(this).animate({'height':'35px', 'line-height':'27px', backgroundPosition:"0 -50px"}, 100, function(){
                    $(this).css({backgroundPosition:"0 0"});
                });
            }
        });
        $('nav a, a.scroll').click(function(){
            var $this = $(this);
            if(!$this.hasClass('active')){
                $('nav a.active').removeClass('active').mouseout();
                $this.addClass('active');
            }
            $('html,body').animate({
                scrollTop: $($this.attr('href')).offset().top
            }, 1000);
            return false;
        });
        $(window).scroll(function (e) { 
            $('#quickinfo_wrap').stop();
            var lastScroll = new Date().getTime();
            if ( ( new Date().getTime() - lastScroll ) >= ( 0 - 20 ) ){

                if(e.currentTarget.scrollY > 880){
                    if(e.currentTarget.scrollY > 1457){
                        $('#quickinfo_wrap').animate({'top': '737px'}, 250);
                    }else {
                        $('#quickinfo_wrap').animate({'top': (e.currentTarget.scrollY - 880)+'px'}, 250);
                    }
                }else{
                    $('#quickinfo_wrap').animate({'top': 0}, 250);
                }
            }
        });

        $('nav a:first').trigger('mouseover').addClass('active');//.trigger('click');
        // Context Menu Stuff
/*
        $('body').contextMenu('context-menu-1', {
            'Copyright &copy; 2011 Analog Interactive': {
                click: function(element) {  // element is the jquery obj clicked on when context menu launched
                    //alert('Menu item 1 clicked');
                },
                klass: "menu-item-1" // a custom css class for this menu item (usable for styling)
            }
        });
        
*/
    });

