
/* - pa_model.js - */
// http://csw.torun.pl/portal_javascripts/pa_model.js?original=1
var context={absolute_url: function(){return $('input#absolute_url').val()},portal_url: function(){return $('input#portal_url').val()}}
var pamodel={__init__: function(e){pamodel.paplayer.__init__()}}
pamodel.paplayer={active:0,current_image:0,orientation:'horizontal',vbuttons:'right',hbuttons:'bottom',images:new Array(),thumb_width:0,thumb_height:0,max_width:0,max_height:0,player_color:'',__init__: function(){pamodel.paplayer.images[0]={'imgtitle':'','imgdesc':'','imgurl':''};if($('#imagesPlayer').length) pamodel.paplayer.active=1;if(pamodel.paplayer.active){pamodel.paplayer.setPlayerStyle();$('a.paplayerImages').each(function(i,link){$(link).click( function(){pamodel.paplayer.showCurrentImage(link);return false});$(link).mouseover( function(){pamodel.paplayer.showThumbLegend(link);return false});$(link).mouseout( function(){$('#thumbLegend').empty();return false});pamodel.paplayer.images[i]={'imgtitle':$('.imgtitlevalue',this).val(),'imgdesc':$('.imgdescvalue',this).val(),'imgurl':$('.imgurlvalue',this).val()}});pamodel.paplayer.connect('previousImage',pamodel.paplayer.previousImage);pamodel.paplayer.connect('nextImage',pamodel.paplayer.nextImage);pamodel.paplayer.connect('firstImage',pamodel.paplayer.firstImage);pamodel.paplayer.connect('lastImage',pamodel.paplayer.lastImage);$('a#paplayerImageZoom').click(pamodel.paplayer.zoomImage);$('img#previewImg').click(pamodel.paplayer.zoomImage);pamodel.paplayer.current_image=0;pamodel.paplayer.showImage()}},connect: function(id,func){var button=$('a#'+id);if(!button.length) return;button.click(func)},showThumbLegend: function(link){var legend=link.title;$('#thumbLegend').empty();$('#thumbLegend').append(legend)},showCurrentImage: function(link){var href=link.href;var legend=link.title;$('img#previewImg').attr('src',href);$('img#previewImg').attr('alt',legend+' (zoom)');$('a.paplayerImages').each(function(i,link){if(href.match(link.href)){$(link).addClass('selected');pamodel.paplayer.current_image=i;var nMax=3;if(pamodel.paplayer.orientation=='vertical'){nMax=parseInt($('#thumbs').height()/(pamodel.paplayer.thumb_height+5))}
else{nMax=parseInt($('#thumbs').width()/(pamodel.paplayer.thumb_width+5))}
if(pamodel.paplayer.images.length>nMax){$('div#thumbsInnerWrapper').css('position','relative');var posIndex=1;if(nMax>2){if(nMax/2>parseInt(nMax/2)){posIndex=parseInt(nMax/2)+1}
else posIndex=nMax/2}
pamodel.paplayer.moveThumbs(i,posIndex,pamodel.paplayer.orientation)}} else{$(link).removeClass('selected')}});zoomUrl=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgurl']+'?isImage=1';Title=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgtitle'];Description=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgdesc'];$('a#paplayerImageZoom').each(function(i,link){link.href=zoomUrl;link.title=Title+" (zoom)"});$('#imgTitle').empty();$('#imgDescription').empty();$('#imgTitle').append(Title);$('#imgDescription').append(Description)},showImage: function(){var image=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgurl'];$('a.paplayerImages').each(function(i,link){if(link.href.match(image)){$(link).addClass('selected');pamodel.paplayer.showCurrentImage(link);return false}
else{$(link).removeClass('selected')}});pamodel.paplayer.displayButtons()},displayButtons: function(){if(pamodel.paplayer.current_image>0){$('a#previousImage').css('visibility','visible');$('a#firstImage').css('visibility','visible')}
else{$('a#previousImage').css('visibility','hidden');$('a#firstImage').css('visibility','hidden')}
if(pamodel.paplayer.current_image<(pamodel.paplayer.images.length-1)){$('a#nextImage').css('visibility','visible');$('a#lastImage').css('visibility','visible')}
else{$('a#nextImage').css('visibility','hidden');$('a#lastImage').css('visibility','hidden')}},previousImage: function(e){if(pamodel.paplayer.current_image>0){pamodel.paplayer.current_image+=-1};pamodel.paplayer.showImage()},nextImage: function(e){if(pamodel.paplayer.current_image<(pamodel.paplayer.images.length-1)){pamodel.paplayer.current_image+=1};pamodel.paplayer.showImage()},firstImage: function(e){pamodel.paplayer.current_image=0;pamodel.paplayer.showImage()},lastImage: function(e){pamodel.paplayer.current_image=pamodel.paplayer.images.length-1;pamodel.paplayer.showImage()},zoomImage: function(event){if(event){event.preventDefault();event.stopPropagation()}
var href=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgurl']+'?isImage=1';var title=pamodel.paplayer.images[pamodel.paplayer.current_image]['imgtitle'];TB_show(title,href)},setPlayerStyle: function(){pamodel.paplayer.thumb_width=parseInt($('#thumbmaxwidthvalue').val());pamodel.paplayer.thumb_height=parseInt($('#thumbmaxheightvalue').val());pamodel.paplayer.max_width=parseInt($('#maxwidthvalue').val());pamodel.paplayer.max_height=parseInt($('#maxheightvalue').val());pamodel.paplayer.player_color=$('#imagesPlayer').css('border-left-color');pamodel.paplayer.orientation='horizontal';if($('.verticalPlayer').length){pamodel.paplayer.orientation='vertical'}
pamodel.paplayer.vbuttons='right';if($('.leftVButtons').length){pamodel.paplayer.vbuttons='left'}
pamodel.paplayer.hbuttons='bottom';if($('.topHButtons').length){pamodel.paplayer.hbuttons='top'}
$('#legendWrapper').css('border-color',pamodel.paplayer.player_color);$('#thumbsWrapper').css('border-color',pamodel.paplayer.player_color);$('.playerButtons').css('border-color',pamodel.paplayer.player_color);$('#thumbLegend').css('border-color',pamodel.paplayer.player_color);$('#thumbLegend').css('color',pamodel.paplayer.player_color);$('#imgDescription').css('color',pamodel.paplayer.player_color);if(pamodel.paplayer.orientation=='vertical'){var controls=$("#thumbsWrapper").clone();$("#thumbsWrapper").remove();controls.prependTo("#imagesPlayer");$("#thumbsWrapper").css('float',pamodel.paplayer.vbuttons);$("#thumbsWrapper").css('border-top','none');$("#thumbsWrapper").css('height','auto');if(pamodel.paplayer.vbuttons=='right'){$("#thumbsWrapper").css('border-left-width','1px');$("#thumbsWrapper").css('border-left-style','solid')}
else{$("#thumbsWrapper").css('border-right-width','1px');$("#thumbsWrapper").css('border-right-style','solid')}
$('.playerButtons').css('float','none');$('#thumbs').css('float','none');$('.paplayerImages').css('float','none');$('#playerControls').css('margin','auto 0');$('.playerButtons').css('margin-top','0');$('#thumbs').css('margin-left','0');$('.paplayerImages').css('margin-left','0');$('.playerButtons').css('margin-bottom','3px');$('#thumbs').css('margin-bottom','3px');$('.paplayerImages').css('margin-bottom','3px');$('#thumbs').height($('#previewWrapper')[0].offsetHeight+$('#thumbLegend')[0].offsetHeight+$('#legendWrapper')[0].offsetHeight-82+'px');$('#thumbs').width(pamodel.paplayer.thumb_width+'px');$('.playerButtons').css('margin-left',parseInt((pamodel.paplayer.thumb_width-38)/2)+'px');$('#thumbsInnerWrapper').height(''+(pamodel.paplayer.thumb_height+5)*$('a.paplayerImages').length+'px');$('#thumbsInnerWrapper').css('width',''+(pamodel.paplayer.thumb_width)+'px');$('#imagesPlayer').width($('#thumbsWrapper')[0].offsetWidth+$('#imagesPlayer')[0].offsetWidth+1+'px')}
else{if(pamodel.paplayer.hbuttons=='top'){var controls=$("#thumbsWrapper").clone();$("#thumbsWrapper").remove();controls.prependTo("#imagesPlayer");$("#thumbsWrapper").css('border-top','none');$("#thumbsWrapper").css('border-bottom-width','1px');$("#thumbsWrapper").css('border-bottom-style','solid')}
$('#thumbs').width(pamodel.paplayer.max_width-85+'px');$('#thumbs').height(pamodel.paplayer.thumb_height+2+'px');$('.playerButtons').css('margin-top',parseInt((pamodel.paplayer.thumb_height-38)/2)+'px');$('#thumbsInnerWrapper').width(''+(pamodel.paplayer.thumb_width+5)*$('a.paplayerImages').length+'px')}},moveThumbs: function(i,posIndex,orientation){var new_pos=0;if(i<pamodel.paplayer.images.length){if(orientation=='vertical'){new_pos=(pamodel.paplayer.thumb_width+5)*(i-posIndex+1) }
else new_pos=(pamodel.paplayer.thumb_height+5)*(i-posIndex+1) }
if(new_pos<0){new_pos=0}
if(orientation=='vertical'){$('div#thumbsInnerWrapper').animate({top:-new_pos})}
else{$('div#thumbsInnerWrapper').animate({left:-new_pos})}}}
$(document).ready(pamodel.__init__);removeEmptyPAFielsets=function(){$('#pacontent fieldset.leftPlaced').each(function(){if($('div',this).length==0) $(this).remove()})}
$(document).ready(removeEmptyPAFielsets);

