//$(document).ready(function(){$('#gallery a').lightBox();});
var galleries;
$(document).ready(function(){
	galleries = $('.ad-gallery').adGallery({
	  loader_image: '/_images/loader.gif',
	  width: 600, // Width of the image, set to false and it will read the CSS width
	  height: 400, // Height of the image, set to false and it will read the CSS height
	  thumb_opacity: 0.5, // Opacity that the thumbs fades to/from, (1 removes fade effect)
						  // Note that this effect combined with other effects might be resource intensive
						  // and make animations lag
	  start_at_index: 0, // Which image should be displayed at first? 0 is the first image
	  animate_first_image: true, // Should first image just be displayed, or animated in?
	  animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
	  display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
	  display_back_and_forward: true, // Are you allowed to scroll the thumb list?
	  scroll_jump: 0, // If 0, it jumps the width of the container
	  slideshow: {
		enable: true,
		autostart: true,
		speed: 5000,
		start_label: 'Start',
		stop_label: 'Stop',
		stop_on_scroll: false, // Should the slideshow stop if the user scrolls the thumb list?
		countdown_prefix: '(', // Wrap around the countdown
		countdown_sufix: ')'
	  },
	  effect: 'fade', // or 'slide-vert', 'resize', 'fade', 'none' or false
	  enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
	  cycle: true // If set to false, you can't go from the last image to the first, and vice versa
	});
});
function game(address,width,height){
	$(".flashbg").show();
	$("#flash_player").html('<div class="cls"><a href="javascript:closeGame();"> Zatvor hru </a></div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="FlashID" title="'+name+'"><param name="movie" value="'+address+'"><param name="quality" value="high"><param name="wmode" value="transparent"><param name="swfversion" value="9.0.45.0"><!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. --><!--[if !IE]>--><object type="application/x-shockwave-flash" data="'+address+'" width="'+width+'" height="'+height+'"><!--<![endif]--><param name="quality" value="high"><param name="wmode" value="transparent"><param name="swfversion" value="9.0.45.0"><div><h4>Content on this page requires a newer version of Adobe Flash Player.</h4><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p></div><!--[if !IE]>--></object><!--<![endif]--></object>').show();
	centerDiv("flash_player");//<param name="expressinstall" value="inc/expressInstall.swf" />
	//swfobject.registerObject("FlashID");
}
function closeGame(){
	$(".flashbg").add("#flash_player").hide();
}
function centerDiv(id,top_only) {
	var top = top_only == "undefined" ? 0 : top_only;
	var windowScroll = WindowUtilities.getWindowScroll();    
	var pageSize = WindowUtilities.getPageSize();    
	
	if(top==0){
		var top = (pageSize.windowHeight - $('#'+id).height())/2;
		top += windowScroll.top;
		top = top < 0 ? 0 : top;
	}
	
	var left = (pageSize.windowWidth - $('#'+id).width())/2;
	left += windowScroll.left;
	
	$('#'+id).css({top: top + 'px', left: left + 'px'});
}
// JavaScript Document
var WindowUtilities = {  
  getWindowScroll: function() {
    var w = window;
      var T, L, W, H;
      L = window.pageXOffset || document.documentElement.scrollLeft;
      T = window.pageYOffset || document.documentElement.scrollTop;

      if (window.ie) {
        W = Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth);
	  } else if (window.khtml){ 
  		  W = document.body.scrollWidth;
	  } else {
  		  W = document.documentElement.scrollWidth;
	  }
  		if (window.ie) {
  		  H = Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight);
		} else if (window.khtml) { 
    	  H = document.body.scrollHeight;
		} else {
    	  H = document.documentElement.scrollHeight;
		}
      return { top: T, left: L, width: W, height: H };
  }, 
  //
  // getPageSize()
  // Returns array with page width, height and window width, height
  // Core code from - quirksmode.org
  // Edit for Firefox by pHaez
  //
  getPageSize: function(){
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {  
      xScroll = document.body.scrollWidth;
      yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {  // all except Explorer
      windowWidth = self.innerWidth;
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
    }  
    var pageHeight, pageWidth;

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
      pageHeight = windowHeight;
    } else { 
      pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
      pageWidth = windowWidth;
    } else {
      pageWidth = xScroll;
    }

    return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  },

  disableScreen: function(className, overlayId, overlayOpacity, contentId) {
    var that = this;
    WindowUtilities.initLightbox(overlayId, className, function() {that._disableScreen(className, overlayId, overlayOpacity, contentId)});
  },

  _disableScreen: function(className, overlayId, overlayOpacity, contentId) {
    var objBody = document.body;

    // prep objects
    var objOverlay = $(overlayId);

    var pageSize = WindowUtilities.getPageSize();

    // Hide select boxes as they will 'peek' through the image in IE, store old value
    if (contentId && window.ie) {
      WindowUtilities._hideSelect();
      WindowUtilities._showSelect(contentId);
    }  
  
    // set height of Overlay to take up whole page and show
    objOverlay.style.height = (pageSize.pageHeight + 'px');
    objOverlay.style.display = 'none'; 
    if (overlayId == "overlay_modal" && Window.hasEffectLib && Windows.overlayShowEffectOptions) {
      objOverlay.overlayOpacity = overlayOpacity;
      new Effect.Appear(objOverlay, Object.extend({from: 0, to: overlayOpacity}, Windows.overlayShowEffectOptions));
    }
    else {
      objOverlay.style.display = "block";
	}
  },
  
  enableScreen: function(id) {
    id = id || 'overlay_modal';
    var objOverlay =  $(id);
    if (objOverlay) {
      // hide lightbox and overlay
      if (id == "overlay_modal" && Window.hasEffectLib && Windows.overlayHideEffectOptions) {
        new Effect.Fade(objOverlay, Object.extend({from: objOverlay.overlayOpacity, to:0}, Windows.overlayHideEffectOptions));
	  } else {
        objOverlay.style.display = 'none';
        objOverlay.parentNode.removeChild(objOverlay);
      }
      
      // make select boxes visible using old value
      if (id != "__invisible__") {
        WindowUtilities._showSelect();
	  }
    }
  },

  _hideSelect: function(id) {
    if (window.ie) {
      id = id ==  null ? "" : "#" + id + " ";
      $$(id + 'select').each(function(element) {
        if (! WindowUtilities.isDefined(element.oldVisibility)) {
          element.oldVisibility = element.style.visibility ? element.style.visibility : "visible";
          element.style.visibility = "hidden";
        }
      });
    }
  },
  
  _showSelect: function(id) {
    if (window.ie) {
      id = id ==  null ? "" : "#" + id + " ";
      $$(id + 'select').each(function(element) {
        if (WindowUtilities.isDefined(element.oldVisibility)) {
          // Why?? Ask IE
          try {
            element.style.visibility = element.oldVisibility;
          } catch(e) {
            element.style.visibility = "visible";
          }
          element.oldVisibility = null;
        }
        else {
          if (element.style.visibility) {
            element.style.visibility = "visible";
		  }
        }
      });
    }
  },

  isDefined: function(object) {
    return typeof(object) != "undefined" && object != null;
  },
  
  // initLightbox()
  // Function runs on window load, going through link tags looking for rel="lightbox".
  // These links receive onclick events that enable the lightbox display for their targets.
  // The function also inserts html markup at the top of the page which will be used as a
  // container for the overlay pattern and the inline image.
  initLightbox: function(id, className, doneHandler) {
    // Already done, just update zIndex
    if ($(id)) {
      Element.setStyle(id, {zIndex: Windows.maxZIndex + 1});
      Windows.maxZIndex++;
      doneHandler();
    }
    // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
    else {
      var objBody = document.body;
      var objOverlay = document.createElement("div");
      objOverlay.setAttribute('id', id);
      objOverlay.className = "overlay_" + className;
      objOverlay.style.display = 'none';
      objOverlay.style.position = 'absolute';
      objOverlay.style.top = '0';
      objOverlay.style.left = '0';
      objOverlay.style.zIndex = Windows.maxZIndex + 1;
      Windows.maxZIndex++;
      objOverlay.style.width = '100%';
      objBody.insertBefore(objOverlay, objBody.firstChild);
      if (window.khtml && id == "overlay_modal") {
        setTimeout(function() {doneHandler()}, 10);
      }
      else {
        doneHandler();
	  }
    }    
  },
  
  setCookie: function(value, parameters) {
    document.cookie= parameters[0] + "=" + escape(value) +
      ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
      ((parameters[2]) ? "; path=" + parameters[2] : "") +
      ((parameters[3]) ? "; domain=" + parameters[3] : "") +
      ((parameters[4]) ? "; secure" : "");
  },

  getCookie: function(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else {
      begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
      end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
  },
    
  _computeSize: function(content, id, width, height, margin, className) {
    var objBody = document.body;
    var tmpObj = document.createElement("div");
    tmpObj.setAttribute('id', id);
    tmpObj.className = className + "_content";

    if (height) {
      tmpObj.style.height = height + "px"
	} else {
      tmpObj.style.width = width + "px"
	}
	
    tmpObj.style.position = 'absolute';
    tmpObj.style.top = '0';
    tmpObj.style.left = '0';
    tmpObj.style.display = 'none';

    tmpObj.innerHTML = content;
    objBody.insertBefore(tmpObj, objBody.firstChild);
    
    var size;
    if (height){
      size = $(id).getDimensions().width + margin;
	}else{
      size = $(id).getDimensions().height + margin;
	}
	objBody.removeChild(tmpObj);
    return size;
  }  
}

