function pullcharacter(){
	var series = $('#seriesselect :selected').val();
  var series2 = $('#newseries input').val();
  	
  if (series2 != '' && series == -1) {
  	var selseries = series2;
  	$("option:first", "select#seriesselect").attr("selected","selected");
  	$('#oldcharacter').hide();
  }
  else {
  	if (series != '-1') {
  		var selseries = series;
  		$('#newseries input').val('');
  		$('#newseries').hide();
  		$('#characterform').show();
  		$('#newcharacter').show();
  		$.ajax({
				beforeSend: function(){$('#characterform').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
 				method: "get", url: "/func2/pullcharacter.php", data: "seriesid=" +selseries,
 				success: function(html){
					$('#characterform').html(html);
 				}
 			});
  	}
  }
}
function pullwigname(){
	var company = $('#wigcompanyselect :selected').val();
  var company2 = $('#newcompany input').val();
  
  if (company2 != '' && company == -1) {
  	var selcompany = company2;
  	$("option:first", "select#wigcompanyselect").attr("selected","selected");
  	$('#oldwigname').hide();
  }
  else {
  	if (company != '-1') {
  		var selcompany = company;
  		$('#newcompany input').val('');
  		$('#newcompany').hide();
  		$('#wignameform').show();
  		$('#newwigname').show();
  		$.ajax({
				beforeSend: function(){$('#wignameform').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
 				method: "get", url: "/func2/pullwigname.php", data: "companyid=" +selcompany,
 				success: function(html){
					$('#wignameform').html(html);
					$('#newwig').hide();
					
 				}
 			});
  	}
  	else {
  		$("option:first", "select#wigcompanyselect").attr("selected","selected");
  		$('#oldwigname').hide();
  	}
  }
}

function resortpics() {
var pics;
  	
  	$('#activepics').tableDnD({
  		onDrop: function(table, row) {
  			pics = $.tableDnD.serialize();
  		},
  		dragHandle: "dragHandle"
  	});
  
  	$('#reorder').click(function() {
  		$.ajax({
	 			beforeSend: function(){$('#orderresult').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
 				method: "get", url: "/func2/updateorder.php", data: "cat=pics&" +pics,
 				success: function(html){
	 				$('#orderresult').html(html);
	 				resortpics();
 				}
 			});
 			return false;
  	});	
}
function toggleChecked(status) {
	$(".messagerow").each( function() {
 		$(this).attr("checked",status);
 	})
}

$(document).ready(function() {
	$('#update').hide();
	$('#remove').hide();
	$('#replace').hide();
	$('#tag').hide();
	$('#hide').hide();
	$('#removephototag').hide();
	$('#copy').hide();
	$('#move').hide();
	$('#costumeremoval').hide();
	$('#credit').hide();
	$('#vipmessage').hide();
	
	
	$('input[name=costype]:radio').click(function() {
		var costype;
		costype = $('input[name=costype]:checked').val();
		if (costype == 'Costume') {
			$('#costumecredit').show();
			$('#wigcredit').show();
			$('propcredit').show();
		}
		else if (costype == 'Prop') {
			$('#costumecredit').hide();
			$('#costumemaker').hide();
			$('#costumemaker2').hide();
			$('#wigcredit').hide();
			$('#wigmaker').hide();
			$('#wigmaker2').hide();
			$('#propcredit').show();
		}
		else if (costype == 'Wig') {
			$('#costumecredit').hide();
			$('#costumemaker').hide();
			$('#costumemaker2').hide();
			$('#wigcredit').show();
			$('#propcredit').hide();
			$('#propmaker').hide();
			$('#propmaker2').hide();
		}
	});
	$('input[name=costumemaker]:radio').click(function() {
		var maker;
		maker = $('input[name=costumemaker]:checked').val();
		if (maker == '') {
			$('#costumemaker').show();
			$('#costumemaker2').hide();
		}
		else {
			if (maker == -1) {
				$('#costumemaker').hide();
				$('#costumemaker2').show();
			}
			else {
				$('#costumemaker').hide();
				$('#costumemaker2').hide();
			}
		}
	});
	
	$('input[name=wigmaker]:radio').click(function() {
		var maker;
		maker = $('input[name=wigmaker]:checked').val();
		if (maker == '') {
			$('#wigmaker').show();
			$('#wigmaker2').hide();
		}
		else {
			if (maker == -1) {
				$('#wigmaker').hide();
				$('#wigmaker2').show();
			}
			else {
				$('#wigmaker').hide();
				$('#wigmaker2').hide();
			}
		}
	});
	
	$('input[name=propmaker]:radio').click(function() {
		var maker;
		maker = $('input[name=propmaker]:checked').val();
		if (maker == '') {
			$('#propmaker').show();
			$('#propmaker2').hide();
		}
		else {
			if (maker == -1) {
				$('#propmaker').hide();
				$('#propmaker2').show();
			}
			else {
				$('#propmaker').hide();
				$('#propmaker2').hide();
			}
		}
	});
	
	$('input[name=storestatus]:radio').click(function() {
		var storestatus;
		storestatus = $('input[name=storestatus]:checked').val();
		if (storestatus == 1) {
			$('#storeoptions').show();
		}
		else {
			$('#storeoptions').hide();
		}
	});
		
	$('#newseriesclick a').click(function() {
		$('#newseries').show();
		$('option:first', 'select#seriesselect').attr('selected','selected');
		$('#oldcharacter').hide();
		$('#newcharacter input').val('');
		$('#newcharacter').show();
		$('#characterform').hide();
		return false;
	});
	
  $('#newcharacterclick a').click(function() {
		$('#newcharacter input').val('');
		$('#newcharacter').show();
		return false;
	});
	
	$('#newcompanyclick a').click(function() {
		$('option:first', 'select#wigcompanyselect').attr('selected','selected');
		$('#oldwigname').hide();
		$('#newwigname input').val('');
		$('#wignameform').hide();
		$('#newcompany').show();
		$('#newwigname').show();
		$('#newwig').show();
		return false;
	});
	
	$('#newwignameclick a').live('click', function() {
		$('#newcompany').hide();
		$('#newwigname input').val('');
		$('#newwigname').show();
		$('#newwig').show('fast');
		return false;
	});
	
	$('input[name=wiglinktype]:radio').click(function() {
		var wiglink = $('input[name=wiglinktype]:checked').val();
		if (wiglink == 'manual') {
			$('#wiglinkseries').show();
		}
		else {
			$.ajax({
	 			beforeSend: function(){$('#wiglinkarea').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
				method: "get", url: "/func2/pullentries.php", data: "linktype=" +wiglink,
				success: function(html){
	 				$('#wiglinkarea').html(html);
				}
			});	
		}
	});
	
	$('li.medium').live('click', (function(e) {
		$('li.selected').removeClass('selected');
		$(this).addClass('selected');
		$(this).find('input:radio').attr('checked', true);
		
		
		
			
	}));
	$('#showoptions a').click(function() {
		$('#optional').show();
		return false;
	});
	
	$('#newconclick a').click(function() {
		$('#newcon').show();
		return false;
	});
	
	$('#updatepic a').click(function() {
		$('#update').show();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').hide();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		
	});
	
	$('#removepic a').click(function() {
		$('#update').hide();
		$('#remove').show();
		$('#replace').hide();
		$('#credit').hide();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		
	});
	
	$('#replacepic a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').show();
		$('#credit').hide();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		
	});
	
	$('#creditpic a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').show();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		
	});

	$('#tagpic a').click(function() {
		var picid = $(this).attr('rel');
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').hide();
		$('#tag').show();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		$.ajax({
 			beforeSend: function(){$('#tag').html('<div class="normal"><img src="/func2/images/loading.gif"> Please Wait...</div>');},
			method: "get", url: "/func2/phototaglistform.php", data: "picid=" +picid,
			success: function(html){
 				$('#tag').html(html);
 				
			}
		});
	});	
	
	$('#hidepic a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').show();
		$('#tag').hide();
		$('#hide').show();
		$('#removephototag').hide();
		$('#copy').hide();
		$('#move').hide();
		
	});
	
	$('#removecredit a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').show();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').show();
		$('#copy').hide();
		$('#move').hide();
		
	});
	
	$('#copypic a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').hide();
		$('#tag').hide();
		$('#hide').hide();
		$('#removephototag').hide();
		$('#copy').show();
		$('#move').hide();
		
	});
	
	$('#movepic a').click(function() {
		$('#update').hide();
		$('#remove').hide();
		$('#replace').hide();
		$('#credit').hide();
		$('#tag').hide();
		$('#removephototag').hide();
		$('#hide').hide();
		$('#copy').hide();
		$('#move').show();
		
	});
	
	$('#massphotographer').click(function() {
		$('#massaddphotographer').attr('checked', true);
	});
	
	$('#massphotolevel').click(function() {
		$('#masschangeaccess').attr('checked', true);
	});
	
	$('#removecostume a').click(function() {
		$('#costumeremoval').show();
		$('#submitform').hide();
	});
	
	$('#noremove').click(function() {
		$('#costumeremoval').hide();
		$('#submitform').show();
	});
	
	$('#sendvipmessage a').click(function() {
		$('#vipmessage').show();
	});
	
	$('#cancelvipmessage').click(function() {
		$('#vipmessage').hide();
	});
	
	$('#notifications').click(function() {
		$('#notificationsettings').toggle();
		return false;
	});
	
  $('#activecostumes tr').mouseover(function() {
  	$(this).addClass("highlightrowon");
  }).mouseout(function() {
  	$(this).removeClass("highlightrowon");
  });
  
  $('a#userclick').click(function() {
  	$('#userinfobox').toggle();
  	return false;
  });
  
  $('#activecostumes').tableDnD({
  	onDrop: function(table, row) {
  		var costumes = $.tableDnD.serialize();
  		$.ajax({
  			beforeSend: function(){$('#orderresult').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
  			method: "get", url: "/func2/updateorder.php", data: "cat=costumes&" +costumes,
  			success: function(html){
  				$('#orderresult').html(html);
  			}
  		});
  	},
  	dragHandle: "dragHandle"
  });
  
  
  $('#favoritecosplayers').tableDnD({
  	onDrop: function(table, row) {
  		var favcosplay = $.tableDnD.serialize();
  		$.ajax({
  			beforeSend: function(){$('#cosplayerorderresult').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
  			method: "get", url: "/func2/updateorder.php", data: "cat=favcosplayers&" +favcosplay,
  			success: function(html){
  				$('#cosplayerorderresult').html(html);
  			}
  		});
  	},
  	dragHandle: "dragHandle"
  });
  
  $('#favoriteseries').tableDnD({
  	onDrop: function(table, row) {
  		var favseries = $.tableDnD.serialize();
  		$.ajax({
  			beforeSend: function(){$('#orderresult').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
  			method: "get", url: "/func2/updateorder.php", data: "cat=favseries&" +favseries,
  			success: function(html){
  				$('#seriesorderresult').html(html);
  			}
  		});
  	},
  	dragHandle: "dragHandle"
  });
  
  $('#favoritephotographers').tableDnD({
  	onDrop: function(table, row) {
  		var favcosplay = $.tableDnD.serialize();
  		$.ajax({
  			beforeSend: function(){$('#cosplayerorderresult').html('<div class="normal"><img src="stuff/loading.gif"> Please Wait...</div>');},
  			method: "get", url: "/func2/updateorder.php", data: "cat=favphotog&" +favcosplay,
  			success: function(html){
  				$('#cosplayerorderresult').html(html);
  			}
  		});
  	},
  	dragHandle: "dragHandle"
  });
  resortpics();
  
  $('#leaveevent').click(function () {
 		$('#leaveeventbox').show();
 		return false;
 	});
 	
 	$('.closecommand').click(function() {
 		$(this).parent('div').hide();
 	});
 	
 	$('#usertype li').click(function () {
 		var usercategory = $('input[name=usercategory]:checked').val();
		if (usercategory == 'Volunteer') {
			$('#volunteerform').show();
		}
		else if (usercategory == 'Admin') {
			$('#volunteerform').show();
		}
		else {
			$('#volunteerform').hide();
		}
	});
});
