
	
/****************************************************************************************************
*
*	Copyright notice
*
*	This file is part of killerCMS.
*
*	killerCMS is a browser-based web content management system with in-place-editing features.
*	killerCMS was developed by Philipp Killer at web-manufaktur gmbh, Zurich from 2004 - 2011.
*
*   Copyright (C) 2004-2011 by Philipp Killer of web-manufaktur gmbh, Zurich
*	(killer@web-manufaktur.com, PhilippKiller@gmx.ch)
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, version 3 of the License.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License version 3
*    along with this programm (killerCMS).  If not, see <http://www.gnu.org/licenses/>.
*
*	This copyright notice MUST APPEAR in all copies of the script and be left unchanged!
*	
****************************************************************************************************/
/*JavaScript Copyright notice*/	

 					
						
						jQuery(function() {
						
							var dbtal_limitingDimension = 'height';
							var dbtal_lightbox_width = jQuery('body').innerWidth()/7*6;
							var dbtal_lightbox_height = jQuery(window).height()/7*6;
							
							//alert(dbtal_lightbox_width+','+dbtal_lightbox_height);
						
							var lightboxWS = jQuery('.grossansicht, .lightbox_auto_scaled').each(function() {
								var current = this;
								
								
								//limiting dimension?
								//if not set in source code: not working for ff: alert(jQuery(current).attr('height'));
								//alert('SETTING UP LIGHTBOX FOR img.grossansicht!');
								//alert(jQuery(current).html());
								
								//maybe tinymce has set lightbox_auto_scaled in parent element of img? make lightbox work anyway
								if (jQuery(current).is('img')==false) {
									current = jQuery(current).find('img')[0];
								}
									//set border to 0
								jQuery(current).attr('border','0');
								
								var src = jQuery(current).attr('src');
								var srcNew = src;
								if (typeof(src)=='string' && src.search(new RegExp('\\?'),'g')) var srcQSArr= src.split('?');
								else return false;
								var srcQS = srcQSArr[srcQSArr.length-1];
								if (typeof(srcQS)=='string' && srcQS.search(new RegExp('&'),'g')) var srcParamsStrArr = srcQS.split('&');
								else return false;
								for (var i=0;i<srcParamsStrArr.length;i++) {
									if (typeof(srcParamsStrArr[i])=='string' && srcParamsStrArr[i].search(new RegExp('='),'i')) var paramArr = srcParamsStrArr[i].split('=');
									else return false;
									
									if (dbtal_limitingDimension=='height') {
										if (paramArr[0]=='twidth') {
											srcNew = srcNew.replace(new RegExp(srcParamsStrArr[i],'g'),paramArr[0]+'='+Math.round(dbtal_lightbox_width));
										}
										if (paramArr[0]=='theight') {
											srcNew = srcNew.replace(new RegExp(srcParamsStrArr[i],'g'),paramArr[0]+'='+Math.round(dbtal_lightbox_height));
										}
										if (paramArr[0]=='crop') {
											//alert(srcParamsStrArr[i]+','+paramArr[0]);
											srcNew = srcNew.replace(new RegExp(srcParamsStrArr[i],'g'),paramArr[0]+'=');
										}
									}
								}
								
								var altText = jQuery(current).attr('alt');
								if (altText==undefined) altText = '';
								
								var relText = jQuery(current).attr('rel');
								if (relText==undefined) relText = 'default';
								
								//alert(srcNew);
								
								//jQuery(this).wrap('<a href=\"'+srcNew+'\" rel=\"lightbox[default]\" title=\"'+altText+'\"></a>');
								jQuery(this).wrap('<a href=\"'+srcNew+'&roundResizedImageWH=1\" rel=\"prettyPhoto['+relText+']\" style="text-decoration:none;"></a>').parent().attr('title',altText);
							});
							
							
							
							// init prettyPhoto
							// THROWS ERRORS! lightboxWS.prettyPhoto();
							
							var prettyPhoto_config_def = {
																	animation_speed: 'normal', /* fast/slow/normal */
																	slideshow: false, /* false OR interval time in ms */
																	autoplay_slideshow: false, /* true/false */
																	opacity: 0.80, /* Value between 0 and 1 */
																	show_title: false, /* true/false */
																	allow_resize: false, /* Resize the photos bigger than viewport. true/false */
																	default_width: 500,
																	default_height: 344,
																	counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
																	theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
																	hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
																	wmode: 'opaque', /* Set the flash wmode attribute */
																	autoplay: true, /* Automatically start videos: True/False */
																	modal: false, /* If set to true, only the close button will close the window */
																	overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
																	keyboard_shortcuts: true /* Set to false if you open forms inside prettyPhoto */
																	//,changepicturecallback: function(){} /* Called everytime an item is shown/changed */
																	//callback: function(){}, /* Called when prettyPhoto is closed */
																	//markup: '',
																	//gallery_markup: '',
																	//image_markup: '<img id="fullResImage" src="" />',
																	//flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
																	//quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
																	//iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
																	//inline_markup: '<div class="pp_inline clearfix">{content}</div>',
																	//custom_markup: ''
							};
							
							
							//
							// size width of each gallery to the width of its content (for inline content, if available)
							//
							var prettyPhoto_galleries = {};
							$("a[rel^='prettyPhoto']").each(function(i,n) {
								
								//var prettyPhoto_config = prettyPhoto_config_def;
								
									//get gallery class (prettyPhoto[class]) to get lightbox content width
								var gallery = $(this).attr('rel').replace('prettyPhoto[','').replace(']','');
									//alert( gallery );
									//alert($('.'+gallery).width());
								
									//store different gallery names
								prettyPhoto_galleries[gallery] = $('.'+gallery).width();//store width
								
							});
							for (key in prettyPhoto_galleries) {
								//alert(key);
								
								var prettyPhoto_config = prettyPhoto_config_def;
								
								//console.log(prettyPhoto_galleries[key]);
								//console.log(key);
									
									//set custom width here
								if (typeof(prettyPhoto_galleries[key])!='undefined' && prettyPhoto_galleries[key]!=null) {
									//console.log('TESTED: '+prettyPhoto_galleries[key]);
									prettyPhoto_config['default_width']=prettyPhoto_galleries[key];
								} else {
									//console.log(prettyPhoto_galleries[key]);	
								}
								//alert('rel="prettyPhoto['+key+']": width of content $(".'+key+'") => '+prettyPhoto_config['default_width']);
								
								function pp_start() {
									//$('.'+key).prettyPhoto(prettyPhoto_config);
									//alert( '\$("a[rel^="prettyPhoto['+key+']"]").length = '+$("a[rel^='prettyPhoto["+key+"]']").length );	
									$("a[rel^='prettyPhoto["+key+"]']").prettyPhoto(prettyPhoto_config);
								}
								pp_start();
							}
							
						});
						
						
