﻿//$(e.target).children("p").html();

function nav(url) {
    window.location = url;
}

function end() {
    $get('ctl00_ContentPlaceHolder1_UpdatePanel1').style.display = 'block';
    if ($get('ctl00_ContentPlaceHolder1_Panel1')) $get('ctl00_ContentPlaceHolder1_Panel1').style.display = 'block';
    if ($get('ctl00_ContentPlaceHolder1_Panel2')) $get('ctl00_ContentPlaceHolder1_Panel2').style.display = 'block';
}

function start() {
    $get('ctl00_ContentPlaceHolder1_UpdatePanel1').style.display = 'none';
    if ($get('ctl00_ContentPlaceHolder1_Panel1')) $get('ctl00_ContentPlaceHolder1_Panel1').style.display = 'none';
    if ($get('ctl00_ContentPlaceHolder1_Panel2')) $get('ctl00_ContentPlaceHolder1_Panel2').style.display = 'none';
}

function setupbox(box, height, image, textwidthlower, lowerID) {

    alert(height);
    
    if (box != "" && box != null) {
        //Set Digizign box values
        var thisBox = $get(box);
        var textLower = $get(lowerID);
        var admin = document.getElementById('admin')

        
        thisBox.style.height = height;
        if (admin) {
            thisBox.style.backgroundImage = "url(../CSS/Images/" + image + ")";
        }
        else {
            thisBox.style.backgroundImage = "url(CSS/Images/" + image + ")";
        }
        thisBox.style.backgroundRepeat = "no-repeat";
        thisBox.style.backgroundPosition = "top right";
        textLower.style.width = textwidthlower + "px";
    }
}

function showSelector(boxID) {
    //REPLACES thickbox();
    //Open Modal window and update content to reflect the box that was clicked.
    $("#ctl00_ContentPlaceHolder1_positionID").val(boxID);
    tb_show("Digizign Box Selector", "#TB_inline?height=450&width=600&inlineId=modal", 'false');
    __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel1', '')
}
function thickbox(boxID) {

    //Open Modal window and update content to reflect the box that was clicked.
    $("#ctl00_ContentPlaceHolder1_positionID").val(boxID);
    tb_show("Digizign Box Selector", "#TB_inline?height=450&width=600&inlineId=modal", 'false');
    __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel1', '')
}

function radio(radiobutton) {
    //Ensure only one radio button is checked at a time.
    $("#ctl00_ContentPlaceHolder1_Design_rBlack")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_Design_rRed")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_Design_rBlue")[0].checked = false;
    radiobutton.checked = true;
}

function lowerRadio(radiobutton) {

    $("#ctl00_ContentPlaceHolder1_rHOClient")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rHOEmail")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rHOFriends")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rHOOther")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rHOSearch")[0].checked = false;
    radiobutton.checked = true;
}

function contactus_radio(radiobutton) {

    var x = hide_contactfields(radiobutton)
    //Ensure only one radio button is checked at a time.
    $("#ctl00_ContentPlaceHolder1_rWebsite")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rDesign")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rDDesign")[0].checked = false;
    $("#ctl00_ContentPlaceHolder1_rCreative")[0].checked = false;
    radiobutton.checked = true;

    if (radiobutton.id == "ctl00_ContentPlaceHolder1_rWebsite" && x == 1) {
        //animate function works as half second pause as opacity is already 100%;
        $("#website").animate({ opacity: 1.0 }, 500).toggle("blind");
    }
    else if (radiobutton.id == "ctl00_ContentPlaceHolder1_rDesign" && x == 1) {
        $("#designandprint").animate({ opacity: 1.0 }, 500).toggle("blind");
    }
    else if (radiobutton.id == "ctl00_ContentPlaceHolder1_rDDesign" && x == 1) {
        $("#detaileddesign").animate({ opacity: 1.0 }, 500).toggle("blind");
    }
    else if (radiobutton.id == "ctl00_ContentPlaceHolder1_rCreative" && x == 1) {
        $("#creative").animate({ opacity: 1.0 }, 500).toggle("blind");
    }
}

