/*Unframe*/
if (top.location.hostname != 'www.josephakins.com') top.location.replace('http://www.josephakins.com/');


/*Define Variables*/
var initPopup = false;

var addthis_config = {
    data_track_clickback: true,
    ui_cobrand: "<b>JosephAkins.com</b>&nbsp;",
    ui_header_color: "#222222",
    ui_header_background: "#AF9347",
    ui_email_note : "I thought you might enjoy solo piano artist and composer Joseph Akins' website. You can join Joseph's mailing list and get free music."
}

var addthis_exclude = "print";

var menuwidth = '166px';
var menubgcolor = '#03031F';
var disappeardelay = 125;
var hidemenu_onclick = "yes";

var ie4 = document.all;
var ns6 = document.getElementById && !document.all;

var navTab00 = new Array();
navTab00[0] = '<a href="a_piano_christmas.htm" title="Get A Piano Christmas on CD and MP3">A Piano Christmas<img src="akins/_legend_new.gif" border="0" width="41" height="14" /></a>';
navTab00[1] = '<a href="spirit_touch.htm" title="Get Spirit Touch on CD, MP3 and Sheet Music">Spirit Touch</a>';
navTab00[2] = '<a href="masterpeace.htm" title="Get Masterpeace on CD, MP3 and Sheet Music">Masterpeace</a>';
navTab00[3] = '<a href="other_recordings.htm" title="Shop for Joseph\'s other recordings">Other Recordings</a>';
navTab00[4] = '<a href="sheet_music.htm" title="Get the new Songbook with music from Spirit Touch and Masterpeace">Songbook<img src="akins/_legend_new.gif" border="0" width="41" height="14" /></a>';

var navTab01 = new Array();
navTab01[0] = '<a href="bio.htm" title="Bio">Bio</a>';
navTab01[1] = '<a href="extended_bio.htm" title="Extended Bio">Extended Bio</a>';
navTab01[2] = '<a href="#Presskit" title="Download Digital Presskit" onclick="showPopupInpage(\'popup/presskit.htm\', \'400\', \'120\'); return false">Presskit</a>';
navTab01[3] = '<a href="booking.htm" title="Booking">Booking</a>';
navTab01[4] = '<a href="licensing.htm" title="Music Licensing">Licensing</a>';
navTab01[5] = '<a href="#Contact" title="Contact Joseph" onclick="showPopup(\'popupContact\', \'30\'); return false">Contact Joseph</a>';

if (ie4 || ns6) document.write('<div id="menu" style="visibility: hidden; width: ' + menuwidth + '; background-color: '+ menubgcolor + '" onmouseover="clearhidemenu()" onmouseout="dynamichide(event)"></div>');


/*Mouseover Images*/;
var aID = new Array("_navbar_shop", "_navbar_sheet_music", "_navbar_concerts", "_navbar_videos", "_navbar_bio", "_navbar_subscribe");

function initMouseoverImages() {
    for (var i = 0; i < aID.length; i++) {
        var sID = aID[i];

        initImage(sID);

        initMouseOver(sID);
    }
}

function initImage(A) {
    window[A + "0"] = new Image();
    window[A + "0"].src = "akins/sp2-2.gif";

    window[A + "1"] = new Image();
    window[A + "1"].src = "akins/!" + A.substr(1) + ".png";
}

function initMouseOver(A) {
    document.getElementById(A).onmouseout = function() {
        if (document.getElementById(A).className != 'noHover') {
            document.getElementById(A).src = window[A + "0"].src
        }
    }

    document.getElementById(A).onmouseover = function() {
        if (document.getElementById(A).className != 'noHover') {
            document.getElementById(A).src = window[A + "1"].src
        }
    }
}


