﻿$(document).ready(function () {

    // Start of Edition selector code
    $(".divPanel").hide();
    $(".divPanel:first").show();
    $("#divScrollLeft").click(function () {
        var thisIndex = $(".divPanel").index($(".divPanel:visible"));
        if (thisIndex > 0) {
            $(".divPanel:eq(" + thisIndex + ")").hide();
            $(".divPanel:eq(" + (thisIndex - 1) + ")").show();
        } else {
            var bottomIndex = $(".divPanel").index($(".divPanel:last"));
            $(".divPanel:eq(" + thisIndex + ")").hide();
            $(".divPanel:eq(" + bottomIndex + ")").show();
        }
    });
    $("#divScrollRight").click(function () {
        var thisIndex = $(".divPanel").index($(".divPanel:visible"));
        var bottomIndex = $(".divPanel").index($(".divPanel:last"));
        if (thisIndex < bottomIndex) {
            $(".divPanel:eq(" + thisIndex + ")").hide();
            $(".divPanel:eq(" + (thisIndex + 1) + ")").show();
        } else {
            $(".divPanel:eq(" + thisIndex + ")").hide();
            $(".divPanel:eq(0)").show();
        }
    });
    // End of Edition selector code

    // Start of traffic module / popular news code
    $(".message:not(:first)").hide();
    $(".message:first").show();
    trafficInterval = setInterval('trafficTimer();', 6000);
    // End of traffic module / popular news code

    // Start of popular news
    $(".topArt:not(:first)").hide();
    $(".topArt:first").show();
    topArtInterval = setInterval('popTimer();', 6000);
    // End of popular news

    // Start of boost code
    $(".BoostDiv").mouseover(function () {
        clearInterval(boostInterval);
        var activeIndex = $(".BoostDiv").index($(this));
        $(".BoostDivSelected").removeClass("BoostDivSelected");
        $(this).addClass("BoostDivSelected");
        $(".BoostImage").hide();
        $(".BoostImage:eq(" + activeIndex + ")").show();
    });
    $(".BoostDiv").mouseout(function () {
        boostInterval = setInterval('boostTimer();', 6000);
    });
    $(".BoostImage").hide();
    $(".BoostImage:first").show();
    boostInterval = setInterval('boostTimer();', 6000);
    // End of boost code

    //Start of comments code
    $("#commentFormDiv").hide();
    //End of comments code

    //Start of nav-menu hover code
    $("#newsDropDown").hide();
    $("#sportDropDown").hide();

    $("#newsHover").mouseover(function () {
        try {
            clearInterval(newsInterval);
        } catch (err) {}
        $("#newsDropDown").slideDown();
    });
    $("#newsHover").mouseout(function () {
        newsInterval = setInterval('hoverTimerNews()', 50);
    });
    $("#newsDropDown").mouseover(function () {
        clearInterval(newsInterval);
    });
    $("#newsDropDown").mouseout(function () {
        newsInterval = setInterval('hoverTimerNews()', 50);
    });

    $("#sportHover").mouseover(function () {
        try {
            clearInterval(sportInterval);
        } catch (err) { }
        $("#sportDropDown").slideDown();
    });
    $("#sportHover").mouseout(function () {
        sportInterval = setInterval('hoverTimerSport()', 50);
    });
    $("#sportDropDown").mouseover(function () {
        clearInterval(sportInterval);
    });
    $("#sportDropDown").mouseout(function () {
        sportInterval = setInterval('hoverTimerSport()', 50);
    });
    //End of nav-menu hover code
});

// Start of traffic module timer code
function trafficTimer() {
    if ($(".message:last").is(":visible")) {
        $(".message:visible").hide(function () { $(".message:first").show(); });
    } else {
        var test = $(".message:visible");
        $(".message:visible").hide(function () { test.next().show(); });
    }
    return false;
}
// End of traffic module timer code

// Start of popular news timer code
function popTimer() {
    if ($(".topArt:last").is(":visible")) {
        $(".topArt:visible").hide(function () { $(".topArt:first").show(); });
    } else {
        var test = $(".topArt:visible");
        $(".topArt:visible").hide(function () { test.next().show(); });
    }
    return false;
}
// End of popular news timer code

// Start of boost timer code
function boostTimer() {
    var newIndex = 0;
    var activeIndex = $(".BoostDiv").index($(".BoostDivSelected"));
    if (activeIndex < 2) {
        newIndex = activeIndex + 1;
    }
    $(".BoostDivSelected").removeClass("BoostDivSelected");
    $(".BoostDiv:eq(" + newIndex + ")").addClass("BoostDivSelected");
    $(".BoostImage").hide();
    $(".BoostImage:eq(" + newIndex + ")").show();
}
// End of boost timer code

// Start of small edition launcher code
function openedition() {
    var launchGuid = "";
    var ddlSelect = $(".ddlLaunch > option:selected").val();
    if (ddlSelect == "0") {
        var rblSelect = $(".rblLaunch input:radio:checked").val();
        if (rblSelect != undefined) {
            launchGuid = rblSelect;
        }
    } else {
        launchGuid = ddlSelect;
    }

    if (launchGuid != "") {
        window.open("http://edition.pagesuite-professional.co.uk/launch.aspx?pbid=" + launchGuid);
    }
}
// End of small edition launcher code

function toggleElement(id) {
    $("#" + id + "").toggle();
}

//Start of search box functions
function SearchFocus(searchBox) {
    if (searchBox.value == 'Enter keywords...') {
        searchBox.value = '';
        searchBox.style.color = '#000000';
    }
}
function SearchBlur(searchBox) {
    if (searchBox.value == '') {
        searchBox.value = 'Enter keywords...';
        searchBox.style.color = '#bfbfbf';
    }
}
//End of search box functions

//Start of login functions
function UsernameFocus(searchBox) {
    if (searchBox.value == 'Username') {
        searchBox.value = '';
        searchBox.style.color = '#000000';
    }
}
function UsernameBlur(searchBox) {
    if (searchBox.value == '') {
        searchBox.value = 'Username';
        searchBox.style.color = 'Gray';
    }
}
function PassFocus(searchBox) {
    if (searchBox.value == 'Password') {
        searchBox.value = '';
        searchBox.type = 'password';
        searchBox.style.color = '#000000';
    }
}
function PassBlur(searchBox) {
    if (searchBox.value == '') {
        searchBox.value = 'Password';
        searchBox.type = 'text';
        searchBox.style.color = 'Gray';
    }
}
//End of login functions

//Start of nav-menu timer code
function hoverTimerNews() {
    $("#newsDropDown").slideUp();
    clearInterval(newsInterval);
}
function hoverTimerSport() {
    $("#sportDropDown").slideUp();
    clearInterval(sportInterval);
}
//End of nav-menu timer code
