﻿/* /////////////////////////////////////////////////////////////////////////   */
/* BANNER SLIDE-SHOW FUNCTIONALITY                                             */
/* BANNER SLIDE-SHOW FUNCTIONALITY                                             */

/* BANNER FEATURE STORY FUCNTIONALITY                                          */
/* BANNER FEATURE STORY FUCNTIONALITY                                          */
/* /////////////////////////////////////////////////////////////////////////   */

 

//Need to determine which artice to display
function getCurrentArticle() {

    var currentArticle = 0;  //Need to determine which artice to display
    if (navigator.appName == 'Microsoft Internet Explorer') {

        var getPos = new Array();
        getPos[0] = parseInt($('#bannerSlideShow').css('backgroundPositionX').replace(/px/i, ''));

        if (getPos[0] == '-2700px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
            currentArticle = 4;
        }
        else if (getPos[0] == '-1800px') {
            currentArticle = 3;
        }
        else if (getPos[0] == '-900px') {
            currentArticle = 2;
        }
        else {
            currentArticle = 1;
        }
    } else { //browser other than IE
        var getPos = $('#bannerSlideShow').css('backgroundPosition').split(" ");

        if (getPos[0] == '-2700px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
            currentArticle = 4;
        }
        else if (getPos[0] == '-1800px') {
            currentArticle = 3;
        }
        else if (getPos[0] == '-900px') {
            currentArticle = 2;
        }
        else {
            currentArticle = 1;
        }
    }
    return currentArticle;
}

function swapBannerImageAuto() {
    
    if (navigator.appName == 'Microsoft Internet Explorer') {

        var getPos = new Array();
        getPos[0] = parseInt($('#bannerSlideShow').css('backgroundPositionX').replace(/px/i, ''));

        if (getPos[0] == '-3600px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
            $('#bannerSlideShow').css('background-position-x', '0px');
        }

        $('#bannerSlideShow').css('background-position-x', getPos[0] - 900 + 'px');
    } else {
        
        var getPos = $('#bannerSlideShow').css('backgroundPosition').split(" ");

        if (getPos[0] == '-3600px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over*/
            $('#bannerSlideShow').css('backgroundPosition', '0px 0px');
        }

        
        $('#bannerSlideShow').stop().animate({
            backgroundPosition: '-=900px 0px'
        }, {
            duration: 0
        });
        





    }
    setTimeout('swapBannerImageAuto()', 6000);
}

function swapBannerImageManual(direction) {

    if (direction == 'forward') {
        if (navigator.appName == 'Microsoft Internet Explorer') {

            var getPos = new Array();
            getPos[0] = parseInt($('#bannerSlideShow').css('backgroundPositionX').replace(/px/i, ''));

            if (getPos[0] == '-3600px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
                $('#bannerSlideShow').css('background-position-x', '0px');
            }

            $('#bannerSlideShow').css('background-position-x', getPos[0] - 900 + 'px');

        } else {
            var getPos = $('#bannerSlideShow').css('backgroundPosition').split(" ");

            if (getPos[0] == '-3600px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
                $('#bannerSlideShow').css('backgroundPosition', '0px 0px');
            }

            $('#bannerSlideShow').stop().animate({
                backgroundPosition: '-=900px 0px'
            }, {
                duration: 0
            });
        }

    } else { /* direction is backwards */
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var getPos = new Array();
            getPos[0] = parseInt($('#bannerSlideShow').css('backgroundPositionX').replace(/px/i, ''));

            if (getPos[0] == '0px') { /* if position reaches bannerWidth * 3 it has cycled four times .. start over */
                $('#bannerSlideShow').css('background-position-x', '-3600px');
            }

            $('#bannerSlideShow').css('background-position-x', getPos[0] + 900 + 'px');
        } else {
            var getPos = $('#bannerSlideShow').css('backgroundPosition').split(" ");

            if (getPos[0] == '0px') { /*if position reaches bannerWidth * 3 it has cycled four times .. start over */
                $('#bannerSlideShow').css('backgroundPosition', '-3600px 0px');
            }

            $('#bannerSlideShow').stop().animate({
                backgroundPosition: '+=900px 0px'
            }, {
                duration: 0
            });
        }
    }
}
function LoadFeatureStory(articleName) {
    /*
    $('#ajaxContainer').load('http://www.johnnyhollow.com/FeatureArticle' + getCurrentArticle() + '/ .ajaxContent', function (response, status, xhr) {
        if (status == "error") {
            alert("Sorry there was an error loading the article. The developer will be shot.");
        }
    });
    */
    
    /* LOADS THE BLOG WITH BANNER ARTICLE FIRST */
    displayAjaxLoader();
    $("#ajaxContainer").load("http://www.johnnyhollow.com/Blog/Index/" + articleName + " .ajaxContent", function (response, status, xhr) {

        hideAjaxLoader();
        if (status == "error") {
            alert("Sorry but there was an error: ");
        }
    });
}

$(window).load(function () {

    setTimeout('swapBannerImageAuto()', 6000);
    $('#bannerControlLeft').click(function () { swapBannerImageManual('backward'); });
    $('#bannerControlRight').click(function () { swapBannerImageManual('forward'); });
    $('#bannerSlideShow').click(function () {

        var articleToDisplay = getCurrentArticle();

        switch (articleToDisplay) {
            case 1:
                LoadFeatureStory("WELCOME");
                break;
            case 2:
                LoadFeatureStory("THIS%20HOLLOW%20WORLD%20-%20Music%20Video");
                break;
            case 3:
                navigateToStore();
                break;
            case 4:
                LoadFeatureStory("DIRTY%20HANDS"); 
                break;
            default:
                LoadFeatureStory("WELCOME");
        }

        /* hide admin panels */
        $('#submitPostWrap').css('display', 'none');
        $('#userUploadWrap').css('display', 'none');
        $('#fanUploadWrap').css('display', 'none');
        $('#submitSpeakUpPostWrap').css('display', 'none');
    });
});
