// centered pop up window
function centeredPopUpWindow(mypage, myname, w, h, scroll){
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// audio player popup
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=320,height=330,left = 600,top = 350');");
}


// get position of child node
function getPosition(main,spec) {
	var items = main.getElementsByTagName(spec.tagName);
	var found = 0;
	for (p = 0; p < items.length; p++) {
		if (items[p] == spec) {
			found = 1;
			break;
		}
	}
	if (found) {
		return p;
	}
	else {
		return -1;
	}
}

// set date elements
var yy = new Date().getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var dd = new Date().getDate();
var mm = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
var monthNumber = new Date().getMonth();
var monthLabel = mm[monthNumber];

// check dimensions of browser window
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var halfWindowWidth = windowWidth / 2;
var halfWindowHeight = windowHeight / 2;

// get class name of element
$.fn.getClassNames = function(){
	if (name = this.attr("className")) {
		return name.split(" ");
	}
	else {
		return [];
	}
};
// get name of element
$.fn.getElementNames = function(){
	if (elementName = this.attr("name")) {
		return elementName.split(" ");
	}
	else {
		return [];
	}
};


$(document).ready(function(){

	// get section template id
	sectionTemplate = $("body").attr("id");

/* ------------------------------------------------------------------------------------------
 artists content show/hide
------------------------------------------------------------------------------------------ */	
	
	// show first group
	$("div#artists div#group1").show();
	
	$("ul#alphabetList li a").click(function(){
		if ( $(this).hasClass("empty") ){
			
			// do nothing
			return false;
			
		} else {
			$("ul#alphabetList li a").removeClass("selected");
			$(this).addClass("selected");
		}
	});
	
	$("a.toggleArtistContent").click(function(){
		
		if ( $(this).parent("div.artistContainer").hasClass("active") ){
			
			if($.browser.msie) {
				$(this).parent("div.artistContainer").removeClass("active").find("div.artistContent").hide(); return false;
			} else {
				$(this).parent("div.artistContainer").removeClass("active").find("div.artistContent").slideUp(500); return false;
			}
			
			
		}
		else {
			
			if($.browser.msie) {
				$("div.artistContainer").removeClass("active").find("div.artistContent").hide();
				$(this).parent("div.artistContainer").addClass("active").find("div.artistContent").show();
				restartSlider();
				return false;
			} else {
				$("div.artistContainer").removeClass("active").find("div.artistContent").slideUp(500);
				$(this).parent("div.artistContainer").addClass("active").find("div.artistContent").slideDown(500);
				restartSlider();
				return false;
			}
			
		
		}
		
	});
	
	
/* ------------------------------------------------------------------------------------------
 previous next arrows for album slider
------------------------------------------------------------------------------------------ */	
	$("a.slideNext").click(function(){
		if ( currentSetView == newAlbumSets ){
			return false;
		}
		if ( currentSetView == newAlbumSets - 1 ){
			$("a.newMusicArrows").removeClass("noMas");
			$(this).addClass("noMas");
			$("div.active ul.albumList").animate({marginLeft: "-" + ( sliderMovement * currentSetView ) + "px"}, {queue: false, duration: 500});
			currentSetView = newAlbumSets;
			$("div.active span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView < newAlbumSets ){
			$("a.newMusicArrows").removeClass("noMas");
			$("div.active ul.albumList").animate({marginLeft: "-" + ( sliderMovement * currentSetView ) + "px"}, {queue: false, duration: 500});
			currentSetView++;
			$("div.active span.currentGroup").text("" + currentSetView + "");
			return false;
		}
	});
	
	$("a.slidePrevious").click(function(){
		if ( currentSetView == 1 ){
			return false;
		}
		if ( currentSetView == 2 ){
			// do nothing
			$("a.newMusicArrows").removeClass("noMas");
			$(this).addClass("noMas");
			$("div.active ul.albumList").animate({marginLeft: "0px"}, {queue: false, duration: 500});
			currentSetView = 1;
			$("div.active span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView > 2 ){
			$("a.newMusicArrows").removeClass("noMas");
			currentSetView--;
			$("div.active ul.albumList").animate({marginLeft: "-" + ( (sliderMovement * currentSetView) - sliderMovement ) + "px"}, {queue: false, duration: 500});
			$("div.active span.currentGroup").text("" + currentSetView + "");
			return false;
		}
	});
	
	
/* ------------------------------------------------------------------------------------------
 media
------------------------------------------------------------------------------------------ */
	
	$("div#releasesColumn ul.albumList li:last").css({background: "none"});
	$("div#videosColumn ul.videoList li:last").css({border: "none"});
	
	// this is for ie7
	totalReleases = $("div#releasesColumn ul.albumList li").size();
	setReleasesListHeight = totalReleases*120;
	$("div#releasesColumn ul.albumList").css({height: "" + setReleasesListHeight + "px"});
	
	
// footer links reset
	var totalFooterLinks = $("ul#footerLinks li").size();
	var secondToLastFooterLink = totalFooterLinks - 2;

	$("ul#footerLinks li:first").css({paddingLeft: "0px"});
	$("ul#footerLinks li:last").css({border: "none", paddingLeft: "0px"});
	$("ul#footerLinks li:eq(" + secondToLastFooterLink + ")").css({border: "none", paddingRight: "0px"});

	
// links with rel="external" will open in a new window
	$("a[rel=external]").click(function(){
		 window.open(this.href);
		 return false;
	});
	
// display year in footer
	$("span.currentYear").text(year);
		
});


/* ------------------------------------------------------------------------------------------
artists
------------------------------------------------------------------------------------------ */
function showGroup(ID){
	$("div.artistGroup").hide();
	$("div#group" + ID + "").fadeIn(500);
}

function restartSlider(){
	
	$("ul.albumList").css({marginLeft: "0px"});
	
	newAlbums = $("div.active ul.albumList li").size();
	newAlbumSets = Math.ceil(newAlbums/7);
	currentSetView = 1;
	
	$("div.active span.currentGroup").text("" + currentSetView + "");
	$("div.active span.totalNewAlbumGroups").text("" + newAlbumSets + "");
	
	if ( currentSetView == 1 ) { $("a.slidePrevious").addClass("noMas"); }
	if ( currentSetView == newAlbumSets ) { $("a.slideNext").addClass("noMas"); }
	
	if ( newAlbumSets <= 1 ){
		$("a.slideNext").addClass("noMas");
		$("a.slidePrevious").addClass("noMas");
	}
	
	// set width based on how many new albums are in the list
	setSliderWidth = newAlbums*114;
	$("div.active ul.albumList").css({width: "" + setSliderWidth + "px"});
	
	// remove divider from every fourth item and last item
	$("div.active ul.albumList li:nth-child(7)").css({background: "none"});
	$("div.active ul.albumList li:last").css({background: "none"});
	
	sliderMovement = 798; // # of pixels to move slider forward/backward
	
}