// cached bwcomplete-1.0.2.js
/************************** VARIABLE DECLARATIONS ************************/
	var cartDisplayDescrip={'buyBook' : 'Books',	'buyMusic' : 'Music',	'buyGame' : 'Games', 'buyDVD' : 'DVDs',
													'buybackBook' : 'Books',	'buybackMusic' : 'Music',	'buybackGame' : 'Games', 'buybackDVD' : 'DVDs'};
	this.window.name = 'BWMain';
	var mouseX,mouseY;
/*************************** Event Modifications *************************/
Event.observe(window,"load",function(){Lightbox.init();});
Event.observe(window,"load",setupBookbag);
Event.observe(document, 'mousemove', function(event){mouseX=Event.pointerX(event); mouseY=Event.pointerY(event);});
/************************** Functions **********************************/


function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

function onLoadAppend(func){
	Event.observe(window,"load",func);
}

var collabJSLoaded=false;
function collabLoad(t,v){
	loadCollaboratorJS();
	if(t) t=t.toLowerCase();
	if(t=='msgid'){
		collabLaunchURL('/intereactor/?z=ajax_home&ID='+v);
	} else if(t=='book'){
		collabLaunchURL('/intereactor/?z=ajax_home&ISBN='+v+'&productType='+t);
	} else if(t=='dvd' || t=='music' || t=='game'){
		collabLaunchURL('/intereactor/?z=ajax_home&UPC='+v+'&productType='+t);
	} else {
		collabLaunchURL('/intereactor/?z=ajax_home');
	}
}

function loadCollaboratorJS(){
	if(collabJSLoaded) return;
	var headtag=document.getElementsByTagName("head")[0];
	var collabScript = document.createElement('script');
	collabScript.type='text/javascript';
	collabScript.onload=collaboratorJSLoaded;
	collabScript.src='/global/javascript/collaborator.js?v2';
	var recommendScript = document.createElement('script');
	recommendScript.type='text/javascript';
	recommendScript.src='/intereactor/ajax_recommend.php';
	headtag.appendChild(recommendScript);
	headtag.appendChild(collabScript);
}
function collaboratorJSLoaded(){
	collabJSLoaded=true;
}

function collabLaunchURL(URL){
	var pd=Lightbox.getPageDimensions();
	Lightbox.setBackground('#FFB030');
	Lightbox.magnetize();
	Lightbox.showBoxString('<br><br><br><br><br><br><center><strong>Please wait...</center></strong>',pd[0]-50,500);
	collabLoadURL(URL);
}


function collabLoadURL(URL){
	new Ajax.Request(URL,
  {
    method:'get',
    onlyLatestOfClass:'collab',
    onSuccess: function(transport){
      var response = transport.responseText || "";
      updateCollab(response);
    },
    onFailure: function(){ alert('error!'); }
  });
}

function updateCollab(collabCode){
	if(!$('collaborator')){
		$('boxContents').innerHTML=collabCode;
	} else {
		$('collaborator').innerHTML=collabCode;
	}
	collabCode.extractScripts().map(function(script) { if(script.length>1)return eval(script) });
}

