jQuery(document).ready( function($) {
// changelog 2009-10-10 added if statement to check focus on radio buttons in function holdbook function
// cookie functions
$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

	// create the suggest box for finding authors or books
	$('#findlist').bind("click",function () {
		$('#findlist').val('');
		});
	$(".suggest").suggest("../wp-content/plugins/booktracker/autocomplete.list.booktracker.php"
	);// end suggest

	$(".publicsuggest").suggest("../wp-content/plugins/booktracker/autocomplete.public.list.booktracker.php"
		);// end suggest



// /cookie functions
  // Reset Font Size
  var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function(){
    $('html').css('font-size', originalFontSize);
  });
  // Increase Font Size
  $(".largestfont").click(function(){
    var currentFontSize = $('html').css('font-size');
	if(currentFontSize=='small')currentFontSize=10;
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    var newFontSize = currentFontSizeNum*1.2;
	var entryFontSize=$('.entry').css('font-size');
    var currentEntryFontSizeNum = parseFloat(entryFontSize, 10);
    var newEntryFontSize = currentEntryFontSizeNum*1.2;
	var newEntryLineHeight=newEntryFontSize+4;
//    $('html').css('font-size', newFontSize);
    $(".entry").css({fontSize:newEntryFontSize +'px',lineHeight: newEntryLineHeight+'px'});

    return false;
  });
  // Decrease Font Size
  $(".normalfont").click(function(){
    var entryFontSize = $('.entry').css('font-size');
    var currentEntryFontSizeNum = parseFloat(entryFontSize, 10);
    var newEntryFontSize = currentEntryFontSizeNum*0.8;
	var newEntryLineHeight=newEntryFontSize+4;
    $(".entry").css({fontSize:newEntryFontSize +'px',lineHeight: newEntryLineHeight+'px'});
    return false;
  });


 $(".styles").mouseover(function() {
   $("#stylehelp").css({display:"block"});
 });

 $(".styles").mouseout(function() {
   $("#stylehelp").css({display:"none"});

 });

	$(".holdbook").click(function(){
		var activity_id=$(this).attr("id");
        $.post("../wp-content/plugins/booktracker/functions.booktracker.php",{
			'f':'callandhold',
			'activity_id' : activity_id},
			function(data){
				$('.worksheet').html(data);// add the data to the div
				$('.worksheet').fadeIn();
				$('html, body').animate({scrollTop:0}, 'fast');
				$('#book_barcode').select().focus();
       			$(".closemakecall").click(function(){
					$('.worksheet').fadeOut();
				});// close the closemakecall function

				$(".validate-field").focus(function(){
					// lock the form, just in case they try to change something
					$('#submit-button').attr('disabled','disabled');
				});

			 	$(".validate-field").blur(function(){
			 		// check for a checked radio button for class form-ready
					var validated=0;
					if($('.form-ready').focus){
						$('#submit-button').attr('disabled',false);
					}
					else if($(this).val()==""){
						alert($("#validation-message").html());
					}
					else{
						$.post('../wp-content/plugins/booktracker/functions.booktracker.php',{
							'f':'validatebarcode',
							'returntype':'print',
							'title':$('#booktitle').val(),
							'barcode':$(this).val()
						},
						function(data){
							if(data=="success"){
								$('#submit-button').attr('disabled',false);
							}
							else{
								if(data=="failure"){
									alert($("#validation-message").html());
								}
								else{// this is the case for an error
									msg=data.split(":");
									alert('The book you are working on is ' + $('#booktitle').val() + '.  ' + msg[1]);
								}
							}
						}
						);// end post


					}
				});// end validate-button

				// if a radio button is checked, enable the form button
				$(".form-ready").click(function(){
					$('#submit-button').attr('disabled',false);
					$('#book_barcode').val('');
				}); // end form ready




			});// close the function
	});// end of holdbook class function

	$(".checkout").click(function(){
		var activity_id=$(this).attr("id");
        $.post("../wp-content/plugins/booktracker/functions.booktracker.php",{
			'f':'checkout',
			'activity_id' : activity_id},
			function(data){
				$('.worksheet').html(data);// add the data to the div
				$('.worksheet').fadeIn();
                $('html, body').animate({scrollTop:0}, 'fast');
				$('.closemakecall').select().focus();
       			$(".closemakecall").click(function(){
					$('.worksheet').fadeOut();
				});// close the closemakecall function
			});// close the function
	});// end of holdbook class function


});// end main jquery call
