$(document).ready(function() {
	
	$.each($('.mailer'),function() {
		Email.mailto(this,'ejt');
	});
	
	$('#text_email').click(function() {
			clearSearch(this);
	});
	
	$('#add_email').click(function() {
		$.ajax({
			   type: 'get',
			   method: 'add',
			   url: '/assets/cfc/ejtmusic.cfc',
			   data: {
				   method: 'add',
				   email_address: $('#text_email').val()
			   },
			   dataType: "json",
			   success: function(r) {
				    if ( r == 0) {
						$('#status').html('You\'re already signed up to receive notifications!');
						$('#status').css('background-color','yellow');
						$('#status').css('border-color','#fc0');
					} else if (r == 1) {
						$('#status').html('Thanks for adding you email address to my mailing list. You\'ll be kept in the loop about my live shows, recordings, and other music events!');
						$('#status').css('background-color','green');
						$('#status').css('border-color','darkgreen');
					} else if (r == 2) {
						$('#status').html('It looks like you might have typed your email address incorrectly. Please try again.');
						$('#status').css('background-color','red');
						$('#status').css('border-color','darkred');
					} else {
						$('#status').html('There was an error in processing you request. Please send me an email at: <a href="mailto:ejt@ejtmusic.com">ejt@ejtmusic.com</a>');
						$('#status').css('background-color','red');
						$('#status').css('border-color','darkred');
					}
					$('#status').slideDown('slow',function(){
						$(this).oneTime(3000,function(){
							$('#status').slideUp('slow');
						});
					});
					$('#status').fadeTo(0,.8);
			   }
		});
	});
	
	/* /E N A B L E  M A I L I N G  L I S T
	$('#kinetic').click(function() {
		window.scrollTo(0,0);
		$('#text_email').focus();
		clearSearch('#text_email');
	});
	/*
	
	/* E N A B L E  S L I D E S H O W
	$('#masthead_bg_images').cycle({
    	speed:4000
	});
	*/
	
	/*
	$('.tweets').tweet({
            username:'etelford',
            join_text:'',
            avatar_size:30,
            count:3,
            loading_text:'loading tweets...'
	});
	*/
});

function clearSearch(i) {
	if($(i).val() == 'Your email') {
		$(i).val('');
	}
}

function downloadFile(fileName) {
	$.ajax({
		type: 'POST',
		url: proxyUrl,
		data: 'method=downloadProxy&fileName=' + fileName + '&ip=' + ip + '&referer=' + referer + '&url=' + url,
		success: function(r) {
			window.location = 'http://' + fileName;
		}
	});

}

var Media = {
	video: function(targ,url,w,h) {
		$(targ).flash({
			swf: url,
			width:w,
			height:h
		});
	},
	vimeo: function(targ,vid_id,w,h) {
		$(targ).flash({
			swf: 'http://vimeo.com/moogaloop.swf?clip_id=' + vid_id + '&amp;server=vimeo.com',
			width:w,
			height:h,
			allowfullscreen:'true',
			allowscriptaccess:'always'			
		});
	},
	odeo: function(targ,url,dur) {
		$(targ).flash({
			swf: 'http://www.odeo.com/flash/audio_player_standard_gray.swf',
			width:300,
			height:52,
			flashvars:{
				valid_sample_rate: true,
				external_url: url,
				audio_duration: dur
			}
		});
	},
	goog: function(targ,url) {
		$(targ).flash({
			swf: 'http://www.google.com/reader/ui/3247397568-audio-player.swf',
			width:375,
			height:27,
			flashvars:{
				audioUrl: url
			}
		});
	}
};

var Email = {
    mailto: function (link, name, domain) {
		if (!domain) {
            domain = "ejtmusic.com";
        }

        link.href = "mailto:" + name + "@" + domain;
        link.onMouseover = null;
    }
};
