$(function() {
    $('body').delegate('#body_search button, .product a.btn_order, td.stock span[title], #functionspane .functions a, #product_order a.btn_delete, #product_order a.btn_details', 'mouseenter', function(event) {
        event.preventDefault();
        try {
            $(this).data('qtip').show();
        } catch(e) {
            $(this).qtip({
                overwrite: true,
                show: {
                    ready: true
                },
                position: {
                    my: 'bottom left',
                    at: 'top center',
                    viewport: $(window)
                },
                style: {
                    classes: 'ui-tooltip-rounded ui-tooltip-title',
                    tip: true
                }
            });
        }
    });
    
    $('.product .product_profile a').click(function(event) {
        event.preventDefault();
    });

    $('.product_profiles_list .product_profile a.titleimage').click(function(event) {
        event.preventDefault();
    });
    
    $('body').delegate('#product_order .product textarea.fld_text, #product_order .product input.fld_amount', 'focus', function() {
        if ($(this).val() == $(this).data('default')) {
            this.value = '';
        }
    });
    $('body').delegate('#product_order .product textarea.fld_text, #product_order .product input.fld_amount', 'blur', function() {
        if ($.trim($(this).val()) == '') {
            this.value = $(this).data('default');
        }
    });
    
    $('body').delegate('#product_order a.btn_details', 'click', function(event) {
        event.preventDefault();
        $this = $(this);
        id = $this.data('id');
        $container = $('#' + id);
        try {
            $container.data('qtip').show();
        } catch(e) {
            $container.qtip({
                id: id,
                overwrite: true,
                content: {
                    title: {
                        text: $('#product_title_' + id).text(),
                        button: 'Schliessen'
                    },
                    text: $('#product_details_' + id)
                },
                hide: {
                    fixed: true,
                    event: false
                },
                show: {
                    ready: true,
                    event: false
                },
                position: {
                    my: 'top left',
                    at: 'top left',
                    adjust: {
                        x: -30,
                        y: -10
                    }
                },
                style: {
                    classes: 'ui-tooltip-product_details',
                    tip: false
                }
            });
        }
    });
});

function init_header_promotion() {
    if (!($.browser.msie && $.browser.version <= 6)) {
        $('#header_promotion > div').wrapAll('<div class="wrapper" style="width:100%; height:100%;" />');
        $('#header_promotion > .wrapper').cycle({fx: 'cover', timeout: 10000});
    }
}
