function show_element(eleId)
{
    var xko = document.getElementById('cardetail-window').offsetHeight;
    document.getElementById(eleId).style.display = 'block'; 
    document.getElementById('cardetail-poptavka2').style.display = 'block'; 
    document.getElementById('cardetail-poptavka2').style.height = xko-2;    
    document.getElementById(eleId).style.height = xko-2;    
}

function hide_element(eleId)
{
    document.getElementById(eleId).style.display = 'none';  
    document.getElementById('cardetail-poptavka2').style.display = 'none';  
}

function redir(redirUrl) {
    window.top.location.href = redirUrl;
}

function showElementById(eleId) {
    $('div#'+eleId).show();
    $('div#'+eleId+'Transparent').show();
    $('div#'+eleId+'Transparent').css({
            'background-color': '#ffffff',
            'opacity': 0.9
        });


}
function hideElementById(eleId) {
    $('div#'+eleId).hide();
    $('div#'+eleId+'Transparent').hide();
    /*  document.getElementById(eleId).style.display = 'none'; */
}


function gallery_window(table,gallery,pic,picwidth,picheight)
{
    picwidth += 80;
    picheight += 60;
    window.open('gallery_window.php?table='+table+'&gallery='+gallery+'&pic='+pic, 'galwindow', 'width='+picwidth+',height='+picheight+'');
}

function pic_window(picfile, title, popis, picwidth, picheight){
    picheight += 100;
    window.open('pic_window.php?pic='+picfile+'&title='+title+'&popis='+popis+'', 'picwindow', 'width='+picwidth+',height='+picheight+'');
}

function pic_window2(picfile, title, picwidth, picheight){
    window.open('pic_window2.php?pic='+picfile+'&title='+title+'', 'picwindow', 'width='+picwidth+',height='+picheight+'');
}

function pic_window3(picfile, picwidth, picheight){
    window.open('pic_window.php?pic='+picfile, 'picwindow', 'width='+picwidth+',height='+picheight+'');
}


/* funkce, ktera jednak vypise mail pres JS, cimz blokne boty a jednak pouzije entity, cimz je to jeste lepsi :) */
function js_protect_email(var1,var2)
{
	var zavinac = "&#64;";
	var mailto = "mai&#108;&#116;&#111;&#58;";
	var e_mail = var1+zavinac+var2;
	var title = "title='"+e_mail+"'";

	document.write("<a href='"+mailto+e_mail+"'"+title+">"+e_mail+"</a>");
}


function pic_window(picfile, title, popis, picwidth, picheight){
	/*picheight += 100;*/
	window.open('pic_window.php?pic='+picfile+'&title='+title+'&popis='+popis+'', 'picwindow', 'width='+picwidth+',height='+picheight+'');
}

function insertFlash(eleId, swfFile, width, height, alt, wmode, flashVars)
{
	directFlashVars = '';
	if(flashVars != '')directFlashVars = '?'+flashVars;

	flashHtml =
	'<!--[if !IE]> -->'+"\n"+
	'<object type="application/x-shockwave-flash" data="'+swfFile+directFlashVars+'" width="'+width+'" height="'+height+'">'+"\n"+
	'<!-- <![endif]-->'+"\n"+
	'<!--[if IE]>'+"\n"+
	'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'+width+'" height="'+height+'">'+"\n"+
	'<param name="movie" value="'+swfFile+directFlashVars+'" />'+"\n"+
	'<!--><!---->'+"\n"+
	'<param name="loop" value="true" />'+"\n"+
	'<param name="menu" value="false" />'+"\n"

	if(wmode)flashHtml += '<param name="wmode" value="transparent" />'+"\n";
	if(flashVars != '')flashHtml += '<param name="flashvars" value="'+flashVars+'" />'+"\n";

	flashHtml += alt+"\n";
	flashHtml += '</object>'+"\n";
	flashHtml += '<!-- <![endif]-->'+"\n";

	obj = document.getElementById(eleId);
	obj.innerHTML = flashHtml;
}



var flash = null;
var ff = false;


function mySubmit(eleId) {        
    $('#'+eleId).submit();     
}


