/**
* DEFINE DEFAULT VARIABLES
*
*/
var dom_ready = false;
var load_banners_onstart = true;
var slided_out;
var show_banners=false;
var IS_FLASH_SHOWN = true;
var banner_flashvar = ''; // holder for banner flashvar which we sent to player

var reload_page_on_log_out = false;
var after_login_function = "";		// procced this function after successful login
var	global_show_comments_page = 1;
var	global_show_comments_order = "asc";
var global_show_comments_type = "article";
var global_show_comments_id   = false;	
var global_show_comments_ajax = true;
var banner_flashvar = ''; // holder for banner flashvar which we sent to player



var videoList_div = new Array();
var videoList_img = new Array();

/**
*   Event loads when DOM is ready
*   This functions will fire right after HTML DOM is ready (before pictures load)
*/
window.addEvent('domready', function()
{
/**
 * SET VARIABLES
 */
dom_ready = true;

/**
 *  PRELOAD FOLLOWING IMAGES:
*/
preload_images = new Array(
        "/static/shared/img/icons/ajax.gif",
        "/static/shared/img/icons/ico_home_page_ff_on.gif",
        "/static/shared/img/icons/ico_home_page_ie_on.gif",
        "/static/shared/img/icons/ico_home_page_netscape_on.gif",
        "/static/shared/img/icons/ico_home_page_opera_on.gif",
        "/static/shared/img/icons/ico_home_page_safari_on.gif",
        "/static/shared/img/icons/ico_home_page_ff_off.gif",
        "/static/shared/img/icons/ico_home_page_ie_off.gif",
        "/static/shared/img/icons/ico_home_page_netscape_off.gif",
        "/static/shared/img/icons/ico_home_page_opera_off.gif",
        "/static/shared/img/icons/ico_home_page_safari_off.gif"
);

preload_images.each ( function(el_url) {
        var tmp_image = new Image();
        tmp_image.src = el_url;
});

// fills in the username or registration link
reload_user_info();

});


/**
*  ########################################################################################
*  ############################  FUNCTIONS BELOW THIS LINE  ###############################
*  ########################################################################################
*/

function iframes_resize(el)
{
        if (el.contentDocument && el.contentDocument.body.offsetHeight) 
        {
                // W3C DOM (and Mozilla) syntax
                el.height = el.contentDocument.body.offsetHeight;
        } 
        else if (el.Document ) 
        {
                el.Document.body.onload = new function() {
                        if (el.Document.body.scrollHeight)
                        {
                                el.height = el.Document.body.scrollHeight;
                        }
                }
        }
}

function include_css(file)  	 
{ 	 
if (document.createElement && document.getElementsByTagName) { 	 
var d_head = document.getElementsByTagName('head')[0]; 	 
 
var d_script = document.createElement('link'); 	 
d_script.setAttribute('type', 'text/css'); 	 
d_script.setAttribute('rel', 'stylesheet'); 	 
d_script.setAttribute('href', file); 	 
 
d_head.appendChild(d_script); 	 
} 	 
}

/**
* Reloads user info with either username or registration link
* @author Matej Balantič <matej@balantic.si>
* @author Tomas Korcak <tomas.korcak@cet21.cz>
*/
function reload_user_info()
{
var username = Cookie.get('jyxo_user');
var key = Cookie.get('jyxo_key');
var fullname = Cookie.get('user') || username;

if (fullname) {
        var display_name = (fullname!=username) ? fullname+' ('+username+')' : fullname;
        display_name = display_name.replace('+', ' ');
        fullname = fullname.replace('+', ' ');
}

// HIDE / SHOW all user blocks
$ES('.user_display_when_loggedin').each ( function (el) {
        if (key) el.style.display = 'block';
                else el.style.display = 'none';
});
$ES('.user_display_when_loggedout').each ( function (el) {
        if (key) el.style.display = 'none';
                else el.style.display = 'block';
});

if (fullname && $('jyxo_username'))
        $('jyxo_username').innerHTML = fullname;

if (fullname && $('jyxo_username_cet'))
        $('jyxo_username_cet').innerHTML = fullname;

if (display_name)
        $ES('.user_username').each ( function (el) {
                el.innerHTML = display_name;
        });

// Forum part
var forum_enable_answer = Cookie.get('forum_user');
if($('forum_enable_answer'))
{
    if(forum_enable_answer) $('forum_enable_answer').setStyle('display', '');
        else $('forum_enable_answer').setStyle('display', 'none');
}
}

