$(function(){
    if (scripts_isIE6) $(document).pngFix();

    $('a.ro').mbRollover();
    
    if ($.fn.prettyPhoto) {
        $("a[rel^='lightbox']").prettyPhoto({
            animationSpeed: 'slow',
            padding: 40,
            opacity: 0.85,
            showTitle: false,
            allowresize: true,
            counter_separator_label: '/',
            theme: 'light_square'
        });
    }
    
    if ($.fn.mbBookShowcase) {
        $("#tray-wrapper").mbBookShowcase({
            targetTray: 'vaultTrays', //div id of tray in your php fetch file trays.php
            detailsImg: 'book-img',
            itemClass: 'book',
            imgClass: 'bookImg',
            mOvrClass: 'book-ovr',
            selClass: 'book-sel',
            phpFetchFile: 'trays.php',
            klass: 'mbBookShowcase',
            bookId: g_showcaseRecord,
            showDetails: true,       	    
            descriptionOnHover: false,  
            descriptionDest: 'showcase_details',
	    descriptionTarget: 'home-book-desc-content',
	    phpDescFile: 'ShowcaseDetails.php',
            followLink: false,
            loadTrayFromExternalFile: true,
        }, function() {
            var str = this.clickid;
            str = str.substring(1);
            $("#showcaseHiddenRecord").val(str);
            if (this.event == "click") {
                $.ajax({
                    url: "/showcaseSaveItem.php?record=" + str
                });
            }
        }, function(){
        	loadDesc(this.clickid);
        });

        $("#book-img").live('click', function () {
            document.showcaseForm.submit();
        });
        
        $("#showcase-left a, #showcase-right a").hover(function(){
        	$(this).toggleClass("showcase-arrow-over");	
        });
    }
});

function loadDesc(cBook, theBook)
{
	if(theBook == null) theBook = 1;
	var phpFile = "ShowcaseDetails.php?recordNum="+cBook;
   	$("#showcase_details").load(phpFile+" #home-book-desc-content");
}

/* old rollover functions, eventually replace with jquery */
function toggleLayer(whichLayer) {
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = style2.display ? "" : "block";
    } else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = style2.display ? "" : "block";
    } else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = style2.display ? "" : "block";
    }
}

function openCloseLayer(whichLayer, action) {
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = action;
    } else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = action;
    } else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = action;
    }
}

function newImage(arg) {
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

function changeImages() {
    if (document.images && (preloadFlag == true)) {
        for (var i = 0; i < changeImages.arguments.length; i += 2) {
            document[changeImages.arguments[i]].src = changeImages.arguments[i + 1];
        }
    }
}

var preloadFlag = false;

function preloadImages() { //pass array of arguments
    var ni = new Array();
    if (document.images && preloadImages.arguments.length > 0) {
        for (var i = 0; i < preloadImages.arguments.length; i++) {
            ni[i] = newImage(preloadImages.arguments[i]);
        }
        preloadFlag = true;
    }
}
