function pageInit(){
    var title = $('#bannerFlashBox h1').text();
    //$('#rightColumnBox h2:first').append(title);
    var levelsOpen = $('#navBox li.sel').size();
    //alert(levelsOpen);
    if (levelsOpen > 1){
        $('#navBox li.sel ul').show();
        } else {
        $('#navBox li.sel ul').animate({height:'show'}, {duration: 800, easing: 'easeInSine'});
        }
    $('#navBox li.sel li:first').addClass('firstSub');
    $('#navBox li.sel ul ul:last').css('border','none');
}
function colours(){
    allColours = [
    '#004b64',
    '#787a2a',
    '#a77239',
    '#7a2a50',
    '#396ea7',
    '#2a787a',
    '#532a7a',
    '#7a2a78',
    '#7a2b2a',
    '#2a7a53',
    '#075669',
    '#22a215',
    '#a21540',
    ];
    max = (allColours.length);
    for (n=0; n<=max; n++){
        var selected= allColours[n];
        var item = $('#navBox #item'+ (n+1));
        item.find('a').css('color',selected);
        if ($('#navBox #item'+ (n+1)).hasClass('sel')){
            item.find('a').css('border-bottom-color',selected);
            item.find('ul').css('border-bottom-color',selected);
            item.find('li a:last').css('border', 'none');
            //$('#rightColumnBox h2').css('background',selected);
            $('#rightColumnBox h2').css('border-bottom-color',selected);
            //$('#rightColumnBox a').css('color',selected);
            $('#contentBox h2').css('color',selected);
        }
    }
}

function flashBanner(image1, image2, image3, image4){

                $('#bannerFlashBox').flash({ 
                    swf: '/flash/banner_06.swf',
                    width: 778,
                    height: 140,
                    hasVersion: 8,
                    flashvars: {img1: image1,  img2: image2, img3: image3, img4: image4},
                    params: {wmode: 'transparent'}
                    
                    });


}
function flashBannerHome(image1){

                $('#bannerFlashBox').flash({ 
                    swf: '/flash/banner_06_home.swf',
                    width: 778,
                    height: 140,
                    hasVersion: 8,
                    flashvars: {img1: image1},
                    params: {wmode: 'transparent'}
                    
                    });


}

function opMenu(typeStr){
		    $('#opMenu h3').each(function(i){
		        var pa = $(this).text();
		        $('#paNav').append('<li>'+pa+' '+typeStr+'</li>');
		        $(this).click(function(){
		            $(this).siblings().hide().end().next('ul').show();
                    $('.init #paNav').children('li:eq('+i+')').addClass('seld').end().animate({height:'show'}, {duration: 800, easing: 'easeOutBack'});
                    $('body').removeClass('init');
                    ulPaginate(10,i);
                });
            });
            $('#paNav li').each(function(i){
                $(this).click(function(){
		            $('#opMenu h3:eq('+i+')').show().siblings().hide().end().next('ul').show();
		            $(this).addClass('seld').siblings().removeClass('seld');
                    ulPaginate(10,i);
                });
            });
}

function ulPaginate(max,listID){
            var listItem = $('#contentBox ul:eq('+listID+')')
            var n = listItem.children().size();
            var pages = Math.ceil(n/max);
            //alert(pages);
            if (pages>1){
                //clear old pagination nav
                $('p.pagination').remove();
                //build pagination nav
                $('<p class="pagination">Go to page: </p>').insertAfter(listItem);
                for (n=1;n<=pages;n++){
                    $('p.pagination').append('<span>'+n+'</span>');
                }
                //display first page of list
                listItem.children('li').show();
                listItem.children('li:gt('+(max-1)+')').hide();
                $('p.pagination span:first').addClass('sel');
            }
            //nav click handler
            $('p.pagination span').each(function(i){
                var starting = (i*max);
                var ending = starting+(max-1);
                $(this).click(function(){
                    $(this).siblings().removeClass('sel').end().addClass('sel');
                    listItem.children('li').hide();
                    listItem.children('li:eq('+starting+')').show();
                    listItem.children('li:gt('+starting+')').show();
                    listItem.children('li:gt('+ending+')').hide();
                });
            });
            
            //$('#contentBox').append('<p>'+listID+' : '+n+'</p>');
}


        function homeRotate(){                var showItem = function(n){                    var thisImg = showBox.children('img').eq(n);                    thisImg.load(function(){                        var w = thisImg.width();                        goHeight = (goWidth/w)*thisImg.height();                    });                    if (firstTime){                        firstTime = false;                        //thisImg.width(goWidth).height(goHeight).show();                        thisImg.css('width', goWidth+'px').css('height', goHeight+'px').show();                    } else {                        thisImg.css('opacity',0).show().animate({
                            opacity: 1,
                            width: goWidth,
                            height: goHeight
                          }, 4000);                                           }                //showBox.children('div.textPanel').eq(n).show('slide', { direction: 'down', easing: 'easeOutQuad' }, slideTime);                showBox.children('div.textPanel').eq(n).fadeIn(650);                nextItem = n+1;                thisItem = n;               //alert(nextItem);        }                                var rotate = function(){                    showBox.everyTime(6000,'rotating', function() {                        iCount++;                        //showBox.children('div.textPanel').eq(thisItem).hide('slide', { direction: 'down', easing: 'easeOutQuad' }, slideTime, function(){                        showBox.children('div.textPanel').eq(thisItem).fadeOut(650, function(){                            if (iCount == totalItems){                                showBox.append('<div id="endBox"></div>');                                $('#endBox').fadeIn(fadeTime);                                return;                            } else {                            showItem(nextItem);                            }		                });                        if (nextItem == totalItems){                            nextItem = 1;                            //add empty textPanel to make up the numbers!                            showBox.prepend('<div class="textPanel"></div>');                            //move last img to bottom so fist img can fade over it                            showBox.children('img').hide();                            showBox.children('img:last').prependTo(showBox).show();                        }                                            }, totalItems);                };
                //----  initialise ----------------
                var totalItems = $('#sfData div').size();                var startItem = Math.floor(Math.random()*totalItems);                var thisItem = 0;                var nextItem = 0;                var iCount = 0;                var fadeTime = 2000;                var slideTime = 900;                var showBox = $('#trophies');                var goWidth = showBox.width();                var goHeight = showBox.height();//default height                var firstTime = true;                                $('#sfData div').each(function(i){
                    //first seperate out image
                    $(this).children('img:first').appendTo(showBox);
                    //handle text
                    $(this).addClass('textPanel').appendTo(showBox);
                    
                });
                                showItem(startItem);                rotate();
                //--------------------------------- 
        }        var newsBanner = function(){            var rotateNews = function(){                                $('#newsContent').everyTime(5000,'rotatingnews', function(ni) {                        $('#newsContent p').eq(ni-1).fadeOut(1000, function(){                            $('#newsContent p').eq(ni).fadeIn(1000);                        });                        if (ni == totalNews){                            $('#newsContent').oneTime(2000,'lastnews', function() {                                $('#newsContent p:last').fadeOut(1000, function(){                                    $('#newsContent p:first').fadeIn(1000);                                    rotateNews();                                });                                                            });                        }                    }, totalNews);                };            //$('#newsContent:not(:empty)').prepend('<h3>Latest News</h3>').show().parent().addClass('newsBG');            var totalNews = $('#newsContent p').size();            if (totalNews>0){                $('#newsContent').prepend('<h3>Latest News</h3>').show().parent().addClass('newsBG');                $('#newsContent p:first').fadeIn(1000);                               if (totalNews>1){                    rotateNews();                }            }        }
