$(document).ready(function(){
	bind_content ();
	bind_hover ();
	bind_banner ();
	bind_gallery_overlay ();
	bind_table ();
	bind_path ();
	bind_panel();
	bind_tabs();
	bind_gallery ();
	bind_lightbox ();
});

function bind_lightbox ()
{
    $('.gallery,.images').each(function(){
    	$('a[rel=lightbox]', this).lightBox({
			overlayBgColor: '#000',
			overlayBgImage: '',
			overlayOpacity: 0.6,
			imageLoading: '/plugins/gallery-lightbox/img-cs/lightbox-ico-loading.gif',
			imageBtnClose: '/plugins/gallery-lightbox/img-cs/lightbox-btn-close.gif',
			imageBtnPrev: '/plugins/gallery-lightbox/img-cs/lightbox-btn-prev.gif',
			imageBtnNext: '/plugins/gallery-lightbox/img-cs/lightbox-btn-next.gif',
			containerResizeSpeed: 350,
			txtImage: 'Obrázek',
			txtOf: '/'
		});
	});
}

function bind_tabs ()
{
	$(function() {
		$("#tabs").tabs();
	});
}

function bind_content ()
{
	$('.content .article:first').addClass('firstarticle');
}

/**
 * hover efekt na menu, tlacitka v paticce a tlacitka plus v cycle banneru
 **/
function bind_hover ()
{
	$(".menu li, .path li, .presentation-link, .gallery .image").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
		
	$(".banner .item .plus .button").hover(
		function() {$(this).parent().addClass("sfhover");},
		function() {$(this).parent().removeClass("sfhover");}
	);

	$("a.media").hover(
		function() {$(this).addClass("sfhover");},
		function() {$(this).removeClass("sfhover");}
	);
}

/**
 * smazani textu v inputech
 **/
function bind_banner ()
{	
	$(".registration-domain").Watermark("domena.cz");
	$(".registration-email").Watermark("Váš e-mail");
}

/**
 * gallery overlay - oranzove oramovani a tlacitko plus
 * overlay pres obrazky v clanku 
 **/
function bind_gallery_overlay ()
{	
	$(".gallery .image").prepend('<div class="overlay"></div>');
	$(".benefit .media").prepend('<div class="overlay"></div>');
	/*$(".content .article img.preview-right, .content .panel img.preview-right").before('<div class="overlay"></div>');*/	
}

/**
 * tabulka - liche a sude bunky
 **/
function bind_table ()
{
	var i=0;
	var j=0;
	$(".content table tr").each(function(){
		// radky
		if(i==1) {
			$(this).addClass("even");
			i=0;
		}
		else {
			$(this).addClass("odd");
			i++;
		}
		// sloupce
		j=0;
		$("td, th", this).each(function(){
			if(j==1) {
				$(this).addClass("even");
				j=0;
			}
			else {
				$(this).addClass("odd");
				j++;
			}
			// true a false
			if($(this).html() == "true") $(this).html('<img src="/img/image-true.png" alt="ano" title="ano" />');
			if($(this).html() == "false") $(this).html('<img src="/img/image-false.png" alt="ne" title="ne" />');
		});
	});
	
    // table for page "Ceny a prehled funkci"
    var i=0;
	var j=0;
	$(".table-capf tr").each(function(){
        if (i!=0){
    		j=0;
    		$("td, th", this).each(function(){
                if(j==0) { $(this).addClass("table-capf-td-funkce"); }
    			else if(j==1) { $(this).addClass("table-capf-td-row2"); }
    			else if (j==2) { $(this).addClass("table-capf-td-row3"); }
                j++;
    		});
        }
        else {i++;}
	});
}

/**
 * path - posledni viditelny prvek
 **/
function bind_path ()
{
	$(".path ul li:visible:last").addClass("end");
}

/**
 *	Prvnim panelum prida .firstpanel
 */
function bind_panel()
{
	//$('.col dl.panel:visible:first').addClass('firstpanel');
	$('.col:not(.nodt) dl.panel:visible:first-child').each(function () { 
		$(this).addClass('firstpanel'); 
	});
}

/**
 *	Vymaze pouze textove inputy
 */
$.fn.clearForm = function() {
  // iterate each matching form
  return this.each(function() {
    // iterate the elements within the form
    $(':input', this).each(function() {
      var type = this.type, tag = this.tagName.toLowerCase();
      if (type == 'text' || type == 'password' || tag == 'textarea')
        this.value = '';
    });
  });
};

/**
 * galerie
 **/
function bind_gallery ()
{
	// http://coffeescripter.com/code/ad-gallery/
	if ($('.ad-gallery').size() == 0) {
		return;
	}
	
	var galleries = $('.ad-gallery').adGallery({
		width: 520, // Width of the image, set to false and it will read the CSS width
  		height: 390, // Height of the image, set to false and it will read the CSS height
  		thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
		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: false, // Are you allowed to scroll the thumb list?
  		slideshow: {
		    enable: false,
		    autostart: true,
		    speed: 4000,
		    start_label: 'Spustit slideshow',
		    stop_label: 'Zastavit slideshow',
		    stop_on_scroll: true, // Should the slideshow stop if the user scrolls the thumb list?
		    countdown_prefix: '(', // Wrap around the countdown
		    countdown_sufix: ')'
		  },
		  effect: 'fade' // 'slide-hori' or 'slide-vert', 'resize', 'fade', 'none' or false
	});
}
