var aButtonTextColors = new Array ();
aButtonTextColors ["search_btn"      ] = ['#E6E6E6', '#FFF', '#F0F0F0', '#FFF'];  <!-- OFF normal mouseover ON normal mouseover -->// Was #777', '#444', '#D00040', '#F02060'
aButtonTextColors ["searchReset_btn"     ] = ['#777', '#444', '#777'   , '#444'   ];
aButtonTextColors ["searchGo_btn"        ] = ['#FFF', '#8F8', '#FFF'   , '#8F8'   ];
aButtonTextColors ["write_btn"           ] = ['#777', '#C90700', '#C90700', '#D43933']; <!-- #AE002F '#ca003f-->
aButtonTextColors ["video_btn"           ] = ['#777', '#C90700', '#C90700', '#D43933']; // '#D00040', '#F02060'
aButtonTextColors ["writeHow_btn"        ] = ['#777', '#444', '#D00040', '#F02060'];
aButtonTextColors ["sequel_btn"          ] = ['#777', '#444', '#D00040', '#F02060'];
aButtonTextColors ["uploadSong_btn"      ] = ['#777', '#444', '#D00040', '#F02060'];
aButtonTextColors ["videoHow_btn"        ] = ['#777', '#444', '#D00040', '#F02060'];
aButtonTextColors ["uploadVideoLink_btn" ] = ['#777', '#444', '#D00040', '#F02060'];
aButtonTextColors ["playerVote_btn"      ] = ['#777', '#444', '#D00040', '#F02060'];

aButtonTextColors ["si_td"      ] = ['#E6E6E6', '#FFF', '#000', '#0F0']; // '#777', '#444', '#D00040', '#F02060'
aButtonTextColors ["register_td"] = ['#E6E6E6', '#FFF', '#000', '#0F0'];

aButtonTextColors ["footerAbout_btn"   ] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerFAQ_btn"     ] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerMediaReg_btn"] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerTc_btn"      ] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerPrivacy_btn" ] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerReport_btn"  ] = ['#808080', '#000', '#00F', '#0F0'];
aButtonTextColors ["footerContact_btn" ] = ['#808080', '#000', '#00F', '#0F0'];
//aButtonTextColors ["link_btn"          ] = ['#808080', '#000', '#00F', '#0F0'];

var aGrowMorphs = new Array ();
var aButtonIconDims = new Array ();
aButtonIconDims ['write_btn_icon'      ] = [35, 27,  0,  0];    // origWidth, origHeight, growX, growY
aButtonIconDims ['video_btn_icon'      ] = [35, 27,  0,  0];
aButtonIconDims ['facebook_btn_icon'   ] = [20, 20, 10, 10];
aButtonIconDims ['myspace_btn_icon'    ] = [20, 20, 10, 10];
aButtonIconDims ['twitter_btn_icon'    ] = [20, 20, 10, 10];
aButtonIconDims ['link_btn_icon'       ] = [20, 20, 10, 10];
aButtonIconDims ['playerVote_btn_icon' ] = [48, 36, 10, 10];

var aButtonStates = new Array ();
aButtonStates ["search_btn"    ] = false;
aButtonStates ["write_btn"     ] = false;
aButtonStates ["video_btn"     ] = false;
aButtonStates ['playerVote_btn'] = false;

/* var pic1 = new Image();
pic1.src = 'assets/images/buttons/black_button_35x27.gif';
var pic2 = new Image();
pic2.src = 'assets/images/buttons/green_button_35x27.gif';
var pic3 = new Image();
pic3.src = 'assets/images/buttons/yellow_button_35x27.gif';
*/
var leftButtonsOff_bg = 'url(assets/images/buttons/black_button_35x27.gif)';
var leftButtonsOn_bg = new Array();
leftButtonsOn_bg ['write_btn'] = 'url(assets/images/buttons/green_button_35x27.gif)';
leftButtonsOn_bg ['video_btn'] = 'url(assets/images/buttons/yellow_button_35x27.gif)';


