$(function(){
   
    // CAROUSEL UI
    $('.carousel-ui').each(function(){
        $$ = $(this);
        $('.carousel-list > ul > li', $$).bind('mouseenter', function() {
            var slide = $(this).addClass('active');
            slide.siblings().removeClass('active');
            $('ul', $$).animate({
                left: '-' + slide.prevAll().length * 604 + 'px' 
            }, {
                duration: 'fast',
                queue: false
            });
            
            $('body').css('cursor', 'pointer');
        }).bind('mouseleave', function() {
            $('body').css('cursor', 'auto');
        });
    });   
    
    // CAROUSEL INTERFACE
    $('.carousel-interface').each(function(){
        $$ = $(this);
        $(window).resize( function() { resizeCarousel(); });
        function resizeCarousel() {
            $$.find('.carousel-view li').css('width', window.innerWidth);
        }
        resizeCarousel();
        $('.carousel-list ul li a', $$).bind('click', function() {
            var slide = $(this).parent().addClass('active');
            slide.siblings().removeClass('active');
            $('.carousel-view ul', $$).animate({
                left: '-' + slide.prevAll().length * window.innerWidth + 'px' 
            }, {
                duration: 'normal',
                queue: false
            });
            return false;
        })
    });

    
    // HIGHLIGHT CODE
    $("pre code").each(function() {
        
        $$ = $(this);
        $$.html( 
            $$.html()
                // html code
                //.replace(/&/g,"&amp;")
                .replace(/"/g,"&quot;")
                .replace(/</g,"&lt;")
                .replace(/>/g,"&gt;")
                // values
                .replace(/(&quot;[a-zA-Z0-9.\[\]#_\. \?=%\/:\\'&,-]*&quot;)/g, '<span class="value">$1</span>')
                .replace(/('[^']*')/g, '<span class="value">$1</span>')
                // comments
                .replace(/(&lt;!-- .* --&gt;)/g, '<span class="comment">$1</span>')
                .replace(/(\/\* .* \*\/)/g, '<span class="comment">$1</span>')
                .replace(/(\/\/.*)(\r\n|\r|\n)/g, '<span class="comment">$1</span>$2')
        );    
  
        if($$.hasClass('js')) { // JAVASCRIPT JQUERY
            $$.html(
                $$.html()
                    .replace(/(([0-9]|true|false|null))/g, '<span class="value">$1</span>')
                    .replace(/(this|var|function|\$|jQuery)/g, '<span class="special">$1</span>')

            );
        } else if($$.hasClass('html')) { // HTML & CSS
            $$.html(
                $$.html()
                    .replace(/(&lt;\/?[a-zA-Z0-9]*)/g, '<span class="special">$1</span>')
                    .replace(/(\/?&gt;)/g, '<span class="special">$1</span>')
                    .replace(/(\r\n|\r|\n)(.*){/g, '$1<span class="special">$2</span>{')
                    .replace(/:([^:;]*);/g, ':<span class="value">$1</span>;')
            );
        } else { // PHP ZEND
            $$.html( 
                $$.html()
                    .replace(/(([0-9]|true|false|null))/g, '<span class="value">$1</span>')
                    .replace(/(\$[a-zA-Z0-9_]*)/g, '<span class="special">$1</span>')
                    .replace(/([^a-zA-Z0-9_]?)(return|if|else|endif|extends|implements|for|foreach|endfor|endforeach|function|public|private|parent|self)([^a-zA-Z0-9_])/g, '$1<span class="special">$2</span>$3')
                    .replace(/(class )/g, '<span class="special">$1</span>')
            );
        }           
    });
    
});

