function collapseMessage(message) {
	$(message).find('.rest').hide();
	$(message).find('.more').show();
	$(message).find('h3').css('color','#848587');
	$(message).find('.more[class*=sprite]').css('display', 'inline-block');
}
function showVideo(src) {
	$('#side img').hide();
	$('#side param[name=movie]').attr('value', 'http://www.youtube.com/v/'+src+'&hl=pl_PL&fs=1&rel=0');
	$('#side embed').attr('src','http://www.youtube.com/v/'+src+'&hl=pl_PL&fs=1&rel=0');
	$('#side embed').show();
	$('#side object').show();
	return false;
}
function hideImage() {
	$('#side img').hide();
	$('#side embed').hide();
	$('#side object').hide();
	return false;
}
function showImage(src) {
	$('#side img').attr('src', src);
	$('#side img').show();
	$('#side embed').hide();
	$('#side object').hide();
	return false;
}
function fixMessage(message) {
	if ($(message).find('a.less.rest').length ==0) {
		$(message).append('<a href="#" class="less rest sprite-icon-less" title="mniej"></a>');
	}
	/*if ($(message).find('a.print').length ==0) {
		$(message).append('<a href="#" class="print rest sprite-icon-print" title="drukuj"></a>');
	}*/
	if ($(message).find('div.clear').length ==0) {
		$(message).append('<div class="clear"></div>');
	}
}
function setActive(that) {

	that.attr('class',that.attr('class')+'-active');
}
$(document).ready(function(){
	$('.message').each(function (index,domEl) {
		fixMessage(domEl);
	});
	$('.lightbox').lightBox();
	$('.message:first-child').css('padding-top','0px');
	$('#main').jScrollPane({
		scrollbarWidth:10,
		scrollbarMargin:0,
		showArrows:false
	});
	$('.message .rest').hide();
	$('.message .more').click(function() {
		$('.message').each(function (index,domEl) {
			collapseMessage(domEl);
		});
		$(this).parent().find('.rest').show();
		$(this).parent().find('h3').css('color','red');
		$(this).parent().find('.rest[class*=sprite]').css('display', 'inline-block');
		$(this).parent().find('.more').hide();
		$('#main').jScrollPaneRemove();
		var m = $('#main');
		var offset = $(this).offset().top - $('#main').offset().top;
		//alert($(this).offset().top + " " + $('#main').offset().top+ " "+offset);
		$('#main').jScrollPane({
			scrollbarWidth:10,
			scrollbarMargin:0,
			showArrows:false
		});
		var m = $('#main');
		var offset = $(this).parent().offset().top - $('#main').offset().top;
		//alert($(this).parent().offset().top + " " + $('#main').offset().top+ " "+offset);
		m[0].scrollTo(offset);
		return false;
	});
	//$('.message .more').html('<span style="position:absolute;left:20px;">więcej</span>');
	$('.message .less').click(function() {
		hideImage();
		if (typeof defaultSideSrc != 'undefined') {
			$('#side img').attr('src', defaultSideSrc);
			$('#side img').show();
		}
		collapseMessage($(this).parent());
		//$('#main').jScrollPaneRemove();
		$('#main').jScrollPane({
			scrollbarWidth:10,
			scrollbarMargin:0,
			showArrows:false
		});
	});
	$('.message .print').click(function() {
		window.print();
		return false;
	});
	$('.message a.yt').click(function() {
		alert($(this).href());
		$('.side param[name=movie]').attr('value', $(this).href());
		return false;
	});
	$('#mainMenuLinks a, #footer a, #subMenuBar a').not('.sprite-copyright').mouseover(function() {
		$(this).attr('class',$(this).attr('class')+'-active');
		return false;
	});
	$('#mainMenuLinks a, #footer a, #subMenuBar a').not('.sprite-copyright').mouseout(function() {
		$(this).attr('class',$(this).attr('class').replace('\-active', ''));
		return false;
	});
	setActive($('.sprite-'+category+',.sprite-f-'+category).unbind('mouseover').unbind('mouseout'));
	setActive($('.sprite-'+page).unbind('mouseover').unbind('mouseout'));
	$('#main .message').first().find('.more').click();
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		DD_belatedPNG.fix('.sprite-innowacje-active, .sprite-innowacje, .sprite-oferta-active, .sprite-oferta, .sprite-sevenet-logo, .sprite-wydarzenia-active, .sprite-wydarzenia ');
	}
});
