(function($){
	$.fn.inputDefaultText = function(options)
	{
		options = $.extend({
			text: 'Hledany vyraz'
		}, options);
	
		return this
			.val(options.text)
			.bind('focus', function(){ if(this.value == options.text) this.value = ''; })
			.bind('blur', function(){ if(this.value == '') this.value = options.text; });
	};
	$.fn.skGet = function(get, dimension, callback) {
		if(!this.length){
			return this;
		}
		
		var result;
		var m = Math[get];
		this.each(function(index) {
			var newResult = $(this)[dimension]();
			result = index ? m(result, newResult) : newResult;
		});
		
		if(typeof callback == 'function'){
			callback.call(this, result);
			return this;
		}
		
		return result;
	};
	
	if(typeof floors !== 'undefined'){
		var svgmap = new $.fbSvgMap('../js/poschodi.xml');
	}
	
	$(document).ready(function(){

		$.fn.kfBox && $('.lightbox').kfBox();

    	/* placeholer with hmtl 5 fallback */
		function supports_input_placeholder() {
		  var i = document.createElement('input');
		  return 'placeholder' in i;
		}
		
    	if(!supports_input_placeholder()){
			$('input[placeholder], textarea[placeholder]').each(function(){
				var text = $(this).attr('placeholder'); 
				$(this).inputDefaultText({text: text});
			});
		}	
		
		

		$('.tabs-list').each(function(index) {
			var tabs = new studenta.Tabs($(this)).init();
		});
		
		$('table')
			.not('.reset, .plain')
			.wrap('<div class="fix-table"></div>')
			.find('tbody tr:odd')
				.addClass('even');
		
	   	
	   	/* Dropdown menu - social links */
		$('a.popover').each(function()
		{
			var $anchor = $(this);
			var $popoverContent = $($anchor.prop('hash'));
			var $element = $('<div class="popover-box"><div class="popover-box-inner-wrap"><div class="popover-box-inner"><div class="popover-box-inner2"><div class="arrow"></div>' + $popoverContent.html() + '</div></div></div></div>');
			var shareDropDown = new studenta.SlideDialog({ element: $element, axis: 'y' });
			shareDropDown.init();
			$anchor.bind('mousedown', function(event)
			{
				$element.css({ top: Math.round($anchor.offset().top + $anchor.outerHeight()), left: 'auto', right: Math.round($('body').width() - $anchor.offset().left - $anchor.outerWidth()) });
				shareDropDown.toggle();
				return false;
			}).bind('click', function(){ return false; });
			
			if($popoverContent.hasClass('open')) $anchor.triggerHandler('mousedown');
		});
		
		
		/* Inicializace carouselů */
		$('.carousel').each(function()
		{
			var $prevnext = $('<div class="prevnext"><a href="#" class="prev">předchozí</a> <a href="#" class="next">další</a></div>');
			var $imageCarousel = $(this);
			$imageCarousel.find('ul').wrap('<div class="hscroll-box"></div>');
		    $imageCarousel.find('.hscroll-box').before($prevnext);
		    var imageScroller = new kff.widgets.Scroller($imageCarousel.find('.hscroll-box'), {
				scrollWidth: 510 + 18,
				loadPosition: false,
				prev: $imageCarousel.find('.prev'),
				next: $imageCarousel.find('.next')
			});
			imageScroller.init();
		});
		
		if(studenta.Photogallery && $('.photogallery'))
		{
			new studenta.Photogallery().init();
		}
	   	
	});


})(this.jQuery);