$(document).ready(function(){
	akcie.init(true);
});
var akcie = {
	interval:null,
	interval_is:false,
	timeout:5000,
	obj:null,
	init:function(auto){
		$("#akcie_flash").find(".links").find("a").each(function(){
			$(this).click(function(){
				akcie.set($(this).attr("check"),true);
				return false;
			});
		});
		if(auto){
			akcie.set(1);
			akcie.interval = setTimeout("akcie.set(2,false);",akcie.timeout);
			akcie.interval_is = true;
		}
		akcie.setBg();
	},
	set:function(id,clickIs){
		if(id!=0){
			obj = $("#akcie_flash");
			akcie.obj = obj;
			obj1 = $(".link_"+id);
			var left1 = obj1.position();
			var posLeft = 0;
			if(left1){
				posLeft = left1.left+(20);
			}
			obj.find(".selected").animate({left:posLeft},"fast");
			obj.find(".image").fadeOut(100);
			setTimeout("akcie.obj.find('#akcia_"+id+"').fadeIn('slow');",150);
			
			
		}
		if(clickIs==true || akcie.interval_is==false){
			clearTimeout(this.interval);
			akcie.interval_is = false;
		}else{
			id++;
			if(id>3){
				id=1;
			}
			akcie.interval = setTimeout("akcie.set("+id+",false);",akcie.timeout);
		}
	},
	setBg:function(){
		obj = $("#akcie_flash");
		var left1 = obj.position();
		var posLeft = 0;
		if(left1){
			posLeft = left1.left;
		}
		obj.find(".imageBG").animate({left:posLeft},"fast");
		obj.find(".imageBG").show();
	}
};
