jQuery(document).ready(function(){
	jQuery('.totop').click(function () {
		scroll(0,0);
		return false;
	});

	jQuery('.container_bookmarks h2 a').click(function () {
		jQuery('.container_bookmarks_active').removeClass('container_bookmarks_active');
		jQuery(this).parents('.container_bookmarks').addClass('container_bookmarks_active');
		return false;
	});
	
	jQuery(".container_gallery li:even").addClass('even');
	
	try {
		jQuery("#accordion ul").hrzAccordion({eventTrigger:"click",openOnLoad:"5",cycle: false});
	} catch(err) {}
	
	function NewsOrderAkordeon() {
		try {
			jQuery('.panel, .container_panel, .container_upcoming_page').jScrollPane();
			jQuery('.description  ol li').each(function () {
				jQuery(this).prepend('<span class="order">'+(jQuery(this).index()+1)+'.</span>');
			});
		} catch(err) {}
	}
	
	NewsOrderAkordeon();
	
	try {
		jQuery('#header').append('<div id="calendar_nav"><a href="#" id="calendar_prev">&lt;</a><span /><a href="#" id="calendar_next">&gt;</a></div>');
		
		jQuery('#calendar_nav span').html(jQuery('tr#month th').html());
		//jQuery('tr#month_nav td.prev-month');
		jQuery('#calendar').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			prev:  '#calendar_prev',
			next:  '#calendar_next',
			before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				jQuery('#calendar_nav span').text(jQuery(nextSlideElement).attr('title'));
			},
			cleartypeNoBg: true
		});
	} catch(err) {}
	
	function GetCalendarium(loadurl, portalId)
	{
		jQuery.ajax
		({	
			type: "POST",
			url: loadurl,
			success: function(msg)
			{		
				jQuery('#accordion .portalId_'+ portalId +' .text').html(msg);
				NewsOrderAkordeon();
			}		
		});
	}
	
	jQuery('#calendar td span.event').click(function(){
		//alert($(this).attr('link'));
		GetCalendarium(jQuery(this).attr('link'), jQuery(this).attr('portalId'));
	});
	
	// pobieranie aktualności z dnia dzisiejszego
	GetCalendarium(jQuery('#calendar .selected-day span').attr('link'), jQuery('#calendar .selected-day span').attr('portalId'));
	
	function ChangeCalendariumMonth(loadurl)
	{
		jQuery.ajax
		({	
			type: "POST",
			url: loadurl,
			success: function(msg)
			{		
				jQuery('#calendar').html(msg);
				jQuery('#calendar_nav span').html(jQuery('#month .month').text());
				//alert(msg);
			}		
		});
	}
	
	jQuery('#calendar_next').click(function(){
		ChangeCalendariumMonth(jQuery('#month_nav .next-month a').attr('href'));
	});
	
	jQuery('#calendar_prev').click(function(){
		ChangeCalendariumMonth(jQuery('#month_nav .prev-month a').attr('href'));
	});
	
	try {
		jQuery('#container_slider').before('<div id="container_slider_pager"></div><div id="caption"></div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 4000, 
			pager:  '#container_slider_pager',
			cleartypeNoBg: true,
			before: function() {  
				//$('#caption').html($(this).find('img').attr('alt')); 
				$('#caption').html("<a href='"+ $(this).find('img').attr('link_multimedia') +"'>" + $(this).find('img').attr('alt')+"</a>");  
				//alert($(this).find('img').attr('alt'));
			} 
		});
		
		jQuery('#caption').html("<a href='"+ jQuery('#container_slider').find('img').attr('link_multimedia') +"'>" + jQuery('#container_slider').find('img').attr('alt')+"</a>");
	} catch(err) {}
	
	try {
		jQuery('#container_slider_video').before('<div id="container_slider_video_pager"></div><div id="caption_video"></div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 4000, 
			pager:  '#container_slider_video_pager',
			cleartypeNoBg: true,
			before: function() {  
				//$('#caption_video').html($(this).find('img').attr('alt')); 
				$('#caption_video').html("<a href='"+ $(this).find('a').attr('href') +"'>" + $(this).find('img').attr('alt')+"</a>"); 
				//alert($(this).find('a').attr('href'));
			} 
		});
		
		jQuery('#caption_video').html("<a href='"+ jQuery('#container_slider_video').find('a').attr('href') +"'>" + jQuery('#container_slider_video').find('img').attr('alt')+"</a>");
	} catch(err) {}
	
	/*
	try {
		jQuery('#container_upcoming_panel').after('<div id="container_upcoming_pager"></div>').cycle({ 
			fx:     'fade', 
			speed:  800, 
			timeout: 0, 
			pager:  '#container_upcoming_pager',
			after: function(currSlideElement, nextSlideElement, options, forwardFlag) {
				jQuery(nextSlideElement).find('.container_upcoming_page').jScrollPane();
			},
			cleartypeNoBg: true
		});
	} catch(err) {}
	*/
	jQuery('.container_upcoming').jScrollPane();
	
	jQuery('#languages img, #bottom img, .widget_links img, #shields img').parents('a').animate({opacity: 1});
	jQuery('#languages img, #bottom img, .widget_links img, #shields img').parents('a').mouseover(function () { jQuery(this).animate({ opacity: .7 }, 100); });
	jQuery('#languages img, #bottom img, .widget_links img, #shields img').parents('a').mouseout(function () { jQuery(this).animate({ opacity: 1 }, 100); });	
	
	jQuery('input:text, input:password, textarea').focus(function () {
		if (jQuery(this).val()==jQuery(this).attr('rel')) jQuery(this).val('');
		jQuery(this).removeClass('invalid');
		jQuery(this).addClass('active');
		jQuery(this).parents('form').css({'background-position':'0 -102px'});
	});
	jQuery('input:text, input:password, textarea').blur(function () {
		if (jQuery(this).val()=='') jQuery(this).val(jQuery(this).attr('rel'));
		jQuery(this).removeClass('active');
		jQuery(this).parents('form').css({'background-position':'0 0'});
	});
	
	if ( jQuery.browser.opera ) {
	}		
	if ( jQuery.browser.msie ) {
		if (jQuery.browser.version == '6.0' || jQuery.browser.version == '7.0') {
		}
	} 	
	if ( /chrome/.test( navigator.userAgent.toLowerCase() ) ) {
	} 	
	if ( /safari/.test( navigator.userAgent.toLowerCase() ) ) {
	} 	

	
	jQuery('.fancybox').each(function() {
		var galeriaAttr = $(this).attr("galeria");		
		$(this).fancybox({
			'scrolling': 'no', 
			'titleShow': true, 
			'titlePosition': 'inside', 
			'overlayOpacity':'.6',
			'padding' : '45',
			'overlayColor':'#000',
			onStart: function(currentArray, currentIndex){
			},
			onComplete: function(currentArray, currentIndex){
				jQuery("#fancybox-counter, #fancybox-go").remove();				
				if(galeriaAttr != undefined)
				{
					jQuery("#fancybox-inner").append('<span class="smallinfo">'+galeriaAttr+'</span>');
				}
				jQuery("#fancybox-inner").append('<p id="fancybox-counter">Zdjęcie nr <span>'+(currentIndex+1)+'</span> / '+currentArray.length+'</p>');
				jQuery("#fancybox-inner").append('<p id="fancybox-go"><input type="text" value="'+(currentIndex+1)+'" maximum="'+currentArray.length+'" /><button /></p>');
				
				jQuery('#fancybox-go input:text').keyup(function () {
					val = Math.abs(parseInt(jQuery(this).val()));
					max = jQuery(this).attr('maximum');
					if (val>0&&val<=max) {
						jQuery(this).val(val);
					} else {
						if (jQuery(this).val()=='') return false;
						if (jQuery(this).val()==0) jQuery(this).val(1);
						if (jQuery(this).val()>max) jQuery(this).val(max);
					}
				});
				jQuery('#fancybox-go button').click(function () {
					jQuery.fancybox.pos(jQuery('#fancybox-go input:text').val()-1);
				});
			}
		});
	});
	
	
	//Fancybox
	$(".imgFancy").fancybox();
	
	$("a#single_image").fancybox();
	
	/* Using custom settings */
	
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	/* Apply fancybox to multiple items */
	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
	$(".FancyReloadOnClose").fancybox({
		  'onClosed': function() {
		    parent.location.reload(true);
		  }
		});
	$('.tabs').tabs();
});


