/*
    @author   : Igor "SkAZi" Potapov <igor@potapoff.org>
    @copyright: Plan-B Ltd.
    @requires : Mootools 1.2
*/


var killMe = function(){
    $('product-flash-door').destroy();
}

window.addEvent('domready', function(){
  
    enableLanguageSelect();
    
    if(detectFlash(9))
        new Swiff('/media/img/product.swf', {
            container: 'product-flash',
            width: "660px",
            height: "755px",
            id: 'flash-portfolio',
            vars: {
                'xmlPath': '/'+LANGUAGE_CODE+'/sales/product/product.xml'
            }
        });
    else {
        
        new Request({
            url: 'product/',
            onSuccess: function(html){
                $("product-flash").set('html', html);
                $$('#product-html ul').setStyle('height', 0).set('tween',{
                    'duration': 300,
                    'transition': 'back:in:out'
                });
                
                $$('#product-html a.local').addEvent('click', function(){
                    var p = $(this).getParent('h4').getNext('ul');
                        
                    if(p.getSize().y) p.tween('height', 0)
                    else p.tween('height', p.getScrollSize().y + 20);
                    
                    return false;
                });
            }
        }).get();
    }
    
    if(detectFlash(9) && frames.top.name.split(',').indexOf('door') == -1){
        new Swiff('/media/img/door.swf', {
            container: 'product-flash-door',
            width: "990px",
            height: "880px",
            id: 'flash-doors'
        });
        frames.top.name += ',door';
    } else
        killMe();
});
