﻿/*********************************************************************************************************/
/*******************************        IRSLIDER VERSION 1.0.1          **********************************/
/*******************************      COPYRIGHT IMAGERED LTD 2010       **********************************/
/*******************************          AUTHOR: IAN RAMSAY            **********************************/
/*********************************************************************************************************/

/*********************************************************************************************************/
/*******************************         VERSION 1.0.1 CHANGES           *********************************/
/*********************************************************************************************************/

// A) FUTURE PROOFING TO USE IN OTHER SITES

/*********************************************************************************************************/
/*******************        GLOBAL VARIABLES THAT WILL CHANGE PER SITE      ******************************/
/*********************************************************************************************************/

var _DynamicSubjectEnquiry = "Y";  //Whether the enquiry uses a dynamic text box depending on which area you clicked the button
var _LabelID = "hidSubject"; //The name of the text box you want to use for the dynamic text
var _UseBGImage = "Y"; //If you wish to use a snazy BG image that moves with the div
var _DivBGInOffsetInitial = 300; //The initial start value of _DivBGInOffset to reset it later
var _DivBGInOffset = 300; //The amount off offset in pixels of the div Background image for sliding into the page
var _tabOffset = 0;
var _DivTopOutOffsetInitial = 0; //The initial offset of the main div for sliding out away from the page
var _DivTopOutOffset = 0; //The amount of offset in pixels of the main div for sliding out away from the page
var _DivBGOutOffsetInitial = 0; //The initial start value of _DivBGOutOffset to reset it later
var _DivBGOutOffset = 0; //The amount off offset in pixels of the div Background image for sliding out of the page
var _EnquiryDivMain = "enquiryDiv"; //ID of the main div
var _TransparantDiv = "transEnquiry"; //ID of the transparent div (no bg [color or image]) [used mainly for IE6]
var _EnquiryWrapper = "enquiryWrapper"; //ID of the wrapper within the main div
var _UsesMessage = "Y"; //whether you want it to display a message before sliding back out
var _slideAmount = 10; //the amount of pixels to slide
var _EnqTxtBx = "EnqTxtBx"

/*********************************************************************************************************/
/*******************        LOCAL VARIABLES [DO NOT CHANGE THESE]           ******************************/
/*********************************************************************************************************/

var SlideInTimeoutID = null;
var SlideOutTimeoutID = null;
var IsItOut = null;

function checkOnClick(perc, dir, InOut, firstTime, EnqTxt) {
    if (SlideInTimeoutID == null) {
        if (IsItOut < 0 || IsItOut == null) {
            slide(perc, dir, InOut, firstTime, EnqTxt)
        }
    }

}

function slide(perc, dir, InOut, firstTime, EnqTxt) {
    if (firstTime == "0") {
        _DivBGOffset = 300;
        perc3 = 0;
        perc4 = 0;

        if (_DynamicSubjectEnquiry == "Y") {
            var EnqBx = document.getElementById(_LabelID);
            EnqBx.value = EnqTxt;
        }
    }

    var EnqDiv = document.getElementById(_EnquiryDivMain);
    var TransDiv = document.getElementById(_TransparantDiv);

    if (EnqDiv != null && TransDiv != null) {
        if (InOut == "IN") {
            if (perc < 0) {
                perc = parseFloat(perc) + parseFloat(_slideAmount);
                IsItOut = perc;
                _DivBGOffset = parseFloat(_DivBGOffset) - parseFloat(_slideAmount);
                _tabOffset = parseFloat(_tabOffset) + parseFloat(_slideAmount);

                if (dir == "top") {
                    TransDiv.style.top = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = "center " + _DivBGOffset + "px";
                    }
                    EnqDiv.style.top = perc + "px";
                }
                if (dir == "left") {
                    TransDiv.style.left = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = _DivBGOffset + "px center";
                    }
                    EnqDiv.style.left = perc + "px";
                }
                if (dir == "right") {
                    TransDiv.style.right = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = _DivBGOffset + "px center";
                    }
                    EnqDiv.style.right = perc + "px";
                }
                if (dir == "bottom") {
                    TransDiv.style.bottom = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = "center " + _DivBGOffset + "px";
                    }
                    EnqDiv.style.bottom = perc + "px";
                }
                SlideInTimeoutID = setTimeout("slide(" + perc + ",'" + dir + "','" + InOut + "','1')", 25);
            }
            else {
                clearTimeout(SlideInTimeoutID);
                SlideInTimeoutID = null;
            }
        }
        else if (InOut == "OUT") {
            SlideOutTimeoutID = setTimeout("SlideOut(" + perc + ",'" + dir + "','" + InOut + "')", 5000);
        }
    }
}

    function SlideOut(perc, dir, InOut) {
        var EnquireWrap = document.getElementById(_EnquiryWrapper);
        var EnqDiv = document.getElementById(_EnquiryDivMain);
        var TransDiv = document.getElementById(_TransparantDiv);

        if (EnqDiv != null && TransDiv != null) {
            if (perc > -300) {
                perc = parseFloat(perc) - parseFloat(_slideAmount);
                IsItOut = perc;
                _DivTopOutOffset = parseFloat(_DivTopOutOffset) + parseFloat(_slideAmount);
                _tabOffset = parseFloat(_tabOffset) - parseFloat(_slideAmount);


                if (dir == "top") {
                    TransDiv.style.top = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = "center " + _DivTopOutOffset + "px";
                    }
                    EnqDiv.style.top = perc + "px";
                }
                if (dir == "left") {
                    TransDiv.style.left = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = _DivBGOffset + "px center";
                    }
                    EnqDiv.style.left = perc + "px";
                }
                if (dir == "right") {
                    TransDiv.style.right = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = _DivBGOffset + "px center";
                    }
                    EnqDiv.style.right = perc + "px";
                }
                if (dir == "bottom") {
                    TransDiv.style.bottom = perc + "px";
                    if (_UseBGImage == "Y") {
                        TransDiv.style.backgroundPosition = "center " + _DivTopOutOffset + "px";
                    }
                    EnqDiv.style.bottom = perc + "px";
                }
                SlideOutTimeoutID = setTimeout("SlideOut(" + perc + ",'" + dir + "','" + InOut + "')", 25);
            }
            else {
                clearTimeout(SlideOutTimeoutID);
                SlideOutTimeoutID = null;
                _DivBGInOffset = _DivBGInOffsetInitial;
                _DivTopOutOffset = _DivTopOutOffsetInitial;
                if (_UsesMessage == "Y") {
                    EnquireWrap.style.display = "block";
                }
            }
        }
    }

    function ShowThanks() {
        var EnquireWrap = document.getElementById("enquiryWrapper");
        EnquireWrap.style.display = "none";
    }
