
$(window).load(function(){

//external link to new window			   
$('body a').filter(function() { 
    return this.hostname && this.hostname !== location.hostname; 
  }).addClass('external')
  .click(function() { 
    window.open(this.href); 
    return false; 
  });
		
});

$(document).ready(function() {
    
    
    $("#md_krizek, .md_overlay").click(function() {
        $(".md_overlay").hide();
        $('#md_content').html('');
        $("#md_doleva, #md_doprava").hide();
    });
        
    $("#md_doleva").click(function(e) {
        prevImage();
        zrusBublani(e);
    });
        
    $("#md_doprava").click(function(e) {
        nextImage();
        zrusBublani(e);
    });
    
    $("#md_content").click(function(e){
        zrusBublani(e);        
    });
});

function showFlash(adresa, sirka, vyska) {

    $('#md_content').flash({swf:adresa,width:sirka,height:vyska});
    $("#md_window").css({"margin-left": "-"+sirka/2+"px", "margin-top": "-"+vyska/2+"px"});
    $("#md_content").css({"width": sirka+"px", "height": vyska+"px"});
    
    $(".md_overlay").show();
}

var mdImagesCount = null;
var mdCurrentImage = null;
var pAdres = null;
var pSirek = null;
var pVysek = null;

function showImage(adresy) {
    
    pAdres = adresy.split(";");  
    mdImagesCount = pAdres.length;
    home = $('.domecek a').attr('href');
    mdCurrentImage = 1;
    
    changeImage(1);
}

function nextImage() {
    if(mdCurrentImage < mdImagesCount) {
        changeImage(++mdCurrentImage);
    }
}

function prevImage() {
    if(mdCurrentImage > 1) {
        changeImage(--mdCurrentImage);
    }
}

function changeImage(cisloObrazku) {
    $(".md_overlay").show();
    $("#md_doleva, #md_doprava").show();


    $("#md_content").html("");
    
    $("#md_content").html("<img src='"+pAdres[cisloObrazku-1]+"' id='md_image' />");
  
    $("#md_image").load(function(){
        mdResize(this.clientWidth, this.clientHeight);    
    });
    
    if(mdCurrentImage == mdImagesCount) {
        $("#md_doprava").attr("src", home+"design/doprava-seda.png");
        $("#md_doprava").css({"cursor": "auto"});
    } else {
        $("#md_doprava").attr("src", home+"design/doprava.png");
        $("#md_doprava").css({"cursor": "hand", "cursor": "pointer"});
    }
     
    if(mdCurrentImage == 1) {
        $("#md_doleva").attr("src", home+"design/doleva-seda.png");
        $("#md_doleva").css({"cursor": "auto"});
    } else {
        $("#md_doleva").attr("src", home+"design/doleva.png");
        $("#md_doleva").css({"cursor": "hand", "cursor": "pointer"});
    }  
}

// !!! vyžaduje nastavenou proměnnou HOME
function showVideo(adresa, sirka, vyska) {
    home = $('.domecek a').attr('href');
    var flash = new SWFObject(home + "swf/video-prehravac.swf", "line", sirka , vyska, "8");
   
    mdResize(sirka, vyska);
    
    flash.addParam("wmode", "transparent");
    flash.addVariable("cesta", adresa);
    flash.write("md_content");
    
    $(".md_overlay").show();
}

function mdResize(sirka, vyska) {
        
    if($(window).height() < vyska) {
        $("#md_window").css({"margin-left": "-"+sirka/2+"px", "margin-top": "-"+(($(window).height() / 2)-5)+"px"});
        $("#md_content").css({"width": (sirka+getScrollerWidth())+"px", "height": ($(window).height()-40)+"px", "overflow" : "auto"});
    } else {
        $("#md_window").css({"margin-left": "-"+sirka/2+"px", "margin-top": "-"+vyska/2+"px"});
        $("#md_content").css({"width": sirka+"px", "height": vyska+"px"});
    }
    

}

function zrusBublani(e) {
    if(e && e.stopPropagation) {
        e.stopPropagation();
    } else {
        window.event.cancelBubble = true;
    }
}




function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;
 
    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';
 

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';
 
    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
 
    document.body.appendChild(scr);
 
    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;
 
    // Remove the scrolling div from the doc
    document.body.removeChild(
    document.body.lastChild);
 
    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}


