function createGallery()
{
    var box = [];
    
    $('a[rel*=lightbox][class="iconGaleriImg"]').each(function() {
        if ( $.inArray($(this).attr('rel'), box) ) {
            box.push($(this).attr('rel'));
        }
    });
    
    $(box).each(function(i, val) {
        $('a[rel='+val+']').lightBox();
    });
}

function getMaxHeight()
{

    return Math.max($(document).height(),$(window).height(),document.documentElement.clientHeight, document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight);
}
/*
function scrollDownAndUp()
{
   sleep(1);
   $('html, body').animate({ scrollTop: getMaxHeight()}, 2000);
   sleep(1);
   $('html, body').animate({scrollTop:0}, 2000);
   sleep(1);
}
*/

function showGoogleMap()
{
	var GPSPOS_X = 50.08793;
	var GPSPOS_Y = 14.480556;
	var ZOOM = 17;

	if ($("div#gmap").length > 0)
	{
		if (GBrowserIsCompatible()) {
			map = new GMap2(document.getElementById('gmap'));
                        map.setMapType(G_HYBRID_MAP);
			map.setCenter(new GLatLng(GPSPOS_X, GPSPOS_Y), ZOOM);
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());

			var point = new GLatLng(GPSPOS_X, GPSPOS_Y);
			map.addOverlay(new GMarker(point));
		}
	}
}

function refreshAds()
{
    if ($('#adsBlock').length > 0)
    {
        var h = 0;
        var arEls = $('#adsBlock .slider_content_step').get();
        var h2;

        for (var i = 0; i < arEls.length; i++) {
            h2 = arEls[i].offsetHeight;
            if(h2 > h) {h = h2;}
        }

        var el = document.getElementById("adsBlock");
        el.style.height = h + "px";
    }
}

function doPopup()
{
   if ($('#newsBlock').length > 0 && $('#popup-window').length > 0)
   {
       showClone();
       $('#popup-window').css('display', 'block');
       $('#popup-window').animate({top: '+=630'}, 2500, function(){});
       $('#popup-window .popup-close').click(function(){
          $('#popup-window').css('display', 'none');
          hideClone();
       });
   }
}

function detectMobileDevice()
{
   var ret = 0;
   try
   {
       if (location.href.search(/interaktivni/) == -1 && isMobileDevice == 1)
       {
          ret = 1; 
       }
   } catch(e)
   {
       ret = 0;
   }
   
   return ret;
}

$(document).ready(function(){
    doPopup();
    createGallery();
    showGoogleMap();
    
    if ($('div.signPostBlock').length > 0)
    {
    //    scrollDownAndUp();
    }
    
    /*if ($('.popup-now').length > 0)
    {
        showInterestForm();
    }*/

   if ($('.pngFix').length > 0)
   {
        $('.pngFix').pngfix();
   }

   $("#hpTabs").tabs({selected: detectMobileDevice()});

    refreshAds();

    $("#adsBlock").easySlider({
        prevText:'<img src="'+MVC_BASE_PATH+'style/img/blank.gif" />',
        nextText:'<img src="'+MVC_BASE_PATH+'style/img/blank.gif" />',
        orientation:'horizontal',
        pause:5000
    });
});