function setupButtons() {
	$$('.btn').each( function(item) {
						item.removeEvents('mouseenter', 'mouseleave', 'mousedown');
						item.addEvent('mouseenter', fnMouseEnterButton);
						item.addEvent('mouseleave', fnMouseLeaveButton);
						item.addEvent('mousedown',  fnClickButton);
						fnSetButtonTextColor(item, false);
						
						if (item.hasClass('disabled')) item.set('opacity', disabledButtonOpacity);
					} );
	
	$$('.btnIcon').each ( function(item) {
						aGrowMorphs[item.id] = new Fx.Morph(item, {link : 'cancel',
																   transition : 'bounce:out',
																   duration : 'normal'});
						item.setStyles ({'width'  : aButtonIconDims[item.id][0],
										 'height' : aButtonIconDims[item.id][1]
										});
				   } );
}

function fnMouseEnterButton(event) {
	if (!(this.hasClass('disabled'))) {
		fnSetButtonTextColor(this, true);
		fnGrowButtonIcon (this, true);
	} else {
		if (this.id == 'playerVote_btn') {
			var x = event.page.x - 420;
			var y = event.page.y - 30;
			$('voteDisabledHelp_div').setStyles({'left' : x, 'top' : y});
			$('voteDisabledHelp_div').fade('in');
		}
	}
}

function fnMouseLeaveButton(event) {
	if (!(this.hasClass('disabled'))) {
		fnSetButtonTextColor(this, false);
		fnGrowButtonIcon (this, false);
	} else {
		if (this.id == 'playerVote_btn') {
			$('voteDisabledHelp_div').fade('out');
		}
	}
}
	
function fnSetButtonTextColor(which, over) {
	var offset = over ? 1 : 0;
	offset += aButtonStates[which.id] ? 2 : 0;
	if ($(which.id+'_text')) {   // If there is text to go with the button
		$(which.id+'_text').setStyle('color', aButtonTextColors[which.id][offset]);
	}
}
	
function fnGrowButtonIcon(which, bGrow) {
	var startW; var endW;
	var iconId = which.id + '_icon';
	if ($(iconId)) {   // If there is an icon to go with the button
		if (bGrow) {
			startW = aButtonIconDims[iconId][0]; endW = aButtonIconDims[iconId][0] + aButtonIconDims[iconId][2];
			startH = aButtonIconDims[iconId][1]; endH = aButtonIconDims[iconId][1] + aButtonIconDims[iconId][3];
		} else {
			endW = aButtonIconDims[iconId][0]; startW = aButtonIconDims[iconId][0] + aButtonIconDims[iconId][2];
			endH = aButtonIconDims[iconId][1]; startH = aButtonIconDims[iconId][1] + aButtonIconDims[iconId][3];
		}
		aGrowMorphs[iconId].start({'width'  : [startW, endW], 'height' : [startH, endH] });
	}
}

