var SLIDES_TEMPLATES            = {                                            start: {                                            id: 'start',                                            template: '<table><tbody><tr><td><h1>%header%</h1></td></tr></tbody></table><div class = "b-content">%content%</div><div class = "tmptag"></div>'                                        },                                                                                section: {                                            id: 'section',                                            template: '<table><tbody><tr><td><h1>%header%</h1></td></tr></tbody></table>'                                        },                                                                                simple: {                                            template: '<h1>%header1%</h1>\n<h2>%header2%</h2><div class = "b-content">%content%</div>'                                        },                                                                                columns: {                                            template: '<h1>%header1%</h1>\n<h2>%header2%</h2>'                                        },                                                                                end: {                                            id: 'end',                                            template: '<div class = "b-content">%content%</div><div class = "tmptag"></div>'                                        }                                  }                                  var NAVIGATION_TEMPLATE         = '<div id = "navigation">\                                        <a href = "#prev" title = "&larr; Сюда" id = "arr-prev">&larr;</a>\                                        <a href = "#notes-mode" title = "Режим заметок" id = "notes-mode">×</a>\                                        <a href = "#next" title = "Туда &rarr;" id = "arr-next">&rarr;</a>\                                  </div>';                                  var STYLESHEET_TEMPLATE         = '<link rel = "stylesheet" type = "text/css" charset = "utf-8" media = "all" href = "layout/stylesheets/%name%.css" />';if(typeof($) == 'function') {        var aNotes              = new Array();    var aSlides             = new Array();    var isNavigationVisible = false;    var title               = document.title;    var aCurrentSlide       = 0;    var aCtrlPressed        = false;    var isPreview           = false;        function showSlide(aSlide) {        aCurrentSlide = aSlide;            $('.l-slide').empty().attr('class', '').addClass('l-slide').append(aSlides[aSlide].template);        if(typeof(aSlides[aSlide].id) == 'string') {            $('body').attr('id', aSlides[aSlide].id);        } else {            $('body').removeAttr('id');        }/*        if($.browser.opera) {            $('.inc, .dec').removeClass('inc').removeClass('dec');        }*/        if(navigator.appVersion.indexOf('MSIE') != -1) { // I HATE ie!!!            $('ul.inc > li').each(function() {                $(this).addClass('inc');            });            $('ul.inc').removeClass('inc');                        $('ol.inc > li').each(function() {                $(this).addClass('inc');            });            $('ol.inc').removeClass('inc');        } else {            $('.l-slide ul.inc, .l-slide ol.inc').removeClass('inc').children('li').addClass('inc');        }        if($('.l-slide .inc').length > 0) {            if($('.l-slide .inc:first').is('div') && $('.l-slide .inc:first()').children('.inc').length > 0) {                $('.l-slide .inc:first()').removeClass('inc').addClass('dec');            }            $('.l-slide .inc:first()').removeClass('inc').addClass('dec active');        } else {            $('.l-slide .dec:last()').addClass('active');        }                /*$('ul.dec, ol.inc').removeClass('inc').children().addClass('inc');*/                $('#pageNumber').removeClass('hidden'); //.html(aSlide + 1);        if(aSlide == 0 || aSlide == (aNotes.length - 1)) $('#pageNumber').addClass('hidden');                $('#navigation a').removeClass('disable');        if($.presentation.isFirstSlide()) $('#arr-prev').addClass('disable');        if($.presentation.isLastSlide()) $('#arr-next').addClass('disable');                $('#navigation select option').attr('selected', '');        $($('#navigation select option').get(aSlide)).attr('selected', 'selected');            }        function switchMode(isSlides) {        /* Swap stylesheets */        $('link').each(function() {            if($(this).attr('href').indexOf('notes') != -1 || $(this).attr('href').indexOf('presentation') != -1) {                $(this).attr('media', $(this).attr('media') == 'all' ? 'print' : 'all');            }        });                if(isSlides) {            /*$.presentation.aCounter = 0;*/            document.title = $(aNotes[0]).find('h1').html();            $('body').addClass('presentation');            $('.l-wrap').empty().append('<div class = "l-slide"></div>').append('<div id = "pageNumber"></div>').append(NAVIGATION_TEMPLATE);            $('#navigation').fadeTo('slow', 0);            $('#arr-prev').click(function() {                if(!$(this).hasClass('disable')) $.presentation.goPrev();                return false;            });            $('#arr-next').click(function() {                if(!$(this).hasClass('disable')) $.presentation.goNext();                return false;            });            $('#notes-mode').click(function() {                /*                if(isPreview) {                    isPreview = false;                    $('body').removeClass('preview');                }                */                $.presentation.switchMode();                return false;            })            /*$.presentation.goTo(0);*/            $.presentation.goToFirst();        } else {            document.title = title;                isPreview = false;                $('body').removeClass('presentation').removeClass('preview');            $('.l-wrap').empty().append('<ol id = "slides"></ol>');            $('#slides').append(aNotes);        }            }        function canGo(toNext) {                if(aCtrlPressed) {            if(toNext) {                $('.inc, .active').removeClass('inc').removeClass('active').addClass('dec');            } else {                $('.dec').removeClass('dec').removeClass('active').addClass('inc');            }            aSlides[aCurrentSlide].template = $('.l-slide').html();            return true;        }                //return true;                var result = true;                if(toNext) {            incCounter = $('.l-slide .inc').length;            if(incCounter >= 0) {                $('.l-slide .active').removeClass('active');                if($('.l-slide .inc:first()').is('div') && $('.l-slide .inc:first()').children('.inc').length > 0) {                    $('.l-slide .inc:first()').removeClass('inc').addClass('dec');                    incCounter--;                }                $('.l-slide .inc:first()').removeClass('inc').addClass('dec active');                incCounter--;            }                        result = incCounter <= 0;         } else {            if($('.l-slide .dec').length >= 0) {                var $last = $('.l-slide .dec:last()');                if($last.parent().is('div') && $last.parent().hasClass('dec') && $last.parent().find('.dec').length == 1) {                    $last.parent().removeClass('dec').addClass('inc');                }                $('.l-slide .active:last()').removeClass('dec').removeClass('active').addClass('inc');                $('.l-slide .dec:last()').addClass('active');            }                        result = $('.l-slide .dec').length == 0;        }                if(result) aSlides[aCurrentSlide].template = $('.l-slide').html();                return result && $('.l-slide .active').length == 0;    }        /*     *  Entry point     */    $(document).ready(function() {                setEngine();                $('#slides > li:last()').addClass('last');        aNotes = $('#slides > li');        for(var i = 0; i < aNotes.length; i++) {            whatIsThis(i, $(aNotes[i]).clone());        }        if(aNotes.length > 0 && aNotes.length == aSlides.length && $.makePresentation( { aSlidesLength  : aSlides.length,                                  onShowSlide    : showSlide,                                  onSwitchMode   : switchMode,                                 canGo          : canGo                              } )) {        } else {            $('script').remove();        }        var f = function() {            if(this.href && this.href.indexOf('preview') != -1) {                isPreview = true;                $('body').addClass('preview');            }            $.presentation.switchMode();            return false;        }                $('.b-mode-switcher a').click(f);        f();        $('.l-wrap').mousemove(function(e) {            if(typeof($.presentation) != 'object' || !$.presentation.isSlides) return false;                        var height = $('.l-wrap').height();            if(!isNavigationVisible && e.pageY >= (height - parseInt(height * 0.2))) {                $('#navigation').fadeTo('slow', 1);                isNavigationVisible = true;            } else if(isNavigationVisible && e.pageY <= (height - parseInt(height * 0.2))) {                $('#navigation').animate( { opacity:0 }, 500 );                isNavigationVisible = false;            }        });                $(document).keydown(function(e) {            if(e.keyCode == 17 && !aCtrlPressed) {                aCtrlPressed = true;            }        });                $(document).keyup(function(e) {            aCtrlPressed = aCtrlPressed && e.keyCode != 17;        });    });        /*     *  Check slide type     */    function whatIsThis(index, note) {        //alert($(note).html());        if(index == 0) {            isStartSlide(note);        } else if(index == aNotes.length - 1) {            isEndSlide(note);        } else if($(note).hasClass('section')) {            isSectionSlide(note);        } else if($(note).children('.column').length > 0) {            isColumnSlide(note);        } else {            isSimpleSlide(note);        }    }        function isStartSlide(note) {        var slide = clone(SLIDES_TEMPLATES.start);            slide.template = slide.template.replace(/%header%/, $(note).find('h1').html());            $(note).find('h1').remove();            slide.template = slide.template.replace(/%content%/, $(note).html());                aSlides.push(slide);    }        function isEndSlide(note) {        var slide = clone(SLIDES_TEMPLATES.end);            slide.template = slide.template.replace(/%content%/, $(note).html());                    aSlides.push(slide);    }        function isSectionSlide(note) {        var slide = clone(SLIDES_TEMPLATES.section);            slide.template = slide.template.replace(/%header%/, $(note).find('h1').html());                    aSlides.push(slide);    }        function isColumnSlide(note) {        var slide = clone(SLIDES_TEMPLATES.columns);            slide.template = slide.template.replace(/%header1%/, $(note).find('h1').html());            slide.template = slide.template.replace(/%header2%/, $(note).find('h2').html());                $(note).find('h1, h2').remove();                            $(note).find('.column:first()').addClass('column-left');            if($(note).find('.column').length > 1) $(note).find('.column:last()').addClass('column-right');            slide.template = slide.template + $(note).html();                    aSlides.push(slide);    }        function isSimpleSlide(note) {        var slide = clone(SLIDES_TEMPLATES.simple);            slide.template = slide.template.replace(/%header1%/, $(note).find('h1').html());            slide.template = slide.template.replace(/%header2%/, $(note).find('h2').html());            $(note).children('h1, h2').remove();                        $(note).children('blockquote').each(function() {                slide.id = 'quote';                if($(this).html().indexOf('«') == -1) $(this).addClass('graphical');            });                        slide.template = slide.template.replace(/%content%/, $(note).html());                aSlides.push(slide);    }    /*     *  Add 2 body class with current engine     */     function setEngine() {                var engine = '';                    if($.browser.mozilla) {            engine = 'gecko';        } else if($.browser.safari) {            engine = 'webkit';        } else if($.browser.opera) {            engine = 'opera';        } else {            if(navigator.appVersion.indexOf('MSIE 7') != -1) {                engine = 'ie7';            } else {                engine = 'ie';            }        }                $('head').append(STYLESHEET_TEMPLATE.replace(/%name%/, engine));        /*$('body').addClass(engine);*/    }        /*     *  Add clone method     */     function clone(myObj) {        if(typeof(myObj) != 'object') return myObj;        if(myObj == null) return myObj;            var myNewObj = new Object();            for(var i in myObj) myNewObj[i] = clone(myObj[i]);        	return myNewObj;    }    /*         Object.prototype.clone = function() {        return eval(uneval(this));    }    */}
