$(function() {

		if ( $('.fullScreenDiv').length == 0 && $('.popupContainer').length == 0 ) {
			getHtmlObj();
		}
		$(window).resize(function() {
			middleBox();
		});
});


//#getHtmlObj
getHtmlObj = function() {
	var linkUrlSwf	= 'http://www.meble.vox.pl/kolekcje-mebli/--young-users-by-vox--/';
	var boxWidth		= '696';
	var boxHeight		= '331';


		$('body').append('<div class="imageLink"><a href="'+linkUrlSwf+'"> <img src="images/btn_young_users.png" alt="" border="0" /></a></div>');
		
		$('.imageLink').css({
			display: 'block',
			position: 'absolute',
			top: '130px',
			right: '0px',
			width: '0px',
			height: '95px',
			overflow: 'hidden',
			cursor: 'pointer'
		});
		
		//wł/wył popup z YU
	//	if($.cookie('popup') != '1')
		if($.cookie('popup') = true)
		{
			$.cookie('popup','1');
			$('body').append('<div class="fullScreenDiv"></div>');
			$('body').append('<div class="popupContainer"></div>');
			
		} else {
			$('.imageLink').css('width','97px');
		}
		
		$('.fullScreenDiv').css({
		  	position: 'absolute',
		  	top: '0px',
			left: '0px',
		  	backgroundColor: '#000000',
			opacity: '0.60'
		});
	
		$('.popupContainer').css({
			position: 'absolute',
			top: '0px',
			left: '0px',
			width: boxWidth+'px',
			height: boxHeight+'px',
			backgroundColor: 'transparent'
		});
	
		$(".popupContainer").flash({
			swf: 'swf/popup.swf',
			id: 'animation',
			width: boxWidth,
			height: boxHeight,
			menu: false,
			wmode: "transparent",
			bgcolor: "FFFFFF",
			flashvars: {
				nazwa_zmiennej: linkUrlSwf
			}
		});
	
		$('.imageLink').bind('click', function() {
			$(this).animate( {width: '0px'}, {queue: false, duration: 300} );
	
			$(this).promise().done(function() {
				$(this).remove();
				getHtmlObj();
			});
		});
		
		middleBox();
}

//#middleBox
middleBox = function() {
	var centerContent = ( $(window).width() - $('.popupContainer').width() ) / 2;
	var middleContent = 130; // ( $(window).height() - $('.popupContainer').height() ) / 2 //

	$('.popupContainer').css({ left: centerContent+'px', top: middleContent+'px' });

	if ( $(window).width() < $('.pageContainer').width() ) {
		$('.fullScreenDiv').css({ width: $(document).width()+'px', height: $(document).height()+'px' });
	} else {
	  $('.fullScreenDiv').css({ width: '100%', height: $(document).height()+'px' });
	}
}

//#mozesz_zamykac
mozesz_zamykac = function() {
	$('.popupContainer').hide();
	$('.fullScreenDiv').animate( {opacity: 'hide'}, {queue: false, duration: 350} );

	$('.fullScreenDiv').promise().done(function() {
		$('.popupContainer').remove();
		$('.fullScreenDiv').remove();
		$('.imageLink').animate( {width: '97px'}, {queue: false, duration: 250} );
	});
}