/*Initialize Crossfader*/
function initCrossfader() {
    var cf = new Crossfader(new Array('cf1', 'cf2', 'cf3', 'cf4', 'cf5', 'cf6', 'cf7', 'cf8'), 3500, 3000);
//    var cf = new Crossfader(new Array('cf0', 'cf1', 'cf2', 'cf3', 'cf4', 'cf5', 'cf6', 'cf7'), 3500, 5000);
}

function initCrossfaderCD(A) {
    var cf = new Crossfader(new Array(A), 1250, 1250);
}

/*Popups*/
function showOverlay() {
        document.getElementById('bg_overlay').style.visibility = 'visible';
}

function hideOverlay() {
        document.getElementById('bg_overlay').style.visibility = 'hidden';
}

function showOverlay2() {
        document.getElementById('bg_overlay2').style.visibility = 'visible';
}

function hideOverlay2() {
        document.getElementById('bg_overlay2').style.visibility = 'hidden';
}

function showBuyNowPopup00() {
    hideBuyNowPopup()

    if (initPopup) {
        document.getElementById('popupBuyNow00').style.visibility = 'visible';    
    }
}

function showBuyNowPopup01() {
    hideBuyNowPopup()

    if (initPopup) {
        document.getElementById('popupBuyNow01').style.visibility = 'visible';    
    }
}

function hideBuyNowPopup() {
    document.getElementById('popupBuyNow00').style.visibility = 'hidden';    
    document.getElementById('popupBuyNow01').style.visibility = 'hidden';    
}


function showCD(A) {
    if (initPopup) {
        hideBuyNowPopup();
        showOverlay();
        initCrossfaderCD(A);
    }
}

function hideCD(A) {
    document.getElementById(A).style.visibility = 'hidden';
    hideOverlay();
}


function showPopup(ID, Top) {
    hideBuyNowPopup();
    showOverlay();

//    if (Top) document.getElementById(ID).style.top = Top + 'px';
    document.getElementById(ID).style.visibility = 'visible';    
}

function hidePopup(ID) {
    document.getElementById(ID).style.visibility = 'hidden';    

    hideOverlay();
}

function showPopupInpage(URL, H, Top) {
    hideBuyNowPopup();

    document.getElementById('popupInpage').style.height = H + 'px';
//    document.getElementById('popupInpage').style.top = Top + 'px';

//    document.getElementById('popupInpage').src = URL;
    window.frames["popupInpageFrame"].location.replace(URL);

    showOverlay();
    document.getElementById('popupInpage').style.visibility = 'visible';
}

function hidePopupInpage(A) {
    hideOverlay();
    document.getElementById('popupInpage').style.visibility = 'hidden';
}

function initPopupTimer() {
    setTimeout("initPopup = true", 750);
    setTimeout("clearMouseoverMask()", 1000);
}

function clearMouseoverMask() {
    document.getElementById('mouseoverMask').style.left = '-200px';
}

function init() {
    initMouseoverImages();

    initCrossfader();

    initPopupTimer();

    if (window.location.search == '?Contact') {
        showPopup('popupContact', '400');
    }
    else if (window.location.search == '?Subscribe') {
        showPopupInpage('popup/subscribe.htm', '496', '120');
    }
    else if (window.location.search == '?Videos') {
        showPopup('popupVideos');
    }
}

window.onload = init;


