$(document).ready(function(){
    //Load pages 
    $("#header").load("html/header.html");
	
	 $("#pageNine").load('html/pageNine.html #pageNineInsert', function(){
        $("#viewerNine").scrollable({
            items: '#panesNine',
            size: 1,
            navi: 'ul.tabsNine',
            activeClass: 'current',
            onSeek: function(){
                $f().unload();
            }
        });
        $f("playerNine", "swf/flowplayer-3.1.3.swf", {
            clip: {
                autoPlay: true,
                autoBuffering: true,
                baseUrl: '../'
            },
            plugins: {
                controls: {
                    //setup no timer
                    time: false,
                    //hide controllbar
                    autoHide: 'always',
                    hideDelay: 2000,
                    //css the controllbar
                    bufferColor: '#343434',
                    progressColor: '#bf85ab',
                    buttonColor: '#bf85ab',
                    buttonOverColor: '#343434',
                    tooltipColor: '#bf85ab',
                    tooltipTextColor: '#ffffff',
                    backgroundColor: '#ffffff',
                    background: ' url(images/viewer/playerBG.png) repeat',
                    backgroundGradient: 'high',
                    opacity: 0.85
                }
            }
        });
        $("#triggerNine").tooltip({
            // place tooltip on the right edge 
            position: ['bottom', 'centre'],
            opacity: [0.90],
            // a little tweaking of the position 
            offset: [20, -35],
            delay: 800,
            // use a simple show/hide effect 
            effect: 'slidedown'
        });
    });
	
    $("#pageEight").load('html/pageEight.html #pageEightInsert', function(){
        $("#viewerEight").scrollable({
            items: '#panesEight',
            size: 1,
            navi: 'ul.tabsEight',
            activeClass: 'current',
            onSeek: function(){
                $f().unload();
            }
        });
        $f("playerEight", "swf/flowplayer-3.1.3.swf", {
            clip: {
                autoPlay: true,
                autoBuffering: true,
                baseUrl: '../'
            },
            plugins: {
                controls: {
                    //setup no timer
                    time: false,
                    //hide controllbar
                    autoHide: 'always',
                    hideDelay: 2000,
                    //css the controllbar
                    bufferColor: '#343434',
                    progressColor: '#bf85ab',
                    buttonColor: '#bf85ab',
                    buttonOverColor: '#343434',
                    tooltipColor: '#bf85ab',
                    tooltipTextColor: '#ffffff',
                    backgroundColor: '#ffffff',
                    background: ' url(images/viewer/playerBG.png) repeat',
                    backgroundGradient: 'high',
                    opacity: 0.85
                }
            }
        });
        $("#triggerEight").tooltip({
            // place tooltip on the right edge 
            position: ['bottom', 'centre'],
            opacity: [0.90],
            // a little tweaking of the position 
            offset: [20, -35],
            delay: 800,
            // use a simple show/hide effect 
            effect: 'slidedown'
        });
    });
    
    $("#pageSeven").load('html/pageSeven.html #pageSevenInsert', function(){
        $("#viewerSeven").scrollable({
            items: '#panesSeven',
            size: 1,
            navi: 'ul.tabsSeven',
            activeClass: 'current',
            onSeek: function(){
                $f().unload();
            }
        });
        $f("playerSeven", "swf/flowplayer-3.1.3.swf", {
            clip: {
                autoPlay: true,
                autoBuffering: true,
                baseUrl: '../'
            },
            plugins: {
                controls: {
                    //setup no timer
                    time: false,
                    //hide controllbar
                    autoHide: 'always',
                    hideDelay: 2000,
                    //css the controllbar
                    bufferColor: '#343434',
                    progressColor: '#bf85ab',
                    buttonColor: '#bf85ab',
                    buttonOverColor: '#343434',
                    tooltipColor: '#bf85ab',
                    tooltipTextColor: '#ffffff',
                    backgroundColor: '#ffffff',
                    background: ' url(images/viewer/playerBG.png) repeat',
                    backgroundGradient: 'high',
                    opacity: 0.85
                }
            }
        });
        $("#triggerSeven").tooltip({
            // place tooltip on the right edge 
            position: ['bottom', 'centre'],
            opacity: [0.90],
            
            // a little tweaking of the position 
            offset: [20, -35],
            delay: 800,
            // use a simple show/hide effect 
            effect: 'slidedown'
        
        });
    });
    
    setTimeout(function(){
    
        $("#pageSix").load('html/pageSix.html #pageSixInsert', function(){
            $("#viewerSix").scrollable({
                items: '#panesSix',
                size: 1,
                navi: 'ul.tabsSix',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $f("playerSix", "swf/flowplayer-3.1.3.swf", {
                clip: {
                    autoPlay: true,
                    autoBuffering: true,
                    baseUrl: '../'
                },
                plugins: {
                    controls: {
                        //setup no timer
                        time: false,
                        //hide controllbar
                        autoHide: 'always',
                        hideDelay: 2000,
                        //css the controllbar
                        bufferColor: '#343434',
                        progressColor: '#bf85ab',
                        buttonColor: '#bf85ab',
                        buttonOverColor: '#343434',
                        tooltipColor: '#bf85ab',
                        tooltipTextColor: '#ffffff',
                        backgroundColor: '#ffffff',
                        background: ' url(images/viewer/playerBG.png) repeat',
                        backgroundGradient: 'high',
                        opacity: 0.85
                    }
                }
            });
            $("#triggerSix").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
        
        
        $("#pageFive").load('html/pageFive.html #pageFiveInsert', function(){
            $("#viewerFive").scrollable({
                items: '#panesFive',
                size: 1,
                navi: 'ul.tabsFive',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $f("player", "swf/flowplayer-3.1.3.swf", {
                clip: {
                    autoPlay: true,
                    autoBuffering: true,
                    baseUrl: '../'
                },
                plugins: {
                    controls: {
                        //setup no timer
                        time: false,
                        //hide controllbar
                        autoHide: 'always',
                        hideDelay: 2000,
                        //css the controllbar
                        bufferColor: '#343434',
                        progressColor: '#bf85ab',
                        buttonColor: '#bf85ab',
                        buttonOverColor: '#343434',
                        tooltipColor: '#bf85ab',
                        tooltipTextColor: '#ffffff',
                        backgroundColor: '#ffffff',
                        background: ' url(images/viewer/playerBG.png) repeat',
                        backgroundGradient: 'high',
                        opacity: 0.85
                    }
                }
            });
            $("#triggerFive").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
        $("#pageFour").load('html/pageFour.html #pageFourInsert', function(){
            $("#viewerFour").scrollable({
                items: '#panesFour',
                size: 1,
                navi: 'ul.tabsFour',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $("#panesFour a").flowplayer("swf/flowplayer-3.1.1.swf");
            $f(".player", "swf/flowplayer-3.1.1.swf", {
                plugins: {
                    controls: null
                },
                clip: {
                    autoPlay: false,
                    autoBuffering: true,
                    baseUrl: '../'
                }
            });
            $("#triggerFour").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
        $("#pageThree").load('html/pageThree.html #pageThreeInsert', function(){
        
            $("#viewerThree").scrollable({
                items: '#panesThree',
                size: 1,
                navi: 'ul.tabsThree',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $("#panesThree a").flowplayer("swf/flowplayer-3.1.1.swf");
            $f(".player", "swf/flowplayer-3.1.1.swf", {
                plugins: {
                    controls: null
                },
                clip: {
                    autoPlay: false,
                    autoBuffering: true
                }
            });
            $("#triggerThree").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
        $("#pageTwo").load('html/pageTwo.html #pageTwoInsert', function(){
            $("#viewerTwo").scrollable({
                items: '#panesTwo',
                size: 1,
                navi: 'ul.tabsTwo',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $("#panesTwo a").flowplayer("swf/flowplayer-3.1.1.swf");
            $f(".playerTwo", "swf/flowplayer-3.1.1.swf", {
                plugins: {
                    controls: null
                },
                clip: {
                    autoPlay: false,
                    autoBuffering: true
                }
            });
            $("#triggerTwo").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
        $("#pageOne").load('html/pageOne.html #pageOneInsert', function(){
            $("#viewerOne").scrollable({
                items: '#panesOne',
                size: 1,
                navi: 'ul.tabsOne',
                activeClass: 'current',
                onSeek: function(){
                    $f().unload();
                }
            });
            $("#panesOne a").flowplayer("swf/flowplayer-3.1.1.swf");
            $f(".player", "swf/flowplayer-3.1.1.swf", {
                plugins: {
                    controls: null
                },
                clip: {
                    autoPlay: false,
                    autoBuffering: true
                }
            });
            $("#triggerOne").tooltip({
                // place tooltip on the right edge 
                position: ['bottom', 'centre'],
                opacity: [0.90],
                
                // a little tweaking of the position 
                offset: [20, -35],
                delay: 800,
                
                // use a simple show/hide effect 
                effect: 'slidedown'
            
            });
        });
        
    }, 3000);
	
    $("#loadSeven").click(function(){
		 $("#pageSeven:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadEight:hidden:first").fadeIn("slow");
    });
    
        $("#loadSix").click(function(){
        $("#pageSix:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadSeven:hidden:first").fadeIn("slow");
    });
    
    $("#loadFive").click(function(){
        $("#pageFive:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadSix:hidden:first").fadeIn("slow");
    });
    
    $("#loadFour").click(function(){
        $("#pageFour:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadFive:hidden:first").fadeIn("slow");
        $("#buttonLoadFour:hidden:first").fadeIn("slow")
    });
    
    $("#loadThree").click(function(){
        $("#pageThree:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadThree:hidden:first").fadeIn("slow")
    });
    
    $("#loadTwo").click(function(){
        $("#pageTwo:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadTwo:hidden:first").fadeIn("slow")
    });
    
    $("#loadOne").click(function(){
        $("#pageOne:hidden:first").fadeIn("slow").width(900);
        $("#buttonLoadOne:hidden:first").fadeIn("slow")
        
    });
    
});


function twitterCallback2(twitters){
    var statusHTML = [];
    for (var i = 0; i < twitters.length; i++) {
        var username = twitters[i].user.screen_name;
        var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url){
            return '<a href="' + url + '">' + url + '</a>';
        }).replace(/\B@([_a-z0-9]+)/ig, function(reply){
            return reply.charAt(0) + '<a href="http://twitter.com/' + reply.substring(1) + '">' + reply.substring(1) + '</a>';
        });
        statusHTML.push('<li><span>' + status + '</span> <a style="font-size:85%" href="http://twitter.com/' + username + '/statuses/' + twitters[i].id + '">' + relative_time(twitters[i].created_at) + '</a></li>');
    }
    document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value){
    var values = time_value.split(" ");
    time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
    var parsed_date = Date.parse(time_value);
    var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
    var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
    delta = delta + (relative_to.getTimezoneOffset() * 60);
    
    if (delta < 60) {
        return 'less than a minute ago';
    }
    else 
        if (delta < 120) {
            return 'about a minute ago';
        }
        else 
            if (delta < (60 * 60)) {
                return (parseInt(delta / 60)).toString() + ' minutes ago';
            }
            else 
                if (delta < (120 * 60)) {
                    return 'about an hour ago';
                }
                else 
                    if (delta < (24 * 60 * 60)) {
                        return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
                    }
                    else 
                        if (delta < (48 * 60 * 60)) {
                            return '1 day ago';
                        }
                        else {
                            return (parseInt(delta / 86400)).toString() + ' days ago';
                        }
}

