var searchType;function lyricSearchClick() {	//hide the other panels and show the search panel	$("#artistPanel").hide();	$("#genrePanel").hide();	$("#result").hide();	$("#searchPanel").show();	//remove class active from other tabs and add active to search tab     				$("#searchTabs li a").removeClass("active");	$('#lyricSearch').addClass("active");		searchType = "search";}function browseArtistsClick() {	//hide the other panels and show the artist panel	$("#searchPanel").hide();	$("#genrePanel").hide();	$("#result").hide();	$("#artistPanel").show();	//remove class active from other tabs and add active to artist tab	$("#searchTabs li a").removeClass("active");	$('#browseArtists').addClass("active");		searchType = "artist";}function browseGenresClick(){	//hide the other panels and show the genre panel		$("#searchPanel").hide();	$("#artistPanel").hide();	$("#result").hide();	$("#genrePanel").show();	//remove class active from other tabs and add active to genre tab     		$("#searchTabs li a").removeClass("active");	$('#browseGenres').addClass("active");		searchType = "genre";}function findButtonClick() {	$("#doSearch").submit();}$(document).ready(function(){	/******/	var queryString;	var updateResultsUrl = "/search/doSearch.action?"	var updateGenresUrl = "/search/genres.action?search.page=1"	var updateArtistsUrl = "/search/contributors.action?search.page=1"		$('p.returnToLyric').unbind('click').bind('click', function() {		//hide the panels and show the results panel		$("#searchPanel").hide();		$("#artistPanel").hide();		$("#genrePanel").hide();		$("#result").show();				//remove class active from tabs					$("#searchTabs li a").removeClass("active");				return false;	});		$('p#returnToSearch a').unbind('click').bind('click', function() {		if (searchType == 'search') {			lyricSearchClick();		} else if (searchType == 'artist') {			browseArtistsClick();		} else if (searchType == 'genre') {			browseGenresClick();		}				return false;	});	$("#doSearch").unbind('submit').bind('submit', function(){		var parameters = {			"search.keywords" : $("#doSearch_search_keywords").val(),			"search.searchType" : $("#searchBy").val()		};		$("#searchForm input").addClass("loading");		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("resultsHeader") == -1 && data.indexOf("no results") == -1 && data.indexOf("errorMessage") == -1) {				$("#searchPanel").html("");			} else {				$("#searchResult").html(data);			}       		$("#searchForm input").removeClass("loading");		});		$('p#returnToSearch').show();		return false;	});		$("#lyricSearch").bind('click', function() { lyricSearchClick(); return false; });	$("#browseArtists").bind('click', function() { browseArtistsClick(); return false; });	$("#browseGenres").bind('click', function() { browseGenresClick(); return false; });	$("#findButton").unbind('click').bind('click', function() { findButtonClick(); });		/*****/	var updateResultsUrl = "../search/doSearch.action?"	var updateContributorsUrl = "../search/contributors.action?"	var updateLyricsUrl = "../search/lyrics.action?"	var resultsPerPage = 10;			$(".contributorBrowse a").unbind('click').bind('click', function(){			$('#searchTabs a').unbind('click');				var selected = $(this).attr("rel");			var parameters = {			"search.contributor" : $(this).attr("rel")		};		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateContributorsUrl, parameters, function(data){ 			if (data.indexOf("results") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else {				$("#artistPanel div").html(data);			}			$(".contributorBrowse a[rel="+selected+"]").addClass('active');			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$(".contributorSearch a").unbind('click').bind('click', function(){		$('#searchTabs a').unbind('click');				$("#searchPanel").hide();				$("#genrePanel").hide();				$("#result").hide();		$("#artistPanel").show();		$("#searchTabs li a").removeClass("active");     		$("#browseArtists").addClass("active");						var parameters = {			"search.contributorId" : $(this).attr("rel")		};		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("results") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else {				$("#artistPanel div").html(data);			}			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$(".genreSearch a").unbind('click').bind('click', function(){				$('#searchTabs a').unbind('click');				var parameters = {			"search.genre" : decodeURIComponent($(this).attr("rel")).replace(/\+/g, " ")		};		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("results") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else {				$("#genrePanel div").html(data);			}			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$(".lyrics a").unbind('click').bind('click', function(){		if ($(this).is("#searchPanel a")) {			searchType = "search";		} else if ($(this).is("#artistPanel a")) {			searchType = "artist";		} else if ($(this).is("#genrePanel a")) {			searchType = "genre";		}				var parameters = {			"itemId" : $(this).attr("rel")		};		var allowed = true;		if ($("#update_lid").val() != 0 && $("#update_lid").val() != $(this).attr("rel")) {			allowed = false;			var warning = "";			warning += "<div style=\"float: left;\"><h1>Switching songs?</h1></div><div style=\"float: right;\"><a href=\"javascript:hidePopUp(\'warningPopup\')\">X</a></div>";			warning += "<br clear=\"both\" /><p>Switching songs will clear out your current design.</p><p>Are you sure you want to switch?</p>";			warning += "<a class=\"button green popupOptions\" href=\"#\" onclick=\"hidePopUp(\'warningPopup\'); clearDesign(" + $(this).attr("rel") + "); return false;\"><span>Continue</span></a>";			warning += "<a class=\"button popupOptions\" href=\"#\" onclick=\"hidePopUp(\'warningPopup\'); return false;\"><span>Cancel</span></a>";			$("#warningPopupContent").html(warning); 			displayPopUp('warningPopup', 150, 200, false);		}				if (allowed) {			$("#searchForm input").addClass("loading");			$("span.loadingSmall").css('visibility', 'visible');			$.post(updateLyricsUrl, parameters, function(data){ 	       		$("#result").attr("rel", "");	       		$("#result").html(data);	       						$('p#returnToSearch').show();								if ($("#update_lid").val() != 0) {					setLyricClasses();				}		       		$("#searchForm input").removeClass("loading");     			$("span.loadingSmall").css('visibility', 'hidden');     			$("#searchTabs li a").removeClass("active");      				$("#searchPanel").hide();				$("#artistPanel").hide();				$("#genrePanel").hide();				$("#result").show();							$("div.blockControl").vAlign();				$("span.lineControl").vAlign();			});						if (!productLoaded) {				loadProductAction();			}		}				return false;	});		$(".paging a").unbind('click').bind('click', function(){		$('#searchTabs a').unbind('click');				var parameters = {			"search.page" : $(this).attr("rel"),			"search.resultsPerPage" : resultsPerPage,			"search.searchType" : $(this).parent().parent().children('#doSearch_search_searchType').val(),			"search.sortType" : $(this).parent().parent().children('.resultsHeader').children('.sortBy').val(),			"search.genre" : decodeURIComponent($(this).parent().parent().children("#doSearch_search_genre").val()).replace(/\+/g, " "),			"search.contributorId" : $(this).parent().parent().children('#doSearch_search_contributorId').val(),			"search.keywords" : $(this).parent().parent().children('#doSearch_search_keywords').val() == "Enter keywords here" ? "" : $(this).parent().parent().children('#doSearch_search_keywords').val()		};		$("#searchForm input").addClass("loading");		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("resultsHeader") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else if ($("#lyricSearch").hasClass("active")) {				$("#searchResult").html(data);			} else if ($("#browseArtists").hasClass("active")) {				$("#artistPanel div").html(data);			} else if ($("#browseGenres").hasClass("active")) {				$("#genrePanel div").html(data);			}       		$("#searchForm input").removeClass("loading");			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$(".goToPage").unbind('change').bind('change', function() {		$('#searchTabs a').unbind('click');				var parameters = {			"search.page" : $(this).parent().children(".goToPage").val(),			"search.resultsPerPage" : resultsPerPage,			"search.searchType" :  $(this).parent().parent().children("#doSearch_search_searchType").val(),			"search.sortType" :  $(this).parent().children(".sortBy").val(),			"search.genre" : decodeURIComponent( $(this).parent().parent().children("#doSearch_search_genre").val()).replace(/\+/g, " "),			"search.contributorId" :  $(this).parent().parent().children("#doSearch_search_contributorId").val(),			"search.keywords" :  $(this).parent().parent().children("#doSearch_search_keywords").val() == "Enter keywords here" ? "" :  $(this).parent().parent().children("#doSearch_search_keywords").val()		};				$("#searchForm input").addClass("loading");		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("resultsHeader") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else if ($("#lyricSearch").hasClass("active")) {				$("#searchResult").html(data);			} else if ($("#browseArtists").hasClass("active")) {				$("#artistPanel div").html(data);			} else if ($("#browseGenres").hasClass("active")) {				$("#genrePanel div").html(data);			}       		$("#searchForm input").removeClass("loading");			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$("#searchByGenre").unbind('change').bind('change', function() {		$('#searchTabs a').unbind('click');				var page = 1;				if (parseInt($(this).parent().parent().parent().children('.resultsHeader').children('.goToPage'))) {			page = parseInt($(this).parent().children(".goToPage").val());		}					//				var parameters = {			"search.page" : page,			"search.resultsPerPage" : resultsPerPage,			"search.searchType" :  $(this).val(),			"search.sortType" :  $(this).parent().parent().parent().children('.resultsHeader').children('.sortBy').val(),			"search.genre" : decodeURIComponent( $(this).parent().parent().parent().children("#doSearch_search_genre").val()).replace(/\+/g, " "),			"search.contributorId" : 0,			"search.keywords" :  ""		};				$("#searchForm input").addClass("loading");		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if ($("#lyricSearch").hasClass("active")) {				$("#searchResult").html(data);			} else if ($("#browseArtists").hasClass("active")) {				$("#artistPanel div").html(data);			} else if ($("#browseGenres").hasClass("active")) {				$("#genrePanel div").html(data);			}       		$("#searchForm input").removeClass("loading");			$("span.loadingSmall").css('visibility', 'hidden');		});		$('p#returnToSearch').show();				return false;	});		$(".sortBy").unbind('change').bind('change', function() {		$('#searchTabs a').unbind('click');				var page = 1;				if (parseInt($(this).parent().children(".goToPage"))) {			page = parseInt($(this).parent().children(".goToPage").val());		}				var parameters = {			"search.page" :  page,			"search.resultsPerPage" : resultsPerPage,			"search.searchType" :  $(this).parent().parent().children("#doSearch_search_searchType").val(),			"search.sortType" :  $(this).parent().children(".sortBy").val(),			"search.genre" : decodeURIComponent( $(this).parent().parent().children("#doSearch_search_genre").val()).replace(/\+/g, " "),			"search.contributorId" :  $(this).parent().parent().children("#doSearch_search_contributorId").val(),			"search.keywords" :  $(this).parent().parent().children("#doSearch_search_keywords").val() == "Enter keywords here" ? "" :  $(this).parent().parent().children("#doSearch_search_keywords").val()		};				$("#searchForm input").addClass("loading");		$("span.loadingSmall").css('visibility', 'visible');		$.post(updateResultsUrl, parameters, function(data){ 			if (data.indexOf("resultsHeader") == -1 && data.indexOf("errorMessage") == -1) {				var error = "Sorry, an unexpected error occurred.<br />Please refresh the page and start over.";				$("#errorPopupContent").html(error); 				displayPopUp('errorPopup', 150, 200, false);			} else if ($("#lyricSearch").hasClass("active")) {				$("#searchResult").html(data);			} else if ($("#browseArtists").hasClass("active")) {				$("#artistPanel div").html(data);			} else if ($("#browseGenres").hasClass("active")) {				$("#genrePanel div").html(data);			}			$("span.loadingSmall").css('visibility', 'hidden');       		$("#searchForm input").removeClass("loading");		});		$('p#returnToSearch').show();				return false;	});		$('a.back').click(function() {		if ($(this).attr('rel') == 'artist') {			$("span.loadingSmall").css('visibility', 'visible');			$.get('/search/contributors.action?search.page=1', function(data){ 	     		$("#artistPanel div").html(data);				$("span.loadingSmall").css('visibility', 'hidden');	     	});			return false;		} else if ($(this).attr('rel') == 'style') {			$("span.loadingSmall").css('visibility', 'visible');			$.get('/search/genres.action?search.page=1', function(data){ 	     		$("#genrePanel div").html(data);				$("span.loadingSmall").css('visibility', 'hidden');	     	});			return false;		}	});});$.fn.vAlign = function() {	return this.each(function(i){		var height = $(this).height();		var containerHeight = $(this).parent().height();		var margin = (containerHeight - height) / 2;		if (margin > 0) {			$(this).css('margin-top', margin);		}	});};
