
var urlop =  {
	init: function(){
		this.manageInputLabel();
		this.search_province();
		//this.lightbox();
		this.place();
		this.advs();
		this.panel_atuts();
		this.add();
		this.statUpdate();
		this.links();
		this.profits_tabs();
		this.placeAdd();
		this.search();
		this.topbanners();
	},		
	topbanners: function(){
		if ($("#topbanners > div").length>1)
			$("#topbanners-nav").tabs("#topbanners > div", {effect: 'fade', fadeInSpeed: 200, rotate: true}).slideshow({autoplay:true,clickable:false,interval:5000});
		if ($("#leftbanners > div").length>1)
			$("#leftbanners-nav").tabs("#leftbanners > div", {effect: 'fade', fadeInSpeed: 200, rotate: true}).slideshow({autoplay:true,clickable:false});
	},
	search: function(){
		/**
		 * Search scripts for the search app
		 */
		$('#search-details-link').click(function(){
			$('#search-details-box').slideToggle();
			return false;
		});
		/*$('#id_search_hotels').click(function(){
			if($(this).attr('checked')){
				$('div#search-details-inactive').css('height',$('#search-details-box').css('height'));
				$('div#search-details-inactive').fadeIn();
			}
			else
				$('div#search-details-inactive').fadeOut();
		});*/
	},
	placeAdd: function(){
		
		
	},
	profits_tabs: function(){
		jQuery('.testimonials-profits-card').hover(function(obj){
			jQuery(this).css('z-index','16');
			jQuery(this).next().css('z-index','17');
			jQuery(this).animate({
				top: '-=100',
				height: '+=100'
			});
		},function(obj){
			jQuery(this).animate({
				top: '+=100',
				height: '-=100',
				zIndex: '14'
			},function(){
				jQuery(this).css('z-index','14');
				jQuery(this).next().css('z-index','15');
			});
		});
	},
	links: function(){
		jQuery(".external").click(function(){
			window.open(jQuery(this).attr("href"));
			return false;
		});
	},
	statUpdate: function(){
		$('#place2-place-web a.url').click(function(){
			jQuery.ajax({
				url:'/updateStats/'+$(this).attr('id')+'/'
			});
			window.open($(this).attr('href'));
			return false;
		});
	},
	add: function() {
		
		
		$('.photos input').change(function(e){
			var next = $('.photos div.hidden')[0];
			$(next).removeClass('hidden');
		});
		$('.categories select').change(function(e){
			var next = $('.categories div.hidden')[0];
			$(next).removeClass('hidden');
		});
		
		/*if (typeof price != 'undefined'){
			$('#id_period').parent().append('<span></span>');
			$('#id_period').change(urlop.change_price);
			this.change_price();
		}*/
	},
	change_price: function() {
		var netto
		var period = $('#id_period').val();
		if (period == 12){
			netto = period * price;
		}
		else{
			netto = Math.round(period * price_half);
		}
		var brutto = netto + (netto *0.23);
		//$('>span', $('#id_period').parent()).text(netto + ' zł netto (' + brutto + ' zł brutto)');
	},
	search_province: function() {
		$('#FAS-wojewodzctwo').change(function(){
			$.post('/miasta/', {province: $('#FAS-wojewodzctwo').attr('value'), region: $("#FAS-region").attr('value')}, function(data){
				$('#FAS-miejscowosc').html(data);
			});
		});
		$('#FAS-region').change(function(){
			$.post('/miasta/', {province: $('#FAS-wojewodzctwo').attr('value'), region: $("#FAS-region").attr('value')}, function(data){
				$('#FAS-miejscowosc').html(data);
			});
		});
	},
	panel_atuts: function() {
		$('.atuts input').change(function(){
			var elements = $('.atuts input');
			var empty =  0;
			for (i=0; i<elements.length; i++)
			{
				if (elements[i].value == "")
					empty++;
			}
			if (empty < 2)
				$('.atuts ol').append('<li><input name="atuts" /></li>');
			
			urlop.panel_atuts();
		});
	},
	advs: function() {
		$('#id_province_1')
			.bind('change', function(){
				$.post('/miasta/', {province: $(this).attr('value')}, function(data){
					$('.select_city_1 select').html(data);
					$($('.select_city_1')[0]).show();
					$('.region2').show();
				});
			})
			.val('');
		$('.select_city_1').bind('change', function(){
			if ($(this).attr('value') != '0') {
				$($('.select_city_1:hidden')[0]).show();
			}
		});
		$('#id_province_2')
			.bind('change', function(){
				$.post('/miasta/', {province: $(this).attr('value')}, function(data){
					$('.select_city_2 select').html(data);
					$($('.select_city_2')[0]).show();
				});
			})
		.val('');
		$('.select_city_2').bind('change', function(){
			if ($(this).attr('value') != '0') {
				$($('.select_city_2:hidden')[0]).show();
			}
		});
	},
	manageInputLabel: function() {
		$( '#formAccommodationSearch, #formNewsletter input, #FAS-miejscowosc, #id_place' ).bind( 'focus blur', function(){
			window.status+='-';
			with( $( this ) ){
				if( attr( 'value' ) == parent().find('label').text() ){
					attr( 'value', '' );
				} else {
					if( $.trim( attr( 'value' ) ) == '' ) {
						attr( 'value', parent().find('label').text() );
					}
				}
			}
		});
	},
    /*lightbox: function(){
		$('#facility ul.photos a').lightBox({
			imageLoading: '/media/gfx/lightbox-ico-loading.gif',
			imageBtnClose: '/media/gfx/lightbox-btn-close.gif',
			imageBtnPrev: '/media/gfx/lightbox-btn-prev.gif',
			imageBtnNext: '/media/gfx/lightbox-btn-next.gif',
			imageBlank: '/media/images/lightbox-blank.gif'
		});
	},*/
	place: function() {
		$('#formQuestionLink').click(function(e){
			e.preventDefault();
			var that = $(this);
			that.hide();
			$('.formRecommend').fadeOut('fast');
			$('#formOpinion').fadeOut('fast');
			$('.formQuestion:not(.forms)').fadeIn('slow');
		});
		
		$('#formRecommendLink').click(function(e){
			e.preventDefault();
			var that = $(this);
			$('#formQuestionLink').show();
			$('.formQuestion').fadeOut('fast');
			$('.formRecommend').fadeIn('slow');
		});
		
		$('#formOpinionLink').click(function(e){
			e.preventDefault();
			var that = $(this);
			$('#formQuestionLink').show();
			$('.formQuestion').fadeOut('fast');
			$('.formRecommend').fadeOut('fast');
			$('#formOpinion').fadeIn('slow');
		});
		
		$('#printFacility').click(function(e){
			e.preventDefault();
			window.print();
		});
	}
};
jQuery(document).ready(function(){
	urlop.init();
});
