jQuery(document).ready(function() {

    var speed = 10;     //Page scroll speed, decrease to speed up


    //Resize the sections
    jQuery(window).resize(function() {
        var height = jQuery(window).height();
        jQuery('.section').each(function(i, el) {
            var element = jQuery(el);
            if(element.height() < height)
            {
                element.css('height', height+'px');
            }
        });
    }).resize();

    //The menu system
    var start = 0;
    var end = 0;
    jQuery('.menu li a').click(function(event) {
        event.preventDefault();

        var name = jQuery(this).attr('href').replace('#', '');
        var anchor = jQuery('a[name='+name+']');
        start = jQuery(window).scrollTop();
        end = anchor.offset().top;
        window.location.hash = name;
        return false;
    });

    //Page scrolling
    function scroll()
    {
        var max = Math.max(start, end);
        var min = Math.min(start, end);
        
        if(max - min > 1)
        {
            var offset = (max-min)/speed;
            if(start > end)
            {
                start -= offset;  
            }
            else
            {
                start += offset;
            }
            jQuery(window).scrollTop(start);
        }
    }
    window.setInterval(scroll, 10);

    //Work section
    jQuery('.work-tabs').tabs({
        fx: {opacity: 'toggle'}
    });

    jQuery('.overlay').hide().parent().mouseover(function() {
      jQuery(this).find('.overlay').slideDown('fast').data('can-hide', false);
    }).mouseout(function() {
        jQuery(this).find('.overlay').data('can-hide', true);
    });
    jQuery('.overlay').mouseover(function() {
        jQuery(this).data('can-hide', false);
    }).mouseout(function() {
        jQuery(this).data('can-hide', false);
    });

    function hideOverlays()
    {
        var o = jQuery('.overlay:visible');
        if(o.data('can-hide'))
        {
            o.slideUp('normal');
        }
    }
    window.setInterval(hideOverlays, 1000);

    jQuery('a[rel^="lightbox"]').prettyPhoto({
		animationSpeed: "fast", /* fast/slow/normal */
		padding: 30, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: false, /* true/false */
		counter_separator_label: "/", /* The separator for the gallery counter 1 "of" 2 */
		theme: "dark_square" /* light_rounded / dark_rounded / light_square / dark_square */
	});
});