/**
* Make ajax request and call callback function on success
* 
* @param string url
* @param function callback
* @param object scope
* @param bool enableCache
* @return void
*/
function ajaxCall(url, callback, scope, enableCache)
{
// Disable request caching
if (enableCache !== true) {
        var ts = +new Date();
        // try replacing _= if it is there
        var ret = url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
        // if nothing was replaced, add timestamp to the end
        url = ret + ((ret == url) ? (url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
}

new Ajax(url, {
         method: 'get'
        ,encoding: 'utf-8'
        ,onComplete: function(response) {
                // Call callback user function
                if (typeof callback == 'function') {
                        // Execute with scope
                        var scope = scope || this || document;
                        callback.call(scope);
                }
    }
}).request();
}

/**
* Logouts user account and refreshes page if needed
* 
* @return void
*/
function doLogout()
{
// Do logout and call reload_user_info when finished
ajaxCall('/lbin/jyxo_reg.php?what=logout', function() {
        if (location.href.match(/\/(registrace|profil)/))
                location.href = '/';

        // Refresh page after user logout??
        if (reload_page_on_log_out == true){
            location.reload(true);
        }
        
        JyxoCrossDomain.logout(this.href);
        reload_user_info();
});
}

function open_close_subform(div_id,div_head)
{
var div_name = $(div_id);
if(div_name)  {
        if (div_name.style.display == "block") {
                if (div_id == 'video_content') {
                        try {
                                $('flvvideo').innerHTML = ""; //remove flvvideo
                        } catch(e) {
                                null;
                        }
                }
                div_name.style.display = "none";
                $(div_head).className = "head";
                
        } else {
                div_name.style.display = "block";
                $(div_head).className = "headopen";
                if (div_id == 'video_content') {
                        video_player_setup(); //reopen flvvideo
                }
        }
}	
}


/**
 * Sends AJAX request to $script_name and updates $div_name with results.
 * Animates $div_name while waiting for AJAX response
 * @param div_name Name of the div to write in
 * @param script_name name of the script to execute
 * @param callbackFn Calback function executed after successful request
 * @param callbackFnScope Scope in which callback function will be executed
 * @author Anže Robida
 * @author Matej Balantič <matej@balantic.si> (ajax-loader animation)
 * @author Tomáš Korčák, CET21, spol. s r.o. (callback function and scope)
 */
function returnContent(div_name,script_name,media_title,media_id,callbackFn,callbackFnScope) {

// hide flash
flash_show(false, $(div_name));

slided_out = false;

// create hover layer
var hover_layer = new Element("div")
        .setStyle('position', 'absolute')
        .setStyles($(div_name).getCoordinates())
        .injectInside(document.body)
        .setOpacity(0.3)
        .setStyles({
                        'background-color':'black',
                        'position': 'absolute',
                        'z-index': '5'
                });


if (div_name == 'vsection_content_margin')
{
        hover_layer.setStyles({
                        'margin-left': '10px'
                });
}

// create ajax loader
var ajax_load = new Element("img")
ajax_load.src = '/static/shared/img/icons/ajax.gif';
move_top  =   ($(div_name).getPosition()['y'] + $(div_name).getSize()['size']['y']/2) - (ajax_load.height/2);
move_left =   ($(div_name).getPosition()['x'] + $(div_name).getSize()['size']['x']/2) - (ajax_load.width/2);
ajax_load.setStyles({
                "position": 	'absolute',
                "top": 		 	move_top,
                "left":			move_left,
                "z-index": 		'10'
        }).injectInside(document.body);

// call ajax script
new Ajax(script_name, {
        method: 'get',
        encoding: 'UTF-8',
        onComplete: function(response)
        {
                $(div_name).innerHTML = response;

                if (div_name == 'videosection' || div_name == 'video_section_main_video') {
                        //put # tag into location
                        var url_temp = window.location.href; //parse fixed location
                        url_temp = url_temp.substring(0,url_temp.indexOf('#')); 
                        var media_id = script_name; //parse media_id
                        media_id = media_id.substring(media_id.indexOf('media_id=')+9);
                        media_id = parseInt(media_id.substring(0,media_id.indexOf('section_id')-1));
                        window.location = url_temp + '#media_id=' + media_id;

                        $('video_main_box').setStyle("visibility",'visible');
                }

                //if video page
                if (div_name == 'videosection' || div_name == 'video_section_main_video' || div_name == 'embed_flvvideo') {
                        //replace title of the window - for ajax calls
                        if (div_name != 'embed_flvvideo') {
                                var explodestring = document.title;
                                explodestring = explodestring.split('-');
                                explodestring = explodestring[explodestring.length-1];
                                explodestring = explodestring.split('#');
                                explodestring = explodestring[0];
                                if (media_title) {
                                        document.title = media_title + ' - ' + explodestring.trim();
                                }
                        }
                        else
                        {
                                autostart = true; // we automaticaly start video if requested through ajax in article
                        }
                }
                
                //change style of active media
                if (media_id) {
                        try {
                                //remove background of non-active media
                                $ES('.small_video').each ( function(el) 
                                {
                                        el.setStyles({background: ''});			  
                                });
                                
                                $("media_id_"+media_id).setStyles({background: 'url(/static/'+app_lang+'/main/img/backgrounds/back_video.gif) repeat-y'});
                                
                        } catch(e) {
                                null;
                        }
                        
                }

                // show flash back
                flash_show(true, $(div_name));

                // destroy ajax loader & div layer
                hover_layer.remove();

                ajax_load.remove();

                // if CZ photogalery page
                if (div_name == 'cz_photo_gallery_list_detail') {
      //setTimeout('cz_photogallery_list_ajax_refresh()', 500);
      cz_photogallery_list_ajax_refresh();
      gal_init();
    }
    
    if (script_name.indexOf("ajax_chart_vote.php?id=") != -1)
        ajaxLoadCentralChartDetail();
    if (script_name.indexOf("ajax_chart_detail.php?id=") != -1)
        ajaxLoadRightChartVote();


		// Call callback user function
		if (typeof callbackFn == 'function') {
			// Execute with scope
			var scope = callbackFnScope || this || document;
			callbackFn.call(scope);
		}


        },
        // do eval scripts inside the AJAX response
        evalScripts: true
}).request();
} 

function do_slide() {

if (!slided_out)
{
        setTimeout(do_slide,300);
        return true;
}
mySlide.slideIn();
}

/**
* REGISTRATION FUNCTIONS
*/

function close_banner() {}
function open_banner() {}
function pre_fullscreen() {
if (typeof(reload_tmout) != 'undefined')
{
        if (reload_tmout != null)
        {
                clearTimeout(reload_tmout);
        }
}
}

function post_fullscreen() {}

function login_show()
{
close_banner();
mbox_open(500, 500);
pre_fullscreen();

step_1_help = new Array("main_help");
active_step = 1;
help_displayed = 0;

new Ajax('/bin/registration2/login.php', {
     method: 'get',
     encoding: 'utf-8',
     update: $('MBOX_window'),
     evalScripts: true
}).request();
}


function register_show()
{
close_banner();
mbox_open(500, 500);
pre_fullscreen();

// help boxes in step 1
step_1_help = new Array("username_help", "password_help", "email_help", "main_help");

// url of script for ajax purposes
registration_script_url = '/bin/registration2/';

// how many steps are there
all_steps = 3;
active_step = 1;

// help box visibility status
help_displayed = false;

password_renewal = false;

load_settings();

url = '/bin/registration2/' + '?action=display' + '&what=1' + '&return=' + location.href;
new Ajax(url, {
     method: 'get',
     encoding: 'utf-8',
     update: $('MBOX_window'),
     onComplete: register_show_complete,
     evalScripts: true
    }).request();
}


function register_show_complete( result )
{
active_step = $('active_step').value;

// get HTML code of ajax loader
ajax_loader     = $('ajax_loader_div').innerHTML;
ajax_loader_big = $('ajax_loader_big_div').innerHTML;

build_indicators( $('active_step').value );
}


function load_settings()
{
new Ajax('/bin/registration2/' + '?action=javascript' + '&what=register', {
     method: 'get',
     encoding: 'utf-8',
     onComplete: load_settings_complete
    }).request();
}


function load_settings_complete( result )
{
eval( result );
}

/*
* Function send article
* @param div_name Name of the div to write in
* @param script_name name of the script to execute
* @param text_ok text if article was sent
* @param text_error text if there goes something wrong
*
*/
function articleSend(div_name,script_name,text_ok, text_error,form_id) {

if(script_name.indexOf('?')>0){script_name+="&title="+encodeURI(document.title);}else{script_name+="?title="+encodeURI(document.title);}
new Ajax(script_name, {
        method: 'post',
        encoding: 'utf-8',
        postBody: document.article_send,
        onComplete: function(response) {
                if (response == 'OK') {
                         $(div_name).innerHTML = text_ok;
                         setTimeout("showSendArticleForm('"+form_id+"')",1300);
                         
                } else {
                        $(div_name).innerHTML = text_error;
                }
        }
}).request();
}

/**
* This function execute PHP file, which write into database rating for current video creator
*/
function ajax_put_video_creator_vote(id, vote) {

var url = '/bin/ajax_video_creator_vote.php?id='+id+'&rate=' + vote;

new Ajax(url, {
        method: 'get'
}).request();
}
/**
* This function execute PHP file, which write into database rating for current article
*/
function ajax_put_vote(article_id, vote) {

var url = '/bin/ajax_article_vote.php?article_id=' + article_id + '&rate=' + vote;

new Ajax(url, {
        method: 'get'
}).request();
}

/**
* This function execute PHP file, which write into database rating for current media
*/
function ajax_put_media_vote(article_id, vote) {

var url = '/bin/ajax_media_vote.php?media_id=' + article_id + '&rate=' + vote;
var result; 
new Ajax(url, {
        method: 'get',
        onComplete: function(response){
                result = response;                        
                result=result.split("~");
                
                if (result.length > 1 && result[1] !='') {
                        $('article_vote_container').style.display = 'block';
                        $('article_vote_container').innerHTML = "<img src='" + result[1] + "' id='vote_stars'/>";
                }
                else {
                        $('article_vote_container_err').style.display = 'block';
                }
        }
}).request();
return "a"+result;
}

/**
* Function sends content of form to email via ajax
*/


function ajax_write_us(text_wait, text_saved, text_pwd, text_bnd, text_pnd, text_err, text_act, text_sent) {

var url = '/lbin/ajax_write_us.php';

//write "wait" message
span_comment_msg_1 = $('span_comment_msg');
if (!span_comment_msg_1)
        return false;
span_comment_msg_1.innerHTML = text_wait;

new Ajax(url, {
        method: 'post',
        postBody: document.comment_send,
        onComplete: function(response) {

                var result_1 = response.replace(/^\s+|\s+$/g, "");
                if (result_1 == 'SUCCESS') {
                        $('comments_form').innerHTML = '<div style="text-align: center;">Vaše zpráva byla úspěšně odeslána. Děkujeme.</div>';
                }
                if (result_1 == 'NO_TEXT') {
                        span_comment_msg_1.innerHTML = "Zadejte prosím text zprávy.";
                }
                if (result_1 == 'F_WORDS') {
                        span_comment_msg_1.innerHTML = "Text obsahuje neslušná slova.";
                }
                if (result_1 == 'MAIL_ERROR') {
                        span_comment_msg_1.innerHTML = "Zprávu se bohužel nepovedlo odeslat.";
                }
                if (result_1 == 'WRONG_EMAIL') {
                        span_comment_msg_1.innerHTML = "Zadejte platnou emailovou adresu.";
                }
                if (result_1 == 'CAPTCHA_ERROR') {
                        span_comment_msg_1.innerHTML = "Chybný kontrolní kód.";
                }
                if (result_1 == 'LADICI') {
                        span_comment_msg_1.innerHTML = "ladime";
                }
        }
}).request();


}


/**
* Function sends comment on article to server
*/
function ajax_comment_send(type, text_wait, text_saved, text_pwd, text_bnd, text_pnd, text_err, text_act, text_sent,text_invalid_captcha,text_empty_username) {

var url = '/bin/ajax_comments_save_'+type+'.php';

if ($('comment_txt').value == '')
        return false;

//write "wait" message
span_comment_msg_1 = $('span_comment_msg');
if (!span_comment_msg_1)
        return false;
span_comment_msg_1.innerHTML = text_wait;

new Ajax(url, {
        method: 'post',
        postBody: document.comment_send,
        onComplete: function(response) {
                var result_1 = response;
                //comment not saved
                if (result_1 == "CAP") {				
                        if(typeof window.cleancommentform == 'function')	
                        {
                                cleancommentform(true)	
                        }		
                        span_comment_msg_1.innerHTML = text_invalid_captcha;
                }
                //comment not saved
                if (result_1 == 'USER_ERR') {				
                        span_comment_msg_1.innerHTML = text_empty_username;

                }			
                //comment saved
                if (result_1 == 'SUCCESS') {
                        if(typeof window.cleancommentform == 'function')	
                        {
                                cleancommentform()	
                        }	
                        span_comment_msg_1.innerHTML = text_saved;
                        show_comments();
                }

                //user banned temp
                if (result_1 == 'BND')
                        span_comment_msg_1.innerHTML = text_bnd;


                //password inavlid
                if (response == 'PWD')
                        span_comment_msg_1.innerHTML = text_pwd;

                //comment already sent
                if (response == 'OK')
                        span_comment_msg_1.innerHTML = text_sent;

                //user banned
                if (response == 'PND')
                        span_comment_msg_1.innerHTML = text_pnd;

                //common error
                if (response == 'ERR')
                        span_comment_msg_1.innerHTML = text_err;

                //user is not activated
                if (response == 'ACT')
                        span_comment_msg_1.innerHTML = text_act;
        }
}).request();
}

function show_comments(type, id, page, order) {
if (!global_show_comments_ajax && page) {
        var params = new Array;
        params['page'] = page;
        params['p_all_items'] = '';
        document.location.href = modify_url(document.location.href, params, null, 'comments');
        return;
}

// updating after user post
if (typeof(id) === "undefined")
{
        type	= global_show_comments_type;
        id 		= global_show_comments_id;
        order 	= global_show_comments_order;
        if (order == "desc" || order == "DESC")
                page = 1;
        else
                page = "last";
}

        
global_show_comments_type = type;
global_show_comments_id   = id;	
global_show_comments_page = page;
global_show_comments_order = order;


var url = '/bin/ajax_comments.php?type='+type+'&id=' + id + '&page=' + page + '&order=' + order + '&max_number=10';

new Ajax(url, {
        method: 'get',
        onComplete: function(resp) {
                new_div = new Element('div')
                .setHTML(resp);

                $('comments').replaceWith(new_div);

        }
}).request();

}
/*
* This Function is used for show all comments without Paging
*/
function show_all_comments(type, id, max_number, order) {
// updating after user post
if (typeof(id) === "undefined")
{
        type	= global_show_comments_type;
        id 		= global_show_comments_id;
        order 	= global_show_comments_order;
        if (order == "desc" || order == "DESC")
                page = 1;
        else
                page = "last";
}

global_show_comments_type = type;
global_show_comments_id   = id;	
global_show_comments_max_number = max_number;
global_show_comments_order = order;

var url = '/bin/ajax_show_all_comments.php?type='+type+'&id=' + id + '&page=1&order=' + order + '&max_number='+max_number;
new Ajax(url, {
        method: 'get',
        onComplete: function(resp) {
                new_div = new Element('div')
                .setHTML(resp);

                $('comments').replaceWith(new_div);

        }
}).request();

}

function homepage_img_change(browser) {
$ES('.homepage_button').each ( function (el) {
        curr_browser = el.id.split("_")[1];
        el.src = '/static/shared/img/icons/ico_home_page_'+curr_browser+'_on.gif';
});
if (!browser)
        browser = selected_browser;

$("image_"+browser).src = '/static/shared/img/icons/ico_home_page_'+browser+'_off.gif';

}

function homepage_browser(browser_name)
{
new Ajax('/bin/ajax/homepage.php?browser='+browser_name, {
        method: 'get',
        encoding: 'utf-8',
        update: $('MBOX_window'),
        onComplete: function () { homepage_insert(browser_name); }
}).request();

}

function homepage_get_browser()
{
if (window.ie)
        return "ie";
if (window.gecko)
        return "ff";
if (window.webkit)
        return "safari";
if (window.opera)
        return "opera";

}
//insert text into MBOX
function homepage_insert(browser_name)
{
if (browser_name=="firefox") browser_name="ff";
if (browser_name=="explorer") browser_name="ie";

selected_browser = browser_name;
homepage_img_change(browser_name);
}

function bookmark_show(siteURL)
{


if (window.ie)
{

        var html_body = document.getElementsByTagName('body').item(0);
        var homepage_link = document.createElement('a');
        html_body.appendChild(homepage_link);
        homepage_link.style.display = 'none';

        homepage_link.style.behavior='url(#default#homepage)';
        homepage_link.setHomePage(siteURL);

}
else
{
        // hide for now - not translated yet
        mbox_open(450,200);
        if (window.gecko)
        {
                homepage_browser('firefox');
        }
        else if (window.webkit || window.webkit419 || window.webkit420)
        {
                homepage_browser('safari');
        }
        else if (window.opera == 'Opera')
        {
                homepage_browser('opera');
        }
/*		else if (browser_name == 'Netscape')
        {
                homepage_browser('netscape');
        }*/
        else {
                homepage_browser('explorer');
        }
}

}


/* Opens MBOX on the webpage
@author Matej Balantič <matej@balantic.si>
*/
function mbox_open(MBOX_WIDTH,MBOX_HEIGHT,IS_DRAGGABLE)
{
flash_show(false);

if ( typeof(IS_DRAGGABLE) == "undefined" )
        IS_DRAGGABLE = true;

// create holders if there isn't any
mbox_create_holders( IS_DRAGGABLE );

left_s = window.getWidth()/2 - MBOX_WIDTH/2;
top_s = window.getScrollTop() +(window.getHeight() - MBOX_HEIGHT)/2;

// push down if it is still above content
if (top_s < 180)
        top_s = 180;

$("MBOX_window").setStyles('left:'+left_s+'px; top: '+top_s+'px; display:block;');
$("MBOX_dragger").setStyles('left:'+left_s+'px; top: '+top_s+'px; display:block;');

$("MBOX_overlay").setStyles('display:block;');

$("MBOX_overlay").setStyles({"height": window.getScrollHeight()+'px', "width": window.getScrollWidth()+'px'});
$("MBOX_window").setStyles({"width": MBOX_WIDTH+'px'});
$("MBOX_dragger").setStyles({"width": MBOX_WIDTH+'px'});



new Fx.Style('MBOX_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut}).start(0,0.6);
new Fx.Style('MBOX_window',  'opacity',{duration: 250, transition: Fx.Transitions.sineInOut, onComplete:function(){  } }).start(0,1);
}


/* closes mbox
@author Matej Balantič <matej@balantic.si>
*/
function mbox_close()
{

new Fx.Style('MBOX_overlay', 'opacity',{duration: 400, transition: Fx.Transitions.sineInOut, onComplete:function(){ $("MBOX_overlay").setStyles('display:none;'); }}).start(0.6,0);
new Fx.Style('MBOX_window',  'opacity',{duration: 250, transition: Fx.Transitions.sineInOut, onComplete:function(  )
            {
                $("MBOX_window").setStyles('display:none;');
                $("MBOX_window").innerHTML = '';
                flash_show(true);

            } }).start(1,0);
$("MBOX_dragger").setStyles({"display": 'none'});
window.location = window.location;
}
/**
* Shows / hides all FLASH & IFRAME objects on the page
* @param bool $display True when showing, false when hiding
* @author Matej Balantič <matej@balantic.si>
*/
function flash_show(display, div_name)
{
if (display)
{
        stats = 'visible';
        IS_FLASH_SHOWN = true;
}
else
{
        stats = 'hidden';
        IS_FLASH_SHOWN = false;
}

if (window.ie)
        flash_container = 'object';
else
        flash_container = 'embed';

// don't set style with mootools; doesn't work in IE6	
$ES(flash_container,div_name).each ( function (el) {
        el.style.visibility = stats;
});

$ES('iframe', div_name).each ( function (el) {
        el.style.visibility = stats;
});
}
/* makes mbox draggable & creates mbox holders
@author Matej
*/
function mbox_create_holders( is_draggable )
{
if ($('MBOX_overlay'))
{
        $("MBOX_overlay").remove();
        $("MBOX_dragger").remove();
        $("MBOX_window").remove();
}

include_css('/static/shared/css/mbox.css');
// CREATE MBOX HOLDERS

var mbox_overlay = new Element('div', {
        'id' : 'MBOX_overlay'
})
.injectInside(document.body);

var mbox_dragger = new Element('div', {
        'id': 'MBOX_dragger'
})
.injectInside(document.body);

var mbox_window = new Element('div', {
        'id': 'MBOX_window'
})
.injectInside(document.body);

var mbox_window_loading = new Element('div', {
        'id': 'MBOX_loading'
})
.injectInside(mbox_window);

var mbox_window_loading_img = new Element('img', {
        'src': "/static/shared/img/ajax-loader-white.gif",
        'alt': 'Loading'
})
.injectInside(mbox_window_loading);

// CREATE DROP
if ( is_draggable ) {
        var main_content = $('left');

        mbox_dragger.addEvent('mousedown', function(e) {
                e = new Event(e).stop();
                mbox_window.setStyles({
                        'opacity':0.7
                });
                drag = mbox_window.makeDraggable({
                        container: main_content
                }); // this returns the dragged element
                drag.start(e); // start the event manual
        });

        mbox_window.addEvent('emptydrop', function() 
        {
                mbox_dragger.setStyles({
                        'left': this.getCoordinates().left,
                        'top': this.getCoordinates().top
                });
                mbox_window.setStyles({'opacity':1});
                drag.detach();
        });
}
}

/*
*  * Image pool function - auto change images
*     @author Matej
*/
function image_change(div_name, image_array, current_img)
{
var container = $(div_name);
var all_imgs = image_array.length;

if (all_imgs <= 1)
        return true;

container.empty();
myImg = new Element("img", {
        src: image_array[current_img]['url'],
        alt: image_array[current_img]['title'],
        title: image_array[current_img]['title']
})
.setStyle("border", 0)
.setStyle("opacity", 0)
.injectInside(container);

myFx = new Fx.Style(myImg, 'opacity' , { duration: 500 }).start(0,1);

current_img = current_img+1;
if (current_img>=all_imgs)
{
        current_img = 0;
}

return current_img;
}

//special back functionallty
function back_mod() {

if (document.referrer != '')
{
        var host = location.href.split('/');
        if (document.referrer.match(host[2])) //here shold be part of domain, where should be in use normal history
        {
                history.go(-1);	
        } else {
                //fake history to current front page
                location.href = 'http://' + host[2] + '/bin/front.php?section_id='+section_id; 
        }
}
}
//ajax function for voting
function poll_vote(formx,voteResponse,answerx,tnx_div) {

document.getElementById(voteResponse).style.visibility = 'hidden';

if (typeof(tnx_div) == 'undefined')
        tnx_div = 'tnx_for_vote';

formx.answer_id.value = answerx;

formx.send ({
        encoding: 'UTF-8',
        onComplete: function(response)
        {
                document.getElementById(voteResponse).innerHTML = response;
                document.getElementById(voteResponse).style.visibility = 'visible';
                
                //if (voteResponse[response] != 'undefined')
                //{
                //	formx.getElements("div[rel=" + tnx_div + "]")[0].setHTML(voteResponse[response]);
                //}
        }
});
}

/*
Function change fotn size of defined object, with requested factor, not exceed limited size
*/

function change_font_size(obj, fact, limit) {
var currentFontSize = obj.style.fontSize;
var currentFontSizeNum = parseFloat(currentFontSize);
var newFontSize = currentFontSizeNum*fact;
if ((fact<1) && (newFontSize<limit)) newFontSize = limit;  
if ((fact>1) && (newFontSize>limit)) newFontSize = limit;  
obj.style.fontSize = newFontSize+"px";





}
/*
Function change font size for article
*/

function change_font_size1(type) {

var resize = 0;

//limit increse to 1
if (type == 'increase' && default_font_size == 4) {
        return false;
}


//limit decrese to 0
if (type == 'decrease' && default_font_size == 0) {


        return false;	
}

//set changes
if (type == 'decrease') {
        default_font_size = parseInt(default_font_size) - 1;
        resize = -2;
} else if (type == 'increase') {
        default_font_size = parseInt(default_font_size) + 1;
        resize = 2;
} else if (type == 'default') {
        resize = (1 - default_font_size) * 2;
        default_font_size = 1; 
} else
        resize = (default_font_size-1) * 2; 
        
//do resize
$ES('h1,h2,h3.source1,p,div.summary','article').each ( function (el) {
        temp_size = parseInt(el.getStyle('fontSize')) + resize;
        el.style.fontSize = temp_size+'px';
});

//disable buttons
if (default_font_size == 4) {
        $('increase').innerHTML = '<img src="/static/slo/main/img/backgrounds/zoom_in_font_size.gif" alt="Povečaj pisavo" title="Povečaj pisavo" />';
        $('decrease').innerHTML = '<a href="" onclick="change_font_size1(\'decrease\'); return false;" alt="Zmanjšaj pisavo" title="Zmanjšaj pisavo">&nbsp;</a>';
        $('default').innerHTML = '<a href="" onclick="change_font_size1(\'default\'); return false;" alt="Privzeta velikost besedila" title="Privzeta velikost besedila">&nbsp;</a>';
} else if (default_font_size == 0) {
        $('increase').innerHTML = '<a href="" onclick="change_font_size1(\'increase\'); return false;" alt="Povečaj pisavo" title="Povečaj pisavo">&nbsp;</a>';
        $('decrease').innerHTML = '<img src="/static/slo/main/img/backgrounds/zoom_out_font_size.gif" alt="Zmanjšaj pisavo" title="Zmanjšaj pisavo"/>';
        $('default').innerHTML = '<a href="" onclick="change_font_size1(\'default\'); return false;" alt="Privzeta velikost besedila" title="Privzeta velikost besedila">&nbsp;</a>';
} else if (default_font_size == 1) {
        $('increase').innerHTML = '<a href="" onclick="change_font_size1(\'increase\'); return false;" alt="Povečaj pisavo" title="Povečaj pisavo">&nbsp;</a>';
        $('decrease').innerHTML = '<a href="" onclick="change_font_size1(\'decrease\'); return false;" alt="Zmanjšaj pisavo" title="Zmanjšaj pisavo">&nbsp;</a>';
        $('default').innerHTML = '<img src="/static/slo/main/img/backgrounds/reset_font_size.gif" alt="Privzeta velikost besedila" title="Privzeta velikost besedila" />';





} else {
        $('increase').innerHTML = '<a href="" onclick="change_font_size1(\'increase\'); return false;" alt="Povečaj pisavo" title="Povečaj pisavo">&nbsp;</a>';
        $('decrease').innerHTML = '<a href="" onclick="change_font_size1(\'decrease\'); return false;" alt="Zmanjšaj pisavo" title="Zmanjšaj pisavo">&nbsp;</a>';
        $('default').innerHTML = '<a href="" onclick="change_font_size1(\'default\'); return false;" alt="Privzeta velikost besedila" title="Privzeta velikost besedila">&nbsp;</a>';

}

//sets cookie
var myCookieSize = Cookie.set('default_font_size', default_font_size);

}

// replace all videos but active with thumbnails
function videoList_forceThumbnails(active) {
for (i = 0; i < videoList_div.length; i++) {
        if (videoList_div[i] != active) {
                $(videoList_div[i]).innerHTML = videoList_img[i];
        }
}
}

function printpr() {
window.print();
return false;
}

function chart_login(box,number) {
login_show();
$('MBOX_window').onclose = function() {
        if (box == 1) {
                returnContent('cz_box_right_chart_vote','/lbin/ajax_chart_vote.php?id='+number);
        } else {
                returnContent('cz_box_central_chart_detail','/lbin/ajax_chart_detail.php?id='+number);
        }
}
}

function showVideoInLightbox(mediaID, microsite, width, height, movie_config, movie_path, movie_color) {
// default values
if (typeof(mediaID) == "undefined") {
return;
}
if (typeof(microsite) == "undefined") {
microsite = "23000";
}
if (typeof(width) == "undefined") {
width = 608;
}
if (typeof(height) == "undefined") {
height = 342;
}
if (typeof(movie_config) == "undefined") {
movie_config = "http://tn.nova.cz/bin/player/config.php?site_id=23000";
}
if (typeof(movie_path) == "undefined") {
movie_path = "http://archiv.nova.cz/static/cz/shared/app/MediaCenter_Catchup.swf";
}
if (typeof(movie_color) == "undefined") {
movie_color = "#086B85";
}
close_banner();
mbox_open(width, height+55);
pre_fullscreen();
$('MBOX_window').innerHTML = '<div style="background: #1a1a1a url(/static/cz/microsites/default/img/lb_player_close.gif) right center no-repeat; text-align: right;"><a href="#" onclick="javascript: mbox_close(); return false;" style="padding-right: 22px; color: #079fc6;">zavřít</a></div><div id="MBOX_video"> </div>';
media_id = mediaID;
player_referer = microsite;
load_banners_onstart = false;
_text_flash_no = "<div class=\"notice\"><span class=\"red\">$$NO_FLASH_4$$</span><br /><div class=\"gray\">$$NO_FLASH_2$$ <a href=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&amp;promoid=BIOW\" target=\"_blank\">$$NO_FLASH_3$$</a>.</div>";
player_width = width;
player_height = height;
config_file = movie_config;
//playlist_file = '';
media_center_swf = movie_path;
player_color = movie_color;
player_h264 = true;

if (window.location.href.indexOf("#video") != -1) {
        autostart = true;
} else {
        autostart = false;
}
autostart = true;
video_div = "MBOX_video";
videoList_forceThumbnails(video_div);
video_player_setup();
}

/*
Function submit form press enter
*/
function submitEnter(form,e,fnc){
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  
  var inputs = $ES('input[type=text],input[type=password]', form); 
  if(keycode == 13){  
    for(var i=0; i<inputs.length ; i++) {
      if(!inputs[i].value.length) {
        inputs[i].focus();
        return false;
      }
    }
    if (fnc) return fnc();
    else $(form).submit();
  }
  return true;
}

function modify_url(url, new_prms, old_prms_regex_test, anchor) {
   // strip anchor	
   var re = /^(\S+)#(\S+)$/i;
   var matches = url.match(re);
   if (matches !== null) {
	   url = matches[1];
	   if (!anchor) {
		   anchor = matches[2]
	   }
   }
   
   var url_elements = url.indexOf('?') < 0 ? [url, ''] : url.split('?');
   var prms = {};
   var i;
   if (url_elements[1]) {
      var prms_array = url_elements[1].indexOf('&') < 0 ? 
         [ url_elements[1] ] : url_elements[1].split('&');
      for (i = 0; i < prms_array.length; i++) {
         var prm_val = prms_array[i].indexOf('=') < 0 ? [prms_array[i], ''] : prms_array[i].split('=');
         var prm_name = unescape(prm_val[0]);
         if (! old_prms_regex_test || old_prms_regex_test.test(prm_name)) {
            prms[prm_name] = unescape(prm_val[1]);
         }
      }
   }
   for (i in new_prms) {
      prms[i] = new_prms[i];
   }
   var new_prms_str = '';

   for (i in prms) {
      if (!/^(undefined|function)$/i.test(typeof(prms[i])) && prms[i]) new_prms_str += '&' + escape(i).replace(/\+/g,'%2b') + '=' + escape(prms[i]).replace(/\//g,'%2F').replace(/\+/g,'%2b');
   }

   var ret = url_elements[0]
             + (new_prms_str ? '?' + new_prms_str.substr(1)  : '')
		     + (anchor ? '#' + anchor : '');
   return ret;
}
