/**
 * JavaScript funkce pro PlaygroundTravel
 */

/*
//function for preloading images
(function(jQuery) {
	var imgList = [];
	jQuery.extend({
		preload: function(imgArr, option) {
			var setting = jQuery.extend({
				init: function(loaded, total) {},
				loaded: function(img, loaded, total) {},
				loaded_all: function(loaded, total) {}
			}, option);
			var total = imgArr.length;
			var loaded = 0;
			
			setting.init(0, total);
			for(i=0; i<total; i++) {
				imgList.push(jQuery('<img src="'+imgArr[i]+'" />')
					.load(function() {
						loaded++;
						setting.loaded(this, loaded, total);
						if(loaded == total) {
							setting.loaded_all(loaded, total);
						}
					})
				);
			}
			
		}
	})
	;
})(jQuery);
*/

//erasing top-right search field
function searchFieldAction() {
	jQuery('#search_field').click(function() {
			// set hint if not set already
			var hint = jQuery(this).attr('hint');
			if (hint == undefined || hint == '') {
				var hint = jQuery(this).val();
				jQuery(this).attr('hint', hint);				
			}
			// erase field if contains hint
			var val = jQuery(this).val();
			if (val == hint) {
				jQuery(this).val('');	
			}
	});
	
	jQuery('#search_field').blur(function() {
		// replace hint if field empty and leaves focus
		var val = jQuery(this).val();
		if (val == '') {
			var hint = jQuery(this).attr('hint');
			jQuery(this).val(hint);			
		}
	});
}

/**
 * FUNCTIONS FOR HEADER SLIDESHOW
 */

function activate_header_slideshow() {
	// show first image
	jQuery('img#teaser_image_img').fadeIn(2000).addClass('active');
	
	// set autorotate
	interval = setInterval('slideChange()', 7000);
	
	// preload images
	//preloadImages();
}

function slideChange() {
	
	// get active slide
	if (window.activeSlide === undefined) {
		window.activeSlide = 1;
	} else {
		window.activeSlide = window.activeSlide + 1;
	}
	
	// pokud jsem přejel počet v slideshow, vracim se na nulu
	if (window.activeSlide > (jQuery('#teaser_image img.slideshow').size() - 1)) 
		window.activeSlide = 0;
	
	// přepínám obrázek
	var new_slide = jQuery('#teaser_image img.slideshow').eq(window.activeSlide);
	jQuery(new_slide).css({'z-index':'7'}).fadeIn(2000, function() {
		// smažu původní .active a udělám active tenhle
		jQuery('#teaser_image img.active').fadeOut(0, function() {
			jQuery(this).removeClass('active');
		});
		
		
		jQuery(new_slide).addClass('active').css({'z-index':''});
	});
	
	//clearInterval(interval);
}

/*
//preload images in list
function preloadImages() {
	var images = [];
	for (c in header_slideshow_cfg) {
		images.push(header_slideshow_cfg[c]);
	}
	jQuery.preload(images);	
}
*/

/**
 * ACTIVATE AFTER PAGE LOAD
 */ 
jQuery(document).ready(function($) {
	// erasing top-right search field
	searchFieldAction();	
	
});

// aktivuje dlaždice na homepage
function aktivace_dlazdic() {
	jQuery('div.dlazdice a').hover(
		function() {
			jQuery(this).children('div.wrap').stop().animate( {top: '-150px'}, 500);
		}, function() {
			jQuery(this).children('div.wrap').stop().animate( {top: '0px'}, 300);
		}
	);
}
