﻿$(document).ready(function () {

    var index = 0;
    var last = 0;

    var divName = getQueryVariable("div");

    if (divName == 'img')
        displayByIndex(10);
    else
        displayByIndex(0);

    $("div.item").each(function (i) {
        var id = i + 1;
        $("#hgtv_" + id).bind('click', function () {
            displayByID('hgtv' + id);
            index = i;
            return false;
        });
        last++;
    });


    $("#next").click(function () {
        if (index < last - 1) {
            index = index + 1;
            displayByIndex(index);
        }

        return false;
    });

    $("#prev").click(function () {
        if (index != 0) {
            index = index - 1;
            displayByIndex(index);
        }

        return false;
    });

    function displayByID(div) {

        $("div.item").each(function (i) {
            if ($(this).attr('id') == div)
                $(this).show();
            else
                $(this).hide();
        });

    }

    function displayByIndex(index) {

        $("div.item").each(function (i) {
            if (i == index)
                $(this).show();
            else
                $(this).hide();
        });

    }
});

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) {
            return pair[1];
        }
    }
}

