var $header_module_content;

jQuery(document).ready(function() {

  $("a#nav-artists").removeAttr("href");
  $("a#nav-artists").attr("href", "showArtists();"); 

	var $location_param = getQueryStringParam( 'location' );
	
	if($location_param !== '1'){	
		$("#login-module").hide();
	}

	$header_module_content = $("#header-promo").html(); /*get the content of the header-promo*/

	$("#nav-artists").toggle(
		 function(){ showArtists(); },
		 function(){ showUserSummary(); }
		);

	$(".stripeMe tr:odd").addClass("alt");

	 $('#toggle-all-media').click(function(){
     $('li.artist-media-video').show();
     $('li.artist-media-audio').show();
     $('li.artist-media-photo').show();
		 toggleHighlight('#toggle-all-media');
   });

	 $('#togglevideo').click(function(){
     $('li.artist-media-video').show();
     $('li.artist-media-audio').hide();
     $('li.artist-media-photo').hide();
		 toggleHighlight('#togglevideo');
   });

	 $('#toggleaudio').click(function(){
     $('li.artist-media-video').hide();
     $('li.artist-media-audio').show();
     $('li.artist-media-photo').hide();
		 toggleHighlight('#toggleaudio');
   });

	 $('#togglephotos').click(function(){
     $('li.artist-media-video').hide();
     $('li.artist-media-audio').hide();
     $('li.artist-media-photo').show();
		 toggleHighlight('#togglephotos');
   });


});


function toggleHighlight(id_string) {
	var sections = ["#toggleaudio","#togglephotos","#togglevideo", "#toggle-all-media"];
	for (x in sections){	
		if(id_string == sections[x]){
			$(id_string).parent().removeClass();
			$(id_string).parent().addClass("active");	
		}	else {
			$(sections[x]).parent().removeClass(); 
		}
	}	
}


function showLogin(){
	
	$("#login-module").toggle();
	return false;

} // end of function showLogin



function showArtists(){

	document.getElementById("header-promo-artist-border").style.backgroundImage = "url(/content/template/full_launch/images/artist_border.gif)";
	$("#header-promo").empty();
	$("#header-promo").append("<img style='padding:80px 113px;' src='/content/template/full_launch/images/loading.gif' />");
	$("#header-promo").load("/content/module_getartists.php", function(){
		$('#carousel-header').jcarousel({
							 scroll: 1
	  });
	});
} //end of function showArtists			



 function showUserSummary() {
	document.getElementById("header-promo-artist-border").style.backgroundImage = "none";
	$("#header-promo").empty();
	$("#header-promo").append($header_module_content);
} //end of function showUserSummary				
		
function getQueryStringParam( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