function hide_contactfields(radiobutton) {

    //If a blind toogles return 1, else return 0
    //this prevents blind states from getting out of order (2 blinds open, for example).
    if ($("#ctl00_ContentPlaceHolder1_rCreative")[0].checked == true && radiobutton.id != "ctl00_ContentPlaceHolder1_rCreative") {
        $("#creative").toggle("blind");
        return 1;
    }
    else if ($("#ctl00_ContentPlaceHolder1_rDesign")[0].checked == true && radiobutton.id != "ctl00_ContentPlaceHolder1_rDesign") {
        $("#designandprint").toggle("blind");
        return 1;
    }
    else if ($("#ctl00_ContentPlaceHolder1_rDDesign")[0].checked == true && radiobutton.id != "ctl00_ContentPlaceHolder1_rDDesign") {
        $("#detaileddesign").toggle("blind");
        return 1;
    }
    else if ($("#ctl00_ContentPlaceHolder1_rWebsite")[0].checked == true && radiobutton.id != "ctl00_ContentPlaceHolder1_rWebsite") {
        $("#website").toggle("blind");
        return 1;
    }
    else {
        return 0;
    }
    
}

function changeimage() {
    $("#changeimage").removeClass("hidden");
}

function btnSubmit_Click() {

    //Move values between Box Editor and Hidden controls
    //Values will be updated to database.
    $("#ctl00_ContentPlaceHolder1_hdnTitle").val($("#ctl00_ContentPlaceHolder1_Design_txtTitle").val());
    $("#ctl00_ContentPlaceHolder1_hdnText").val($("#ctl00_ContentPlaceHolder1_Design_txtText").val());
    $("#ctl00_ContentPlaceHolder1_hdnImageName").val($("#ctl00_ContentPlaceHolder1_Design_txtImage").val());
    $("#ctl00_ContentPlaceHolder1_hdnImageHeight").val($("#ctl00_ContentPlaceHolder1_Design_txtHeight").val());
    $("#ctl00_ContentPlaceHolder1_hdnBoxURL").val($("#ctl00_ContentPlaceHolder1_Design_txtURL").val());

    //Check radio buttons, use value for checked button.
    if ($("#ctl00_ContentPlaceHolder1_Design_rBlack")[0].checked == true) {
        $("#ctl00_ContentPlaceHolder1_hdnTitleType").val("Black");
    }
    else if ($("#ctl00_ContentPlaceHolder1_Design_rRed")[0].checked == true) {
        $("#ctl00_ContentPlaceHolder1_hdnTitleType").val("Red");
    }
    else if ($("#ctl00_ContentPlaceHolder1_Design_rBlue")[0].checked == true) {
    $("#ctl00_ContentPlaceHolder1_hdnTitleType").val("Blue");
    }

    $("#ctl00_ContentPlaceHolder1_TextBox2").val("True");
    
    __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel1', '');
}

function hometext(recordID) {

    //hdnmodal2 holds the value of the Record ID that is passed when the row is clicked on.
    $("#ctl00_ContentPlaceHolder1_hdnmodal2").val(recordID);
    tb_show("Edit Center Text", "#TB_inline?height=270&width=600&inlineId=modal2", 'false');
    __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel3', '')
}
function newhometext() {

    $("#ctl00_ContentPlaceHolder1_hdnmodal2").val("0");
    tb_show("Add New Center Text", "#TB_inline?height=270&width=600&inlineId=modal2", 'false');
    __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel3', '')
    
}

function updateCenter() {
    
    $("#ctl00_ContentPlaceHolder1_hdnRecordID").val($("#ctl00_ContentPlaceHolder1_fv_Center_Rows_hdnRecordID").val());
    $("#ctl00_ContentPlaceHolder1_hdnLeft1").val($("#ctl00_ContentPlaceHolder1_fv_Center_Rows_txtLeftEntry").val());
    $("#ctl00_ContentPlaceHolder1_hdnRight1").val($("#ctl00_ContentPlaceHolder1_fv_Center_Rows_txtRightEntry").val());
    $("#ctl00_ContentPlaceHolder1_hdnBold1").val($("#ctl00_ContentPlaceHolder1_fv_Center_Rows_ddlBold").val());  

    __doPostBack('ctl00_ContentPlaceHolder1_btnSubmitCenter1', 'btnSubmitCenter1');
}

function refreshPage() {
    __doPostBack('ctl00_ContentPlaceHolder1_btnSubmitCenter1', 'Refresh');
}

function selectbox(boxID) {
    if (confirm('Change box?, If yes page will reload.')) {
        __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel1', boxID)
    }
    else { return false; }
}

