// 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(); }
}

// 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 [];
	}
};

/* ------------------------------------------------------------------------------------------
home page functionality
------------------------------------------------------------------------------------------ */

$(document).ready(function(){
	
	
/* ------------------------------------------------------------------------------------------
new music album slider
------------------------------------------------------------------------------------------ */

	newAlbums = $("ul.albumList li").size();
	newAlbumSets = Math.ceil(newAlbums/4);
	currentSetView = 1;
	
	// counter
	$("span.currentGroup").text("" + currentSetView + "");
	$("span.totalNewAlbumGroups").text("" + newAlbumSets + "");
	
	if ( currentSetView == 1 ) { $("a.slidePrevious").addClass("inactive"); }
	if ( currentSetView == newAlbumSets ) { $("a.slideNext").addClass("inactive"); }
	
	if ( newAlbumSets <= 1 ){
		$("a.slideNext").addClass("inactive");
		$("a.slidePrevious").addClass("inactive");
	}
	
	// set width based on how many new albums are in the list
	setSliderWidth = newAlbums*122;
	$("ul.albumList").css({width: "" + setSliderWidth + "px"});
	
	// remove divider from every fourth item and last item
	$("ul.albumList li:nth-child(4)").css({background: "none"});
	$("ul.albumList li:last").css({background: "none"});
	
	sliderMovement = 488; // # of pixels to move slider forward/backward
	
	$("a.slideNext").click(function(){
		
		if ( currentSetView == newAlbumSets ){
			$("a.newMusicArrows").removeClass("inactive");
			$(this).addClass("inactive");
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView == newAlbumSets - 1 ){
			$("a.newMusicArrows").removeClass("inactive");
			$(this).addClass("inactive");
			$("ul.albumList").animate({marginLeft: "-" + ( sliderMovement * currentSetView ) + "px"}, {queue: false, duration: 500});
			currentSetView = newAlbumSets;
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView < newAlbumSets ){
			$("a.newMusicArrows").removeClass("inactive");
			$("ul.albumList").animate({marginLeft: "-" + ( sliderMovement * currentSetView ) + "px"}, {queue: false, duration: 500});
			currentSetView++;
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		
	});
	
	$("a.slidePrevious").click(function(){
		
		if ( currentSetView == 1 ){
			$("a.newMusicArrows").removeClass("inactive");
			$(this).addClass("inactive");
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView == 2 ){
			// do nothing
			$("a.newMusicArrows").removeClass("inactive");
			$(this).addClass("inactive");
			$("ul.albumList").animate({marginLeft: "0px"}, {queue: false, duration: 500});
			currentSetView = 1;
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
		if ( currentSetView > 2 ){
			$("a.newMusicArrows").removeClass("inactive");
			currentSetView--;
			$("ul.albumList").animate({marginLeft: "-" + ( (sliderMovement * currentSetView) - sliderMovement ) + "px"}, {queue: false, duration: 500});
			$("span.currentGroup").text("" + currentSetView + "");
			return false;
		}
			
	});
	
/* ------------------------------------------------------------------------------------------
announcements
------------------------------------------------------------------------------------------ */

	totalAnnouncements = $("ul#announcementsList li").size();
	
	$("ul#announcementsList li:eq(0)").show();
	$("ul#announcementsList li p:nth-child(2n)").css({background: "none"});
	
	// create list item for each announcement group
		$("div#announcements ul#announcementsList").each(function(n){
			for( i = 0; i < totalAnnouncements; i++ ){
				$(this).parent().find("ul.announceNav").append("<li>" + ( i + 1 ) + "</li>");
			}		
		});
		
	// make previous list clickable to show/hide announcement groups
		$("div#announcements ul.announceNav li:first").addClass("highlight");
		$("div#announcements ul.announceNav li:last").css({border: "none"});
		$("div#announcements ul.announceNav li").click(function(){
			
			var groupPosition = getPosition(this.parentNode,this);
						
			$("div#announcements ul.announceNav li").removeClass("highlight");
			$(this).addClass("highlight");
			$("ul#announcementsList li").hide();
			$("ul#announcementsList li:eq(" + groupPosition + ")").fadeIn(500);
			return false;
			
		});


/* ------------------------------------------------------------------------------------------
coming soon
------------------------------------------------------------------------------------------ */

	$("div#comingSoon ul li:first").css({marginRight: "3px"});


/* ------------------------------------------------------------------------------------------
newsletter sign up form
------------------------------------------------------------------------------------------ */
	
	$("input#Subscribe").click(function(){
		$(this).select();
	});
	
	
// 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);
	
	
}); // $(document).ready