﻿$(document).ready(function () {

    var i = 0;

    var pheight = $(window).height();
    var sheight = $("#wrapper").height();

    if (sheight < pheight) {
        $("#footer").css("position", "absolute");
        $("#footer").css("bottom", "0");
    }

    $(function () {
        $('.gallery').lightBox();
    });

    $("#region").change(function () {
        var regions = document.getElementById("region");
        var n = regions.selectedIndex;
        var path = window.location.pathname;
        var page = path.substring(path.lastIndexOf('/') + 1);

        switch (n) {
            case 0:
                window.location = "http://www.spcoils.co.uk/";
                break;
            case 1:
                window.location = "http://www.spcoils.com/";
                break;
            case 2:
                window.location = "http://www.spcoils.ae/";
                break;
            default:
                alert("Invalid Region Selected");
        }
    });

    var swidth = $(window).width();
    var nwidth = (swidth - 900) / 2;
    if (swidth >= 900) {
        $("#blue").width(nwidth + 1);
    }

    $("#jlink1").click(function () {
        $("#pinfo").slideToggle("medium");
        moveFooter(200);
    });

    $("#jlink2").click(function () {
        $("#lit").slideToggle("medium");
        moveFooter(200);
    });

});

function moveFooter(extra) {
    var pheight = $(window).height();
    var sheight = $("#wrapper").height();
    var nheight = pheight - sheight;
    i += 1;
    if (i == 1) {
        if (sheight < pheight) {
            $("#footer").css("position", "absolute");
            $("#footer").css("bottom", "0");
        } else {
            $("#footer").css("position", "absolute");
            $("#footer").css("bottom", nheight - extra);
        }
    } else {
        i = 0;
    }
}

$(window).resize(function () {

    var swidth = $(window).width();
    var nwidth = (swidth - 900) / 2;

    if (nwidth < 5) {
        nwidth = 0;
    }

    $("#blue").width(nwidth+1);

    moveFooter(100);
});