function deletebox(boxID) {
    if (boxID == 6 || boxID == 8 || boxID == 9) {
        alert('This box cannot be deleted');
        return false;
    }
    if (confirm('Delete this box? This box will no longer be avaliable on any page, this cannot be undone')) {
        $("#ctl00_ContentPlaceHolder1_deleteBox").val("True");
        alert($("#ctl00_ContentPlaceHolder1_deleteBox").val());
        __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel1', boxID)
    }
}

function editcenter() {
    tb_show("Edit Center Text", "#TB_inline?height=500&width=750&inlineId=modal2", 'false');
}

function newCenterRow() {
    
    //Create new Center Row.
    var pageID = $("#ctl00_ContentPlaceHolder1_hdnPageID").val();
    $("#ctl00_ContentPlaceHolder1_hdnID").val(pageID);
    $("#ctl00_ContentPlaceHolder1_hdnPageID").val("newRow");

    tb_show("New Center Row", "#TB_inline?height=340&width=600&inlineId=modal3", 'false');
    $("#ctl00_ContentPlaceHolder1_txtSecondBox").removeClass("hidden").addClass("w550");
    
}

function selectlayout(layoutID, layoutName) {

    if (confirm('Select ' + layoutName + ' layout?')) {
        __doPostBack('ctl00_ContentPlaceHolder1_UpdatePanel2', layoutID)       
    }
}

