(function($){

		var fileName = 'DSC02542.JPG';

			var $zoom;

			var destroy = true;

			var boxy;

			function boxyCreate() {
				boxy = new Boxy($zoom, {
					closeable: true,
					title: "&nbsp;",
					modal: true,
					//unloadOnHide: true,
					beforeUnload: hideZoomer
				});

			}

			function showZoomer( options ){

				if( typeof options != 'object' ){
					options = {};
				}

				$zoom = $("<div>");
				
				boxyCreate();

				var ratio = $('#pic').width() / $('#pic').height();

				var wWidth  = document.documentElement.clientWidth;
				var wHeight = document.documentElement.clientHeight;

				var zWidth = Math.floor( wWidth / 2 );
				var zHeight = Math.floor( zWidth / ratio );

				var opts = $.extend(true,{
					url:
				"http://cdn.bildero.info/23/samochody/"+$('#pic').data('fileName')+".mpx",
					zoom: -1.0,
					width: zWidth,
					height: zHeight,
					events: {
						onFullscreen:   function( e ){
							$zoom.removeClass('boxy-content');
							boxy.hide();
						},
						onBoxMode:      function(){
							$zoom.addClass('boxy-content');
							boxy.show();
							boxy.center();
						}
					}
				},options);

				$zoom.mskDeepZoomer(opts)
					.mskDeepZoomerNavigation()
					.mskDeepZoomerPreview()
					.mskDeepZoomerCarousel({
					
						itemThumbUrlCallback: function( u ){ return u.replace(/mpx$/,'JPG?res=small'); },
						 
						images: {
								0:
						"http://cdn.bildero.info/23/samochody/DSC02542.mpx",
								1:
						"http://cdn.bildero.info/23/samochody/DSC02543.mpx",
								2:
						"http://cdn.bildero.info/23/samochody/DSC02544.mpx",
										3:
						"http://cdn.bildero.info/23/samochody/DSC02550.mpx"
							},
						placement: 'left'
					});

				boxy.center();
				$(window).bind('resize',onRezize);
			}

			function hideZoomer(){
				//$zoom.removeClass('boxy-content');
				$('body').append($zoom);
				$zoom.data('mskDeepZoomer').destroy();
				$zoom.replaceWith('');
				$('#pic').show();
				$(window).unbind('resize',onRezize);
			}

			function onRezize(){
				boxy.center();
			}

			function showImage( file ){
				$('#pic').data('fileName',file).attr('src','http://cdn.bildero.info/23/samochody/'+file+'?res=400')
					.mskImagePreview({
						previewUrl:
						"http://cdn.bildero.info/23/samochody/"+file+"?res=1024",
						crop: {
							scale: 3
						},
						onClick: function(){
							showZoomer();
						}
				}).load(function(){
				 $('.msk-image-preview-region').append('<div style="font-size:9px; margin:1px 1px 0 0; display:inline-block; float:right; background: #000; padding:4px 6px; color:#fff;" mce_style="font-size: 5px; margin:1px 1px 0 0; display:inline-block; float:right; background: #000; padding:4px 6px; color:#fff;"></div><div class="clr"></div>');
				});
			}
			
			$.mskShowImage = showImage;
			
	$(document).ready(function(){
			showImage(fileName);
					
				$('.jQ_goFS').click(function(){
					showZoomer({
						fullscreen: true
					});
				});
				
				$('.showZ').click(function(){
					showZoomer();
				});
				
			});

})(jQuery)

