$(document).ready(function() {
if( ! $.browser.msie){

	//image preload for homepage [preloads rollover and hit images so there is no flicker]
	$.preloadCssImages({statusTextEl: '#textStatus', statusBarEl: '#status'});
	
	if($('#header a.home-link')){
		$('#header a.home-link').click(function(){
			var answer = confirm('Are you sure you want to leave the this sale and go to http://gale.cengage.com?');
			if(answer){ return true; } else { return false; }
		});
	}

	//submit jump menu
	if($('#id')){
		$('#id').change(function(){
			$('#jump').submit();
		});
	}

	//spawn jump menu [not for IE]
	if( ! $.browser.msie){
		if($('#library_type')){
			$('#library_type').change(function(){
				var answer = $('#library_type').val();
				$("#goebook").remove();
				$("#pop p").hide();
				if(answer == 'TIER1'){ $("#jump p").append(" <input id='goebook' type='submit' value='' name='goebook' />"); }
				else{
					$("#goebook").remove();
					if(answer == 'A'){ $("#pop p").show(); $("#pop p select").html("<option value=''>Please select...</option><option value='TIER1'>less than 5,000</option><option value='2_TIER'>5,000 to 14,999</option><option value='3_TIER'>15,000 and over</option>"); }
					else{ $("#pop p").show(); $("#pop p select").html("<option value=''>Please select...</option><option value='TIER1'>less than 80,000</option><option value='2_TIER'>80,000 to 399,000</option><option value='3_TIER'>400,000 and over</option>"); }
				}
			});
			$('#population').change(function(){ $("#goebook").remove(); $("#pop p").append(" <input id='goebook' type='submit' value='' name='goebook' />"); });
		}
	}


	//disable search box if they are not in a specific area [circulating, reference, ebook]
	//if they click on the input search area show popup
	if($('#searcharea')){
		var answer = $('#searcharea').val();
		if( ! answer){
			$('#search').focus(function(){ alert("Please choose Circulating, Print Reference or eBooks and then enter a search term."); });
			$('#go').attr('disabled', 'disabled');
		}
	}

	//delete an item from the cart warning
	$('.remove').click(function(){
		var title = $(this).attr('title');
		var answer = confirm('Are you sure you want to remove:\n'+ title +'?');
		if(!answer){ return false; }
	});
	
	//direct form submission on checkout2.pl page
	if($('#same_shipping')){
		$('#same_shipping').click(function(){
			$("input[name='p']").val('checkout4');
		});
	}
	if($('#add_shipping')){
		$('#add_shipping').click(function(){
			$("input[name='p']").val('checkout3');
		});
	}


	//open any anchor with a rel="" in a new window
	$("a[@rel]").click(function() {
		newWindow = window.open(this, "newWin", "toolbar=no,menubar=no,location=yes,scrollbars=yes,resizable=yes,width=940,height=550")
		newWindow.focus();
		return false; //stop link from working normally
	});

	//load product detial via ajax into the #show div
	if($("#show")){
		var item = $("#show").attr("class");
		var data = $("#show").load("/servlet/ItemDetailServlet", { region: "9", imprint: "860", titleCode: "TP909", type: "3", id: item, banner: "false"}, function(response, textStatus, XML){ if(textStatus == 'error'){ $("#show").html("<strong>There is currently no data for this title.</strong>"); } $("#loader").remove(); } );
	}
	
	if($("#standing")){
		$("#standing.tablesorter").tablesorter({
			sortList: [[1,0]], widgets: ['zebra','addIncart'],
			// pass the headers argument and assing a object 
			headers: { 
				// assign the six column (we start counting zero) 
				5: { 
					// disable it by setting the property sorter to false 
					sorter: false
				}
			}
		});
	}
	
	//show popup dialog above anchors with class of 'partnership'
	imagePreview();

} // end ! $.browser.msie
}); // end $(document).ready


/*
* Image preview script 
* powered by jQuery (http://www.jquery.com)
* written by Alen Grakalic (http://cssglobe.com)
* for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*/
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 150;
		yOffset = 270;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){

		this.t = this.title;
		this.title = "";

		var c = (this.t != "") ? this.t + "<br/>" : "";
		if($.browser.msie) { $("body table tr td select").css("visibility","hidden"); }
		$("body").append("<p id='preview'><span id='top'></span>"+ c +"<span id='bottom'></span></p>");
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
		if($.browser.msie) { $("body table tr td select").css("visibility","visible"); }
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - yOffset) + "px")
			.css("left",(e.pageX - xOffset) + "px");
	});			
};



//Image Rollover for the letter M
if (document.images) {
     button1 = new Image
     button2 = new Image

     button1.src = '/more/images/m_base.gif'
     button2.src = '/more/images/m_over.gif'
 }