function setupControls() {

        $(".center").hover(function() {
            $(this).addClass("hovercenter");
        },
        function() {
            $(this).removeClass("hovercenter")
        });

        $(".center").click(function() {

            var value = $(this).attr("title");
            var controlID = $(this).attr("ID");
            var text = $("#" + controlID + " > p").html();
            var ID = value.charAt(10);

            //Is the second box in use?
            $("#ctl00_ContentPlaceHolder1_hdnText2").val("No");

            //Set up controls
            $("#ctl00_ContentPlaceHolder1_hdnID").val(ID);
            $("#ctl00_ContentPlaceHolder1_txtSecondBox").addClass("hidden");
            $("#title1").html("Enter Text");
            $("#title2").html("");
            tb_show("Update Text Area " + ID, "#TB_inline?height=200&width=600&inlineId=modal3", 'false');
            $("#ctl00_ContentPlaceHolder1_txtTopText").val(text);
        });


        $(".centrecontent > li").hover(function() {
            $(this).addClass("hovercenter");
            $(this).css("border", "solid 1px gray");
            $(this).css("cursor", "pointer");
        },
        function() {
            $(this).removeClass("hovercenter")
            $(this).css("border", "solid 1px white");
            $(this).css("cursor", "default");
        });

        $(".centrecontent > li").click(function() {

            var ID = $("p", this).html();
            $("#ctl00_ContentPlaceHolder1_hdnID").val(ID);
            //Is the second box in use?
            $("#ctl00_ContentPlaceHolder1_hdnText2").val("Yes");

            //Set Up first box
            var div = $("div:first", this).html();
            $("#ctl00_ContentPlaceHolder1_txtTopText").val(trimAll(div));

            //Set up second box
            var div2 = $("div:last", this).html();
            //If div1 = div 2 then there is only a single div.
            //remove second textbox open thickbox according to how many textboxes required.
            if (div != div2) {
                tb_show("Update Center Record " + ID, "#TB_inline?height=340&width=600&inlineId=modal3", 'false');
                $("#ctl00_ContentPlaceHolder1_txtSecondBox").removeClass("hidden").addClass("w550").val(trimAll(div2));
                //Add bold Labels
                $("#title1").html("Left Entry");
                $("#title2").html("Right Entry");
            } else {
                tb_show("Update Center Record " + ID, "#TB_inline?height=200&width=600&inlineId=modal3", 'false');
                $("#ctl00_ContentPlaceHolder1_txtSecondBox").addClass("hidden").val("");
                $("#title1").html("Enter Text");
                $("#title2").html("");
            }
        });

        $("#btnUpdateTopText").click(function() {

            if ($("#ctl00_ContentPlaceHolder1_hdnPageID").val() == "newRow") {
                var text = $("#ctl00_ContentPlaceHolder1_txtTopText").val();
                var text2 = $("#ctl00_ContentPlaceHolder1_txtSecondBox").val();
                $("#ctl00_ContentPlaceHolder1_hdnText").val(text);
                $("#ctl00_ContentPlaceHolder1_hdnText2").val(text2);
                $("#ctl00_ContentPlaceHolder1_btnNewRow").click();
            }
            else {

                if ($("#ctl00_ContentPlaceHolder1_hdnText2").val() == "Yes") {
                    //center columns
                    if (confirm('Update Text Area(s)?')) {
                        var text = $("#ctl00_ContentPlaceHolder1_txtTopText").val();
                        var text2 = $("#ctl00_ContentPlaceHolder1_txtSecondBox").val();
                        $("#ctl00_ContentPlaceHolder1_hdnText").val(text);
                        $("#ctl00_ContentPlaceHolder1_hdnText2").val(text2);
                        //Updated from server side on button2 event.
                        $("#ctl00_ContentPlaceHolder1_Button2").click();
                    }
                } else {
                    //4 main text areas
                    if (confirm("Update Text Area?")) {
                        var text = $("#ctl00_ContentPlaceHolder1_txtTopText").val();
                        var ID = $("#ctl00_ContentPlaceHolder1_hdnID").val();
                        $("#ctl00_ContentPlaceHolder1_hdnText").val(text);
                        //Updated from server side on button1 event.
                        $("#ctl00_ContentPlaceHolder1_Button1").click();
                    }
                }
            }
        });

        if ($("#cbxShow")) {
            $("#cbxShow").click(function() {
                tb_show("Page Control Panel", "#TB_inline?height=600&width=600&inlineId=modal1", 'false');
            });
        }

        if ($("#a")) {
            $("#a").click(function() {
                $("#changeImage").removeClass("hidden");
            });
        }

        if ($("#ctl00_ContentPlaceHolder1_ddlPages")) {
            $("#ctl00_ContentPlaceHolder1_ddlPages").change(function() {
                var ID = $("#ctl00_ContentPlaceHolder1_hdnID").val($("select#ctl00_ContentPlaceHolder1_ddlPages option:selected").val());
                $("#ctl00_ContentPlaceHolder1_btnPageChange").click();
            });
        }
        if ($("#btnNewPage")) {
            $("#btnNewPage").click(function() {
                $("#ctl00_ContentPlaceHolder1_btnNewPage").click();
            });
        }

        if ($("#ctl00_ContentPlaceHolder1_gv_contacts")) {
            $("#ctl00_ContentPlaceHolder1_gv_contacts tr").hover(function() {
                if ($(this).children("th").length == 0) {
                    $(this).css("background", "#dcdcdc");
                    $(this).css("cursor", "pointer");
                }
            }
            , function() {
                $(this).css("background", "#fff");
                $(this).css("cursor", "default");
            });

            $("#ctl00_ContentPlaceHolder1_gv_contacts td").click(function() {

                var contactID = $("#ctl00_ContentPlaceHolder1_hdnContactID").val();

                if ($(this).attr("class") == "noclick" || $(this).attr("class") == "noclick rowback") {

                    if ($(this).hasClass("rowback")) {
                        $(this).removeClass("rowback").siblings().removeClass("rowback");

                    } else {
                        $(this).addClass("rowback").siblings().addClass("rowback");
                    }
                } else {
                    window.location = "Contact.aspx?ID=" + $(this).siblings(".hidden").html();
                }
            });
        }
        
        if($("#ctl00_ContentPlaceHolder1_gv_archive")) {
            $("#ctl00_ContentPlaceHolder1_gv_archive tr").hover(function() {
            if ($(this).children("td").length != 1 && $(this).children("th").length == 0) {
                    $(this).css("background", "#dcdcdc");
                    $(this).css("cursor", "pointer");
                }
            }
            , function() {
                $(this).css("background", "#fff");
                $(this).css("cursor", "default");
            });

            $("#ctl00_ContentPlaceHolder1_gv_archive tr").click(function() {
                window.location = "Contact.aspx?ID=" + $(this).children(".hidden").html();
            });
        }

        if ($("#emailview")) {
            var li = $("li").each(function() {
                if ($(this).html() == "") $(this).html("&nbsp;");
            });
        }

        if ($("#ctl00_ContentPlaceHolder1_gv_PortfilioItems")) {
            $("#ctl00_ContentPlaceHolder1_gv_PortfilioItems tr").hover(function() {
                if ($(this).children("td").length != 1 && $(this).children("th").length == 0) {
                    $(this).css("background", "#dcdcdc");
                    $(this).css("cursor", "pointer");
                }
            }
            , function() {
                $(this).css("background", "#fff");
                $(this).css("cursor", "default");
            });

            $("#ctl00_ContentPlaceHolder1_gv_PortfilioItems tr").click(function() {
                var ID = $(this).children("td").children("span").html();
                //Open edit window in thickbox iframe (using inline one causes file upload control to stop working)
                tb_show("Update Portfolio Item", "PortfolioItem.aspx?ID=" + ID + "&keepThis=true&TB_iframe=true&height=600&width=600", 'false');
            });
        }
        
        if($("#btnNewItem")) {
            $("#btnNewItem").click(function () {
                tb_show("Create New Portfolio Item", "PortfolioItem.aspx?ID=0&keepThis=true&TB_iframe=true&height=600&width=620", 'false');
            });
        }

        if ($("#btnViewPDF").length > 0) {
            $("#btnViewPDF").click(function() {
                $("#ctl00_ContentPlaceHolder1_pdflistholder").slideToggle("slow");
            });
        }

        if ($(".pdflist").length > 0) {
            $(".pdflist li").hover(function() {
                $(this).css("border", "solid 1px gray");
            }, function() {
                $(this).css("border", "solid 1px #dcdcdc");
            });

            $(".pdflist li").click(function() {
                if (confirm("Delete this PDF? This cannot be undone.")) {
                    var pdfName = $(this).html();
                    $("#ctl00_ContentPlaceHolder1_hdnPDF").val(pdfName);
                    $("#ctl00_ContentPlaceHolder1_btnDeletePDF").click();
                }
            });
        }

        if ($("#btnViewFilters").length > 0) {
            $("#btnViewFilters").click(function() {
                $("#ctl00_ContentPlaceHolder1_panFilters").slideToggle("slow");
            });

        }

        if ($("#btnViewRSS").length > 0) {
            $("#btnViewRSS").click(function() {
                $("#ctl00_ContentPlaceHolder1_panRSS").slideToggle("slow");
            });

        }

        if ($("#btnAddRSS").length > 0) {
            $("#btnAddRSS").click(function() {
                tb_show("Create New RSS Item", "CreateRSS.aspx?ID=0&keepThis=true&TB_iframe=true&height=240&width=350", 'false');
            });
        }
    }

