/*

=== COPYRIGHT NOTICE ===

Copyright (c) 2010 by Shedstore LLP - All Rights Reserved

All rights, including copyright, in the content of this Shedstore LLP JavaScript file are
owned or controlled for these purposes by Shedstore LLP.

In accessing this Shedstore LLP JavaScript File, you agree that you may only download the
content for your own personal non-commercial use.

Except where expressly stated otherwise, you are not permitted to copy, broadcast, download,
store (in any medium), transmit, show or play in public, adapt or change in any way the content
of this Shedstore LLP owned JavaScript file for any other purpose whatsoever without the prior
written permission of Shedstore LLP.

*/

var bug = new Image();
var d = new Date();

function showDiv(strDivName) {
    try {
        $("#" + strDivName).css("visibility", "visible");
        $("#" + strDivName).css("display", "block");
    } catch (err) { }
}
function hideDiv(strDivName) {
    try {
        $("#" + strDivName).css("visibility", "hidden");
        $("#" + strDivName).css("display", "none");
    } catch (err) { }
}

var intCurrentTab = 1;
function showTab(intTabNumber) {
    intCurrentTab = intTabNumber;
    $(".tab-off").css("background-color", "#E2E9E2");
    $(".tab-off").css("color", "#000000");
    $(".tab-on").css("background-color", "#FFFFFF");
    $(".tab-on").css("color", "#000000");
    showDiv("tab-dropdown");
    $("#tab-" + intTabNumber).css("background-color", "#A2A9A2");
    $("#tab-" + intTabNumber).css("font-weight", "bold");
    //$("#tab-" + intTabNumber).css("opacity", "1.0");
    $("#tab-" + intTabNumber).css("color", "#FFFFFF");

    for (i = 1; i <= 8; i++) {
        if (i == intTabNumber) {
            showDiv("tab-dropdown-" + i);
        } else {
            hideDiv("tab-dropdown-" + i);
        }
    }
}
function showTabs() {
    showDiv("tab-dropdown");
    $("#tab-" + intCurrentTab).css("background-color", "#A2A9A2");
    $("#tab-" + intCurrentTab).css("color", "#FFFFFF");
    $("#tab-" + intCurrentTab).css("font-weight", "bold");
    //$("#tab-" + intCurrentTab).css("opacity", "1.0");
}
function hideTabs() {
    hideDiv("tab-dropdown");
    $(".tab-off").css("background-color", "#E2E9E2");
    $(".tab-off").css("color", "#000000");
    $(".tab-off").css("font-weight", "normal");
    //$(".tab-off").css("opacity", "0.9");
    $(".tab-on").css("background-color", "#FFFFFF");
    $(".tab-on").css("color", "#000000");
}

function showDialog(strTitle, strContentDiv, strButtons) {
    showDiv("dialog");
    $("#dialog-title").html(strTitle);
    $("#dialog-content").html($("#" + strContentDiv).html());
    $("#dialog-buttons").html(strButtons);
}
function hideDialog() {
    hideDiv('dialog');
}

function validateSearch() {
    var strValue = $("#search-field").val();
    if (strValue.replace("  ", "").replace(" ", "") == "") {
        alert('Please enter a search term.');
        return false;
    } else {        
        try {
            bug.src = 'http://t.shedstore.co.uk/1/track-search.aspx?q=' + escape($("#search-field").val()) + '&referrer=' + escape(document.referrer) + '&t=' + d.getTime()
        } catch (err) { };
        return true;
    }
}

var scrollSpeed = 30;
var step = 1;
var current = 0;
var imageWidth = 1220;
var headerWidth = 309;

var restartPosition = -(imageWidth - headerWidth);

function scrollBg() {
    current -= step;
    if (current == restartPosition) {
        current = 0;
    }

    $('#side-secure').css("background-position", current + "px 0");
}

function selectLetter(strLetter) {
    $(".glossary-letter").css("visibility", "hidden");
    $(".glossary-letter").css("display", "none");
    $(".glossary-letter-hidden").css("visibility", "hidden");
    $(".glossary-letter-hidden").css("display", "none");
    $("#glossary-" + strLetter).css("visibility", "visible");
    $("#glossary-" + strLetter).css("display", "block");
    $(".glossary-link").css("background-color", "#EEE");
    $(".glossary-link").css("border", "1px solid #CCC");
    $(".glossary-link").css("color", "#000");
    $("#glossary-link-" + strLetter).css("background-color", "#999");
    $("#glossary-link-" + strLetter).css("border", "1px solid #999");
    $("#glossary-link-" + strLetter).css("color", "#FFF");
}

