// delay plugin
$.fn.delay = function(time, callback){
	// Empty function:
	jQuery.fx.step.delay = function(){};
	// Return meaningless animation, (will be added to queue)
	return this.animate({delay:1}, time, callback);
}

$(document).ready(function() {

	if(document.body.id == "home") {
	  
	}

	if(document.body.id == "itunes") {
		$('#back_home').click(function () { 
			$(this).animate({
	    	opacity: 0,
	    	left: '-=200'
	  		}, 500, function() {
	    	// Animation complete.
	    	});
	  	$('#back_home_options').animate({
	    	left: '10px'
	  		}, 500, function() {
	    	// Animation complete.
	  	});
	  	return false;
		});

		/* itunes playlist page */
		$("form#itunes_playlist").submit(function() {
		
			var email = $("input#email").val();
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			
				if (email == "" || email == "Your Email" || reg.test(email) == false) {
					$("#itunes_bar").css({'background-position' : '0 -48px'});
					$("input#email").select();
					$("input#email").attr("value","");
					return false;
				}
						
			var dataString = '&email=' + email;
		});
	}
	
	if(document.body.id == "iamcreation") {
		$('#back_home').click(function () { 
			$(this).animate({
	    	opacity: 0,
	    	left: '-=200'
	  		}, 500, function() {
	    	// Animation complete.
	    	});
	  	$('#back_home_options').animate({
	    	left: '10px'
	  		}, 500, function() {
	    	// Animation complete.
	  	});
	  	return false;
		});
		
		$('#view_written').click(function() {
			$(this).addClass('active');
			$('#video_testimony').hide();
			$('#share_video').hide();
			$('#view_video').removeClass('active');
			$('#written_testimony').show();
			return false;
		});
	
		$('#view_video').click(function() {
			$(this).addClass('active');
			$('#written_testimony').hide();
			$('#view_written').removeClass('active');
			$('#video_testimony').show();
			$('#share_video').show();
			return false;
		});
	
		$("#share_button").toggle(function(){
			$('#share_video').animate({
	    		height: "76px"
	  			}, 500, function() {
	    		// Animation complete.
	    	});
			}, function () {
			$('#share_video').animate({
		  		height: "28px"
					}, 500, function() {
		  		// Animation complete.
		  	});
		  return false;
		});
	}

if(document.body.id == "worship") {
		$('#back_home').click(function () { 
			$(this).animate({
	    	opacity: 0,
	    	left: '-=200'
	  		}, 500, function() {
	    	// Animation complete.
	    	});
	  	$('#back_home_options').animate({
	    	left: '10px'
	  		}, 500, function() {
	    	// Animation complete.
	  	});
	  	return false;
		});
	
		$("#share_button").toggle(function(){
			$('#share_video').animate({
	    		height: "76px"
	  			}, 500, function() {
	    		// Animation complete.
	    	});
			}, function () {
			$('#share_video').animate({
		  		height: "28px"
					}, 500, function() {
		  		// Animation complete.
		  	});
		  return false;
		});
	}

	$(".autocomplete_off").attr("autocomplete","off");
	
	// for table row
	//$("table.styled tbody tr:odd").css("background-color", "#e0f7f8");
	//$("ul.itunes_playlist li:odd").css("background-color", "#e0f7f8");

	// wallaper thumbnail selelctor and image swap
	$("ul.wallpaper_disp li:first").show();
	$("ul.wallpaper_thumbnails li:first").addClass('active');
	$("ul.wallpaper_thumbnails li a").click(function(){
		$("ul.wallpaper_thumbnails li").removeClass('active');
		$(this).parent().addClass('active');
		var currentTab = $(this).attr('href');
		$("ul.wallpaper_disp li").hide();
		$(currentTab).show();
		return false;
	});

	// testimony
	$("#random_testimony").click(function(){ 
		$("#testimony").load("../includes/random_testimony.php"); 
	});

	// input with fading labels
	$('div.form_wrap_overlay input.text, div.form_wrap_overlay textarea.text').focus(function () {
		if ($(this).val() == ""){
			$(this).prev("label").find("span").css("display","block").fadeTo(400, 0.4);
		} else {
			$(this).prev("label").find("span").hide();
		}
	});
	
	$('div.form_wrap_overlay input.text, div.form_wrap_overlay textarea.text').blur(function () {
		if ($(this).val() == ""){
			$(this).prev("label").find("span").css("display","block").fadeTo(300, 1.0);
		} else {
			$(this).prev("label").find("span").hide();
		}
	});
	
	if ($('div.form_wrap_overlay input.text, div.form_wrap_overlay textarea.text').val() == ""){
		$(this).prev("label").find("span").css("display","block").fadeTo(300, 1.0);
	} else {
		$(this).prev("label").find("span").hide();
	}

	$('div.form_wrap_overlay input.text, div.form_wrap_overlay textarea.text').keypress(function () {
		$(this).prev("label").find("span").hide();
	});
	
});