
$(document).ready(function() {

	$("a").each(function(){
		if($(this).attr('href') != null ){
			if($(this).attr('href').indexOf('http') != -1){
				$(this).attr('target','_blank');
			}
		}
	})
	
	$(".grid-panel").each(function(){
		if($(this).attr('href').indexOf('/video/') != -1){
			$(this).attr('href', $(this).attr('href').replace('/video/', '/video#'));
		}
		if($(this).attr('href').indexOf('/audio/') != -1){
			$(this).attr('href', $(this).attr('href').replace('/audio/', '/audio#'));
		}
	});
	
	// subnav 
	if(!$('.sub-nav').hasClass('show-sub-nav')){
		$('.sub-nav .c1').css({'opacity': 0, 'display':'none'});
		
		$('.sub-nav .c1, .nav-link-campaigns').bind('mouseenter',function(){
			$('.sub-nav .c1').stop().css({'display':'block'}).animate({'opacity':1}, 500);
		});
		
		$('.sub-nav, .nav-link-campaigns').bind('mouseleave',function(){
			
			$('.sub-nav .c1').stop().animate({'opacity':0}, 500, function(){
				$('.sub-nav .c1').css({'display':'none'});
			});
			
		});
	}

	$(".embed-button").click(function(){
		$(this).hide();
		$(this).next().show();
	});	
	$("#webform-client-form-18 label").text("email address...");
	
	$("#block-views-ArtistEvent-block_1 .thumb").each(function(){
		$(this).find("a").append($(this).find(".info"));
	});

	// clients images center
	$(".client .grey, .client .color").each(function(){
		$(this).find("img").hide();
		var src = $(this).find("img").attr('src');
		$(this).css('background', 'url(\'' +src+ '\') no-repeat center center');
		
	})

	// Live Shows Filters
	
	if($(".block-views-Live_Shows-block_1").length >= 1){
		
		$(".artist-filter").parents('.views-row').hide()
		
		$(".block-views-Live_Shows-block_1 h3").each(function(){
			
			var artist = $.trim( $(this).text() );
			
			$(".artist-filter").filter(function(){
					var filterArtist =  $.trim( $(this).text() );
					if(filterArtist == artist){
						return true;
					} else {
						return false;
					}
			}).parents('.views-row').show();
		});
		
		
		$(".block-views-Live_Shows-block_1 .view-content h3").addClass('artist-group');
		$(".block-views-Live_Shows-block_5 .view-content").prepend('<h3 class="location-group">No Location Filter</h3>');
		
		$(".artist-filter").click(function(){
			$(".artist-filter, .location-filter").removeClass("active");
			$(this).addClass("active");
		
			var artist = $(this).text();
			
			$(".block-views-Live_Shows-block_1 .content").show();
			$(".block-views-Live_Shows-block_5").hide();
			
			$(".block-views-Live_Shows-block_1 h3").hide();
			$(".block-views-Live_Shows-block_1 h3").filter(function(index) {
  				return $(this).text() == artist;
			}).show();
			
			$(".block-views-Live_Shows-block_1 .views-row").hide();
			$(".block-views-Live_Shows-block_1 .views-row").filter(function(index) {
  				return ($(this).find(".artist").text() == (artist + " - "));
			}).show();
		});
		$(".location-filter").click(function(){
			$(".artist-filter, .location-filter").removeClass("active");
			$(this).addClass("active");
			var location = $(this).text();
		
			$(".block-views-Live_Shows-block_1 .content").hide();
			$(".block-views-Live_Shows-block_5").show();
			
			$(".block-views-Live_Shows-block_5 h3.location-group").text($(this).text());
			
			$(".block-views-Live_Shows-block_5 .views-row").hide();
			$(".block-views-Live_Shows-block_5 .views-row").filter(function(index) {
  				return $(this).find(".location").text() == location + " - ";
			}).show();
		});

	};

	// clear contact form on email sent 
	/*
	if($(".messages").text().trim() == "Your message has been sent."){
		$(".block-contact_form_blocks .form-text").val("");
		$(".block-contact_form_blocks textarea").html("");
	}
	*/
	
	initHideLabels();
});


function initHideLabels(){
	$("#block-webform-client-block-18 .form-item .form-text").each(function(){
		
		$(this).addClass('hidelabel');
		$(this).val("");

		$(this).focus(function(){
			hideLabels($(this));
			$(this).parents(".form-item").find("label").hide();
		});
		
		$(this).blur(function(){
			hideLabels($(this));
		});
		
		$(this).keyup(function(){
			hideLabels($(this));
			$(this).parents(".form-item").find("label").hide();
		});
		
		hideLabel($(this));
		
	});
}

function hideLabels(jInput){
	jInput.parents("form").find(".hidelabel").each(function(){
		hideLabel($(this));
	});
}

function hideLabel(jInput){
	if((jInput.val() == "" || jInput.val()== null) && (jInput.html() == "" || jInput.html()== null)){
		jInput.parents(".form-item").find("label").show();
	} else {
		jInput.parents(".form-item").find("label").hide();
	}
}



function isEmailValid (email){
	var emailReg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (emailReg.test(email) == true){
		return true;
	} else {
		return false;
	}
}