$(document).ready(
    function() {
        $("#search-field").focus(function() { $("#search-border").addClass("search-border-on"); $("#search-border").removeClass("search-border"); $("#search-button").addClass("green-button"); $("#search-button").removeClass("white-button") });
        $("#search-field").blur(function() { $("#search-border").addClass("search-border"); $("#search-border").removeClass("search-border-on"); $("#search-button").addClass("white-button"); $("#search-button").removeClass("green-button") });
        $("#search-field").focus();
        //$("body").click(function() { hideTabs(); })
        $(".header").click(function() { hideTabs(); })
        //$(".promotion").click(function() { hideTabs(); })
        $(".content").click(function() { hideTabs(); })
        $(".footer").click(function() { hideTabs(); })

        $('.has-tooltip').tooltip({ showBody: " - ", track: true, delay: 0, showURL: false });
        $('.has-tooltip-wide').tooltip({ showBody: " - ", track: true, delay: 0, showURL: false, extraClass: "w350" });
        $('.has-left-tooltip').tooltip({ showBody: " - ", track: true, delay: 0, showURL: false, positionLeft: true });

        try {
            $('#side-benefits').cycle('fade');
        } catch (err) {
            // no cycle rotation
        }

        $('.side-benefits-content').tooltip({ showBody: " - ", track: true, delay: 0, showURL: false, positionLeft: true });
        $('.tab-link').tooltip({ showBody: " - ", track: true, delay: 0, showURL: false, positionLeft: true });
        setInterval("scrollBg()", scrollSpeed);

        $('.glossary-image-tooltip').tooltip({ track: true, delay: 0, showURL: false, extraClass: "glossary-tooltip",
            bodyHandler: function() {
                return $("<img class='glossary-image-tooltip-large'/>").attr("src", this.src.replace("-100.", "-250."));
            }
        });

        var strProductFeatures = $("#product-features").html();
        try {
            if (strProductFeatures.indexOf("<br>") != -1) {
                while (strProductFeatures.indexOf("<br>") != -1) {
                    strProductFeatures = strProductFeatures.replace("<br>", "</li><li>")
                }
                $("#product-features").html("<span class='blue'><ul><li>" + strProductFeatures + "</li></ul></span>")
            }
        } catch (err) {
            // no features to style
        }

        try {
            $('#loupe-1').loupe({
                width: 150, // width of magnifier
                height: 150, // height of magnifier
                loupe: 'loupe-viewer' // css class for magnifier
            });
            //$('#loupe-1').loupe();
        } catch (err) {
            // no loupe on page to style
        }

    }
)





    //  V1

    // Shedstore UK

    var req;
    var reqDiv;

    function ajaxDiv(url, div) {
        req = false;
        // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try {
                req = new XMLHttpRequest();
            } catch (e) {
                req = false;
            }
            // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    req = false;
                }
            }
        }
        if (req) {
            reqDiv = div;
            document.getElementById(reqDiv).innerHTML = "Loading ...";
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        }
    }

    function processReqChange() {
        // only if req shows "loaded"
        if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
                document.getElementById(reqDiv).innerHTML = req.responseText;
            } else {
                //document.getElementById(reqDiv).innerHTML = "<div class='p5'>This feature is undergoing maintentance (status: " + req.status + " statusText: " + req.statusText + ").</div>";
            }
        }
    }

    function showDivInline(strDivID) {
        try {
            document.getElementById(strDivID).style.visibility = 'visible';
            document.getElementById(strDivID).style.display = 'inline';
        } catch (e) { }
    }
    function makeBold(strDivID) {
        try {
            document.getElementById(strDivID).style.fontWeight = 'bold';
        } catch (e) { }
    }
    function makeNormal(strDivID) {
        try {
            document.getElementById(strDivID).style.fontWeight = 'normal';
        } catch (e) { }
    }

    function jumpToSection(strSectionName) {
        var strCurrentURL;
        var strTargetURL;
        strCurrentURL = window.location.href;
        if (window.location.href.indexOf('#') > -1) {
            // has # in URL
            strTargetURL = left(window.location.href, window.location.href.indexOf('#')) + '#' + strSectionName;
            location.href = strTargetURL;
        } else {
            location.href = window.location.href + '#' + strSectionName;
        }
    }

    function jumpToCategorySection(strSectionName) {
        var strCurrentURL;
        var strTargetURL;
        strCurrentURL = window.location.href;
        if (window.location.href.indexOf('#') > -1) {
            // has # in URL
            strTargetURL = left(window.location.href, window.location.href.indexOf('#')) + '#' + strSectionName;
            location.href = strTargetURL;
        } else {
            location.href = window.location.href + '#' + strSectionName;
        }
    }


    function showPhoto(strPath) {
        $('#v1photo').attr("src", strPath);
        $('#v1photolayer').show();
        //$('#v1photolayer').fadeIn(500);
    }

    function hidePhoto() {
        $('#v1photolayer').hide();
        //$('#v1photolayer').fadeOut(500);
        //$('#v1photo').attr("src", "http://i.shedstore.co.uk/white.png");
        hidetip();
    }

    function left(str, n) {
        if (n <= 0)
            return "";
        else if (n > String(str).length)
            return str;
        else
            return String(str).substring(0, n);
    }
    function right(str, n) {
        if (n <= 0)
            return "";
        else if (n > String(str).length)
            return str;
        else {
            var iLen = String(str).length;
            return String(str).substring(iLen, iLen - n);
        }
    }