function fnClickButton() {
/*	if (typeof(aButtonStates[this.id]) == 'boolean') {       If they've clicked on something that should be toggled
		aButtonStates[this.id] = !aButtonStates[this.id];
		fnSetButtonTextColor($(this.id), true);
	} */
	if (!(this.hasClass('disabled'))) {

		switch (this.id) {
			case 'search_btn':
			aButtonStates[this.id] = !aButtonStates[this.id];
			fnSetButtonTextColor($(this.id), true);
				if (aButtonStates['search_btn']) {
					$('search_btn').setStyle ('background-image', 'url(assets/images/buttons/srch_open_off_103x19.gif)');
					resized();
					mySlide.slideIn();
				} else {
					$('search_btn').setStyle ('background-image', 'url(assets/images/buttons/srch_clsd_off_103x19.gif)');
					mySlide.slideOut().chain(resized);
				}
			break;
				
			case 'searchReset_btn':
//				alert ('This resets all the search fields');
				resetSearchWindow();
				$('slStatus_div').set('html', 'Resetting Search');
				$('slStatus_div').setStyle('visibility', 'visible');
				setTimeout( function() {
									 fnSubmitSearchForm();
							}, 2000 );
			break;
				
			case 'searchGo_btn':
				fnSubmitSearchForm();
			break;
			
			case 'bigLogo_div':
				$('write_btn_icon').setStyle('background-image', leftButtonsOff_bg);
				writeLinksSlide.slideOut();
				$('video_btn_icon').setStyle('background-image', leftButtonsOff_bg);
				videoLinksSlide.slideOut();
			break;
		
			case 'write_btn':
			aButtonStates[this.id] = !aButtonStates[this.id];
			fnSetButtonTextColor($(this.id), true);
				if (aButtonStates['write_btn']) {
					$('write_btn_icon').setStyle('background-image', leftButtonsOn_bg['write_btn']);
					aButtonStates['video_btn'] = false;
					fnSetButtonTextColor($('video_btn'), false);
					$('video_btn_icon').setStyle('background-image', leftButtonsOff_bg);
					videoLinksSlide.slideOut();
					writeLinksSlide.slideIn();
				} else {
					$('write_btn_icon').setStyle('background-image', leftButtonsOff_bg);
					writeLinksSlide.slideOut();
				}
			break;
	
			case 'video_btn':
			aButtonStates[this.id] = !aButtonStates[this.id];
			fnSetButtonTextColor($(this.id), true);
				if (aButtonStates['video_btn']) {
					$('video_btn_icon').setStyle('background-image', leftButtonsOn_bg['video_btn']);
					aButtonStates['write_btn'] = false;
					fnSetButtonTextColor($('write_btn'), false);
					$('write_btn_icon').setStyle('background-image', leftButtonsOff_bg);
					writeLinksSlide.slideOut();
					videoLinksSlide.slideIn();
				} else {
					$('video_btn_icon').setStyle('background-image', leftButtonsOff_bg);
					videoLinksSlide.slideOut();
				}
			break;
	
			case 'facebook_btn' :
				if (statusDisplay) alert ('Facebook widget clicked');
				var u='http://www.citylovemusic.com/index.php?play=' + nowPlaying.token.substr(0, 8);
				var t='Vote here for my CityLove song';
				setTimeout( function() {
					window.open('http://www.facebook.com/sharer.php?u=' + u + '&t=' + t);
						}, 250 );				
				vId = 1;
				ajaxLogActivity ('widget', vId, user.id);
			break;
			
			case 'myspace_btn' :
				var u='http://www.citylovemusic.com/index.php?play=' + nowPlaying.token.substr(0, 8);
				var t='Vote here for my CityLove song';
				setTimeout( function() {
				window.open('http://www.myspace.com/index.cfm?fuseaction=postto&u=' + u + '&t=' + t + 
							'&c=Please help me win this competition&l=3');
						}, 250 );				
				vId = 2;
				ajaxLogActivity ('widget', vId, user.id);
			break;

			case 'twitter_btn' :
				var u='http://www.citylovemusic.com/index.php?play=' + nowPlaying.token.substr(0, 8);
				setTimeout( function() {
				window.open('http://twitter.com/home?status=Listening to ' + nowPlaying.mediaName + ' at ' + u);
						}, 250 );				
				vId = 3;
				ajaxLogActivity ('widget', vId, user.id);
			break;
			
			case 'link_btn' :
				vId = 4;
				ajaxLogActivity ('widget', vId, user.id);
				showPopup('link');
			break;
			
			case 'playerVote_btn' :
				if (user.access_level > 0) {
					fnTogglePlayerVote();
				} else {
					bTryingToVote = true;
					showPopup('register');
				}
			break;
			
			case 'writeHow_btn':
				aTcPopupNav.length = 0;
				aTcPopupNav[0] = ['Songwriter Instructions'  , 'writeSongsHelp'];
				aTcPopupNav[1] = ['Songwriter / Artist Terms', 'songwriterTerms'];
				aTcPopupNav[2] = ['Songwriting Agreement'    , 'songwriterAgreement'];
				aTcPopupNav[3] = ['Master Use Agreement'     , 'masterUseAgreement'];
				showModal('tcPopup_div', 'writeSongsHelp', null, null);
			break;
				
			case 'sequel_btn':
				if (user.access_level == 0) {					// If not signed in
					alert ('Please register or sign in');
				} else if (user.access_level & 2) {
					if (user.validated != 1) {
						alert ('Your registration has not been validated yet.');
					} else {
						showPopup('sequel');
					}
				} else {
					alert ('Only songwriters can download Sequel & backing tracks.  Please update your registration.');
				}
			break;
				
			case 'uploadSong_btn':
				if (user.access_level == 0) {					// If not signed in
					alert ('Please register or sign in');
				} else if (user.access_level & 2) {
					if (user.validated != 1) {
						alert ('Your registration has not been validated yet.');
					} else {
						showPopup('uploadSong');
					}
				} else {
					alert ('Only songwriters can upload songs.  Please update your registration.');
				}
			break;
				
			case 'videoHow_btn':
				aTcPopupNav.length = 0;
				aTcPopupNav[0] = ['Video Maker Instructions', 'makeVideoHelp'];
				aTcPopupNav[1] = ['Music Video Terms'        , 'musicVideoTerms'];
				aTcPopupNav[2] = ['Music Video Agreement'    , 'musicVideoAgreement'];
				showModal('tcPopup_div', 'makeVideoHelp', null, null);
			break;
				
			case 'uploadVideoLink_btn':
				if (user.access_level == 0) {					// If not signed in
					alert ('Please register or sign in');
				} else if (isVideoMaker()) {
					if (user.validated != 1) {
						alert ('Your registration has not been validated yet.');
					} else {
						showPopup('uploadVideo');
					}
				} else {
					alert ('Only video makers can upload video links.  Please update your registration.');
				}
	
			break;
				
			case "si_td_text":
				if (user.access_level == 0) {
					modalMsg = '';
					showModal('si_div', null, function() {
														hideModal('si_div');			// onSuccess
													   },
													   
													   function() {						// onFailure
															hideModal('si_div');
													   });
				} else {
					fnSignOut();
				}
			break;
				
			case "register_td_text":
				regNeedCompanyInfo = false;
				showPopup('register');
			break;
	
			case 'footerAbout_btn':
				$('container_divWrapper' ).setStyle('display', 'none');
				$('bigBanner_divWrapper' ).setStyle('display', 'none');
				showPage('landing');
			break;
			
			case "footerFAQ_btn":
				aTcPopupNav.length = 0;
				aTcPopupNav[0] = ['Frequently Asked Questions', 'faq'];
				showModal('tcPopup_div', 'faq', null, null);
			break;

			case "footerMediaReg_btn":
				regNeedCompanyInfo = false;
				showPopup('register');
			break;
			
			case "footerTc_btn":
				aTcPopupNav.length = 0;
				aTcPopupNav[0] = ['General User Terms'       , 'generalTerms'];
				aTcPopupNav[1] = ['Songwriter / Artist Terms', 'songwriterTerms'];
				aTcPopupNav[2] = ['Music Video Terms'        , 'musicVideoTerms'];
				aTcPopupNav[3] = ['Media Terms'              , 'mediaTerms'];
				aTcPopupNav[4] = ['Songwriting Agreement'    , 'songwriterAgreement'];
				aTcPopupNav[5] = ['Master Use Agreement'     , 'masterUseAgreement'];
				aTcPopupNav[6] = ['Music Video Agreement'    , 'musicVideoAgreement'];
				showModal('tcPopup_div', 'generalTerms', null, null);
			break;

			case "footerPrivacy_btn":
				aTcPopupNav.length = 0;
				aTcPopupNav[0] = ['Privacy Policy', 'privacy'];
				showModal('tcPopup_div', 'privacy', null, null);
			break;

			case 'footerContact_btn':
				contactMode = 0;
				showModal('contact_div', null, function() {hideModal('contact_div');}, function() {hideModal('contact_div');});
			break;
			
			case 'footerReport_btn':
				contactMode = 1;
				showModal('contact_div', null, function() {hideModal('contact_div');}, function() {hideModal('contact_div');});
			break;
			
/*			case 'regSuggestCity_text':
				alert ('Allows user to suggest a city not in the list');
			break;
*/			
			case 'regSuggestCity_text':
				contactMode = 2;
				showModal('contact_div', null, function() {}, function() {});
			break;
		}
	}
}

function fnTogglePlayerVote() {
	for (var songNum=0; songNum<aSlSongs.length; songNum++) {						// Find the songNum and rowNum
		for (var rowNum=0; rowNum<aSlSongs[songNum].totalVersions; rowNum++) {
			if (aSlSongRows[songNum][rowNum].versionId == nowPlaying.versionId) {	// Found it
				var newVote = (aSlSongRows[songNum][rowNum].vote == 1) ? 0 : 1;
				ajaxRecordVote(nowPlaying.versionId, songNum, rowNum, user.id, newVote, function() {});
			}
		}
	}
}

function fnLightPlayerVoteButton() {
	if (aButtonStates['playerVote_btn']) {
		$('playerVote_btn_icon').src='assets/images/buttons/heartButton_red_58x45.gif';
	} else {
		$('playerVote_btn_icon').src='assets/images/buttons/heartButton_black_58x45.gif';
//		$('playerVote_btn_icon').setStyle('background-image', 'url(assets/images/buttons/vote_icon_off_50x50.gif)');
	}
}
		