jQuery(window).load(function(){
});

function CountCardClick(id)
{
	jQuery.ajax
	({	
		type: "POST",
		url: "/pl/ikarta/countcardclick/"+id,
		success: function(msg)
		{		
			
		}		
	});
}

function image_resize($class, $w, $h) 
{
    $("."+$class).each(function () {
		var maxWidth = $w;
		var maxHeight = $h;
		var ratio = 0;
		var width = $(this).width();
		var height = $(this).height();

		if (width > maxWidth) 
		{
			ratio = (maxWidth / width);
			$(this).attr({
				width : maxWidth,
				height : (height * ratio)
			});

			height = (height * ratio);
			width = (width * ratio);

			if (height > maxHeight)
			{
				ratio = (maxHeight / height);
				$(this).attr({
					height : maxHeight,
					width : (width * ratio)
				});
			}
		}

		$(this).show();
	});
}

function ToggleView(id)
{
	$("#"+id).toggle();
}

var ZoomStep = 0;

function ChangeFont(id)
{
	if(ZoomStep<2 && ZoomStep>=0)
	    ZoomStep++;
	else
	    ZoomStep=-3;
	
	$('#'+id).find('ul, ol').each(function(index) {
	        var elemfontsize = parseInt($(this).css("font-size"));
	        $(this).css("font-size",elemfontsize +(2*ZoomStep)+'px');
	});	
	
	$('#'+id).find('font, strong, a, p, i, span, li, tr, td, th, h1, h2, h3, h4, h5, h6, div').each(function(index) {
	    if($(this).clone().children().remove().end().text().trim().length)
	    {
	        var elemfontsize = parseInt($(this).css("font-size"));
	        $(this).css("font-size",elemfontsize +(2*ZoomStep)+'px');
	    }
	});
	
	if(ZoomStep==-3)
	    ZoomStep=0;
}

function ChangeFontByClass(css_class)
{
	if(ZoomStep<2 && ZoomStep>=0)
	    ZoomStep++;
	else
	    ZoomStep=-3;
	
	$('.'+css_class).find('ul, ol').each(function(index) {
        var elemfontsize = parseInt($(this).css("font-size"));
        $(this).css("font-size",elemfontsize +(2*ZoomStep)+'px');
	});	
	
	$('.'+css_class).find('font, strong, a, p, i, span, li, tr, td, th, h1, h2, h3, h4, h5, h6, div').each(function(index) {
	    if($(this).clone().children().remove().end().text().trim().length)
	    {
	        var elemfontsize = parseInt($(this).css("font-size"));
	        $(this).css("font-size",elemfontsize +(2*ZoomStep)+'px');
	    }
	});
	
	if(ZoomStep==-3)
	    ZoomStep=0;
}
