function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
$(document).ready(function(){
    $("#messageMid").empty();
    $("body").prepend("<div id='blueChairButtonAndText'><a href='/index.html'><img src='/graphics/bluechairbuttonandtext.gif' alt='Blue Chair Childrens Books' border='0' /></a></div>")
    .prepend("<div id='friendsBoxTop'><img src='/graphics/2/friendstitle.gif' border='0' alt='Friends' /></div>")
    .prepend("<div id='authorVisits'>\n"+
				"\t<div id='authorVisitsBot'><img src='/graphics/2/authorVisitsBot.gif' alt='' /></div>\n"+
	      "</div>");
    // Fix the PNG transparency for IE < 7
    //$('#holidayCatalog img').ifixpng('/graphics/pixel.gif');
    $('img[@src$=.png]').ifixpng('/graphics/pixel.gif'); 
    // load the author visits info from the authors.html file
    $.get('/authors.html',function(loadedHtml) {
	    // isolate the loaded data in the #authorVisitsDiv div
	    var $authorVisitsContent = $("#authorVisitsDiv", loadedHtml);
	    //alert("loaded = "+$authorVisitsContent+", xml="+$authorVisitsContent.attr("id"));
	    $("#authorVisits").prepend($authorVisitsContent);
    });
    //.prepend("<img id='underWhyBlueChair' src='graphics/underwhybluechair.gif' border='0' alt='' />");
    $("a[id^='menu-']").each(function(i) {
      if (window.pageName && $(this).attr("href")==pageName) {
	  $(this).addClass($(this).attr("id")+"-classHover");
	  $(this).removeAttr("href");
      } else {
	$(this).addClass($(this).attr("id")+"-class");
      }
      if ($(this).attr("id")!='menu-contact')
         $(this).after("<div class='divider'><img src='/graphics/divider.gif' alt='|' border='0' /></div>");
    })
    .filter("a[href]")
    .hover(
	 function () {
		$(this).addClass($(this).attr("id")+"-classHover");
		$(this).removeClass($(this).attr("id")+"-class");
	 }, 
	 function () {
		$(this).addClass($(this).attr("id")+"-class");
		$(this).removeClass($(this).attr("id")+"-classHover");
	 }
       );
    MM_preloadImages('/graphics/menu-home_f2.gif','/graphics/menu-events_f2.gif','/graphics/menu-picks_f2.gif','/graphics/menu-blog_f2.gif','/graphics/menu-store_f2.gif','/graphics/menu-contact_f2.gif');
    $("#friendsBox").append("<img id='friendsBoxBot' src='/graphics/2/friendsbot.gif' border='0' alt='' />");
    $("#friendsBox div a").each(function(i) {
	$(this).click(function(event){
	    var data = $(this).attr("data").replace(/\[/g,"<").replace(/\]/g,">");
	    var urlMatch = data.match(/ href=\'([^\']*)\'/i);
	    if (urlMatch[1].indexOf('mailto:') == -1) urlMatch[1] = 'http://'+urlMatch[1];
	    data = data.replace(/( href=\')[^\']*\'/i,"$1"+urlMatch[1]+"\'");
	    $(this).attr("data",data);
	    $(this).parent().append("<div class='friendsPopup' id='friendsPopup-"+i+"'><a href='javascript:closeBox(\"friendsPopup-"+i+"\");' class='closeBoxLink'>[hide]</a><div class='friendsPopupTitle'>"+$(this).html()+"</div><div class='friendsPopupMain'>"+$(this).attr("data")+"</div></div>");
	    event.preventDefault();
	    $(".friendsPopup").hide("fast");
	    $("#friendsPopup-"+i).show("fast");
	});
    });
    $("#newsletters").prepend("<div id='newslettersTop'><img src='/graphics/2/newsletterstop.gif' border='0' alt='Newsletters' /></div>");
    $("#messageMid").append("<img id='mainPhotos' src='/graphics/2/mainphotos.gif' border='0' alt='' />");
    $("body").prepend("<div id='cartTitle'><img src='/graphics/2/carttitle.gif' border='0' alt='Shopping Cart' /></div>")
	.prepend("<div id='whyBlueChair'><img src='/graphics/2/whybluechair.gif' border='0' alt='Why Blue Chair' /></div>")
        .append("<img id='bottomBar' src='/graphics/2/bottombar.gif' border='0' alt='' />");
    $("#cartBox").append("<img id='cartBot' src='/graphics/2/cartbot.gif' border='0' alt='' />");
    $("label").append(":");
    });

function closeBox(objID) {
    $("#"+objID).hide("fast");
}

/*
 * jQuery ifixpng plugin
 * renamed from pngfix to ifixpng due to naming conflict 
 * with another plugin
 * Version 1.7  (18/09/2007)
 * @requires jQuery v1.1.3 or above
 *
 * Examples at: http://jquery.khurshid.com
 * Copyright (c) 2007 Kush M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
 
 /**
  *
  * @example
  *
  * optional if location of pixel.gif if different to default which is images/pixel.gif
  * $.ifixpng('media/pixel.gif');
  *
  * $('img[@src$=.png], #panel').ifixpng();
  *
  * @apply hack to all png images and #panel which icluded png img in its css
  *
  * @name ifixpng
  * @type jQuery
  * @cat Plugins/Image
  * @return jQuery
  * @author jQuery Community
  */
 
(function($) {
	
	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || '/graphics/pixel.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent),
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=crop,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var base = $('base').attr('href'); // need to use this in case you are using rewriting urls
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
					// use source tag value if set 
					var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src');
					// apply filter
					$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
					  .attr({src:$.ifixpng.getPixel()})
					  .positionFix();
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .positionFix();
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[@src$=.png]').iunfixpng();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').iunfixpng();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name iunfixpng
	 */
	 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);
