/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function() {
    //dynamicke nahrazeni poll divu v clanku obsahem z JSONu
    $('div[id*=article-poll-]').each(function() {
        var id = $(this).attr('id');
        $(this).replaceWith(articlePollsHtmlToJson[id]);
    });
    
    //dynamicke nahrazeni poll divu obsahem z JSONu
    $('div[id*=poll-]').each(function() {
        var id = $(this).attr('id');
        $(this).replaceWith(pollsHtmlToJson[id]);
    });
    
    //hlasovani
    $('a.poll-option-vote-enabled').livequery('click', function() {
        var href = $(this).attr('href');
        var pollDiv = $(this).parent().parent().parent();
        var pollDivClasses = pollDiv.attr('class');

        //zablokovani celeho boxu s anketou
        pollDiv.blockCustom01();

        //trackujeme do GA
        trackPageview(href);

        //zjistujeme typ boxu, ktery potrebujem vratit
        var type = '';
        if (pollDivClasses.indexOf('poll-box-01') != -1) {
            type = 'poll-box-01';
        } else if(pollDivClasses.indexOf('poll-box-02') != -1) {
            type = 'poll-box-02';
        }

        //potreba poslat vsecky bannerove pozice, ktere jsou na strance
        var bannersPositions = getBannersPositions();
        $.get(href,
            {
                'type': type,
                'bannersPositions': bannersPositions
            },
            function(data) {
                pollDiv.replaceWith(data['pollHtml']);
                swapBanners(data['bannersHtml']);
                pollDiv.unblock();
            }
        );       
        
        return false;
    })
})