function setupBookbag(){
    // this will be used to create the dropdown bookbag (Set in footer)
	if(bigCookie) var cart=bigCookie;
	if(!cart||cart==null) return;
	var cartItems=cart.split("|");
	var displayCart={};
	var cartContents='<table border=0 align=center cellpadding=10><tr><td>';
	for(var i=0;i<cartItems.length;i++){
		if(cartItems[i]!=""){
			var thisItem=cartItems[i].split("+");
			if(displayCart[thisItem[1]]==null)
				displayCart[thisItem[1]]=new Array();
			displayCart[thisItem[1]][displayCart[thisItem[1]].length]=thisItem[2];
		}
	}
	for (var i in displayCart){
		if(displayCart[i].length>0&&cartDisplayDescrip[i]!=null){
			cartContents+="<p><strong>"+cartDisplayDescrip[i]+"</strong><BR>\n";
			for(var j=0;j<displayCart[i].length;j++){
				cartContents+=displayCart[i][j]+"<BR>\n";
			}
			cartContents+='</p>';
		}
	}
	cartContents+='</td><td align=right valign=bottom>';
	cartContents+='<P>&nbsp;</P><p><a href="/search/?z=start_price_comparison" class="nohover" title="start textbook price comparison" alt="start textbook price comparison"><img src="/images/global/40/round-butt-startcomparison.gif" width=230 height=39 border=0  ALT="Begin Textbook Price Comparison to find the Lowest Prices on College Texbooks and other stuff." TITLE="College Textbook Price Comparison"></a><BR>';
	cartContents+='<a href="/search/?z=viewbag">or review bookbag details</a></P>';
	cartContents+='</td></tr></table>';
	$('cartContents').innerHTML=cartContents;
	$('cartLink').setStyle({display:'inline'});//$('cartLink').show();
}

/// this group of code here makes it pop out and back in! ///
var allowedCS=true; // is it allowed (cart slide)
var cs=false; // is it out (the cart, silly)
var delayHideDropDown=null;
function slideCartDown(){	if(!allowedCS) return; allowedCS=false; Effect.SlideDown('cartDropdown', { queue: 'end',duration:.75,afterFinish:allowCS}); cs=true; }
function attemptHideDropDown(e){ if(delayHideDropDown==null){ delayHideDropDown=setTimeout('hideDropDown();',200); } }
function hideDropDown(){ 	clearTimeout(delayHideDropDown); delayHideDropDown=null; var cartHeight=$('cartDropdown').getHeight(); if(mouseY>cartHeight) slideCartUp(); }
function slideCartUp(){ 	if(!allowedCS) return; allowedCS=false;	Effect.SlideUp('cartDropdown', { queue: 'end',duration:.25,afterFinish:allowCS});	cs=false; }
function allowCS(){				allowedCS=true; }
/// end ridiculous amount of code to do something so simple ///
///////////// flying logo /////////////////////////
var flyingLogoMoving=false;
function checkFlyingLogoPosition(){ if(flyingLogoMoving||flDragging){ return; } try{var flyinglogo = $('flyinglogo');var lightboxpos = $('box');}catch(e){return;} var aflp=Position.cumulativeOffset(flyinglogo); if(lightboxpos.visible()){ var lbp=new Array(parseInt(lightboxpos.style.left)+5,parseInt(lightboxpos.style.top)+5);} else {var lbp=new Array(54,5);}	var adjust = new Array(lbp[0]-aflp[0],lbp[1]-aflp[1]);	if(adjust[0]==0 && adjust[1]==0){ return; }	flyingLogoMoving=true;	return new Effect.Move(flyinglogo,{x:adjust[0],y:adjust[1],mode:'relative',duration:1,afterFinish:function(){flyingLogoMoving=false;}});}
/////////// flying logo animation for intereactor end ////

function checkKey(e){
	if(window.event){	 // IE
		return e.keyCode;
	} else if(e.which){	 // Netscape/Firefox/Opera
		return e.which;
	}
}

var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    }
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire +"; domain=.bigwords.com; path=/");
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    }
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') === '1');
  }
};

Ajax.currentRequests = {};
Ajax.Responders.register({
	onCreate: function(request) {
		if (request.options.onlyLatestOfClass && Ajax.currentRequests[request.options.onlyLatestOfClass]) {
			// if a request of this class is already in progress, attempt to abort it before launching this new request
			try { Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}
		}
		// keep note of this request object so we can cancel it if superceded
		Ajax.currentRequests[request.options.onlyLatestOfClass] = request;
	},
	onComplete: function(request) {
		if (request.options.onlyLatestOfClass) {
			// remove the request from our cache once completed so it can be garbage collected
			if(Ajax.currentRequests.length>=request.options.onlyLatestOfClass)
				if(Ajax.currentRequests[request.options.onlyLatestOfClass]!=null)
					Ajax.currentRequests[request.options.onlyLatestOfClass] = null;
		}
	}
});
//EOF-bigwords.js
var helperCount=0;
var hb;
var hbs;
var disp;

