swfobject.registerObject('bg', '9');
swfobject.registerObject('products_flash_content', '9');
swfobject.registerObject('mainpage_flash_content', '9');
var fi_protie_root = null;

jQuery(function()
{
    if (Cufon)
    {
        Cufon.replace
        (
            '#navigation ul li a span.title, #user_content_feedback p a, #your_own_recipe a',
            {
                fontFamily: 'Officina',
                fontSize: '11.5px',
                letterSpacing: '-0.5px'
            }
        );
        
        Cufon.replace
        (
            '#footer div.footer_link a',
            {
                fontFamily: 'Officina',
                fontSize: '11.5px'
            }
        );
        
        Cufon.replace
        (
            'h1.wendy, body.mainpage #lightbox_content h3',
            {
                fontFamily: 'Wendy',
                fontSize: '38px'
            }
        );
    }
    
    if (jQuery('object, embed').size() > 0)
    {
        jQuery('body').addClass('has_flash');
    }
    
    jQuery('#print_shopping_list').click(function()
    {
        window.print();
        return false;
    });
    
    jQuery('#lightbox_content').attr('rel', jQuery('#lightbox_content').height());
    
    jQuery('#lightbox_content').lightbox_resize();
    jQuery(window).resize(function()
    {
        jQuery('#lightbox_content').lightbox_resize();
    });
    
    if (jQuery('body.mainpage').size())
    {
//        var so = new SWFObject("/flash/oolannin.swf", "Oolannin", "955", "330", "9", "#FFF");
//        so.write("mainpage_flash");
//        var ticker = new SWFObject("/flash/ticker.swf", "Oolannin", "955", "22", "9", "#FFF");
//        ticker.write("ticker");
    }
    
    jQuery('#lightbox_matte').css('height', jQuery('body').height() + 'px');
    jQuery('#lightbox_matte, #lightbox_close').click(function()
    {
        if (fi_protie_root)
        {
            window.location = fi_protie_root;
            return true;
        }
        
        jQuery('#lightbox_matte, #lightbox_content').fadeOut(500, function()
        {
//            jQuery(this).remove();
        });
        
        return false;
    });
    
    jQuery('#lightbox_content div.wrapper').each(function(i)
    {
        var height = jQuery(this).height();
        var parent_height = jQuery(this).parent().height() - 40;
        
        if (height >= parent_height)
        {
            return;
        }
        
        var padding = Math.ceil((parent_height - height) / 2);
        jQuery(this)
            .addClass('post-align')
            .css('padding-top', padding + 'px');
    });
    
    jQuery('#mainpage_image a').click(function()
    {
        if (jQuery(this).hasClass('direct'))
        {
            return true;
        }
        
        var href = jQuery(this).attr('href');
        
        if (href.match(/\?/))
        {
            href += '&ajax';
        }
        else
        {
            href += '?ajax';
        }
        
        if (jQuery('#lightbox_matte').size() == 0)
        {
            jQuery('<div></div>')
                .attr('id', 'lightbox_matte')
                .appendTo('#content-text')
                .click(function()
                {
                    jQuery('#lightbox_matte, #lightbox_content').fadeOut(500);
                });
        }
        
        jQuery('#lightbox_matte').css('display', 'block');
        
        if (jQuery('#lightbox_content').size() == 0)
        {
            jQuery('<div></div>')
                .attr('id', 'lightbox_content')
                .appendTo('#content-text');
        }
        
        jQuery('#lightbox_content')
            .addClass('liftup')
            .fadeIn(0);
        
        jQuery('#lightbox_content')
            .addClass('mainpage')
            .load(href, {}, function()
            {
                jQuery('#lightbox_close a').click(function()
                {
                    jQuery('#lightbox_matte, #lightbox_content').fadeOut(500);
                    return false;
                });
                jQuery(window).resize(function()
                {
                    jQuery('#lightbox_content').lightbox_resize();
                });
                
                if (Cufon)
                {
                    Cufon.replace
                    (
                        '#lightbox_content h1, #lightbox_content h3',
                        {
                            fontFamily: 'Wendy',
                            fontSize: '38px'
                        }
                    );
                }
                else if (sIFR)
                {
                    sIFR.replace(wendy,
                    {
                        css: '.sIFR-root { color: #ee3225; font-size: 33px; margin-left: 5; leading: -10; }',
                        cursor: 'pointer',
                        wmode: 'transparent',
                        fitExactly: true,
                        selector: '#lightbox_content h1, #lightbox_content h3'
                    });
                }
                
            });
        return false;
    });
});

jQuery.fn.lightbox_resize = function()
{
    if (jQuery('body').hasClass('know'))
    {
//        return;
    }
    
    if (jQuery('#lightbox_content div.mainpage').size() > 0)
    {
        jQuery(this).css({
            top: '50%',
            marginTop: '-300px' 
        });
    }
    
    if (jQuery(window).height() > jQuery(this).height())
    {
        jQuery(this).css('height', jQuery(this).attr('rel') + 'px');
        jQuery(this).css('top', '50%');
        jQuery(this).css('margin-top', '-' + Math.ceil(Number(jQuery(this).attr('rel')) / 2) + 'px');
    }
    else
    {
        jQuery(this).css('height', jQuery(window).height() + 'px');
        jQuery(this).css('top', 0);
        jQuery(this).css('margin-top', 0);
    }
}
