function nyroShowBackground(elts, settings, callback){
	elts.bg.css({opacity: 0.5}).show(0.5, callback);
	
}
function nyroHideBackground(elts, settings, callback){
	elts.bg.hide();
	callback();
}

function nyroShowContent(elts, settings, callback) {
	elts.contentWrapper
    .css({ // Reset the CSS at the start position
      marginTop: (-100/2 + settings.marginScrollTop)+'px',
      marginLeft: (-100/2 + settings.marginScrollLeft)+'px',
      height: '100px',
      width: '100px',
      opacity: 0,
      display: 'block',
      width: settings.width+'px',
      marginLeft: (settings.marginLeft)+'px',
      opacity: 0.5,
      height: settings.height+'px',
      marginTop: (settings.marginTop)+'px',
      opacity: 1
    });
  	
  	callback();
}

function newsletterError(form , errors){
    
    $(".nsep").remove();
    $("<div class='ctrl-form-field-error-text'></div>").text(errors.alerts[0]).insertAfter($( "<div class='nsep'><br /></div>").insertAfter(".input-remove").css( {"clear": "both", 'margin-top': '1px !important'} )).css('width', '90%');
    $(".ctrl-form-field-error").removeClass("ctrl-form-field-error");
}

function nyroHideContent(elts, settings, callback) {
  
	elts.contentWrapper.find(".ctrl-wyswig").each(function(){
		var context = $(this);
		if(ctrlWyswigEditors[context.attr("id")] != undefined){
			ctrlWyswigEditors[context.attr("id")].destroy();
		}
	});
  
  elts.contentWrapper.hide();
  callback();
}

function nyroHideTransition(elts, settings,callback){
	elts.contentWrapper
	.hide()
	.css({
		width: settings.width+'px',
		height: settings.height+'px',
		marginLeft: settings.marginLeft+'px',
		marginTop: settings.marginTop+'px',
		opacity: 1
	});
	elts.loading
		.animate({
			width: settings.width+'px',
			height: settings.height+'px',
			marginLeft: settings.marginLeft+'px',
			marginTop: settings.marginTop+'px'
		}, {complete: function() {
				elts.contentWrapper.show();
				elts.loading.fadeOut(400, function() {
					elts.loading.hide();
					
					
					callback();
				});
			}, duration: 350});
}
$(function(){
	if($.fn.nyroModal){
		$.fn.nyroModal.settings.showContent = nyroShowContent;
		$.fn.nyroModal.settings.hideContent = nyroHideContent;
		$.fn.nyroModal.settings.showBackground = nyroShowBackground;
		$.fn.nyroModal.settings.hideBackground = nyroHideBackground;
		$.fn.nyroModal.settings.hideTransition = nyroHideTransition;
	}
});


var regional = $.datepicker.regional[''];
regional.dateFormat = 'dd M yy';
$.datepicker.regional[''] = regional;

$.datepicker.regional['pl'] = {
		closeText: 'Zamknij',
		prevText: '&#x3c;Poprzedni',
		nextText: 'Następny&#x3e;',
		currentText: 'Dziś',
		monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec',
		'Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
		monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze',
		'Lip','Sie','Wrz','Paź','Lis','Gru'],
		dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
		dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
		dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
		dateFormat: 'dd M yy', firstDay: 1,
		isRTL: false
	};
	
if(window.langValue == 'pl'){
    
    $.datepicker.setDefaults($.datepicker.regional['pl']);
}

// Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){




	// NOTE: We are trimming the jQuery collection down to the
	// first element in the collection.
	if (this.size() > 1){
		this.eq( 0 ).print();
		return;
	} else if (!this.size()){
		return;
	}
 
	// ASSERT: At this point, we know that the current jQuery
	// collection (as defined by THIS), contains only one
	// printable element.
 
	// Create a random name for the print frame.
	var strFrameName = ("printer-" + (new Date()).getTime());
 
	// Create an iFrame with the new name.
	var jFrame = $( "<iframe name='" + strFrameName + "' />" );
 
	// Hide the frame (sort of) and attach to the body.
	jFrame
		.css( "width", "1px" )
		.css( "height", "1px" )
		.css( "position", "absolute" )
		.css( "left", "-9999px" )
		.appendTo( $( "body:first" ) )
	;
 
	// Get a FRAMES reference to the new frame.
	var objFrame = window.frames[ strFrameName ];
 
	// Get a reference to the DOM in the new frame.
	var objDoc = objFrame.document;
 
	// Grab all the style tags and copy to the new
	// document so that we capture look and feel of
	// the current document.
 
	// Create a temp document DIV to hold the style tags.
	// This is the only way I could find to get the style
	// tags into IE.
	var jStyleDiv = $( "<div/>" ).append($( "base" ).clone()).append($( "style" ).clone()).append($( "link[media*=print]" ).clone());
	
	// Write the HTML for the document. In this, we will
	// write out the HTML of the current element.
	objDoc.open();
	objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
	objDoc.write( "<html>" );
	objDoc.write( "<head>" );
	objDoc.write( "<title>" );
	objDoc.write( document.title );
	objDoc.write( "</title>" );
	objDoc.write( jStyleDiv.html() );
	objDoc.write( "</head>" );
	objDoc.write( "<body>" );
	objDoc.write( '<div id="'+this.attr('id')+'" style="'+this.attr('style')+'" >' + this.html() + "</div>" );
	objDoc.write( "</body>" );
	objDoc.write( "</html>" );
	objDoc.close();
	
	// Print the document.
	//alert(this.html());
	/*$(objFrame).ready(function() {
		objFrame.focus();
		objFrame.print();
	});*/
 	setTimeout(function(){objFrame.focus(); objFrame.print();}, 400);
 	
	// Have the frame remove itself in about a minute so that
	// we don't build up too many of these frames.
	setTimeout(function(){jFrame.remove();}, (60 * 1000));
};

$(function(){
	$(".print").click(function(){
		
		if($(this).is(".no-standard")){
			$("#"+$(this).attr("rel")).print();
		}
		else $("#content").print();
		
		return false;
	});
	
	$(".book").click(function(){
		Booking.Open({ Checkin: $('input[name*=date_from]').val(), Checkout: $('input[name*=date_to]').val(), locale: language });
		return false;
	});
});


		
