$(document).ready(function() {

	/* 	EVENT LIST JS */
	
	$('#list_modifier_container').hover(function() {
		$('#list_modifier_dropdown').show();
	}, function() {
		$('#list_modifier_dropdown').hide();
	});
	
	$('#event_list_checkbox_master').click(function () {
		var thisCheckbox = $(this);
		var checkState = $(this).attr('checked');
		if (checkState) {
			$('.event_list_checkbox_slave').attr('checked', true);
		} else {
			$('.event_list_checkbox_slave').attr('checked', false);
		}
	});
	
	$('.event_modifier_link').click(function(e) {
		e.preventDefault();
		var event_ids = [];
		$('.event_list_checkbox_slave').each(function() {
			if ($(this).attr('checked') == true) {
				var checkboxVal = $(this).val();
				event_ids.push(checkboxVal);
			}
		});
		var action = $(this).attr('alt');
		$.get('../controllers/admin/event_status_controller.php', {'event_ids[]': event_ids, action: action, source: "list"}, function(response) {
			if(response){
				window.location.reload();
			}
		});
	});
	
	/* 	EVENT EDIT JS */

	$('#event_image_upload_form').ajaxForm(function(returnValue) {
		$('#event_photo_container').html('<img class="event_image" src="' + returnValue + '">');
		$('#event_image_delete_link').show();
	});

	$('#event_flyer_upload_form').ajaxForm(function(returnValue) {
		$('#event_flyer_container').html("<a class=\"event_flyer_preview\" href=\"" + returnValue + "\" ></a><br><a href=\"" + returnValue + "\" target=\"_blank\">Click here to download.</a><br>");
		$('a.event_flyer_preview').media({width:400, height:300});
		$('#event_flyer_delete_link').show();
	});
	
	$('a.event_flyer_preview').media({width:400, height:300});
	
	$('#event_flyer_delete_link').click(function() {
		var deleteConfirmed = confirm("Are you sure you want to delete this flyer?  This cannot be undone.")
		if (deleteConfirmed){
			event.preventDefault();
			var url = $(this).attr("href");
			$.post(url);
			$('#event_flyer_container').html("(None)<br><br>");
			$('#event_flyer_delete_link').hide();
			$('#event_flyer_upload_form .file_input').val("");
		} else {
			return false;
		}
	});

	$('#event_image_delete_link').click(function() {
		var deleteConfirmed = confirm("Are you sure you want to delete this photo?  This cannot be undone.")
		if (deleteConfirmed){
			event.preventDefault();
			var url = $(this).attr("href");
			$.post(url);
			$('#event_photo_container').html("(None)<br><br>");
			$('#event_image_delete_link').hide();
			$('#event_image_upload_form .file_input').val("");
		} else {
			return false;
		}
	});
	

	/* 	MEMBER EDIT JS */

	$('#member_image_upload_form').ajaxForm(function(returnValue) {
		$('#member_photo_container').html('<img class="member_image" src="' + returnValue + '">');
		$('#member_image_delete_link').show();
	});

	$('#member_image_delete_link').click(function() {
		var deleteConfirmed = confirm("Are you sure you want to delete this photo?  This cannot be undone.")
		if (deleteConfirmed){
			event.preventDefault();
			var url = $(this).attr("href");
			$.post(url);
			$('#member_photo_container').html("(None)<br><br>");
			$('#member_image_delete_link').hide();
			$('#member_image_upload_form .file_input').val("");
		} else {
			return false;
		}
	});
	
		
	/* STUDIO LIST JS */
	$('.studio_modifier_link').click(function(e) {
		e.preventDefault();
		var studio_ids = [];
		$('.event_list_checkbox_slave').each(function() {
			if ($(this).attr('checked') == true) {
				var checkboxVal = $(this).val();
				studio_ids.push(checkboxVal);
			}
		});
		var action = $(this).attr('alt');
		$.get('../controllers/admin/studio_status_controller.php', {'studio_ids[]': studio_ids, action: action, source: "list"}, function(response) {
			if(response){
				window.location.reload();
			}
		});
	});
	
	
	/* MEMBER LIST JS */
	$('.member_modifier_link').click(function(e) {
		e.preventDefault();
		var member_ids = [];
		$('.event_list_checkbox_slave').each(function() {
			if ($(this).attr('checked') == true) {
				var checkboxVal = $(this).val();
				member_ids.push(checkboxVal);
			}
		});
		var action = $(this).attr('alt');
		$.get('../controllers/admin/member_status_controller.php', {'member_ids[]': member_ids, action: action, source: "list"}, function(response) {
			if(response){
				window.location.reload();
			}
		});
	});
	
	
	/* FOOTER JS */
	$('#footer_link_facebook').hover(function() {
			$('#footer_tooltip_facebook').show();
		}, function() {
			$('#footer_tooltip_facebook').hide();
		}
	);
	
	$('#footer_link_twitter').hover(function() {
			$('#footer_tooltip_twitter').show();
		}, function() {
			$('#footer_tooltip_twitter').hide();
		}
	);
	
	$('#footer_link_newsletter').hover(function() {
			$('#footer_tooltip_newsletter').show();
		}, function() {
			$('#footer_tooltip_newsletter').hide();
		}
	);
	
	
	$('.admin_file_upload_form').ajaxForm(function(returnValue) {
		alert("File Uploaded Successfully!  Reload the page to view the thumbnail.");
/*
		$(this).siblings(".admin_file_container").html("File Uploaded Successfully!  Reload the page to view the thumbnail.<br><br><a href=\"" + returnValue + "\" target=\"_blank\">Click here to download.</a><br><br>");
		$(this).siblings(".admin_file_delete_link").show();
*/
	/* 		$(this).siblings(".admin_file_container").html("<iframe style=\"border-style: none;\" src=\"http://docs.google.com/viewer?url=" + returnValue + "&embedded=true\" height=\"390\" width=\"400\"></iframe><br><a href=\"" + returnValue + "\" target=\"_blank\">Click here to download.</a><br><br>"); */
	});
	
	$('.admin_file_delete_link').click(function() {
		var deleteConfirmed = confirm("Are you sure you want to delete this flyer?  This cannot be undone.")
		if (deleteConfirmed){
			event.preventDefault();
			var url = $(this).attr("href");
			$.post(url);
			$(this).siblings(".admin_file_container").html("(None)<br><br>");
			$(this).hide();
			$(this).siblings(".admin_file_upload_form").children(".file_input").val("");
		} else {
			return false;
		}
	});


	
	

});

