var speed = 200;

function initLightBox(element){
    element.lightBox({
        imageLoading:  R4BaseUrl + '/public/images/lightbox-ico-loading.gif',
	imageBtnPrev: R4BaseUrl + '/public/images/lightbox-btn-prev.gif',
	imageBtnNext: R4BaseUrl + '/public/images/lightbox-btn-next.gif',
	imageBtnClose: R4BaseUrl + '/public/images/lightbox-btn-close.gif',
	imageBlank: R4BaseUrl + '/public/images/lightbox-blank.gif',
        txtImage: '',
        txtOf: '-'
    });
}

$(document).ready( function(){
    $('div#menu > ul > li ').mouseenter(function( event ){
        /*var a = $(this).children('a');
        a.prepend('<img src="'+R4BaseUrl+'/public/images/arrow-right.gif" class="menu-arrow-right" />');
        a.children('img').rotateAnimation( 90 );*/
        $('ul.sub-menu', $(this)).fadeIn(speed, null);
    });

    $('ul.sub-menu').click( function(){$(this).fadeOut(speed, null)} );

    $('div#menu > ul > li').mouseleave(function( event ){
        $('ul', $(this)).fadeOut(speed, null);
        /*$('.menu-arrow-right').remove();*/
    });
    $('div#menu > ul > li > ul > li > a ').mouseenter( function(){
          $(this).css( 'background-color', 'white' );
          $(this).css( 'color', '#0071c1' );
    });
    $('div#menu > ul > li > ul > li > a ').mouseleave( function(){
          $(this).css( 'background-color', '#0071c1' );
          $(this).css( 'color', 'white' );
    });

    initLightBox( $('.lightbox') );
});

function fireEvent(obj,evt){
    var fireOnThis = obj;
    if( document.createEvent ) {
        var evObj = document.createEvent('MouseEvents');
        evObj.initEvent( evt, true, false );
        fireOnThis.dispatchEvent(evObj);
    } else if( document.createEventObject ) {
        fireOnThis.fireEvent('on'+evt);
    }
}

function showLightboxFromUrl( url ){
    var parts = url.split('/');
    var id = '';
    if( parts.length > 2 ) id = parts[ parts.length-2 ];
    if( $( '.light-box-container-'+id ).length > 0 ){
        fireEvent($( '.light-box-container-'+id ).children('a').get(0), 'click');
    }else{
        $.get(url, function( html ){
            var lightboxContainer = $(html).clone();
            $('body').append(lightboxContainer);
            initLightBox( lightboxContainer.children('a') );
            fireEvent(lightboxContainer.children('a').get(0), 'click');
        });
    }
}

var heads_index = 0;
var slide_images = 5;
var slider_counter = 0;
var flash_html = '<div id="fabricom-slideshow-0" class="slide"  width="950" height="296">'
    flash_html += '<object id="fabricom-slideshow-flash" width="950" height="296" style="z-index:0; position: relative;" type="application/x-shockwave-flash" data="' + R4BaseUrl + '/public/images/slide2.swf" >'
    flash_html += '<param name="movie" value="' + R4BaseUrl + '/public/images/slide2.swf" />';
    flash_html += '<param name="WMODE" value="Transparent" />';
    flash_html += '</object>';
    flash_html += '</div>';

function indexSlider(){
    var next = heads_index + 1;
    
    if( next >= slide_images ){
        next = 0;
    }
    if( slider_counter > 0 && next==0 ){//nejedu poprve
        $('#fabricom-slideshow-1').before( flash_html );
    }
    $('#fabricom-slideshow-' + heads_index).fadeOut(2000, function(){
        if( heads_index==0 ){
            $('#fabricom-slideshow-' + heads_index).remove();
        }
    });
    $('#fabricom-slideshow-' + next).fadeIn(1000);
    heads_index = next;
    slider_counter++;
}

