var requestShown = false
var formShown = false
var duration = 500

$(document).ready( function(){
    if ($('#request').length) {
        $('#request-trigger').click( function(){
            $('#request').animate({left: requestShown?'-252px':'0px'}, duration)
            $('#request').toggleClass('selected')
            requestShown = !requestShown
            return false
        })
    }
    if ($('body').hasClass('body-main')) {
        $('.scene-closed-link').click( function(){
            target = parseInt(this.parentNode.id.match(/-\d+/))
            
            $('#scene-sections').animate({left: target*984+'px'}, duration)
            $('#scene-sections > li').animate({width: '984px'}, duration)
            $('.scene-big').animate({left: '0px'}, duration)
            $('#scene-switchers').fadeIn(duration)
            $('.scene-open').fadeIn(duration)
            $('#scene-switcher-' + (-target)).addClass('selected')
            $('.scene-closed-link').fadeOut(duration)
            $('.scene-big').attr('rel', '0')
            return false
        })
        $('.scene-go-back, .scene-explainer-go-back').click( function(){
            target = $('#scene-sections li').attr('id').match(/-\d+/)
            
            $('#scene-sections').animate({left: '0px'}, duration)
            $('#scene-sections > li').animate({width: '328px'}, duration)
            $('.scene-big').animate({left: '-328px'}, duration)
            $('#scene-switchers').fadeOut(duration)
            $('.scene-open').fadeOut(duration)
            $('#scene-switchers .selected').removeClass('selected')
            $('.scene-closed-link').fadeIn(duration)
            return false
        })
        $('#scene-switchers a').click( function() {
            if (!$(this).hasClass('selected')) {
                target = this.id.match(/-\d+/)
                
                $('#scene-sections').animate({left: target*984+'px'}, duration)
                
                $('#scene-switchers .selected').removeClass('selected')
                $(this).addClass('selected')
            }
            return false
        })
        
        animate = function(th, dir) {
       		if(parseInt(dir)==1){
	            thebig = $(th).parent().parent().parent().children('.scene-big')
	            rel = parseInt(thebig.attr('rel')) + 1
	            if (rel >= thebig.children('li').length)
	                rel = 0;
	            thebig.attr('rel', rel)
	            thebig.animate({left: (rel*-984) + 'px'})
       		}
       		else{
	            thebig = $(th).parent().parent().parent().children('.scene-big')
	            rel = parseInt(thebig.attr('rel')) - 1;
	            if (rel < 0)
	                rel = thebig.children('li').length -1;
	            thebig.attr('rel', rel)
	            thebig.animate({left: (rel*-984) + 'px'})
       		}
        }        
        
        $('.scene-prev').click( function() {
            animate(this, -1)
            return false
        })
        $('.scene-next').click( function() {
            animate(this, 1)
            return false
        })
        $('.scene-pause').click( function() {
            return false
        })
    }
    
    if ($('#feedback-roll, #ask-link').length) {
        $('#ask-form').hide()
        $('#feedback-roll, #ask-link').click( function() {
            formShown = !formShown
            if (formShown) {
                $('#ask-form').show(duration)
            } else {
                $('#ask-form').hide(duration)
            }
            return false
        })
    }
    
    if ($('body').hasClass('body-ask-section')) {
        $('.ask-one dl').hide()
        $('.ask-one .collapser').click( function(){
            $(this).toggleClass('active')
            
            dl = $(this).parent().next()
            if ($(this).hasClass('active')) {
                dl.show()
            } else {
                dl.hide()
            }
            return false
        })
    }
    
    /*
    $('.schemes-zoom').click( function() {
        $('#lightbox-img').attr('src', $(this).attr('rel'))
        $('body').addClass('body-zoom')
        $('#lightbox').fadeIn()
    })
    */
    $('#lightbox-close').click(function(){
        $('body').removeClass('body-zoom')
        $('#lightbox').fadeOut()
    })
})
