function ProjectionScreen() {
    this.elementReference=null;
}

ProjectionScreen.prototype.showQTMovie = function (url) {
    if (this.elementReference != null) {
        this.elementReference.stop();
        this.elementReference.remove();
        this.elementReference = null;
    }

    this.elementReference = $('<div></div>');
    var bkg = $('<div style="position:fixed; left:0; top:0; width:100%; height:100%; background:url(graphics/projectionBkg.png)"></div>');
    var object = this;
    bkg.mousedown(function (event) { object.hideQtMovie();});
    var qtObject = $('<div style="position:absolute; left:50%; top:50%; margin-left:-320px; margin-top:-180px"><EMBED SRC="' + url + '" WIDTH=640 HEIGHT = 360 AUTOPLAY=true CONTROLLER=true LOOP=false PLUGINSPAGE=http://www.apple.com/quicktime/"></div>');
    this.elementReference.append(bkg).append(qtObject);
    $(document.body).append(this.elementReference);
    this.elementReference.hide();
    this.elementReference.fadeIn();
};

ProjectionScreen.prototype.showFlashMovie=function(url,isRadio,closeCallback,initialVolume){
	$.fancybox("flash/moviePlayer.swf",
	{
		'padding'			: 0,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		// 'showCloseButton'   : false,
		'type':'swf',
		'swf':{
			'flashvars':'isRadio='+(isRadio?'true':'false')+'&movie='+url+'&volume='+initialVolume,
			'quality':'hight',
			'allowFullScreen':'true',
			'bgcolor':'#000000',
		},
		'width':'640',
		'height':'380',
		'onClosed':closeCallback,
	});
};



