jQuery(function($){
	
	$('a[rel=shadowbox]').addClass('shadowbox').append('<span class="zoom-icon"/>');
	
/* 
	 * Collapsible Archive List 
	 */
	$('.collapsible_archives_list li ul').hide();
	$('.collapsible_archives_list li ul:first').show();
	$('.collapsible_archives_list li:first').toggleClass('open');
	$('.collapsible_archives_list li:first img:first').attr('src', '/wp-content/themes/DanWilsonMusic/assets/img/arrow-down.png');
	
	$('.collapsible_archives_list li .haschildren').click(function(e){
		e.preventDefault();
		$(this).parent().children('ul').toggle('fast');
		$(this).parent().toggleClass('open');
		//var src = ($(this).attr("src") === "/wp-content/themes/DanWilsonMusic/assets/img/arrow-down.png") ? "/wp-content/themes/DanWilsonMusic/assets/img/arrow-right.png" : "/wp-content/themes/DanWilsonMusic/assets/img/arrow-down.png";

		var src = ($(this).parent().hasClass('open')) ? '/wp-content/themes/DanWilsonMusic/assets/img/arrow-down.png' : '/wp-content/themes/DanWilsonMusic/assets/img/arrow-right.png';
		$(this).attr('src', src);
		
	});


	/* 
	 * Player Bar 
	 * /
	$('.player-content-expanded').hide();
	var playerOpen = false;
	
	$('.player-content-collapsed').click(function(){
		togglePlayerContent();
	});
	
	function togglePlayerContent(){
		$('.player-content-expanded').slideToggle('fast');
		if(playerOpen){
			$(this).removeClass('open').addClass('closed');
			$('#player-toggle').removeClass('open').addClass('closed');
			playerOpen = false;
		} else {
			$(this).removeClass('closed').addClass('open');
			$('#player-toggle').removeClass('closed').addClass('open');
			$('#player-album-list').jcarousel({
				vertical: true,
				scroll: 1
			});
			playerOpen = true;
		}
		return false;
	}
	/* // */



	/* 
	 * Main Navigation and Menus 
	 */
	$('.navigation .menu-flyout').hide();
	
	function navHovers(){
		$(".menu-mainli").hover(
			function(){
				// on mouse over
				$('.menu-flyout').hide().clearQueue(); // hide all flyouts
				$('.menu-mainlink').removeClass('menu-mainlink-MOUSEOVER').clearQueue(); // remove all over states
				$(this).children('.menu-mainlink').addClass('menu-mainlink-MOUSEOVER');
				$(this).children(".menu-flyout").show(0);
			},
			function(){
				// on mouse out
				$(this).children(".menu-mainlink").delay(800).queue(function(next){
					$(this).removeClass('menu-mainlink-MOUSEOVER');
					next();
				});
				$(this).children(".menu-flyout").delay(800).hide(0);
		});
	}
	
	setTimeout(navHovers,1000);
	
	/* // */





	/* 
	 * Newsletter
	 */
	var DefaultValues = new Array();
	DefaultValues[0] = 'Enter Name';
	DefaultValues[1] = 'Enter Email (required)';
	DefaultValues[2] = 'Send a message to Dan!';
	var mouseOverForm = false;

	function resetForm(){
		$('#cm-name').val(DefaultValues[0]);
		$('#cm-email').val(DefaultValues[1]);
		$('#cm-comments').val(DefaultValues[2]);
		$('#form-email-sign-up').slideUp('fast');
		$(window).unbind('click');
	}
	
	$('#form-email-sign-up').hover(function(){ mouseOverForm = true; },function(){ mouseOverForm = false; });
	
	$("input[type=text][title],textarea[title]").each(function() {  
		$(this).val($(this).attr("title"));  
		if($.trim($(this).val()) == "")  
			$(this).val($(this).attr("title"));  
		$(this)
		.focus(function() {  
			if($(this).val() == $(this).attr("title")) $(this).val("");  
		})  
		.blur(function() {  
			if($.trim($(this).val()) == "") $(this).val($(this).attr("title"));  
		});  
	});

	 
	$('#newsletter-signup').click(function(e){
		e.preventDefault();
		$('#form-email-sign-up').slideDown('fast', function(){
			$(window).click(function(){
				if(!mouseOverForm){
					resetForm();
				}
			});
		});
	});
	
	$('#cm-cancel').click(function(e){ 
		e.preventDefault();
		resetForm();
	});
	
	function validateForm(){
		var re = new RegExp(),valid=true;
		re.pattern = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
		var email = $('#cm-email').val();
		if( !re.test(email) || email == DefaultValues[1] || email == 'Email is required' || email == ''){
			valid=false;
			$('#cm-email').val('Email is required.');
		}
		return valid;
	}
	
	$('#NewsletterForm').submit(function(){ 
		if( validateForm() ){
			$.ajax({
				type: "POST",
				url: "/wp-content/themes/DanWilsonMusic/Subscriber.Add.php",
				data: "name=" + $('#cm-name').val() + "&email=" + $('#cm-email').val() + "&comments=" + $('#cm-comments').val(),
				success: function(msg){
					resetForm();
					$('#div-confirm').slideDown('fast').delay(2000).slideUp('fast');
				}
			});
		}
		return false; 
	});
/* // */
	

	
	
	/* 
	 * External Links 
	 */
	$.expr[':'].external = function(obj){
		return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname);
	};
	$('a:external').addClass('external').attr('target','_blank');
});

function closeSignUpForm(){
	jQuery('#form-email-sign-up').slideUp('fast');
}

Shadowbox.init({
	overlayColor: "#160b07",
	overlayOpacity: 0.7
});

/* Hyphenation */
Hyphenator.run();

