$(function()
{
    $('.ro').mbRollover();
	
    $("a[rel^='lightbox']").prettyPhoto({
			animationSpeed: 'slow',
			padding: 40,
			opacity: 0.85,
			showTitle: false,
			allowresize: true,
			counter_separator_label: '/',
			theme: 'light_rounded'
    });
    
    var replace;
    $("input[title!='']").focus(function(){
    	replace = $(this).attr("title");
    	var thisVal = $(this).val();
    	if(thisVal == replace)
    		$(this).val("");
    });
    
    $("input[title!='']").blur(function(){
    	var thisVal = $(this).val();
    	if(thisVal == "")
    		$(this).val(replace);
    });
    
    $("input.hasInputReplace").click(function(){
    	var prevVal = $(this).prev().val();
    	var prevTitle = $(this).prev().attr("title");
    	//alert(prevVal + " " + prevTitle);
    	if(prevVal == prevTitle)
    		 $(this).prev().val('');
    	
    });
        
    if($(".myacct_home_btn").length>0){
    	$(".myacct_home_btn").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    }
    
    if($(".feedback_submit").length>0){
    	$(".feedback_submit").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    }
    
    if($(".myAcctBtn").length>0){
    	$(".myAcctBtn").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    }
    
    if($("#sc_cart_buttons_tbl .qsrch").length>0)
    {
    	$("#sc_cart_buttons_tbl .qsrch").each(function(){
    		$(this).wrap('<span class="more" />');
	});
    
    }
    
    if($(".cartCreateAcctBtn").length>0)
    {
    	$(".cartCreateAcctBtn").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    
    }
    if($(".cartSignOnBtn").length>0)
    {
    	$(".cartSignOnBtn").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    
    }
    if($(".noResultsSubmit").length>0)
    {
    	$(".noResultsSubmit").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    
    }
    
    if($(".srch_results_td_alt").length>0)
    {
    	$(".srch_results_td_alt:first").css("border", "0px solid #000");
    	$(".srch_results_td_alt:first").css("padding-top", "5px");
    
    }
    
    if($(".wa_want_btn1").length>0 && $(".wa_want_btn2").length>0)
    {
    	$(".wa_want_buttons input").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    
    }
    
    if($("input.forgotpw_submit").length>0) {
    	$("input.forgotpw_submit").each(function(){
    		$(this).addClass('qsrch');
    		$(this).wrap('<span class="more" />');
	});
    }

   // landing pages
   if (jQuery.fn.mbBookShowcase) {
        $("#horizontal-showcase #tray-wrapper").mbBookShowcase({
            targetTray: 'categoryTrays',
            //div id of tray in your php fetch file trays.php
            itemClass: 'book',
            imgClass: 'bookImg',
            mOvrClass: 'book-ovr',
            selClass: 'book-sel',
            klass: 'mbBookShowcase',
            trayOffset: 20,
            followLink: false,
            bookId: g_showcaseRecord
        }, function () {
            var str = this.clickid;
            
            // check if natural width is larger than space allocated and add resize class to parent if so
            /*var imgpath = $("#"+this.clickid).attr("rel");
            $.getJSON("manager/include/json_getImageSize.php?image=../../"+imgpath+"&attribute=width&callback=?", function (data) {
                if (isNaN(data)){
                    $("#book-img").removeClass("resizeCatImage");
                }else {
                    if(data>320){
                    	$("#book-img").addClass("resizeCatImage");
                    } else {
                    	$("#book-img").removeClass("resizeCatImage");
                    }
                }
            });*/
            
            str = str.substring(1);
            $("#showcaseHiddenRecord").val(str);
            if (this.event == "click") {
                $.ajax({
                    url: "/showcaseSaveItem.php?record=" + str
                });
            }
        });
        
        if($("div#book-img.catalog").length <= 0){
        	$("#book-img").live('click', function () {
            		document.showcaseForm.submit();
	        });
        }else{
       		setTimeout(function(){
        		$("div#book-img.catalog").children('a').children('img').unwrap();
	        }, 500);
        }
        // home page
        $("#vertical-showcase.vcase1 #tray-wrapper").mbBookShowcase({
            targetTray: 'featuredTray',
            //div id of tray in your php fetch file trays.php
            itemClass: 'book',
            imgClass: 'bookImg',
            mOvrClass: 'book-ovr',
            selClass: 'book-sel',
            position: "vertical",
            trayOffset: 25,
            klass: 'mbBookShowcase',
            followLink: false,
            bookId: g_showcaseRecord,
            largeImgMaxWidth: 250
        }, function () {
            var str = this.clickid;
            
            // check if natural width is larger than space allocated and add resize class to parent if so
            /*var imgpath = $("#"+this.clickid).attr("rel");
            $.getJSON("manager/include/json_getImageSize.php?image=../../"+imgpath+"&attribute=width&callback=?", function (data) {
                if (isNaN(data)){
                    $("#book-img").removeClass("resizeHomeImage");
                }else {
                    if(data>250){
                    	$("#book-img").addClass("resizeHomeImage");
                    } else {
                    	$("#book-img").removeClass("resizeHomeImage");
                    }
                }
            });*/
            
            str = str.substring(1);
            $("#showcaseHiddenRecord").val(str);
            if (this.event == "click") {
                $.ajax({
                    url: "/showcaseSaveItem.php?record=" + str
                });
            }
        });
        
        // about pages, adv search, etc.
        $("#vertical-showcase.vcase2 #tray-wrapper").mbBookShowcase({
            targetTray: 'featuredTray',
            //div id of tray in your php fetch file trays.php
            itemClass: 'book',
            imgClass: 'bookImg',
            mOvrClass: 'book-ovr',
            selClass: 'book-sel',
            position: "vertical",
            trayOffset: 25,
            klass: 'mbBookShowcase',
            followLink: true,
            bookId: g_showcaseRecord
        }, function () {
            var str = this.clickid;
            str = str.substring(1);
            $("#showcaseHiddenRecord").val(str);
            if (this.event == "click") {
                $.ajax({
                    url: "/showcaseSaveItem.php?record=" + str
                });
            }
        });
        
        // catalogs
        $("#vertical-showcase.vcase3 #tray-wrapper").mbBookShowcase({
            targetTray: 'featuredTray',
            //div id of tray in your php fetch file trays.php
            itemClass: 'book',
            imgClass: 'bookImg',
            mOvrClass: 'book-ovr',
            selClass: 'book-sel',
            position: "vertical",
            trayOffset: 20,
            klass: 'mbBookShowcase',
            followLink: false,
            bookId: ''
        }, function () {
           /*
            var str = this.clickid;
            str = str.substring(1);
            $("#showcaseHiddenRecord").val(str);
            if (this.event == "click") {
                $.ajax({
                    url: "/showcaseSaveItem.php?record=" + str
                });
            }
           */
       		setTimeout(function(){
        		$("div#book-img.catalog").children('a').children('img').unwrap();
	        }, 500);
           
        });	
        
        if( $("#formWantList").length > 0 ) {
        	$("#formWantList").prepend('<div id="want-feedback"></div>');
        	$("#wantTD2 .wa_want_buttons td:first").append('<span id="want-feedback-loading"><img src="/images/loading.gif" /></span>');
        }
   }
   
   
    
});