/*JPlayer setup*/
$(document).ready(function(){

	var Playlist = function(instance, playlist, options) {
		var self = this;

		this.instance = instance; // String: To associate specific HTML with this playlist
		this.playlist = playlist; // Array of Objects: The playlist
		this.options = options; // Object: The jPlayer constructor options for this playlist

		this.current = 0;

		this.cssId = {
			jPlayer: "jquery_jplayer_",
			interface: "jp_interface_",
			playlist: "jp_playlist_"
		};
		this.cssSelector = {};

		$.each(this.cssId, function(entity, id) {
			self.cssSelector[entity] = "#" + id + self.instance;
		});

		if(!this.options.cssSelectorAncestor) {
			this.options.cssSelectorAncestor = this.cssSelector.interface;
		}

		$(this.cssSelector.jPlayer).jPlayer(this.options);

		$(this.cssSelector.interface + " .jp-previous").click(function() {
			self.playlistPrev();
			$(this).blur();
			return false;
		});

		$(this.cssSelector.interface + " .jp-next").click(function() {
			self.playlistNext();
			$(this).blur();
			return false;
		});
	};

	Playlist.prototype = {
		displayPlaylist: function() {
			var self = this;
			$(this.cssSelector.playlist + " ul").empty();
			for (i=0; i < this.playlist.length; i++) {
				var listItem = "<div id='" + this.cssId.playlist + this.instance + "_item_" + i + "' class=playlistent>" + this.playlist[i].name +"</div>";

				// Associate playlist items with their media
				$(this.cssSelector.playlist + " ul").append(listItem);
				$(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() {
					var index = $(this).data("index");
					if(self.current !== index) {
						self.playlistChange(index);
					} else {
						$(self.cssSelector.jPlayer).jPlayer("play");
					}
					$(this).blur();
					return false;
				});

			}
		},
		playlistInit: function(autoplay) {
			if(autoplay) {
				this.playlistChange(this.current);
			} else {
				this.playlistConfig(this.current);
			}
		},
		playlistConfig: function(index) {
			$(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current");
			$(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current");
			this.current = index;
			$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
		},
		playlistChange: function(index) {
			this.playlistConfig(index);
			$(this.cssSelector.jPlayer).jPlayer("play");
		},
		playlistNext: function() {
			var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
			this.playlistChange(index);
		},
		playlistPrev: function() {
			var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
			this.playlistChange(index);
		}
	};

//<img class=z2 src=buy_now.png width=16 height=13>
	var audioPlaylist = new Playlist("2", [
		{
			name:"&ldquo;Spirit Touch&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/Spirit Touch.mp3"
		},
		{
			name:"&ldquo;We Three Kings&rdquo; from <i>A Piano Christmas</i><span onmouseover='showBuyNowPopup00()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/apianochristmas/We%20Three%20Kings.mp3"
		},
		{
			name:"&ldquo;The Butterfly Ride&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/The Butterfly Ride.mp3"
		},
		{
			name:"&ldquo;O Little Town of Bethlehem&rdquo; from <i>A Piano Christmas</i><span onmouseover='showBuyNowPopup00()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/apianochristmas/O%20Little%20Town%20of%20Bethlehem.mp3"
		},
		{
			name:"&ldquo;Feeling Joy&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/Feeling Joy.mp3"
		},
		{
			name:"&ldquo;O Come Emmanuel&rdquo; from <i>A Piano Christmas</i><span onmouseover='showBuyNowPopup00()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/apianochristmas/O%20Come%20O%20Come%20Emmanuel.mp3"
		},
		{
			name:"&ldquo;Night Shadows&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/Night Shadows.mp3"
		},
		{
			name:"&ldquo;Silent Night&rdquo; from <i>A Piano Christmas</i><span onmouseover='showBuyNowPopup00()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/apianochristmas/Silent%20Night.mp3"
		},
		{
			name:"&ldquo;Dance for my Ancestors&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/Dance of My Ancestors.mp3"
		},
		{
			name:"&ldquo;The Christmas Song&rdquo; from <i>A Piano Christmas</i><span onmouseover='showBuyNowPopup00()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/apianochristmas/The%20Christmas%20Song.mp3"
		},
		{
			name:"&ldquo;Tennessee Waltz&rdquo; from <i>Spirit Touch</i><span onmouseover='showBuyNowPopup01()'><img class='buyNow' src='skin/sp2-2.gif' width='17' height='19'></span>",
			mp3:"mp3/spirittouch/Tennessee Waltz.mp3"
		}

	], {
		ready: function() {
			audioPlaylist.displayPlaylist();
//			audioPlaylist.playlistInit(true); // Parameter is a boolean for autoplay.
			audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
		},
		ended: function() {
			audioPlaylist.playlistNext();
		},
		play: function() {
			$(this).jPlayer("pauseOthers");
		},
		swfPath: "js",
		supplied: "mp3"
	});

});


/*Dropdown Menus*/
function getposOffset(what, offsettype) {
    var totaloffset = (offsettype == "left")? what.offsetLeft : what.offsetTop;
    var parentEl = what.offsetParent;
    while (parentEl != null) {
        totaloffset = (offsettype == "left")? totaloffset + parentEl.offsetLeft : totaloffset + parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth) {
    if (ie4 || ns6) dropmenuobj.style.left = dropmenuobj.style.top = "-500px"

    if (menuwidth != "") {
        dropmenuobj.widthobj = dropmenuobj.style
        dropmenuobj.widthobj.width = menuwidth
    }

    if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover") obj.visibility = visible
    else if (e.type == "click") obj.visibility = hidden
}

function iecompattest() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge) {
    var edgeoffset = 0

    if (whichedge == "rightedge") {
        var windowedge = ie4 && !window.opera ? iecompattest().scrollLeft + iecompattest().clientWidth - 15 : window.pageXOffset + window.innerWidth - 15
        dropmenuobj.contentmeasure = dropmenuobj.offsetWidth
        if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) edgeoffset = dropmenuobj.contentmeasure - obj.offsetWidth
    }
    else {
        var topedge = ie4 && !window.opera ? iecompattest().scrollTop : window.pageYOffset
        var windowedge = ie4 && !window.opera ? iecompattest().scrollTop + iecompattest().clientHeight - 15 : window.pageYOffset + window.innerHeight - 18
        dropmenuobj.contentmeasure = dropmenuobj.offsetHeight

        if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) {
            edgeoffset = dropmenuobj.contentmeasure + obj.offsetHeight
            if ((dropmenuobj.y - topedge) < dropmenuobj.contentmeasure) edgeoffset = dropmenuobj.y + obj.offsetHeight - topedge
        }
    }

    return edgeoffset

}

