function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, resizable=yes, scrollbars=yes');
}


function openWindow(path, name, width, height) {

   var winl = (screen.width - width) / 2;
   var wint = (screen.height - height) / 2;

   style = eval("'status=no,width="+width+",height="+height+",left="+winl+",top="+wint+",resizable=no,menubar=no,scrollbars=yes,toolbar=no'");
   window.open(path, name, style) ;
}

var qslLabel = "";
function quickSearchLabel(val) {
	var v = $("#qSearch").val();
	qslLabel = val;
	if (v=="") {
		$("#qSearch").val(qslLabel);
		$("#qSearch").addClass("labelify");
	} 

	$("#qSearch").click(function() {
		$(this).removeClass("labelify");
		if ($(this).val()==qslLabel) {
			$("#qSearch").val("");
		}
	});

	$("#qSearchF").submit(function() {
		if ($("#qSearch").val()==qslLabel) {
			alert(qslLabel);
			return false;
		} else {
			return true;			
		}	
	});

	
}

window.onload = function() {  

	fancyBoxInit();
	externalLinks(); 

	//$("#cnt").height($("#main").height());
                 
    var offset = $("#floatForm").offset();
    var topPadding = -5;  
    $(window).scroll(function() {
        if ($(window).scrollTop() > offset.top) {
            $("#floatForm").css({
                top: $(window).scrollTop() - offset.top + topPadding
            });
            $("#floatForm span.grad").show();
        } else {
            $("#floatForm").css({
                top: 0
            });
            $("#floatForm span.grad").hide();
        };
    }); 

	
	if ($("#tipSc").length>0) {
     	$("#tipSlide").easySlider({
        	continuous: true,
			controlsShow: false,
        	auto: true,
			pause:	5000			
     	});
	}

    jQuery(function($){
		$(".book").find("li").hover(function() { $(this).addClass('over'); },function() { $(this).removeClass('over'); });
        
        $(".terminS").datepicker({tipSobota: 'true', showOn: 'both', 
			buttonImage: '/img/kalendar.gif', buttonImageOnly: true});                
		$(".terminSB").datepicker({tipSobota: 'true'});       
        
        var dates = $( "#terS, #terS2" ).datepicker({  
               numberOfMonths: 1,
               tipSobota: true,
               onSelect: function( selectedDate ) {
                   var option = this.id == "terS" ? "minDate" : "maxDate",
                       instance = $( this ).data( "datepicker" ),
                       date = $.datepicker.parseDate(
                           instance.settings.dateFormat ||
                           $.datepicker._defaults.dateFormat,
                           selectedDate, instance.settings );
                   dates.not( this ).datepicker( "option", option, date );

               } 
        });

		$(".addFav a").click(function() {
			addFav($(this).attr("rel"));
			$(this).addClass("active");
		});

		$("div#left").find("li").hover(function() { $(this).addClass('over'); },function() { $(this).removeClass('over'); });
 
    });      
}  

function fancyBoxInit() {

    $("a.thickbox").fancybox({   
        'titlePosition' : 'inside',     
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'elastic'
    });
    

    $("a.thickbox[rel=gallery]").fancybox({
        'transitionIn'        : 'elastic',
        'transitionOut'        : 'elastic',
        'titlePosition'     : 'inside',        
        'titleFormat'        : function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-inside">Obrázek ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }

    });
}

    

function checkEmail(val) {

    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(val)){
         return (true)
    }
    return (false)
}
