/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$.pyte.setBasePath('assets/js/');
$.pyte.setBasePath('assets/css/', $.pyte.STYLESHEET);

$.require( 'functions.json' );
$.require( 'functions.delegate' );
$.require( 'apps.ynk.UrlMatcher' );
$.require( 'apps.ynk.remoting.Remoting' );
$(function()
{
    var urlMatcher = new apps.ynk.UrlMatcher();

    urlMatcher.check(
        [ '' ],
        [ 'plugins.ynk_lava', 'plugins.easing' ],
        function()
        {
            apps.ynk.remoting.Remoting.setGateway( $('base').attr('href') + 'json.php' );
            $('ul.lava.menu').ynkLava();
        }
    );

    urlMatcher.check(
        [ $('base').attr('href'), $('base').attr('href')+'index.php' ],
        [],
        function()
        {
            $('div.quiz_shortcut, div.info_shortcut, div.top5_shortcut').height( Math.max( $('div.top5_shortcut p').height() + 50, 200 ));

            var counter = 1;
            $('div.twitter_ticker div div').hide().css('text-align', 'center');
            $('div.twitter_ticker div div:first').fadeIn();
            setInterval( function(){
                $('div.twitter_ticker div div').hide();

                $($('div.twitter_ticker div div')[ counter ]).width( $('div.twitter_ticker div').width() );
                /*while( $($('div.twitter_ticker span')[ counter ]).height() != 19 )
                {
                    $($('div.twitter_ticker span')[ counter ]).width( $($('div.twitter_ticker span')[ counter ]).width() + 1 );
                }*/
                $($('div.twitter_ticker div div')[ counter ]).css( { 'margin-left': 0, width: $($('div.twitter_ticker div div')[ counter ]).width() } );
                $($('div.twitter_ticker div div')[ counter ]).fadeIn();
                /*if ( $($('div.twitter_ticker div div')[ counter ]).width() > $('div.twitter_ticker div').width() - 50 )
                    $($('div.twitter_ticker div div')[ counter ]).animate( {marginLeft: -($($('div.twitter_ticker div div')[ counter ]).width() - ( $('div.twitter_ticker div').width() - 50 ) ) }, { duration: 3000, easing: 'easeInOutSine' } );*/
                counter++;
                if ( counter == $('div.twitter_ticker div div').length )
                    counter = 1;
            }, 5000 );
        }
    );

    urlMatcher.check(
        [ '/quiz' ],
        [ 'apps.ynk.view.ViewStack',
          'apps.quiz.view.ExplainView',
          'apps.quiz.view.PersonInfoView',
          'apps.quiz.view.QuizView',
          'apps.quiz.view.QuizResultView' ],
        function()
        {
            $('#content div.quiz_uitleg, #content div.quiz_gegevens, #content div.quiz_game, #content div.quiz_result').css( 'visibility', 'visible' );

            $('div.difficulty ul.lava').ynkLava({
                overlap : {horizontal:20, vertical:10 },
                disableClick: true
            });
            
            var viewStack = new apps.ynk.view.ViewStack( [
                new apps.quiz.view.ExplainView( '#content div.quiz_uitleg' ),
                new apps.quiz.view.PersonInfoView( '#content div.quiz_gegevens' ),
                new apps.quiz.view.QuizView( '#content div.quiz_game' ),
                new apps.quiz.view.QuizResultView( '#content div.quiz_result' )
            ], true );
            viewStack.goToViewName( 'explainView' );
            //var app = new apps.Quiz();
            //app.start();
        }
    );

    urlMatcher.check(
        [ '/cijfers_van_oranje' ],
        [   'apps.ynk.view.ViewStack',
            'apps.cvo.view.CategoryChoiseView',
            'apps.cvo.view.InfoSliderView',
            'apps.cvo.view.InfoContentView'],
        function()
        {
            var views = [
                new apps.cvo.view.CategoryChoiceView( '#content div.category' ),
                new apps.cvo.view.InfoSliderView( '#content div.info_slider' ),
                new apps.cvo.view.InfoContentView( '#content div.info_view' )
            ];
            var viewStack = new apps.ynk.view.ViewStack( views , true, false );
            viewStack.goToViewName( 'categoryChoiceView' );
            views[0].preAction();
        }
    );
});
