$(function() {
    try {document.execCommand("BackgroundImageCache",false,true); }
    catch (e) {}

    //apply shading when we're not in editmode
    if (typeof(m_bEditMode) == "undefined")
    {
        //do this in the window load because when an inner image is not yet loaded, we will be using the wrong height
        $(window).load( function () {
            //force the bounds of shaded elements so that the shading is applied correctly in IE
            $("div.Menu").width( $("div.Menu ul").outerWidth() );
            $("div.QMailFormPart:has(fieldset)").height( $("div.QMailFormPart fieldset").outerHeight() ).addClass("Shade");

            //add shading to tables and panels
            $("table.Shade, div.PanelShade").wrap("<div class='Shade'></div>").each( function () {
                $(this).parent().width($(this).outerWidth()).height($(this).outerHeight());
            });

            //highlight the columns of which the header contains the class "Highlight"        
            $("table.Shade th.Highlight").each(function() {
                $(this).parents("table.Shade:first").find("tr td:nth-child(" + ($(this).parent().find("th").index(this)+1) + ")").addClass("Highlight");
            });
                
            //add shading to images
            $("img.Shade").wrap("<div class='Shade'></div>").each( function() {
                $(this).parent()
                    .width($(this).outerWidth()).height($(this).outerHeight())
                    .css("margin", "5px 0px 5px 0px")
                    .css("float",$(this).attr("align"))
                    //example: when floating to the right we don't use the left-margin because IE uses this for the first line of the paragraph as well
                    .css("margin-" + $(this).attr("align"), ($.browser.msie && parseInt($.browser.version) == 6) ? "5px" : "10px") //floating margin IE6 bug
                    .css($(this).attr("align"), "-10px")
            } );

            //append shading layers
            $(".Shade:not(img,table), .LightShade:not(img,table)").prepend("<div class='ShadeTop ShadePart'></div><div class='ShadeBottom ShadePart'></div><div class='ShadeLeft ShadePart'></div><div class='ShadeRight ShadePart'></div><div class='ShadeTopRight ShadePart'></div><div class='ShadeBottomRight ShadePart'></div><div class='ShadeTopLeft ShadePart'></div><div class='ShadeBottomLeft ShadePart'></div>");

            //IE rendering issue when an image loads in the gallery, remove the shadow, set the height, and add the shadow again
            $(".GalleryImagePart img").load(function () {
                var tmp_oShadows = $(this).parent().find("div.ShadePart").remove();
                $(this).parent().height($(this).outerHeight()).width($(this).outerWidth()).prepend(tmp_oShadows);
            } ).load();
        });
    }
})

function SetGalleryIndex(index)
{
    //get the images
    var tmp_oThumbnails = $(".GalleryThumbnailsPart:first");
    var tmp_oImages = tmp_oThumbnails.attr("images").split(",");
    if (index < 0) index = tmp_oImages.length - 1;
    else if (index >= tmp_oImages.length) index = 0;
    
    //set the new image and mark its thumbnail as active
    tmp_oThumbnails.find("ul li.Active").removeClass("Active");
    $(".GalleryImagePart:first img").attr("src", tmp_oImages[index]);
    tmp_oThumbnails.find("ul li").eq(index).addClass("Active");
    
    //set the text parts
    $(".GalleryImageInfo .Name").text( tmp_oThumbnails.attr("name" + index) );
    $(".GalleryImageInfo .Company").text(  tmp_oThumbnails.attr("company" + index) );
    $(".GalleryImageInfo .Quote").text( tmp_oThumbnails.attr("quote" + index) );
 
    //hide or show the text parts
    $(".GalleryImageInfo div, .GalleryImageInfo").each(function () {
       if ($(this).text() == "") $(this).hide();
       else $(this).show();
    });
}