var playStation = {
    isPlayStation:navigator.platform.toUpperCase() == "PLAYSTATION 3",
    images:null,
    current:0,
    debug:null,
    previousButton:null,
    nextButton:null,
    studioImage:null,
    studioImageTitle:null,
    imageCount:null,
    init:function() {
        if (document.getElementById('galleryPage')) {
            // get all the elements
            playStation.previousButton = document.getElementById('previous');
            playStation.nextButton = document.getElementById('next');
            playStation.images = document.getElementById('imageList').getElementsByTagName('a');
            playStation.studioImage = document.getElementById('studioImage');
            playStation.studioImageTitle = document.getElementById('studioImageTitle');
            playStation.imageCount = document.getElementById('imageCount');
            // set first image
            playStation.swapImage(0);
            // add events
            playStation.previousButton.onclick = function() {playStation.previousImage()};
            playStation.nextButton.onclick = function() {playStation.nextImage()};
        } else {
            var galleryButton = document.getElementById('gallery').getElementsByTagName('a')[0];
            if (galleryButton) galleryButton.className = galleryButton.className + ' veiwGallery';
        }
    },
    nextImage:function() {
        if (playStation.current + 1 != playStation.images.length) playStation.swapImage(playStation.current + 1);
        return false;
    },
    previousImage:function() {
        if (playStation.current - 1 >= 0) playStation.swapImage(playStation.current - 1);
        return false;
    },
    swapImage:function(i) {
        playStation.studioImage.src = playStation.images[i].href;
        playStation.studioImageTitle.innerHTML = playStation.images[i].title;
        playStation.imageCount.innerHTML = i+1 + " ";
        playStation.current = i;
        playStation.hideShowButtons();
    },
    hideShowButtons:function() {
        (playStation.current == playStation.images.length - 1) ? playStation.nextButton.style.display = 'none':playStation.nextButton.style.display = '';
        (playStation.current == 0) ? playStation.previousButton.style.display = 'none':playStation.previousButton.style.display = '';
    }
};