function refreshRSS() {

    $("#ctl00_ContentPlaceHolder1_Button3").click();
    
}

function setUpHome() {

    //Set Up Basic Digizign Box object.
    if ($(".box")) {
        //Opacity hover functions
        $(".box").hover(function() {

            var settings = $(this).children(".hidden").html().split("|");
            if (settings[1] != " paua.png " && settings[1] != " websitedv.jpg ") {
                $(this).addClass("opac");
            }
        },
        function() {
            $(this).removeClass("opac");
        });
        

        $(".box").each(function() {
            //basic settings and click functions.
            if ($(this).children(".hidden").html() != null) {
                var settings = $(this).children(".hidden").html().split("|");
                var admin = $get("admin")
                $(this).css("height", settings[0] + "px").css("backgroundRepeat", "no-repeat").css("backgroundPosition", "top right");
                $(this).children(".text").css("width", settings[2] + "px");

                if (admin) {
                    //If admin settings are slightly different
                    $(this).css("backgroundImage", "url(../CSS/Images/" + trimAll(settings[1]) + ")");
                    $(this).click(function() { showSelector(trimAll(settings[4])) });
                } else {
                    //Normal settings.
                    $(this).css("backgroundImage", "url(CSS/Images/" + trimAll(settings[1]) + ")");
                    $(this).click(function() { nav(settings[3]); });
                }
            }
            else {
                $(this).addClass("hidden");
            }
        });
    }

    $("#subscribe").click(function() {
        tb_show("Subscribe to our RSS feed", "RSSInform.aspx?ID=0&keepThis=true&TB_iframe=true&height=100&width=370", 'false');

    });


    $('#blendme').cycle();
    
    //Set Up Blend Images box.
    if ($(".blend")) {
        $(".blend").hover(function() {
            $(this).addClass("opac");
        },
        function() {
            $(this).removeClass("opac");
        });

        $(".blend img").click(function() {
            var url = $(this).attr("class");
            window.open(url);
        });
    }

    $(".nobox").hover(function() {
        $(this).addClass("hovercenter");
    },
    function() {
        $(this).removeClass("hovercenter");
    });
    
    
    //This is for the rollover menus.
    
    var menuitems = $(".menu > li");
    var submenuitems = $(".innermenu > li");
    var pageName = $("#page_name").html();
    var subpage_name = $("#subpage_name").html();

    

    for (i = 1; i < menuitems.length; i++) {
        if (trimAll(pageName) == trimAll(menuitems[i].innerHTML)) {
            var item = menuitems[i];
            $(item).addClass("rollover2");
        }
    }

    for (i = 0; i < submenuitems.length; i++) {
        if (trimAll(subpage_name) == trimAll(submenuitems[i].innerHTML)) {
            var item = submenuitems[i];
            $(item).addClass("rollover");
        }
    }

    $(".menu > li").hover(function() {
    if (trimAll(this.innerHTML) != trimAll(pageName) && trimAll(this.innerHTML) != "services" && trimAll(this.innerHTML) != "") {
            $(this).addClass("rollover2");
        }
    }, function() {
        if (trimAll(this.innerHTML) != trimAll(pageName)) {
            $(this).removeClass("rollover2");
        }
    });
    
    $(".innermenu > li").hover(function() {
        
        if (trimAll(this.innerHTML) != trimAll(subpage_name)) {
            $(this).addClass("rollover");
        }
    }, function() {
        if (trimAll(this.innerHTML) != trimAll(subpage_name)) {
            $(this).removeClass("rollover");
        }
    });
}

