var feedAccordion = null;

function makeAccordion() {
    feedAccordion = jQuery('#accordionSmall .accordion').accordion({
        'autoHeight':false,
        header: "a.faq-header"
    });
}

jQuery(document).ready(function() {
    makeAccordion();

    jQuery('a.favorite_add_detail').click(function(){
        var clickedOn = jQuery(this);
        jQuery.post(
            jQuery(this).attr('href') + '/format/json',
            null,
            function(data) {
                var answer = eval(data);
                try {
                    if (answer.data.scalar.success.length > 0) {
                        clickedOn.toggleClass('favorite_partner');
                    } else if (answer.data.scalar.redirect.length > 0) {
                        window.location.href = answer.data.scalar.redirect;
                    } else if (answer.data.scalar.error.length > 0) {
                       // console.log(answer.data.scalar.error);
                    }
                } catch(e) {
                   // console.log(e.message);
                }
            },
            "json");
        return false;
    });
    
    jQuery('.videobox').each(function(n,i){
        hoehe = jQuery(this).find('.videoflash').outerHeight() + 26;
        if(jQuery(this).find('.dialoglink').length > 0){
            hoehe += jQuery(this).find('.dialoglink').outerHeight() + 8;
        }
        
        jQuery(this)
            .addClass('video'+n)
            .dialog({
                width: 360,
                height: hoehe,
                autoOpen: false,
                resizable: false,
                draggable: false,
                closeText: 'Schliessen',
                dialogClass: 'video',
                close: function(event, ui) {
                    if(jQuery(this).dialog( "isOpen" )){
                        jQuery('#flvplayer_wm').each(function(n,player){
							try {
							 player.externalStop();
							}
							catch(err){
							}
                        })
                    }
                }
            });
    });
    
    jQuery(".zeigevideo").each(function(n,i){
        jQuery(this)
            .click(function(){
                jQuery('.videobox').dialog('close');
                jQuery('.videobox.video'+n).dialog('open');
                return false;
                });
    });

    jQuery('.ui-dialog').draggable();

});


