// $Id: photos.js,v 1.1.2.3 2008/08/27 17:02:16 eastcn Exp $
Drupal.behaviors.photos = function (context) {
	$('a.click-des').click( function() {
		$('#edit-des').val($('.desbody').text());
		$('#imgedit').show(300);
		$('.editdes').hide(300);
	});
	$('#edit-editnone').bind('click', function(){ 
		$('.editdes').show(300);
		$('#imgedit').hide(300);
		return false;
	});
	$('a.photos-vote').click(function(){
		//$(this).addClass('photos-vote-load');
		u = $(this).attr('href');
		url = u.split('destination');
		c = $(this).attr('class');
		cc = c.indexOf('photos-vote-up',0);
		$.get(url[0], function(x){
		   v = x.replace(',','/');
		   $('span.photos-vote-sum').text(v);
		});
		if(cc != -1 ) {
			$(this).addClass('photos-vote-up-x');
			$('span.photos-vote-down').removeClass('photos-vote-down-x') ;
		}else {
			$(this).addClass('photos-vote-down-x') ;
			$('span.photos-vote-up').removeClass('photos-vote-up-x') ;
		}
		$(this).removeClass('photos-vote-load');
		return false;
	});
	$('#imagesedit input[@type="checkbox"]').click( function(){
		$(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected');
	});
	$('.allck').click(function() {
		$("input[@class='form-checkbox']").each(function() {
			$(this).attr("checked", true);
			$(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected');
		})
	});
	$('.allnone').click(function() {
		$("input[@class='form-checkbox']").each(function() {
			$(this).attr("checked", false);
			$(this).parents('tr:first')[ this.checked ? 'addClass' : 'removeClass' ]('selected');
		})
	});
	$('input[@class="image-quote-link"]').hover(function(){
		$(this).select();
	},function(){
		return;
	}); 
	$('input[@class="photos-p"]').change(function() {
		i = 0;
		$('#edit-insert-wrapper').show(500);
		$("input[@class='photos-p'],input[@class='photos-pp']").each(function() {
			if($(this).attr("checked")) {
				t = $(this).val().split('&&&');
				img = '<a class="image-quote" href="http://' + window.location.host +'/photos/image/' + t[2] + '">' + '<img alt="' + t[1] + '" src="' + t[0] + '" /></a>\n';
				inval = $('#edit-insert').val();
				$('#edit-insert').val(inval + img).select();
				$(this).parents('.photos-quote').hide(600,function(){
					$(this).remove();
				});
				i++;
			}	
		})
		if(i > 0) {
			$('.photo-msg').text(Drupal.t('Please copy the above code.')).show(500);
		}
		return false;
	})
};