function populatemenu(what) {
    if (ie4 || ns6) dropmenuobj.innerHTML = what.join("")
}

function showmenu(obj, e, menucontents, menuwidth) {
    if (window.event) event.cancelBubble = true
    else if (e.stopPropagation) e.stopPropagation()

    clearhidemenu()
    dropmenuobj = document.getElementById ? document.getElementById("menu") : menu
    populatemenu(menucontents)

    if (ie4 || ns6) {
        showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
        dropmenuobj.x = getposOffset(obj, "left")
        dropmenuobj.y = getposOffset(obj, "top")
        dropmenuobj.style.left = dropmenuobj.x - clearbrowseredge(obj, "rightedge") + "px"
        dropmenuobj.style.top = dropmenuobj.y - clearbrowseredge(obj, "bottomedge") + obj.offsetHeight + "px"
    }

    return clickreturnvalue()
}

function clickreturnvalue() {
    if (ie4 || ns6) return false
    else return true
}

function contains_ns6(a, b) {
    while (b.parentNode) {
        if ((b = b.parentNode) == a) return true;
        return false;
    }
}

function dynamichide(e) {
    if (ie4 && !dropmenuobj.contains(e.toElement)) hidemenu()
    else if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget)) hidemenu()
}

function xmenu(e) {
    if (typeof dropmenuobj != "undefined") {
        if (ie4 || ns6) dropmenuobj.style.visibility = "hidden"
    }
}

function hidemenu() {
    if (ie4 || ns6) delayhide = setTimeout("xmenu()", disappeardelay)
}

function clearhidemenu() {
    if (typeof delayhide != "undefined") clearTimeout(delayhide)
}

if (hidemenu_onclick == "yes") document.onclick = xmenu