function trimAll(sString) {
    //Trim function to remove leading and trailing spaces.
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}


////////////////////////////////////////////////////////////////////////////////
// Begin Drag/Scroll Handlers
////////////////////////////////////////////////////////////////////////////////

function scrollHandler(e) {
    // This function handles the draging of the filmstrip from left to right
    if (e == null) { e = window.event; }                        // Get event data
    _totalChange = (_dragXoffset - e.clientX);                      // Calculate total movement
    if (e.button <= 1 && _scrollOK) {                                // Is mouse down and scroll enabled?
        _totalOffset = _originalOffset + (_dragXoffset - e.clientX);   // Find the distance mouse has moved
        if ((_totalOffset) < 0) {                                // Are we scrolling too far left?
            _totalOffset = 0;                                       // Yes, set the offset to 0
            _originalOffset = 0;                                    // and the original
            _dragXoffset = e.clientX;                               // and reset the mouse.
            _totalChange = 20;                                      // Simulate a move so we don't open a pic.
        }
        if ((_totalOffset + _landingZone.offsetWidth) >= (_filmWidth - 5)) { // Are we too far right?
            _totalOffset = (_filmWidth - _landingZone.offsetWidth - 5);   // Yes, set offset to max
            _originalOffset = (_filmWidth - _landingZone.offsetWidth - 5); // and the original
            _dragXoffset = e.clientX;                                 // reset the mouse
            _totalChange = 20;                                      // Simulate a move so we don't open a pic.
        }
        // Set the visible clip here.
        _filmstrip.style.clip = 'rect(0px,' + (_landingZone.offsetWidth + _totalOffset) + 'px,80px,' + _totalOffset + 'px)';
        // And set the left offset
        _filmstrip.style.left = (_leftOffset - _totalOffset) + 'px';
        // return false so the browser won't try to do it's events!
        return false;
    }
}

function cleanup(e) {
    // called when user releases a mouse button after a drag event
    _scrollOK = false;                                         // Setting this to false disables scrollHandler
    _dragOK = false;                                          // This disables the move handler (detail window)
    _savedTarget.style.cursor = _orgCursor;                     // Change back to the original cursor shape
    document.onmousemove = null;                                // Disable the mousemove handler
    document.onmouseup = null;                                  // Disable the mouseup handler
}

function moveHandler(e) {                                     // Called on mousemove when detail layer is dragable
    if (e == null) { e = window.event; }                      // Get the event data
    if (e.button <= 1 && _dragOK) {                                // Make sure mouse button is down and ok to drag
        _savedTarget.style.left = e.clientX - _dragXoffset + 'px';   // Move to the new left offset
        _savedTarget.style.top = e.clientY - _dragYoffset + 'px';    // Move to the new top offset.
        return false;                                          // Return false so browser doesn't do its own thing
    }                                                         // End button/dragOK check
}

