{% extends "admin/change_form.html" %}
{% load adminmedia i18n %}

{% block extrahead %}{{ block.super }}
<style type="text/css">

	.create-variations li {list-style-type:none; float:left;}
	.create-variations label {width:120px;}
	.create-variations li label {width:auto;}
    .create-variations input {margin:-1px 3px 0px 5px;}
    .create-variations {margin-top:20px;}
	.sku input {width:100px !important;} 
	.tiny {font-size:70%;}
	.unit_price input, .sale_price input, .num_in_stock input {
	    width:50px !important;}
	.item img {vertical-align:middle; margin-right:10px !important;}
	.viewsitelink {display:none !important;}
	tr.add-row {display:none;}
	
</style>
<script type="text/javascript">

$(function() {

    var grappelli = $('.admin-title').length == 1;
    var django12 = $('#id_variations-__prefix__-sku').length == 1;

	// Move the "create variations" fieldset to under current variations.
	var variationsFieldset;
	if (grappelli) {
	    if (django12) {
	        variationsFieldset = $('#id_variations-INITIAL_FORMS').parent();
	    } else {
	        variationsFieldset = $('#id_variations-INITIAL_FORMS + ' + 
	            '.items').parent();
	    }
	} else {
	    variationsFieldset = $('#id_variations-INITIAL_FORMS + ' + 
	        'fieldset').parent().parent();
	}
	$('.create-variations').insertAfter(variationsFieldset);
	
	// Deselect default variation when another is selected as default.
	var variationDefaults = variationsFieldset.find(' .default input:checkbox');
	variationDefaults.click(function() {
		var clicked = $(this);
		if (clicked.attr('checked')) {
		    $.each(variationDefaults, function(i, variation) {
		        variation = $(variation);
		        if (variation.attr('name') != clicked.attr('name')) {
		            variation.attr('checked', false);
		        }
		    });
		}
	});
	
	// Grappelli removes the string value of inline objects, so show these 
	// for the product variations.
	if (grappelli) {
	    $.each(variationsFieldset.find('h3'), function(i, variation) {
	        variation = $(variation);
	        var title = variation.html().split('</b>')[1];
	        variation.parent().find('.sku input').before(
	            '<div class="tiny">' + title + '</div>');
	    });
	}
	
	// Remove Django 1.2's dynamic inline stuff.
	if (django12) {
	    if (grappelli) {
        	$('#id_variations-__prefix__-sku').parent().parent()
        	    .parent().remove();
        }
	} 
	

});

</script>
{% endblock %}
