$j = jQuery.noConflict();

tinyMCE.init({
    mode: 'specific_textareas',
    editor_selector: 'mceEditor',
    content_css: '/css/styles.css',
    body_id: 'content',
    theme: 'advanced'
});

function updatePrice(){
    width = $j('#ProductWidth').val();
    height = $j('#ProductHeight').val();
    product_price = $j('#ProductPrice').val();

    total = height * width * product_price / 1000000;

    $j('#price').html(total.toFixed(2).replace('.', ','));
}

$j(document).ready(function(){
    $j('#ProductHeight').keyup(function(){updatePrice();});
    $j('#ProductWidth').keyup(function(){updatePrice();});

    initColorbox();

    $j('label.required').append('*');

    if($j('#ProductUploadButton').length > 0){
        new AjaxUpload('#ProductUploadButton', {
            autoSubmit: true,
            action: '/admin/products/uploadImage/products',
            name: 'image',
            onComplete: function(file, response){
                if(response != 'error'){
                    $j('#ProductImageUrl').append('<option value=/img/products/' + response + '>' + response + '</option>');
                }
            }
        });
    }

    if($j('#ProductGroupUploadButton').length > 0){
        new AjaxUpload('#ProductGroupUploadButton', {
            autoSubmit: true,
            action: '/admin/products/uploadImage/products',
            name: 'image',
            onComplete: function(file, response){
                if(response != 'error'){
                    $j('#ProductGroupImageUrl').append('<option value=/img/products/' + response + '>' + response + '</option>');
                }
            }
        });
    }

    if($j('#CategoryUploadButton').length > 0){
        new AjaxUpload('#CategoryUploadButton', {
            autoSubmit: true,
            action: '/admin/products/uploadImage/products',
            name: 'image',
            onComplete: function(file, response){
                if(response != 'error'){
                    $j('#CategoryImageUrl').append('<option value=/img/products/' + response + '>' + response + '</option>');
                }
            }
        });
    }

    if($j('#PageUploadButton').length > 0){
        new AjaxUpload('#PageUploadButton', {
            autoSubmit: true,
            action: '/admin/products/uploadImage/pages',
            name: 'image',
            onComplete: function(file, response){
                if(response != 'error'){
                    $j('#UploadSucces').append(response + ' uploaded');
                }
            }
        });
    }
});
