//Homepage functionality
Util.namespace('Nerland.View.Home', function ()
{
	var slideshow;
	var slider;
	
    var init = function ()
    {
    
    	//initialize slideshow
    	slideshow = $("#slideshow");
    	Nerland.Components.Slideshow.init( slideshow, {time:4000,speed:1000} ); 
    	
    	//initialize slider
    	slider = $("#slider");
    	Nerland.Components.Slider.init( slider, {time:5000,speed:500, padding:17} );
    	
    };

    return {
        'init': init
    };
    
});

Util.namespace('Nerland.View.About', function () {
    var flickrSlideshow;
    var worldSlideshow;
    var officeSlideshow;

    var init = function () {
        // show checkmark next to active menu section
        $("#menu-about").addClass("active");

        var flickComponent;

        $("#flickr-slides").jflickrfeed({
            limit: 5,
            qstrings: {
                id: '47821697@N03'
            },
            itemTemplate:
    	    '<div class="flickr-slide">' +
				'<a href="{{link}}" target="_blank"><img src="{{image_m}}" alt="{{title}}" /></a>' +
                '<h4>{{title}}</h4>' +
				'<p>{{description}}</p>' +
            '</div>'
        }, function (data) {
            // add ids
            $("#flickr-slides").children().each(function (index) {
                $(this).attr("id", "flickr-slide-" + (index + 1));
            });

            // initialize flickr slideshow
            flickrSlideshow = $("#flickr-slideshow");
            flickrComponent = Nerland.Components.FadingSlideshow.init(flickrSlideshow, {
                time: 4000,
                speed: 500,
                pager: "#flickr-controls",
                slideWrapper: "#flickr-slides",
                slideClass: "flickr-slide",
                activeClass: "active"
            });
        });

        // initially hide office slideshow embedded videos
        $(".video-embed").hide();
        // initialize Nerland world slideshow
        worldSlideshow = $("#world-slideshow");
        Nerland.Components.FadingSlideshow.init(worldSlideshow, {
            time: 0,
            speed: 0,
            pager: "#world-pager",
            slideWrapper: "#world-slides",
            slideClass: "world-slide",
            activeClass: "active",
            beforeAnimate: function ($slideId) {
                // handle special case: the #world-office slide hides the right column
                if ($slideId == "#world-office") {
                    // pause the flickr slideshow
                    flickrComponent.pause();
                    // hide the right column
                    $("#world").addClass("twocol");
                    // show the embedded videos
                    $(".video-embed").show();
                }
            },
            afterAnimate: function ($previousId, $currentId) {
                // handle special case: all slides other than the #world-office slide show the right column
                if ($previousId == "#world-office") {
                    $("#world").removeClass("twocol");
                    flickrComponent.resume();
                    // hide the embedded videos
                    $(".video-embed").hide();
                }
            }
        });
        // initialize the office slideshow
        officeSlideshow = $("#office-slideshow");
        Nerland.Components.FadingSlideshow.init(officeSlideshow, {
            time: 0,
            speed: 0,
            pager: "#office-pager",
            slideWrapper: "#office-slides",
            slideClass: "office-slide",
            activeClass: "active"
        });
        // handle office slideshow pager scrolling
        Nerland.Components.OfficePagerScroller.init({
            thumbnailWidth: 135
        });
    };

    return {
        'init': init
    };

});

Util.namespace('Nerland.View.Bio', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-about").addClass("active");
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.Video', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-about").addClass("active");
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.WhatWeDo', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-what-we-do").addClass("active");
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.Category', function ()
{
    var categorySlideshow;
    var colorbox;
	
	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-what-we-do").addClass("active");

		// initialize colorbox
		$('.lower-left ul li.colorbox a').colorbox();

		// initialize category slideshow
		categorySlideshow = $("#category-slideshow");
		Nerland.Components.FadingSlideshow.init( categorySlideshow, {
			time:0,
			speed:0
		});
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.HowWeThink', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-how-we-think").addClass("active");
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.Work', function () {
    var colorbox;

    var init = function () {
        // show checkmark next to active menu section
        $("#menu-work").addClass("active");

        // initialize colorbox
        $('.work .media a').colorbox();

        $('#sort-category').click(function () {
            $("#sort-category").addClass("active");
            $("#sort-media").removeClass("active");
            $("#sort-client").removeClass("active");
            $("#sort-latest").removeClass("active");
            $('#list-clients').hide();
            $('#list-media').hide();
            $('#list-categories').show();
        });
        $('#sort-media').click(function () {
            $("#sort-category").removeClass("active");
            $("#sort-media").addClass("active");
            $("#sort-client").removeClass("active");
            $("#sort-latest").removeClass("active");
            $('#list-clients').hide();
            $('#list-categories').hide();
            $('#list-media').show();
        });
        $('#sort-client').click(function () {
            $("#sort-category").removeClass("active");
            $("#sort-media").removeClass("active");
            $("#sort-client").addClass("active");
            $("#sort-latest").removeClass("active");
            $('#list-categories').hide();
            $('#list-media').hide();
            $('#list-clients').show();
        });

    };

    return {
        'init': init
    };

});

Util.namespace('Nerland.View.CaseStudies', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-case-studies").addClass("active");
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.Careers', function ()
{

	var init = function ()
	{
		// init carrot dropdowns
		$(".job-slider").hide();
		$(".job-header").click(function(){
			$(this).toggleClass('open');
			$(this).next().slideToggle(); //toggleClass('hide');
		});
	};
	
	return {
		'init': init
	};
	
});

Util.namespace('Nerland.View.TrustWorks', function ()
{

	var init = function ()
	{
		// show checkmark next to active menu section
		$("#menu-what-we-do").addClass("active");
	};
	
	return {
		'init': init
	};
	
});