function createBigHelper(owner,displayText,tipText,linkURL){
  var myHelper=createHelper(owner,displayText,tipText,linkURL);
  if(!myHelper) return;
  myHelper.setAttribute("big","true");
  myHelper.big=true;
}
function createHelper(owner,displayText,tipText,linkURL){
	if(!document.getElementById || !document.getElementsByTagName) return;
	if(helperCount==0){ Event.observe(window,"load",createHelperBubble); }
	var o=document.getElementById(owner);
	if(!o) return;

	o.id="h"+helperCount;
	if(tipText){ o.tip=tipText; o.setAttribute("tip",tipText); }
	if(linkURL) o.link=linkURL;
	o.setAttribute("id","h"+helperCount);

	if(linkURL || displayText){
		h=document.createElement("span");
		if(linkURL) h.setAttribute("link",linkURL);
		h.appendChild(document.createTextNode(displayText));
		h.className='helperText';
		o.appendChild(h);
	}

	o.onmouseover=showHelperBubble;
	o.onmouseout=hideHelperBubble;
	o.onmousemove=moveHelperBubble;
	if(linkURL) o.onclick=execHelperLink;

	helperCount++;
	return o;
}

function showHelperBubble(e){
	if(this.big){
		hb.className='helperBubble bigBubble';
		hbs.className='helperBubbleShadow bigBubbleShadow';
	} else {
		hb.className='helperBubble';
		hbs.className='helperBubbleShadow';
	}
	disp.innerHTML=this.tip;
		var bubble=document.getElementById("t");
		var bubbleHeight;
	if(bubble.offsetHeight){
    		bubbleHeight=bubble.offsetHeight;
    	} else if(bubble.style.pixelHeight) {
			bubbleHeight=bubble.style.pixelHeight;
	}

	bubbleHeight-=25;
	document.getElementById("ts").style.height=bubbleHeight+'px';

	hb.style.visibility='visible';
	hbs.style.visibility='visible';
}
function hideHelperBubble(e){
	hb.style.visibility='hidden';
	hbs.style.visibility='hidden';
}
function execHelperLink(e){
	location.href=this.link;
}
function moveHelperBubble(e){
	var posx=0,posy=0;
	if(e==null) e=window.event;
	if(e.pageX || e.pageY){
	    posx=e.pageX; posy=e.pageY;
	    }
	else if(e.clientX || e.clientY){
	    if(document.documentElement.scrollTop){
	        posx=e.clientX+document.documentElement.scrollLeft;
	        posy=e.clientY+document.documentElement.scrollTop;
	        }
	    else{
	        posx=e.clientX+document.body.scrollLeft;
	        posy=e.clientY+document.body.scrollTop;
	        }
	    }
	hb.style.top=(posy+15)+"px";
	hb.style.left=(posx-20)+"px";
	hbs.style.top=(posy+22)+"px";
	hbs.style.left=(posx-30)+"px";
}
function createHelperBubble(){


	////// CREATE BUBBLE
	var p=document.createElement("div");
	p.id="hb";
	p.setAttribute("id","hb");
	p.style.position="absolute";
	p.className='helperBubble';
	p.style.visibility="hidden";

	var t=document.createElement("div");
	t.className='t';
	t.id='t';
	t.setAttribute("id","t");

	var d=document.createElement("div");
	d.id="disp";
	d.className='disp';
	d.setAttribute("id","disp");
	t.appendChild(d);
	p.appendChild(t);

	var b=document.createElement("div");
	b.className='b';
	p.appendChild(b);



	////// CREATE SHADOW
	var ps=document.createElement("div");
	ps.id="hbs";
	ps.setAttribute("id","hbs");
	ps.style.position="absolute";
	ps.className='helperBubbleShadow';
	ps.style.visibility="hidden";

	var ts=document.createElement("div");
	ts.className='ts';
	ts.id='ts';
	ts.setAttribute("id","ts");
	ps.appendChild(ts);


	var bs=document.createElement("div");
	bs.className='bs';
	bs.id='bs';
	bs.setAttribute("id","bs");
	ps.appendChild(bs);

	// Append shadow
	document.getElementById("bubbleholder").appendChild(ps);
	hbs=document.getElementById("hbs");
	setOpacity(hbs,'50');
	// Append bubble
	document.getElementById("bubbleholder").appendChild(p);
	hb=document.getElementById("hb");
	disp=document.getElementById("disp");
}
function setOpacity(el,pct){
	el.style.filter="alpha(opacity:"+pct+")";
	el.style.KHTMLOpacity="0."+pct;
	el.style.MozOpacity="0."+pct;
	el.style.opacity="0."+pct;
}
//EOF-helperbubble.js
/*
	Multifaceted Lightbox by Greg Neustaetter - http://www.gregphoto.net
	The Lightbox Effect without Lightbox PJ Hyett http://pjhyett.com/articles/2006/02/09/the-lightbox-effect-without-lightbox
	Lightbox JS: Fullsize Image Overlays  by Lokesh Dhakar - http://www.huddletogether.com
	Licensed under:	Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
*/
var checkFlyingLogo;
var Lightbox = {
	lightboxType : null,
	lightboxCurrentContentID : null,
	magnetized : false,

	magnetize : function(bg){
		checkFlyingLogo=setInterval("checkFlyingLogoPosition()",1000);
		$('flyinglogo').style.zIndex=9999;
		this.magnetized=true;
	},

	setBackground : function(bg){
		$('box').setStyle({backgroundColor:bg});
	},

	showBoxString : function(content, boxWidth, boxHeight){
		this.setLightboxDimensions(boxWidth, boxHeight);
		this.lightboxType = 'string';
		var contents = $('boxContents');
		contents.innerHTML = content;
		this.showBox();
		return false;
	},


	showBoxImage : function(href) {
		this.lightboxType = 'image';
		var contents = $('boxContents');
		var objImage = document.createElement("img");
		objImage.setAttribute('id','lightboxImage');
		contents.appendChild(objImage);
		imgPreload = new Image();
		imgPreload.onload=function(){
			objImage.src = href;
			Lightbox.showBox();
		}
		imgPreload.src = href;
		return false;
	},

	showBoxByID : function(id, boxWidth, boxHeight) {
		this.lightboxType = 'id';
		this.lightboxCurrentContentID = id;
		this.setLightboxDimensions(boxWidth, boxHeight);
		var element = $(id);
		var contents = $('boxContents');
		contents.appendChild(element);
		Element.show(id);
		this.showBox();
		return false;
	},

	showBoxByAJAX : function(href, boxWidth, boxHeight) {
		this.lightboxType = 'ajax';
		this.setLightboxDimensions(boxWidth, boxHeight);
		var contents = $('boxContents');
		var myAjax = new Ajax.Updater(contents, href, {method: 'get'});
		this.showBox();
		return false;
	},

	setLightboxDimensions : function(width, height) {
		var windowSize = this.getPageDimensions();
		if(width) {
			if(width < windowSize[0]) {
				$('box').style.width = width + 'px';
			} else {
				$('box').style.width = (windowSize[0] - 50) + 'px';
			}
		}
		if(height) {
			if(height < windowSize[1]) {
				$('box').style.height = height + 'px';
			} else {
				$('box').style.height = (windowSize[1] - 50) + 'px';
			}
		}
	},


	showBox : function() {
		this.blackOut();
		this.center('box');
		return false;
	},


	hideBox : function(){
		var contents = $('boxContents');
		if(this.lightboxType == 'id') {
			var body = document.getElementsByTagName("body").item(0);
			Element.hide(this.lightboxCurrentContentID);
			body.appendChild($(this.lightboxCurrentContentID));
		}
		contents.innerHTML = '';
		$('box').style.width = null;
		$('box').style.height = null;
		Element.hide('box');
		this.unBlackOut();
		if(this.magnetized){
			$('flyinglogo').style.zIndex=0;
			clearInterval(checkFlyingLogo);
			checkFlyingLogo=setTimeout("checkFlyingLogoPosition()",1100);
			this.magnetized=false;
		}
		return false;
	},

	// taken from lightbox js, modified argument return order
	getPageDimensions : function(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}

		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(windowWidth,windowHeight,pageWidth,pageHeight)
		return arrayPageSize;
	},

	blackOut : function(){
		var windowSize = this.getPageDimensions();
		$('overlay').style.height = windowSize[3] + 'px';
		Element.show('overlay');
	},

	unBlackOut : function(){
		Element.hide('overlay');
	},

	center : function(element){
		try{
			element = document.getElementById(element);
		}catch(e){
			return;
		}
		var windowSize = this.getPageDimensions();
		var window_width  = windowSize[0];
		var window_height = windowSize[1];

		element.style.position = 'absolute';
		element.style.zIndex   = 99;

		var scrollY = 0;

		if ( document.documentElement && document.documentElement.scrollTop ){
			scrollY = document.documentElement.scrollTop;
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop;
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset;
		}else if ( window.scrollY ){
			scrollY = window.scrollY;
		}

		var elementDimensions = Element.getDimensions(element);
		var setX = ( window_width  - elementDimensions.width  ) / 2;
		var setY = ( window_height - elementDimensions.height ) / 2 + scrollY;

		setX = ( setX < 0 ) ? 0 : setX;
		setY = ( setY < 0 ) ? 0 : setY;

		element.style.left = setX + "px";
		element.style.top  = setY + "px";
		Element.show(element);
	},

	init : function() {
		var lightboxtext = '<div id="overlay" style="display:none"></div>';
		lightboxtext += '<div id="box" style="display:none">';
		//lightboxtext += '<img id="close" src="/images/icons/close.gif" onClick="Lightbox.hideBox()" alt="Close" title="Close this window" />';
		lightboxtext += '<div id="boxContents"></div>';
		lightboxtext += '</div>';
		var body = document.getElementsByTagName("body").item(0);
		new Insertion.Bottom(body, lightboxtext);
	}
}
//EOF-lightbox.js

///add2bag stuff
function add2bag(nonjsurl){
	var newURL="/search/?z=add_to_bag_ajax"+nonjsurl.substring(nonjsurl.indexOf("&"));
	Lightbox.setBackground('#FFFFFF');
	Lightbox.showBoxString('<img src="/images/icons/loading.gif"> Please wait while we add this item to your bag...<br><br clear="all"><center><small>If this is taking a <i>really</i> long time, click <a href="/search/?z=viewbag">here</a> to reset it.</small></center>', 200, 125);
	new Ajax.Request(newURL,
	  {
	    method:'get',
	    onSuccess: function(transport){
	      var response = transport.responseText || "";
	      added2bag(response);
	    },
	    onFailure: function(){ alert('error!'); } // failover to no js
  });
  return false;
}

function added2bag(results){
	Lightbox.hideBox();
	Lightbox.setBackground('#FF9900');
	Lightbox.magnetize();
	$('boxContents').setStyle({'overflow':'hidden','overflowX':'hidden','overflowY':'hidden'});
	$('box').setStyle({'overflow':'hidden','overflowX':'hidden','overflowY':'hidden'});
	Lightbox.showBoxString(results, 800, 700);
	results.evalScripts();
    setupBookbag();
	//
}
//end add2bag