function basename(path) {
    return path.replace(/\\/g,'/').replace( /.*\//, '' );
}



$(window).load(function() {


    var pageGal = new Array();

    if($('a.galPic').length) {
        $('a.galPic').each(function(){
            pageGal.push($(this).get(0));
        });

        $('body').append(
        '<div id="galCover">&nbsp;</div>' +
        '<div id="galContent">&nbsp;</div>' +
        '<a href="#" id="galClose">X</a>'
        );

        $('div#galCover').css({
            'position': 'absolute',
            'width': '100%',
            'height': ($('body').height() - 0)+'px',
            'top': '0px',
            'left': '0px',
            'background-color': '#000000',
            'display': 'none',
            'z-index': '20',
            'opacity': '0'
        });

        $('div#galContent').css({
            'position': 'absolute',
            'width': '100%',
            'top': '0px',
            'left': '0px',
            'padding-top': '10px',
            'text-align': 'center',
            'display': 'none',
            'z-index': '21',
            'opacity': '0'
        });

        $('a#galClose').css({
            'position': 'absolute',
            'top': '12px',
            'right': '10px',
            'color': '#fff',
            'font-weight': 'bold',
            'text-decoration': 'none',
            'display': 'none',
            'opacity': '0'
        });

        $('div#galContent').append('<div id="galImgTitle">&nbsp;</div>');
        $('div#galContent').append('<a href="#" id="galLeft">&nbsp;</a>');
        $('div#galContent').append('<a href="#" id="galRight">&nbsp;</a>');
        $('div#galContent').append('<img class="galBigImg" src="'+$(pageGal[0]).attr('href').replace('sm/', 'big/')+'" alt="'+$(pageGal[0]).find('img').attr('alt')+'" />');
        $('div#galContent').append('<div class="clearer">&nbsp;</div>');

        $('a#galLeft').css('display', 'none');
        $('a#galRight').css('display', 'none');

        var x = 0;
        $.each(pageGal, function(){
            //$('div#galContent').append('<img src="'+$(this).find('img').attr('src')+'" class="galSm" alt="'+$(this).find('img').attr('alt')+'" width="'+Math.floor($(this).find('img').width() / 1.5)+'" />');
            $('div#galContent').append('<img src="'+$(this).find('img').attr('src')+'" class="galSm" alt="'+$(this).find('img').attr('alt')+'" />');
            ++x;
            if(x == 6) {
                $('div#galContent').append('<div class="clearer">&nbsp;</div>');
                x = 0;
            }
        });

        $('div#galContent img').css({
            'margin-right': '30px',
            'margin-bottom': '30px',
            'cursor': 'pointer'
        });

        $('img.galBigImg').css({
            'cursor': 'default',
            'border': '1px solid #ffffff'
        });
        
        $('img.galSm').css({
            'cursor': 'default',
            'height': '50px',
            'border': '1px solid #ffffff'
        });
        

        if($('div#galCover').height() < $('div#galContent').height()) {
            $('div#galCover').height($('div#galContent').height() + 115);
        }

        $('div#galContent img').click(function(event){
            event.stopPropagation();
            event.preventDefault();

            $('div#galContent img.galBigImg').attr('src', $(this).attr('src').replace('/sm', '/big'));
            //$('div#galContent img.galBigImg').attr('src', $(this).attr('src').replace('/med', '/big'));
            $('div#galContent img.galBigImg').attr('alt', $(this).attr('alt'));

            if($('div#galContent img.galBigImg').attr('alt')) {
                $('div#galImgTitle').html($('div#galContent img.galBigImg').attr('alt'));
            } else {
                $('div#galImgTitle').html('&nbsp;');
            }
        });

        $('a.galPic').click(function(event){
            event.stopPropagation();
            event.preventDefault();

            $('div#galCover').css('display', 'block').animate({'opacity': 0.85}, 'fast');
            $('div#galContent').css('display', 'block').animate({'opacity': 1});
            $('a#galClose').css('display', 'block').animate({'opacity': 1});

            $('html,body').animate({'scrollTop': 0}, 'normal');

            $('div#galContent img.galBigImg').attr('src', $(this).find('img').attr('src').replace('/sm', '/big'));
            //$('div#galContent img.galBigImg').attr('src', $(this).find('img').attr('src').replace('/med', '/big'));
            $('div#galContent img.galBigImg').attr('alt', $(this).find('img').attr('alt'));

            $('div#galContent img.galBigImg').unbind('load');

            $('div#galContent img.galBigImg').load(function(){
                var pos = $('img.galBigImg').position();

                $('div#galImgTitle').css({
                    'position': 'relative',
                    'width': $('img.galBigImg').width()+'px',
                    'left': pos.left+'px',
                    //'background-color': '#fff',
                    'color': '#fff',
                    'margin-bottom': '4px',
                    'font-size': '20px',
                    'font-weight': 'bold'
                });

                if($('div#galContent img.galBigImg').attr('alt')) {
                    $('div#galImgTitle').html($('div#galContent img.galBigImg').attr('alt'));
                } else {
                    $('div#galImgTitle').html('&nbsp;');
                }

                //sipky
                var iWidth = $('img.galBigImg').width();
                var iHeight = $('img.galBigImg').height();

                $('a#galLeft').css({
                    'position': 'absolute',
                    'display': 'block',
                    'text-decoration': 'none',
                    'top': pos.top,
                    'left': pos.left,
                    'width': Math.round(iWidth / 2),
                    'height': iHeight,
                    'background-image': 'url("http://77.93.216.36/gng-web/engine/grafika/arr_left.png")',
                    'background-position': 'left center',
                    'background-repeat': 'no-repeat'
                    //'opacity': 0.8
                });

                $('a#galLeft:link').css({
                    'color': 'transparent'
                });


                $('a#galRight').css({
                    'position': 'absolute',
                    'display': 'block',
                    'text-decoration': 'none',
                    'top': pos.top,
                    'left': (pos.left + Math.round(iWidth / 2)),
                    'width': Math.round(iWidth / 2),
                    'height': iHeight,
                    'background-image': 'url("http://77.93.216.36/gng-web/engine/grafika/arr_right.png")',
                    'background-position': 'right center',
                    'background-repeat': 'no-repeat'
                    //'opacity': 0.8
                });

                $('a#galRight:link').css({
                    'color': 'transparent'
                });
                $('a#galRight:alink').css({
                    'color': 'transparent'
                });
                $('a#galRight:vlink').css({
                    'color': 'transparent'
                });

                $('a#galLeft').unbind('click');
                $('a#galLeft').click(function(event){
                    event.stopPropagation();
                    event.preventDefault();

                    var pic = $('div#galContent img.galBigImg').attr('src').replace('/big', '/sm');
                    var prev = '';
                    var found = false;
                    $('img.galSm').each(function(){
                        if(basename($(this).attr('src')) == basename(pic)) {
                            if(prev != '') {
                                $('div#galContent img.galBigImg').attr('src', prev.attr('src').replace('/sm', '/big'));
                                //$('div#galContent img.galBigImg').attr('src', prev.attr('src').replace('/med', '/big'));
                                $('div#galContent img.galBigImg').attr('alt', prev.attr('alt'));
                                if(prev.attr('alt') != '') {
                                    $('div#galImgTitle').html(prev.attr('alt'));
                                } else {
                                    $('div#galImgTitle').html('&nbsp;');
                                }
                            }
                            return false;
                        }
                        prev = $(this);
                    });
                });

                $('a#galRight').unbind('click');
                $('a#galRight').click(function(event){
                    event.stopPropagation();
                    event.preventDefault();

                    var pic = $('div#galContent img.galBigImg').attr('src').replace('/big', '/sm');
                    var found = false;
                    $('img.galSm').each(function(){
                        if(found == true) {
                            $('div#galContent img.galBigImg').attr('src', $(this).attr('src').replace('/sm', '/big'));
                            //$('div#galContent img.galBigImg').attr('src', $(this).attr('src').replace('/med', '/big'));
                            $('div#galContent img.galBigImg').attr('alt', $(this).attr('alt'));
                            $('div#galImgTitle').html($(this).attr('alt'));
                            if($(this).attr('alt') != '') {
                                $('div#galImgTitle').html($(this).attr('alt'));
                            } else {
                                $('div#galImgTitle').html('&nbsp;');
                            }
                            return false;
                        }

                        if(basename($(this).attr('src')) == basename(pic))found = true;
                    });
                });
            });
        });

        function closeGal(event){
            event.stopPropagation();
            event.preventDefault();

            $('div#galCover').animate({'opacity': 0}, 'fast', 'linear', function(){$('div#galCover').css('display', 'none')});
            $('div#galContent').animate({'opacity': 0}, 'fast', 'linear', function(){$('div#galContent').css('display', 'none')});
            $('a#galClose').animate({'opacity': 0}, 'fast', 'linear', function(){$('a#galClose').css('display', 'none')});
        }

        $('a#galClose').click(closeGal);
        $('div#galContent').click(closeGal);
    }











    // OVERLAY EFEKT
    $('a.overPic img').each(function() {
    
       popisekFotky = $(this).attr("alt");
       fotoWidth = $(this).width()+2;
       fotoHeight = $(this).height()+2;
              
       textPadding = Math.ceil((fotoHeight-20)*0.45);       
      
      
       $(this).before("<span class='picWrapper'><span class='picTextWrapper'>"+popisekFotky+"</span></span>");
       
       /*
       alert("HEIGHT: "+fotoHeight);      
       alert("REAL HEIGHT: "+fotoRealHeight);
       alert("VYSKA POPISKU: "+fotoRealHeight);
       alert("TEXT PADDING: "+textPadding);
        */
        
       $(this).prev('.picWrapper').css({
           'width': fotoWidth+'px',
           'height': (fotoHeight-textPadding)+'px',
           'padding-top': textPadding+'px'                 
       });
       
       $(this).mouseenter(function(){
           $(this).prev('.picWrapper').show();        
       });
       
    });

    
    /* CSSKOVE DEFINICE */    
    $('.picWrapper').css({
       'position': 'absolute',
       'z-index': 3,
       'background-color': '#464646',
       'color': '#ffffff',
       'display': 'block', 
       'text-align': 'center',
      
       'opacity': 0.8            
    });
    
    $('.picTextWrapper').css({    
        /* 'display': 'block', */
        'line-height': '20px',
        'margin': '0px',
        'padding': '0px',
        'text-transform': 'uppercase',
        'font-weight': 'bold'
        /* 'padding-top': '30%' */    
    });
    
    /* schova pri prvnim nacteni a pri mouseoutu */
    $('.picWrapper').hide().mouseleave(function() { $(this).hide(); });
    
    
 


    // OVERLAY EFEKT PRO FOTOGALERII, DETAIL
    $('a.refGalPic img').each(function() {
    
       popisekFotky = $(this).attr("alt");
       fotoWidth = $(this).width();
       fotoHeight = $(this).height();
              
       textPadding = Math.ceil((fotoHeight-40)*0.45);    
       leftPadding = Math.ceil((204 - fotoWidth)/2);   
      
      
       $(this).before("<span class='picGalWrapper'><span class='picGalTextWrapper'>"+popisekFotky+"<br/>(kliknutím otevřete)</span></span>");
       

       $(this).prev('.picGalWrapper').css({
           'width': fotoWidth+'px',
           'height': (fotoHeight-textPadding)+'px',
           'padding-top': textPadding+'px',
           'margin-left': leftPadding+'px'            
       });
       //'margin-left': '23px'
              
       $(this).mouseenter(function(){
           $(this).prev('.picGalWrapper').show();        
       });
       
    });

    
    /* CSSKOVE DEFINICE */    
    $('.picGalWrapper').css({
       'position': 'absolute',
       'z-index': 3,
       'background-color': '#464646',
       'color': '#ffffff',
       'display': 'block', 
       'text-align': 'center',
      
       'opacity': 0.8            
    });
    
    $('.picGalTextWrapper').css({    
        /* 'display': 'block', */
        'line-height': '20px',
        'margin': '0px',
        'padding': '0px',
        'text-transform': 'uppercase',
        'font-weight': 'bold'
        /* 'padding-top': '30%' */    
    });
    
    /* schova pri prvnim nacteni a pri mouseoutu */
    $('.picGalWrapper').hide().mouseleave(function() { $(this).hide(); });
    










    
    
    

});




