// Dan Email
function danEmailLink(myEmailSubject) {
	document.write('<a href="mailto:' + 'dan' + '@' + 'danrodney' + '.com?subject=' + myEmailSubject + '">' + 'dan' + '@' + 'danrodney.com' + '</a>')
}

/****************************************************
base64.js
---------
A JavaScript library for base64 encoding and decoding by Danny Goodman (http://www.dannyg.com). Described in "JavaScript and DHTML Cookbook" published by O'Reilly & Associates. Copyright 2003.

[Inspired by many examples in many programming languages, but predominantly by Java routines seen in online course notes by Hamish Taylor at http://www.cee.hw.ac.uk/courses/2nq3/4/
The binary data manipulations were very helpful.]

Two "public" functions accept one string argument (the string to convert) and return a string (the converted output). Because this library is designed only for client-side encoding and decoding (i.e., no encoded data is intended for transmission to a server), the encoding routines here ignore the 76-character line limit for MIME transmission. See details of encoding scheme in RFC2045: http://www.ietf.org/rfc/rfc2045.txt

These routines are being used to encode/decode html element attribute values, which may not contain an equals (=) symbol. Thus, we do not allow padding of uneven block lengths.

To encode a string, invoke: var encodedString = base64Encode("stringToEncode");
To decode a string, invoke: var plainString = base64Decode("encodedString");

Release History
---------------
v.1.00    07Apr2003    First release

****************************************************/
// Global lookup arrays for base64 conversions
var enc64List, dec64List;
// Load the lookup arrays once
function initBase64() {
    enc64List = new Array();
    dec64List = new Array();
    var i;
    for (i = 0; i < 26; i++) {
        enc64List[enc64List.length] = String.fromCharCode(65 + i);
    }
    for (i = 0; i < 26; i++) {
        enc64List[enc64List.length] = String.fromCharCode(97 + i);
    }
    for (i = 0; i < 10; i++) {
        enc64List[enc64List.length] = String.fromCharCode(48 + i);
    }
    enc64List[enc64List.length] = "+";
    enc64List[enc64List.length] = "/";
    for (i = 0; i < 128; i++) {
        dec64List[dec64List.length] = -1;
    }
    for (i = 0; i < 64; i++) {
        dec64List[enc64List[i].charCodeAt(0)] = i;
    }
}

function base64Decode(str) {
    var c=0, d=0, e=0, f=0, i=0, n=0;
    var input = str.split("");
    var output = "";
    var ptr = 0;
    do {
        f = input[ptr++].charCodeAt(0);
        i = dec64List[f];
        if ( f >= 0 && f < 128 && i != -1 ) {
            if ( n % 4 == 0 ) {
                c = i << 2;
            } else if ( n % 4 == 1 ) {
                c = c | ( i >> 4 );
                d = ( i & 0x0000000F ) << 4;
            } else if ( n % 4 == 2 ) {
                d = d | ( i >> 2 );
                e = ( i & 0x00000003 ) << 6;
            } else {
                e = e | i;
            }
            n++;
            if ( n % 4 == 0 ) {
                output += String.fromCharCode(c) + 
                          String.fromCharCode(d) + 
                          String.fromCharCode(e);
            }
        }
    }
    while (typeof input[ptr] != "undefined");
    output += (n % 4 == 3) ? String.fromCharCode(c) + String.fromCharCode(d) : 
              ((n % 4 == 2) ? String.fromCharCode(c) : "");
    return output;
}
/****************************************************/

// For InDesign Script Pages, hide content via CSS style to avoid flash on page load
$("html").addClass("js");

$(document).ready(function(){
	//nav rollovers
	$('#nav li').removeClass('noJS')  //disable the CSS rollovers
	$('#nav li a').wrapInner('<span>')
	$('#nav li a span').css('opacity', 0)  //must hide the rollovers initially
	$("#nav li a").hover(
		function () {
			$(this).children("span").stop().animate({'opacity': '1'}, 225)
		},
		function () {
			$(this).children("span").stop().animate({'opacity': '0'}, 275)
		}
	)
	
	
	// For InDesign Script Pages, toggle the content
	$("a #buyButton").click(function () {
	  $("#orderDetails").slideToggle(750, 'easeOutExpo');
	  $("#downloadDetails").slideUp(750, 'easeOutExpo');
	  $("#upgradeDetails").slideUp(750, 'easeOutExpo');
	});
	
	$("a #downloadFreeButton").click(function () {
	  $("#orderDetails").slideUp(750, 'easeOutExpo');
	  $("#downloadDetails").slideToggle(750, 'easeOutExpo');
	});

	$("a #upgradeButton, .upgradeLink").click(function () {
	  $("#orderDetails").slideUp(750, 'easeOutExpo');
	  $("#upgradeDetails").slideToggle(750, 'easeOutExpo');
	});
	
	
	//MBJ upgrade
	$("#upgradeCodeMBJForm").submit(function () {
		initBase64();
		if( $("#upgradeCode").val() == base64Decode('Z2V0LW1iajQtdXBncmFkZQ==') ){
			
			$(".ajaxLoading").attr("src","/img/ajax-loader.gif")
			
			var MBJajax = $.ajax({
			  url: "/inc/masthead-makebookjacket-up.html"
			})
			
			MBJajax.success(function(data) {
				//alert("It worked!");
				$("#upgradeAddToCart").html(data)  // load empty div with ajax loaded data
				$("#upgradeCodeInput").slideUp(300);		
				$("#upgradeAddToCart").slideToggle(300, 'easeOutExpo');
			});
			
			MBJajax.error(function() {
				alert("Sorry but there was an error: " + MBJajax.status + " " + MBJajax.statusText + "\nPlease try again.")
				$(".ajaxLoading").attr("src","/img/spacer.gif")
			});
		}
		else{
			$("#upgradeCodeInput").effect("shake", { times:3 }, 80, function(){
				$("#upgradeCode").focus();  //performed as a callback so focus works
			});
		}
	});
	
}); // end document.ready
