/* cufon */
try{
	Cufon.replace('.header-top ul li a', { fontFamily: 'MetaProBold', hover:true });
	Cufon.replace('.main-navigation a, ul.sub-navigation li a, .search-section a', { fontFamily: 'MetaPro', hover:true });
	Cufon.replace('.section-name a', { fontFamily: 'MetaPro', hover:true });
	Cufon.replace('.standard-box h3', { fontFamily: 'MetaPro' });
	Cufon.replace('.section-name .section-name-inner', { fontFamily: 'MetaPro' });
	Cufon.replace('#homepage-template .column h2, #homepage-template .column h3, .rating-box h4, .rating-box .value, .rating-box ul li, , .last-column .sidebar-nav-list h3', { fontFamily: 'MetaPro' });
} catch(error){};

/* jquery */
$(function(){
	
	// korekcja wysokosci naglowka w lewej kolumnie nad menu w przypadku gdy posiada wiecej niz 2 linie tekstu
	(function(){
		if($('.section-name-inner').length > 0){
			var innerHeight = $('.section-name-inner').innerHeight();
			var header = $(".section-name");
			if(header.innerHeight() < innerHeight){
				header.height(innerHeight);
			}
		}

		/* #1698978 */
		if($('.column-3 .standard-box:first-child .banner').length == 1){
			if($('.column-3 .standard-box').length < 2){
                $('.column.column-3.last-column').css({
                    background: 'none'
                });
                $('.column-3 .standard-box:first-child').css({
                    background: 'none'
                });
			}
			if($('#homepage-template').length < 1){
				$('.column-3 .standard-box:first-child .banner').css({
					marginTop: '-21px'
				});
			}
		}

		if($('.column-3 .standard-box').length == 0){
			$('.column-3').css({
				background: 'none'
			});
		}
	})();

	BRE.lang = $('html').attr('lang');
		
	//zmiana wygladu selectow (korzysta z ui.selectmenu.js)
	//gdy na selecie jest klasa "redirect" pobiera wartosc (powinna byc adresem) i przekierowuje  
	$('select').selectmenu({
		style: 'dropdown',
		change: function(){
			if($(this).hasClass('redirect')){
				window.location = $(this).val();			
			}
		},
		open: function(e, data){
            var menu = $('ul#'+$(this).attr('id')+'-menu');
            menu.find('li:first-child.disabled').remove();
        }
	});
	//ograniczenie wysokosci podmienionego menu dla 'znajdz oddzial'
	$('#pos-search-menu').css('height', 220);
	//ograniczenie wysokosci podmienionego menu dla 'landing-page'
	$('#pos-menu').css('height', 220);
	
	if($(".img-replace").length > 0){
		BRE.imgHover.init($(".img-replace"));
	}
	
	BRE.searchFocus.init($("#search_input"));
	if($("#searcher_input").length > 0){
		BRE.searchFocus.init($("#searcher_input"));
	}	
	
	BRE.hoverIE6($(".side-navigation li"));
	
	if($(".default-counter").length > 0){
		BRE.countChars();	
	}
	
	if($(".counter-1000").length > 0){
		BRE.countChars({
			limit: 1000
		});
	}
	
	if(BRE.lang === 'pl'){	
		$.datepicker.regional['pl'] = {
            closeText: 'Zamknij',
            prevText: '&#x3c;Poprzedni',
            nextText: 'Następny&#x3e;',
            currentText: 'Dziś',
            monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
            monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze','Lip','Sie','Wrz','Pa','Lis','Gru'],
            dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
            dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
            dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
            weekHeader: 'Tydz',
            dateFormat: 'yy-mm-dd',
            firstDay: 1,
            isRTL: false,
            showMonthAfterYear: false,
            yearSuffix: ''};
			
		$.datepicker.setDefaults($.datepicker.regional['pl']);		
	}	
			
	if($('.datepicker-input').length > 0){
		$(".datepicker-input").datepicker({
			dateFormat: 'yy-mm-dd',
			showAnim: 'fadeIn'
		});
	}
	
	/* #1693714 + #1700205 */
	if($('.faq-list li').length > 0){
		$('.faq-list li .question a').bind('click', function(event){
			event.preventDefault();
			if($(this).parent().parent().find('.answer').is(':visible')){
				$(this).parent().parent().find('.answer').hide();
			} else {
				$(this).parent().parent().parent().find('.answer').hide();
				$(this).parent().parent().find('.answer').show('slow');
			}
		});
	};
});

