window.addEvent('domready', function() {
	new mooInputLabel({
		inputs: $$('input.label')
	});
});

function OpenEnlargement(style,view,width,height,method,window_width,window_height) {
	method = method || 'crop';
	window_width = window_width || width;
	window_height = window_height || height;
	window.open("http://www.whatcutandwhere.com/i/hairstyles/" + style + "-" + view + "_photo-" + width + "-" + height + '-' + method +".jpg","enlargement","status=0,toolbar=0,menubar=0,location=0,resizeable=0,height=" + window_height + ",width=" + window_width);
}

function ImageDeleter(table,row,column) {
	var confirmation = confirm('Are you sure you want to delete this image?');
 	if (!confirmation) {
 		return;
 	}
 	else {
 		document.location.href='/cgi-local/image_deleter.cgi?table='+table+'&row='+row+'&column='+column;
 	}
}

function likeHairstyle(id,redirect) {
    var likeRequest = new Request({
        url: '/cgi-local/like.cgi',
        onSuccess: function(responseText) {
            if (responseText == 'ok') {
                if (redirect) {
                    document.location.href = redirect;
                }
                else {
                    location.reload();
                }
            }
            else {
                alert('You have already "liked" this hairstyle. Only one per person, please!');
            }
        }
    });
    likeRequest.send('id=' + id);
}

var mooInputLabel = new Class({
	Implements: [Options, Events],
	options: {
		inputs: [ ]
	},
	initialize: function(options) {
		this.setOptions(options);
		var inputs = this.options.inputs;
		var self = this;
		inputs.each(function(e) {
			e.addEvent('focus', function() {
				self.inputFocus(e);
			})
			.addEvent('blur', function() {
				self.inputBlur(e);
			})
			.setProperty('value', e.title)
			.addClass('inactive');
		});
	},
	inputFocus: function(x) {
		if ($(x).value == x.title) {
			$(x).value = '';
		}
		$(x).morph('input.active');
	},
	inputBlur: function(x) {
		if ($(x).value == '') {
			$(x).setStyle('color', '#fff');
			$(x).value = x.title;
			$(x).morph('input.inactive');
		}
		else if ($(x).value == x) {
			$(x).morph('input.inactive');
		}
		else {
			$(x).morph('input.active');
		}
	}
});

