Shadowbox.init({ skipSetup: true });




$(document).ready(function() {
    // fake :last-child pseudoclass for IE6, IE7, IE8
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 8) {
        $("#topnav li ul li:last-child").addClass("ie_last-child");
    }

    // fake rounded corners for IE6, IE7
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 7) {
        /*$("#topnav li ul").corner("bl br 10px cc:#fff");        // white background assumes the page will be tall enough to have white under the dropdown
        $("#topnav li ul li:last-child a").hover(function() {
            $(this).corner("bl br 10px cc:#fff");               // white background assumes the page will be tall enough to have white under the dropdown
        });
        if(!($("body.homepage").length > 0)) {
            $("#content").corner("bl br 10px");
        }*/
        //$("body.homepage #col0").corner("tl 20px");
    }

    // fake :hover pseudoclass for IE6
    if(jQuery.browser.msie && parseInt(jQuery.browser.version) <= 6) {
        $('#topnav li').hover(function() {
            $(this).addClass('ie6_hovering');
        }, function() {
            $(this).removeClass('ie6_hovering');
        });
    }




    // Show/hide default form field text
    $("input[title]").hint();




    // homepage slideshow
    $("ul#slideshow").cycle({
        timeout: 3000,
        speed: 400,
        pause: true,
        pauseOnPagerHover: true,
        pagerEvent: "mouseover",
        pager: "#slideshow_nav ul",
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#slideshow_nav li:eq(' + (idx) + ')';
        }
    });

    // follow links in the slideshow nav
    $("#slideshow_nav a").click(function(event) {
        window.location = $(this).attr('href');
    });





    // Shadowbox
    if($("#col1 #ad-gallery").length == 0) // 12/6/2011 - do not invoke Shadowbox code on newly-published pages; they use openDOMWindow and AdGallery
    {
        $("#col1 a.productPhoto").each(function() {
            var caption = $(this).attr("title");
            if(caption != "") {
                Shadowbox.setup(this, {
                    continuous:     true,
                    overlayOpacity: 0.75,
                    gallery:        "Product Photos",
                    title:          $(this).text() + ": " + $(this).attr("title")
                });
            } else {
                Shadowbox.setup(this, {
                    continuous:     true,
                    overlayOpacity: 0.75,
                    gallery:        "Product Photos",
                    title:          $(this).text()
                });
            }
        });

        // When user clicks "Product Photos" button, trigger click event on the first Shadowbox link
        $("#productLinks .productPhotosLink").click(function() {
            $("#col1 a.productPhoto:first").click();
        });
    }


    // Shadowbox the RFQ forms
    Shadowbox.setup("a.requestQuoteLink");

    // 12/6/2011 - only invoke openDOMWindow and AdGallery on newly-published pages
    if($("#col1 #ad-gallery").length > 0)
    {
        $("a.productPhotosLink").openDOMWindow({
            eventType:'click',
            //positionType:'centered',
            //overlayColor:'#383838',
            //overlayOpacity:'90',
            width:600,
            height:520,
            //borderSize:0,
            windowPadding:40,
            //windowBGColor:'transparent',
            loader:1,
            loaderImagePath:'images/loader.gif',
            loaderHeight:28,
            loaderWidth:28,
            functionCallOnOpen:runAdGallery
        });
    }
});


var galleryExists = false;  // JavaScript doesn't have static variables

function runAdGallery() {
    if(!galleryExists) {
    $('.ad-gallery').adGallery({
        effect:'fade',
        loader_image: 'images/loader.gif',
        display_next_and_prev: true,    // arrows on the image
        display_back_and_forward: true, // arrows for the scrolling thumbnails
        slideshow: {
            enable: false
        }
    });
        galleryExists = true;
    }
}




// one of the few times we want to wait for images to download
$(window).load(function() {
    if(!($("body.homepage").length > 0)) {
        var highestCol = Math.max($('#col0').height(),$('#col1').height());
        $('#col0, #col1').height(highestCol);
    }

    highestCol = Math.max($('body.homepage .left').height(),$('body.homepage .right').height());
    $('body.homepage .left, body.homepage .right').height(highestCol);
});