ProjectionScreen.prototype.showFancy=function(url,closeCallback){
	var p=[];
	for(var h=0;h<url.length;h++){
		// p[h]={
			// href:url[h],
			// title:'<a target="_blank" href="http://www.artcore.pl">pizd</a>'
		// };
		p[h]=url[h];
	}
	$.fancybox(p,
	{
		'padding'			: 0,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		// 'showCloseButton'   : false,
		'type':'image',
		'onClosed':closeCallback,
	}
	);
}
	
	
ProjectionScreen.prototype.showImage=function(url){
	var object=this;
	
	this.elementReference=$('<div></div>');
	var bkg = $('<div style="position:absolute; left:0px; top:0px; background:url(graphics/projectionBkg.png);text-align:center"></div>');
	// this.elementReference.append(bkg);
	
	var shadowedContainer=$('<div style="display:table">'
								+'<div style="display:table-row">'
									+'<div style="display:table-cell; width:20px;height:20px;background:url(graphics/shadow/tl.png) no-repeat"></div>'
									+'<div style="display:table-cell; height:20px;background:url(graphics/shadow/t.png) repeat-x"></div>'
									+'<div style="display:table-cell; width:20px;height:20px;background:url(graphics/shadow/tr.png) no-repeat"></div>'
								+'</div>'
								+'<div style="display:table-row">'
									+'<div style="display:table-cell; width:20px;background:url(graphics/shadow/l.png) repeat-y"></div>'
									+'<div class="imageShadowContainer" style="display:table-cell"></div>'
									+'<div style="display:table-cell; width:20px;background:url(graphics/shadow/r.png) repeat-y"></div>'
									+'</div>'
								+'<div style="display:table-row">'
									+'<div style="display:table-cell; width:20px;height:20px;background:url(graphics/shadow/bl.png) no-repeat"></div>'
									+'<div style="display:table-cell; height:20px;background:url(graphics/shadow/b.png) repeat-x"></div>'
									+'<div style="display:table-cell; width:20px;height:20px;background:url(graphics/shadow/br.png) no-repeat"></div>'
								+'</div>'
							+'</div>');
	var imageContainer=$('<div><img src="graphics/preloader.gif" style="margin-top:200px" /></div>');
	// imageContainer.css('left:50%');
	// imageContainer.css('top:50%');
	shadowedContainer.find('.imageShadowContainer').html(imageContainer);
	var wholeContainer=$('<div style="display:inline-block;position:absolute">'
			+'</div>');
	wholeContainer.css('left','50%');
	wholeContainer.css('margin-left','-12px');
	wholeContainer.css('top',window.pageYOffset-20);
	wholeContainer.html(shadowedContainer);
	
	//wholeContainer.css("margin-left",'-50px');
	//wholeContainer.css('margin-top','-50px');
	
	//wholeContainer.css('position','absolute');
	//wholeContainer.css('left',"50%");
	//wholeContainer.css('top',"50%");
	
	this.elementReference.append(bkg);
	bkg.append(wholeContainer);
	
	bkg.width($(document).width());
	bkg.height($(document).height());
	
	
	this.elementReference.hide();
	this.elementReference.fadeIn(200);
	bkg.mousedown(function (event) { object.hideImage();});
	$(document.body).append(this.elementReference);

	loadImage(url,function(newImage,realWidth,realHeight){
		//newImage.hide();
		imageContainer.html(newImage);
		// imageContainer.height(newImage.height());
		// imageContainer.width(newImage.width());
		//imageContainer.animate({height:newImage.height(),width:newImage.width()},200,function(){
			newImage.hide();
			imageContainer.html(newImage);
			newImage.fadeIn();
			// newImage.attr('max-height',newImage.height());
			// newImage.attr('max-width',newImage.width());
			if($(window).width()>realWidth && $(window).height()>realHeight){
				wholeContainer.css('margin-left', -realWidth/2);
				wholeContainer.css('margin-top', ($(window).height()-realHeight)/2);
			}else{
				var screenRatio=$(window).height()/$(window).width();
				var imageRatio=realHeight/realWidth;
				if(screenRatio<imageRatio){
					newImage.attr('height',$(window).height());
					wholeContainer.css('left','50%');
					wholeContainer.css('margin-left', -(realWidth/imageRatio)/2);
				}else{
					// alert(realHeight);
					// alert(realWidth);
					newImage.attr('width',$(window).width());
					// wholeContainer.css('margin-left', $(window).width()/2-realWidth/2);
					// wholeContainer.css('margin-top', ($(window).height()-realHeight)/2);
					
					// wholeContainer.css('margin-left', -realWidth/2);
					// wholeContainer.css('margin-top', ($(window).height()-realHeight)/2);
					wholeContainer.css('left','50%');
					wholeContainer.css('margin-left', -($(window).width())/2);
					wholeContainer.css('margin-top', ($(window).height()-screenRatio*$(window).width())/2);
				}
			}
			// newImage.attr('height',$(window).height());
			// newImage.attr('width',$(window).width());
			
			
			// wholeContainer.css('margin-left', -newImage.width()/2);
			// wholeContainer.css('margin-left',-(window.pageYOffset*1,441)/2-20);
		//});
		/*wholeContainer.animate({"margin-left":-newImage.width()/2-10+'px'
			, "margin-top":-newImage.height()/2-10+'px'}
			,200);*/
		// wholeContainer.css("margin-left",-newImage.width()/2-10);
		// wholeContainer.css('margin-top',-newImage.height()/2-10);
		//wholeContainer.css("margin-left",'-415px');
		//wholeContainer.css('margin-top','-600px');
		
		//wholeContainer.css('position','absolute');
		// wholeContainer.css('left',newImage.width()/2);
		//wholeContainer.css('left',"50%");
		// wholeContainer.css('top',newImage.height()/2);
		//wholeContainer.css('top',"50%");
		
		
		 bkg.width($(document).width());
		 bkg.height($(document).height());
		//imageContainer.empty();
	}
	,function(){
		imageContainer.html('<div>Nie można pobrać obrazka.</div>');
	});
};

ProjectionScreen.prototype.hideImage=function(){
	var object = this;
    this.elementReference.unbind();
    this.elementReference.fadeOut(200, function () {
        object.elementReference.remove();
        object.elementReference = null;
    });
};

ProjectionScreen.prototype.hideFlashMovie=function(){
	var object = this;
    this.elementReference.unbind();
    this.elementReference.find('.fl').empty();
    this.elementReference.fadeOut(200, function () {
        object.elementReference.remove();
        object.elementReference = null;
    });
};

ProjectionScreen.prototype.hideQtMovie = function () {
    var object = this;
    this.elementReference.unbind();
    this.elementReference.fadeOut(200, function () {
        object.elementReference.remove();
        object.elementReference = null;
    });
};
