var carousel = null;

function getBrowserWindowSize () {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return ({width: myWidth, height: myHeight});
}

function resizeFlash () {
 $$('embed').each (function (i) {
 	if (i.name=='tlo02' || i.name=='tlo01') {
 		var bheight=getBrowserWindowSize().height;
 		var iheight=((window.innerHeight && window.scrollMaxY)?(window.innerHeight + window.scrollMaxY):((document.body.scrollHeight > document.body.offsetHeight)?(document.body.scrollHeight):(document.body.offsetHeight)));
		var newHeight = (bheight>iheight)?bheight:iheight;
		i.style.height=newHeight+'px';
 	}
 });
}

function prepareImages () {
	$$('#horizontal_carousel div.container ul li').each (function (i) {
		var img = Element.firstDescendant (i);
		var smallimg = img.title;
		var bigimg = img.title.replace(/miniature\//,'');
		i.innerHTML='<a href="'+bigimg+'" rel="lightbox[portfolio]"><img src="'+smallimg+'"/></a>';
	});

	carousel = new UI.Carousel("horizontal_carousel");
	new Lightbox();
	$$('#miniaturki ul li img').each (function (i) {
		i.src="/galleryimg.php?img="+i.title+"&w=150&addhost=";
		var onClick = function () {
			carousel.scrollTo(this.id.split('_')[1]);
		}
		i.onclick = onClick;
		i.style.cursor = "pointer";
	});

}

Event.observe (window, 'resize', resizeFlash);   
Event.observe(window, 'load', function () {
	var cnt=1;
	$$('span.menu_buttons').each (function (i) {
		i.innerHTML=(cnt<10)?'0'+cnt:cnt;
		cnt++;
	});
	resizeFlash();
	if ($('horizontal_carousel')) prepareImages();	
});

