// You may specify partial version numbers, such as "1" or "1.3",
//  with the same result. Doing so will automatically load the
//  latest version matching that partial revision pattern
//  (e.g. 1.3 would load 1.3.2 today and 1 would load 1.4.2).
google.load("jquery", "1.4.2");

google.setOnLoadCallback(function() {


    var url = String(window.location);
    var start = url.lastIndexOf("/");
    var length = url.length;

    var page = url.substr(start, (length - start));
/*
if(page.indexOf('team') > 0)
{
$('.hero div.heroCopy').attr('style', 'background:url("http://static.tumblr.com/l1qvjt6/2eZl8p36o/team.png") no-repeat scroll left top transparent;');
$('#teamMenu').show();
$('li#team').addClass('current');
}
else if(page.indexOf('approach') > 0)
{
$('.hero div.heroCopy').attr('style', 'background:url("http://static.tumblr.com/l1qvjt6/kEul8pf1i/approach.png") no-repeat scroll left top transparent;');
$('li#approach').addClass('current');
}
else if(page.indexOf('work') > 0)
{
$('.hero div.heroCopy').attr('style', 'background:url("http://static.tumblr.com/l1qvjt6/FGxl8p378/work.png") no-repeat scroll left top transparent;');
$('li#work').addClass('current');
}
else if(page.indexOf('contact') > 0)
{
$('.hero div.heroCopy').attr('style', 'background:url("http://static.tumblr.com/l1qvjt6/rk3l8pf8x/contact.png") no-repeat scroll left top transparent;');
$('li#contact').addClass('current');
}
else if(page.indexOf('/') == 0) // Insights
{
$('.hero div.heroCopy').attr('style', 'background:url("http://static.tumblr.com/l1qvjt6/vSfl8p5hg/growth.png") no-repeat scroll left top transparent;');
if(page.length == 1) {
$('.recentWork').show();
$('#insights').show();
$('li#insights').addClass('current');
}
}
*/
    $('#teamMenu h3').click(function() {
        if ($('#teamMenu').hasClass('down')) {
            $('#teamMenu ul').slideUp();
            $('#teamMenu').removeClass('down').addClass('right');
        }
        else {
            $('#teamMenu ul').slideDown();
            $('#teamMenu').addClass('down').removeClass('right');
        }
        return false;
    });
    var twitter_url = 'http://twitter.com/statuses/user_timeline/150693416.json';



    var currentPosition = 0;
    var slideWidth = 680;
    var slides = $('.slide');
    var numberOfSlides = slides.length;

    // Remove scrollbar in JS
    $('#slidesContainer').css('overflow', 'hidden');

    // Wrap all .slides with #slideInner div
    slides.wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
    .css({
        'float': 'left',
        'width': slideWidth
    });

    // Set #slideInner width equal to total width of all slides
    $('#slideInner').css('width', slideWidth * numberOfSlides);

    // Insert left and right arrow controls in the DOM
    $('#slideshow').prepend('<span class="control" id="leftControl">Move left</span>').append('<span class="control" id="rightControl">Move right</span>');

    // Hide left arrow control on first load
    manageControls(currentPosition);

    // Create event listeners for .controls clicks
    $('.control').bind('click', function() {
        // Determine new position
        if( $(this).attr('id') == 'rightControl')
        {
        	if(currentPosition == numberOfSlides-1)
        	{
        		currentPosition = 0;        	
        	}
        	else
        	{
        		currentPosition = currentPosition + 1;
        	}
        }
        else
        {
        //	alert(currentPosition + " " + numberOfSlides);
        	if(currentPosition == 0)
        	{
	        	currentPosition = numberOfSlides-1;
        	}
        	else
        	{
        		currentPosition = currentPosition - 1;
        	}
        }

        // Hide / show controls
        manageControls(currentPosition);
        // Move slideInner using margin-left
        $('#slideInner').animate({
            'marginLeft': slideWidth * (-currentPosition)
        }, 400, function() {
            //        	manageControls(currentPosition);
        });
    });



    // manageControls: Hides and shows controls depending on currentPosition


    function manageControls(position) {

        $('#slideshow').hover(function() {
            $('.control').show();
        }, function() {
            $('.control').hide();

        });
    }

//	alert($("#wrapper").height());
	$(".sidebar").height($("#wrapper").height()-40);


});