function dragHandler(e) {
    _totalChange = 0;                                                           // Total pixels moved
    var cursorType = '-moz-grabbing';                                           // Set hand to "grab"
    if (e == null) { e = window.event; cursorType = 'pointer'; }                // Package event for IE
    var target = e.target != null ? e.target : e.srcElement;                  // Get the target object
    //Handle filmstrip
    if (target.className == "filmstrip" || target.className == "thumbnail") {       // Check if event over filmstrip
        _savedTarget = target;                                                   // This is our target object
        _orgCursor = target.style.cursor;                                        // This was our orginal cursor
        _originalOffset = _totalOffset;                                          // Mark the current offset
        target.style.cursor = cursorType;                                        // Set mouse to grab if possible
        _scrollOK = true;                                                        // flag filmstrip as scrollable
        _dragXoffset = e.clientX;                                                // remember original X position
        document.onmousemove = scrollHandler;                                    // set up a mouse-move handler
        document.onmouseup = cleanup;                                            // set up a button-up handler
        return false;                                                          // return FALSE -- IMPORTANT!!!!
    } else {
        //Handle detail window
        if (target.className.indexOf('detail') >= 0) {                           // Check to see if we're over a datail layer
            _savedTarget = document.getElementById('detailFrame');                // This is our target object
            _orgCursor = target.style.cursor;                                     // This was our orginal cursor
            target.style.cursor = cursorType;                                     // Set mouse to grab if possible
            _dragOK = true;                                                       // flag filmstrip as scrollable
            _dragXoffset = e.clientX - parseInt(_savedTarget.style.left);           // Remember original X position
            _dragYoffset = e.clientY - parseInt(_savedTarget.style.top);            // Remember original Y position
            document.onmousemove = moveHandler;                                   // set up a mouse-move handler
            document.onmouseup = cleanup;                                         // set up a button-up handler
            return false;                                                       // return FALSE -- IMPORTANT!!!!!!!
        }
    }
}
////////////////////////////////////////////////////////////////////////////////
// End drag/scroll Handlers                                         
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// These functions support the detail Window                                  //
////////////////////////////////////////////////////////////////////////////////
function showPic(idx, recordID, title, pdf1, pdf2, pdf3, url1, url2) {

    if ((_totalChange < -5) || (_totalChange > 5)) { return false }                 // User scrolled, not a click event so return.
    
    detail = document.getElementById('detailFrame');                                // get the detail window
    theTitle = document.getElementById('title');
    txt = 'text_' + recordID;
    detailComments = document.getElementById('comments');                           // get the comments window
    detailImg = document.getElementById('detailPic');                               // get the picture window
    detailImg.innerHTML = '<img src="CSS/images/' + idx + '" class="detailImg">';   // Insert the pic
    detailComments.innerHTML = document.getElementById(txt).innerHTML;
    theTitle.innerHTML = title;
    var pdfs = "";
    var urls = "";

    document.getElementById('pdfs').innerHTML = "";
    document.getElementById('urls').innerHTML = "";

    if(pdf1 != " | #" && pdf1 != null) {
        var url = trimAll(pdf1.split("|")[1]);
        pdfs = "<a target=_blank href='PDF/" + url + "'>" + trimAll(pdf1.split("|")[0]) + "</a> &nbsp;";
    }
    if (pdf2 != " | #" && pdf2 != null) {
        var url = trimAll(pdf2.split("|")[1]);
        pdfs = pdfs + " | &nbsp; <a target=_blank href=PDF/" + url + ">" + trimAll(pdf2.split("|")[0]) + "</a> &nbsp;";
    }
    if (pdf3 != " | #" && pdf3 != null) {
        var url = trimAll(pdf3.split("|")[1]);
        pdfs = pdfs + " | &nbsp; <a target=_blank href=PDF/" + url + ">" + trimAll(pdf3.split("|")[0]) + "</a> &nbsp;";
    }

    if (url1 != " | #" && url1 != null) {
        urls = "<a target=_blank href=" + url1.split("|")[1] + ">" + trimAll(url1.split("|")[0]) + "</a> &nbsp;";
    }
    if (url2 != " | #" && url2 != null) {
        urls = urls + " |&nbsp; <a target=_blank href=" + url2.split("|")[1] + ">" + trimAll(url2.split("|")[0]) + "</a> &nbsp;";
    }
    
    document.getElementById('pdfs').innerHTML = pdfs;
    document.getElementById('urls').innerHTML = urls;
    

}

////////////////////////////////////////////////////////////////////////////////
// End detail window functions                                                //
////////////////////////////////////////////////////////////////////////////////

