
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function isArray(obj) {
    if (obj.constructor.toString().indexOf("Array") == -1)
        return false;
    else
        return true;
}

$(document).ready(function(){
    
        /* TOOLTIP/DIALOG */
        new Tooltip(new TooltipRequest({
            url: '/ajax/messenger/'
        }));
	
	/* ZOBRAZENI PRIHLASOVACIHO BOXU NAHORE V HLAVICCE */
	$('#button-login').click(function() {
		$('#login-box').toggle();
		return false;
	});
	
	/* SKYSCRAPER - ROLLOVANI BANNERU SE STRANKOU */
	var bodywidth = $('#body').width();
	var bodyheight = $('#body').height();
	var skyscraperAd = $('.skyscraper');
        var leftpanel = $('.left-panel');

        if (skyscraperAd.length > 0) {
            var skyscraperOffset = skyscraperAd.offset().top;
            var skyscraperBottom = $("#footer").offset().top - skyscraperAd.height() + 400;
            skyscraperright = (bodywidth/2) - 125 - 517
            //$('#skyscraper').css('right', skyscraperright)
            $(window).scroll(function() {
            skyscraperAd.stop();
            var windowTop = $(window).scrollTop();
            if (windowTop > skyscraperOffset) {
		if (windowTop > skyscraperBottom) windowTop = skyscraperBottom;
		if (windowTop < 0) windowTop = 0;
		skyscraperAd.animate({top: windowTop + 15 + 'px'}, 'fast');
            } else
		skyscraperAd.animate({top: skyscraperOffset + 'px'},'fast');
            });
	
            $(window).resize(function() {
		var windowwidth = $(window).width();
		if (windowwidth < 1280) {
                    $('.skyscraper').hide();
                } else {
                    $('.skyscraper').show();
                }
            });
        
            $(window).trigger('resize');
        }
        
	/* LEFT PANEL */
        if (leftpanel.length > 0) {
            leftpanel.each(function() {
                var iter = 0;
                var adsleftpos = (bodywidth - 1044) / 2;
                var _panel = $(this);
                /* nastaveni */
                _panel.css('left',adsleftpos);
                
                $(window).resize(function(){
                    var adsleftpos = ($(window).width() - 1044) / 2;
                    _panel.css('left', adsleftpos);
                });
                
                $('.pane',_panel).each(function(){
                    var _self = $(this);
					var _content = {
                        instance: $('.content',_self),
                        size: $('.content',_self).width()
					};

					/*_self.css('width',_content.size);*/
                
                    /* manipulace s panelem */
                    $('a.href',_self).click(function(){
                        if (_content.instance.css('display') == 'none') {
                            _content.instance.show('normal');
                        } else {
                            _content.instance.hide(300,function(){
								$(this).attr('style','');
							});
                        }return false;
                    });
                
                    $('#body').click(function(){
                        if (_content.instance.css('display') != 'none') {
                            _content.instance.hide(300,function(){
								$(this).attr('style','');
							});
                        }
                    });
                
                    setTimeout(function(){
						_self.css('visibility','visible');
                        _self.animate({
                            opacity: 1
                        },200,function(){
                            _self.animate({
                                'padding-left': '+=15'
                            },200,function(){
                                _self.animate({
                                    'padding-left': '-=15'
                                });
                            });
                        });
                    },(iter++)*1000);
                });
            });
        }        
        
        /* NASTAVI VYCHOZI HODNOTY PRO INPUT POLE */
        $(':input').each(function(){
            
            if ($(this).attr('title')) {
            
                if ($(this).val() == '' && $(':focus').get(0) != $(this).get(0)) {
                    $(this).val($(this).attr('title'));
                } else if ($(this).attr('title') != $(this).val()) {
                    $(this).addClass("actInput");
                }
                
                
                $(this).blur(function(){
                    if ($(this).val() == '') {
                        $(this).val($(this).attr('title'));
                        $(this).removeClass("actInput");
                    }
                });
                
                $(this).focus(function(){
                    if ($(this).val() == $(this).attr('title')) {
                        $(this).val('');
                        $(this).addClass("actInput");
                    }
                });
                
            }

        });
        
        /* PRI ODESLANI JAKEHOKOLIV FORMULARE VYMAZE VYCHOZI HODNOTY */
        $('form').submit(function(){
            $(':input',$(this)).each(function(){
                if ($(this).attr('title') == $(this).val()) {
                    $(this).val('');
                }
            });
        });
        
        /* JCAROUSEL */
        $('.jcarousel').each(function() {
            var frameID = $(this).attr('id');
            
            function carousel_init(carousel) {
                $('#'+frameID+'_next').bind('click',function(){
                    carousel.next();
                    carousel.startAuto(0);
                    return false;
                });
                $('#'+frameID+'_prev').bind('click',function(){
                    carousel.prev();
                    carousel.startAuto(0);
                    return false;
                });

                carousel.clip.hover(function() {
                    carousel.stopAuto();
                }, function() {
                    carousel.startAuto();
                });
            }
           
            $(this).jcarousel({
                scroll: 1,
                auto:6,
                initCallback: carousel_init,
                wrap: 'circular',
                buttonNextHTML: null,
                buttonPrevHTML: null
            }); 
        });
        
	/* MENU - SUBMENU */
        function displayMenu(col) {
            if (col.find('a:first-child').hasClass('act') == false) {
                col.find('a').addClass('submenu-act');
                col.parent().find('a.act').css('z-index', '1000')
                col.parent().find('a.submenu-act').css('z-index', '10000000')
                col.find('.submenu-content').css('left', col.find('a').offset().left - $('#menu').offset().left)
                col.find('.submenu-content').show();
                col.find('.submenu-leftcorner').show();
            }
        }
        
        function hideMenu(col) {
            col.find('a').removeClass('submenu-act');
            col.parent().find('a.act').removeAttr('style');
            col.parent().find('a.submenu-act').removeAttr('style');
            col.find('.submenu-content').hide();
            col.find('.submenu-leftcorner').hide();            
        }
        
	$('#menu li.submenu').mouseenter(function() {
            displayMenu($(this));
	}).mouseleave(function(){
            hideMenu($(this));
        });
        
        $('#menu li.submenu a:first-child').click(function() {
            var regExp = new RegExp('^javascript','i');
            
            if ($(this).attr('href').match(regExp) || $(this).attr('href') == '') {
                displayMenu($(this).parent());
                return false;
            }
            
            return true;
        });
	
	/* DISKUZNI TEMATA - ZVYRAZNUJE VYBRANY RADEK V SEZNAMU TEMAT */
	$("table.list td").mouseenter(function(){
		$(this).parent().addClass('act')
	}).mouseleave(function(){
		$(this).parent().removeClass('act')
	});
	
	/* PREPINANI ZALOZEK V PRAVEM SLOUPCI - POMOC ONLINE */
	$('.tab-href span').click(function() {
		$('.sidetab-switcher li').removeClass('act');
		$(this).parent().parent().addClass('act');
		
		return false;
	});
	
	/* SWITCH PRO VYBER MUZE - POMOC ONLINE */
	$('.switch-male').click(function() {
		$(this).addClass('switch-male-act');
		$('.switch-female').removeClass('switch-female-act');
		$('#online-tab-1 .right img').addClass('hide');
		$('.male-front').removeClass('hide');
		
		return false;
	});
	
	/* SWITCH PRO VYBER ZENY - POMOC ONLINE */
	$('.switch-female').click(function() {
		$(this).addClass('switch-female-act');
		$('.switch-male').removeClass('switch-male-act');
		$('#online-tab-1 .right img').addClass('hide');
		$('.female-front').removeClass('hide');
		
		return false;
	});
        
        $('.poll').inquiry();
        $('.figure').figureSignpost({bodylists: $('.bplist')});
        $('.like-page').likes();
        $('.discussion').discussion();
        $('.list-switcher').listSwitcher();
        $('.chatroom').onlinechat();
        $('.form.clinic').clinic();
        $('#rightcol .ad').floatingAdvert();
        
        Loader.run('jquery-newsletter.js',{callback:function(){
            nwl_board();
        }});
        Loader.dispatch();
	
	/* ZOBRAZENI VSECH GRAFICKYCH SELEXTBOXU */
	$('.selectbox').selectbox();
	
	$('.checkbox').prettyCheckboxes({'display':'inline'});
	$('.radio').prettyCheckboxes({'display':'inline'});
        
        $('a').click(function(){
            var regex = [
                new RegExp('www.ordinace.cz','i'),
                new RegExp('ordinace.cz','i'),
                new RegExp('javascript:','i'),
                new RegExp('vyvoj.ordinace.cz','i'),
                new RegExp('new.ordinace.cz','i'),
                new RegExp('preview.ordinace.cz','i')
            ];
            var cnt = 0;

            for(var i=0;i<regex.length;i++) {
                if (!($(this)[0].href.match(regex[i]))) {
                    cnt++;
                } else {
                    break;
                }
            }
            
            if (cnt == regex.length) {
                window.open($(this).attr('href'),'_blank');
                //odkomentovani nic neudela, ponechal jsem pro strycka prihodu
                //logURL(window.location,this.href);
                return false;
            }
            
            return true;
        });

        /* Google+ plusOne */
        window.___gcfg = {lang: 'cs'};

        (function() {
            var po = document.createElement('script');
            po.type = 'text/javascript';
            po.async = true;
            po.src = 'https://apis.google.com/js/plusone.js';
            
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(po, s);
        })();
});	