var BRE;

if (typeof BRE == "undefined") BRE = {};
if(typeof BRE.searchFocus == "undefined"){
	BRE.searchFocus = {
		init: function(input){
			var defaultValue = input.val(); 
			input.focus(function(){
				if($(this).val() === defaultValue ){
					$(this).val('');
				}
			});
			input.blur(function(){
				if($(this).val() === ''){
					$(this).val(defaultValue);
				}
			});
		}
	}
}

if (typeof BRE.flash == "undefined") {
	BRE.flash = function(options){
		
		var _defaults = {
			src: '',
			width: '',
			height: '',
			flashContent: 'flash-content',
			flashVersion: '9.0.0',
			flashVars: {},
			params: {
				play: true,
				loop: true,
				menu: false,
				quality: 'best',
				scale: 'noscale',
				wmode: 'opaque'
			},
			attributes: {}
		}

	 	var opts = $.extend(_defaults,options);		

		var init = function(){
			if(opts.src !== ''){
				swfobject.embedSWF(opts.src, opts.flashContent, opts.width, opts.height, opts.flashVersion, false, opts.flashVars, opts.params, opts.attributes);
			}	
		};
	
		init();
	
	}
}

// dodawanie klasy hoover w IE6
if (typeof BRE.hoverIE6 == "undefined") {
	BRE.hoverIE6 = function(itemToHover){
		   
		var browserLessThanIE7 = function (){
			return (/MSIE ((5\\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
		};		
		
		var init = function(){
			if(browserLessThanIE7() === true){
				itemToHover.hover(function(){
					$(this).addClass('hover');
				}, function(){
					$(this).removeClass('hover');
				})		
			}
		}; 
		
		init();
	}
}

if (typeof BRE.countChars == "undefined") {
	BRE.countChars = function(options){
		
		var _defaults = {
			limit: 1000, /* #1808611 */
			elementToCount: $('textarea'),
			resultOutput: 'count-result'	
		}
	
		var opts = $.extend(_defaults,options);
				
		var init = function(){
			opts.elementToCount.parent('div').after('<p class="'+opts.resultOutput+'">'+message()+' <span>'+ opts.limit +'</span></p>');	 
			opts.elementToCount.keyup(function(){
				var count_chars = $(this).val().length;
				if (count_chars > opts.limit){
					var new_value = $(this).val().substring(0, opts.limit);
					$(this).val(new_value);
				}
				$(this).parent().next().children('span').html(""+opts.limit - $(this).val().length+"");
			});	
		};
		
		var message = function(){
			var text = "Pozostała ilość znaków do wpisania:";
			if(BRE.lang === 'en'){
				text = "The remaining number of characters to be entered:";
			}
			return text;
		}
		
		init();
		
	}
}

if (typeof BRE.imgHover == "undefined") {
	BRE.imgHover = {
		init: function(img){
		 	var defaultSrc, hoverSrc;						
			img.hover(function(){
				defaultSrc = $(this).attr('src');
				var prev = $(this).prev();
				if(prev.hasClass('img-hide-src')){
					hoverSrc = prev.attr('src');	
				}else{
					hoverSrc = defaultSrc;
				}
				$(this).attr('src',hoverSrc); 
			},function(){
				$(this).attr('src',defaultSrc);
			});
		}
	}
}
