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 teShrink(no) {
	$("li#te"+no).stop().animate({width:'26px'},500);
}

function teExpand(no) {
	$("li#te"+no).stop().animate({width:'326px'},450);
}

function topEvent() {

	var topL = 2;

	$("ul#topevent h3 a").click(function() {
		var id = parseInt($(this).parent().parent().attr("id").substr(2,10));
		
		for (i=1; i<=topL; i++) {
			if (i!=id) {
				teShrink(i);
			}
		}

		teExpand(id);

	});


}

function float(el) {

	//$(el).css("top",-$("div#page").position().top);
	//$(el+"L").css("top",-$("div#page").position().top+0);
}
    

window.onload = function() {

	fancyBoxInit();	
	topEvent();
    externalLinks();

	$("#linkBuildData a").attr("target","_blank");

	$("#fbframe").html('<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fharrachovinfo.cz&amp;width=130&amp;colorscheme=light&amp;show_faces=true&amp;stream=false&amp;header=true&amp;height=660" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:130px; height:660px; background: #fff;" allowTransparency="false"></iframe>');

	$("ul#menu>li").prepend("<span class=\"roh\"></span>"); 

	$(window).scroll(function () { 
      float("div#sky");
    });
	$(window).resize(function () { 
      float("div#sky");
    });
	float("div#sky"); 

    $("ul#menu>li").mouseover(function(){ 
      $(this).addClass("over");
    }).mouseout(function(){    
      $(this).removeClass("over");
    });     
    
    jQuery(function($){
        $(".txtDate").datepicker({showOn: 'both', buttonImage: '/img/calendar.gif', buttonImageOnly: true});
        $(".txtDateO").datepicker({showOn: 'both', buttonImage: '/img/pt.gif', buttonImageOnly: true});
        $(".txtDateS").datepicker({tipSobota: 'true', showOn: 'both', buttonImage: '/img/calendar.gif', buttonImageOnly: true});        
    }); 

	
	$('a[href*=#]').click(function() {
	    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	    && location.hostname == this.hostname) {
	      var $target = $(this.hash);
	      $target = $target.length && $target 
	      || $('[name=' + this.hash.slice(1) +']');
	      if ($target.length) {
	        var targetOffset = $target.offset().top;
	        $('html,body')
	        .animate({scrollTop: targetOffset}, 1000);
	       return false;
	      }
	    }
	});    


}  

function fancyBoxInit() {

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

    $("a.pano").fancybox({   
		'width': 850,
		'height': 550,
        'titlePosition' : 'inside',     
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'elastic'
    });

    $("a.iframe").fancybox({   
		'width': 1045,
		'height': 770,
		'type': 'iframe',
        'titlePosition' : 'inside',     
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'elastic'
    });

    $("a.iframe2").fancybox({   
		'width': 650,
		'height': 540,
		'type': 'iframe',
        '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>';
        }

    });

    $("a.iframe1").fancybox({   
		'width': 1065,
		'height': 770,
		'type': 'iframe',
        'titlePosition' : 'inside',     
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'elastic'
    });

    $("a.iframe21").fancybox({   
		'width': 665,
		'height': 510,
		'type': 'iframe',
        'titlePosition' : 'inside',     
        'transitionIn'    : 'elastic',
        'transitionOut'    : 'elastic'
    });
}

var lastGM = "gMapD";
var timeOutC = 1;

function gM(id,no,link) {
    $("#gUl>li").removeClass("active");
    $("#gm"+no).addClass("active");    
    
    if (id==lastGM) { 
		if (no==3) { window.location.href = link; }
		return; 
	}
    
	clearTimeout(tOut);

    $("#"+lastGM).css("zIndex",10);
    $("#"+id).css("zIndex",9);    
    $("#"+id).show();                
    $("#"+lastGM).fadeOut(500,function() { $(this).hide(); });    
    
    lastGM = id;
}

function nejChange() { 
	return 0;

	switch (timeOutC) {
	case 2:
		gM('gDop',1); timeOutC = 0; 
		break;
	case 1:
		gM('gNej',2); timeOutC = 2; 
		break;
	default:
		gM('gMapD',3,'{{gmMapLink}}'); timeOutC = 1; 
	} 


	tOut = setTimeout("nejChange()",4000);
}


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) ;
}   







