var downloadEmail='';
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false;
		}else return true;
}
function downloadFile(id){

	var tempIFrame = document.createElement('iframe');
	var holderdiv=document.getElementById('fdownload');

	tempIFrame.src='/includes/fdownload.php?fileid='+id;
	tempIFrame.width=0;
	tempIFrame.height=0;
	holderdiv.appendChild(tempIFrame);
}

function submitEmail(email){

	$.ajax({
		type: "POST",
		url: "/saveEmail.php",
		data: "email="+email,
		success: function(msg){
			//alert('email sent'.msg);
			return false;
		}
	});
	return false;
	
}

$(document).ready(function(){
		/*				   
	$('#mainContent img:first').fadeIn(1000, function() {
		$('#mainContent').cycle({ 
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 6000,
		speed: 3000
		});
	});
	*/
	$("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'dark_rounded',
		autoplay: true
	});
	$('#downloadEmail').click(function(){
	
		if($(this).val()=='Your Email'){
			$(this).val('');	
		}
		$(this).click(function(){
							   return false;
							   });
	
	});
	$('#downloadSubmit, #highDownload').click(function(){
		downloadEmail=$('#downloadEmail').val();
		if(echeck(downloadEmail)){
			//trigger download
			downloadFile(1);
			submitEmail(downloadEmail)
			$('#emailSubmit').html('<br>THANKS!<br><br>');
		}else{
			alert('Please enter a valid email address');	
		}
		return false;
	});
	/*
	$('#lowDownload').click(function(){
		
			downloadFile(0);
			
		return false;
	});
	*/
	$("#mp3url").focus(function(){
	// only select if the text has not changed
		if(this.value == this.defaultValue){
			this.select();
		}
	});
	
	
});