/* Russian (UTF-8) initialisation for the jQuery UI date picker plugin. */
/* Written by Andrew Stromnov (stromnov@gmail.com). */
jQuery(function($){
		var	date=Date("Year");
				
        $.datepicker.regional['ru'] = {
                closeText: 'Закрыть',
                prevText: '&#x3c;Пред',
                nextText: 'След&#x3e;',
                currentText: 'Сегодня',
                yearRange: ""+(date-100)+":"+(date+50)+"",
                showYearNavigation:true,
                monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь',
                'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'],
                monthNamesShort: ['Янв','Фев','Мар','Апр','Май','Июн',
                'Июл','Авг','Сен','Окт','Ноя','Дек'],
                dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'],
                dayNamesShort: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
                dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'],
                dateFormat: 'dd.mm.yy', firstDay: 1,
                changeYear: true,
				readonly:true,
                //minDate: new Date(),
                isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['ru']);
});

function declOfNum(number, titles) {
  cases = [2, 0, 1, 1, 1, 2];  
  return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
    /* callback */
function callback_function()
{
  $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
  });
  $('.modal-callback .button input').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_callback.php", $(".modal-callback form").serialize(),
          function(data){
                $('.css-style').html(data);
        });
  });
}

function order_callback_php ()
{
        //$('.order-callback-js').click(function (e) {
          //$.modal(data, {  opacity: 90  });
          //$.modal.opacity=90;
         // alert("test-callback");
        // e.preventDefault();

                $.get( 'modal/modal_success.html', function(data){
                  $.modal(data, {
                        autoPosition: false,
                        opacity: 90,
                        onClose: modalOnClose,
                        onOpen: modalOnOpen,
                        onShow: function(dialog){callback_function();}
                  });
                });
          $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
        //});
}

function modalOnOpen(dialog) {
        //Animate the open of the popup
        dialog.overlay.fadeIn('fast', function() {
                dialog.container.fadeIn('fast', function() {
                        dialog.data.hide().slideDown('fast');
                });
        });
}
function modalOnClose(dialog) {
        //Animates the closing of the dialogs
   dialog.data.fadeOut('fast', function() {
           dialog.container.slideUp('fast', function() {
                   dialog.overlay.fadeOut('fast', function() {
                           $.modal.close();
                   });
           });
   });
}

$(document).ready(function(){
    // datapicker
	
	$(".single-hostel-prices .ajax-content a").click(function(){
		$.post("/modal/setroom.php",
			   {"room_id":$(this).attr("rel")},
			   function(date){
		});
	});
	
    $('#hostel-date-in').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange});
    $('#hostel-date-out').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange});
    function customRange(input) {
        var input_id = input.id;
                
                if ($("#hostel-date-in").datepicker("getDate")) date=$("#hostel-date-in").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-in"){return {maxDate: $("#hostel-date-out").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-out"){return {minDate: date, maxDate: null};}
    }
	
    $('#hostel-date-from').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange2, altField: '#h-datefrom-alt', altFormat: '@'});
    $('#hostel-date-to').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange2, altField: '#h-dateto-alt', altFormat: '@'});
    function customRange2(input) {
        var input_id = input.id;
                
                if ($("#hostel-date-from").datepicker("getDate")) date=$("#hostel-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-from"){return {maxDate: $("#hostel-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-to"){return {minDate: date, maxDate: null};}
    }
     
    $('#tour-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
    $('#tour-date-search').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
    $('#birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
	
	$('.content-form .date #p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, maxDate:new Date()});
	$('.content-form .date #transport-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
	
	$('.content-form .date #excursion-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
	
    $(".form-hostel-services span.link").click(function () {
      $(".form-hostel-services").toggleClass("services-full");
      $(".form-hostel-services").toggleClass("services-short");
      return false;
    });

    $(".contest-types .text table p.archive-link a").click(function () {
      $(this).toggleClass("active");
      $(this).parent().next('ul').toggle('fast');
      return false;
    });

	$(".captcha-num a").click(function (e) {
		e.preventDefault();
		var img_id = ".captcha-num img";
		var timestamp = new Date().getTime();
		var img_src = $(img_id).attr("src").split("?")[0] + "?" + timestamp;
		$.ajax({
			type: "GET",
			url: img_src,
			success: function(msg){$(img_id).attr('src',img_src);}
		});
	});
	
	/*$(".content-form .button .finish-js").click(function(e)
	{
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$(".content-form form").submit();
	});*/
	
	$(".content-form .button a").click(function(e)
	{
		//alert('test');
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$("#dur").attr("value",$("#visa-duration_title .textTitle").html());
		//alert($("#visa-duration_title .textTitle").html());
		$(".content-form form").submit();
	});
	
	/*$(".next-js").click(function(e){
		e.preventDefault();
		
		if ()
	});*/
	
	/*$(".content-form .finish-js").click(function(e)
	{
		e.preventDefault();
		$("#send_reg").attr("value","1");
		$(".content-form form").submit();
	});*/
	
	$(".form-hostel-services input").click(function(){
		var int="";
		
		$(".form-hostel-services input").each(function(){
		   if ($(this).attr("checked")==true) 
		   {
			  int++;
			  // alert($(this).attr("value"));
		   }
		});
		
		if (int)	$(".form-hostel-services .selected").html("Выбрано услуг: "+int);
		else	$(".form-hostel-services .selected").html("");
	});

    $('.content-form .date input').change(function() {
	//	alert("test");
      date_in = parseInt($("#h-datefrom-alt").val());
      date_out = parseInt($("#h-dateto-alt").val());
	  
      if (date_in > 0 && date_out > 0) {
        days_count = ((date_out - date_in)/(86400000));
        $(".content-form .quant-day").html('<em>' + days_count + '</em>' +declOfNum(days_count, [' ночь', ' ночи', ' ночей']));
      }
    });

   $(".modal-box .count-number a").click(function () {
	needed_number = $('.modal-box:visible .count-number select').val();
	current_children = $(".modal-box:visible .counts .count-item:visible");
	all_children = $(".modal-box:visible .counts .count-item");
	current_number = current_children.size();
	if (needed_number > 0) {
	  if (needed_number < current_number) {
		$(current_children).each(function( intIndex){
		  if (intIndex >= needed_number) {$(this).hide();}
		});
	  }
	  if (needed_number > current_number) {
		$(all_children).each(function(intIndex){
		  if (intIndex < needed_number) {$(this).show();}});
	  }
	}
	else {$(current_children).hide();}
  });



    // blox height
    function mainBoxHeighEqual() {
        var height1 = $('#main-2-row .main-right-box').height();
        var height2 = $('#main-2-row .main-left-box').height();
        var difference = height1 - height2;
        if (difference > 0){
            $('#main-2-row .main-left-box .all').css('margin-bottom', difference/2 + 'px');
            $('#main-2-row .main-left-box .all').css('margin-top', difference/2 + 'px');
        }
        if (difference < 0){$('#main-2-row .main-right-box .contest-list').css('padding-bottom', difference);}
    }
    mainBoxHeighEqual();
    $(".hostel-search select").msDropDown();
    $(".hostels-search select").msDropDown();
    $(".news-sort select").msDropDown();
    $(".contest-sort select").msDropDown();
    $(".cabinet-sort select").msDropDown();
    $(".hostels-rating-sort select").msDropDown();
    $(".group-form select").msDropDown();
    $(".cabinet-settings-form select").msDropDown();
    $(".tour-search-form select").msDropDown();
    $(".tickets-order select").msDropDown();
    $(".hostels-tour-order select").msDropDown();
	$(".content-form .cols select").msDropDown();
	$(".content-form .p-gender select").msDropDown();
	$(".content-form .tour-ppl-count select").msDropDown();
	
	$(".content-form .part-left select").msDropDown();
	$(".content-form .part-center select").msDropDown();
	$(".content-form .part-right select").msDropDown();
	$(".excursion-type select").msDropDown();
	

    /* Tickets destination change */
    $('.change a').click(function (e) {
      e.preventDefault();
      var from = $('#ticket-from').val();
      var to = $('#ticket-to').val();
      $('#ticket-from').val(to);
      $('#ticket-to').val(from);
    });

    /* Map */
    function map_markers() {
      $(".modal-box .map .s").hover(
        function () {
          num = $(this).attr("alt");
          $('.map .m[alt="'+ num +'"]').addClass('active');
        },
        function () {
          num = $(this).attr("alt");
          $('.map .m[alt="'+ num +'"]').removeClass('active');}
      );
    }

    /* Search map hover */
    $(".map-list table td").hover(
      function () {$(this).parent().addClass('active');},
      function () {$(this).parent().removeClass('active');}
    );

    /* Hostel price by date */
    //$('#date-start').datepicker({beforeShow: customRangeHostel, altField: '#date-start-alt', altFormat: '<i>D</i> dd.mm.yy'});
   // $('#date-end').datepicker({beforeShow: customRangeHostel, altField: '#date-end-alt', altFormat: '<i>D</i> dd.mm.yy'});
    function customRangeHostel(input) {
        var input_id = input.id;
                
                if ($("#date-start").datepicker("getDate"))     date=$("#date-start").datepicker("getDate");
                else    date=new Date();

        if (input_id == "date-start"){return {maxDate: $("#date-end").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "date-end"){return {minDate: date, maxDate: null};}
    }
    //$('.date-start').click(function () {
    //  $('#date-start').datepicker('show');
    //});
    $("#date-start").change( function() {
      date = $('#date-start-alt').val();
      $('.date-start').html(date);
    });
    //$('.date-end').click(function () {$('#date-end').datepicker('show');});
    $("#date-end").change( function() {date = $('#date-end-alt').val();$('.date-end').html(date);});

    //$('.hostel-date-count').click(function (e) {
    //  e.preventDefault();
    //  var href = $(this).attr('href');
    //  var block_height = $('.single-hostel-prices .ajax-content').height();
    //  $('.single-hostel-prices h2').fadeOut("fast");
    //  $('.single-hostel-prices form').fadeOut("fast");
    //  $('.single-hostel-prices > p').fadeOut("fast");
    //  $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
    //    $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
    //    $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
    //    $('.single-hostel-prices .ajax-content').fadeIn('fast', function() {
    //      $.post(href, $("#hostel-price-period").serialize(),
    //      function(data){
    //        $('.single-hostel-prices h2').fadeIn("fast");
    //        $('.single-hostel-prices form').fadeIn("fast");
    //        $('.single-hostel-prices > p').fadeIn("fast");
    //        $('.single-hostel-prices .ajax-content').html(data);
    //        hostel_order_js();
    //      });
    //    });
    //  });
    //});

    function date_search() {
      var block_height = $('.single-hostel-prices .ajax-content').height();
      $('.single-hostel-prices h2').fadeOut("slow");
      $('.single-hostel-prices form').fadeOut("slow");
      $('.single-hostel-prices > p').fadeOut("slow");
      $('.single-hostel-prices .ajax-content').fadeOut('slow', function() {
        $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
        $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
        $('.single-hostel-prices .ajax-content').fadeIn('slow', function() {
          
          $.post('modal/hostel-price.php', $("#hostel-price-period").serialize(),
          function(data){
            $('.single-hostel-prices h2').fadeIn("slow");
            $('.single-hostel-prices form').fadeIn("slow");
            $('.single-hostel-prices > p').fadeIn("slow");
            $('.single-hostel-prices .ajax-content').html(data);
            hostel_order_js();
          });
             
          $.post('modal/new-cperiod.php', $("#hostel-price-period").serialize(),
          function(data){
            $('.single-hostel-prices .period').html(data);
          });
		  
          $.post('modal/get_some.php?special=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.special').html(data);
          });
		  
		  $.post('modal/get_some.php?info=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.info').html(data);
          });
		  
		  $.post('modal/get_some.php?text=1', $("#hostel-price-period").serialize(),
          function(data){
            $('.hostel-date-count').html(data);
          });
		  
        });
      });
    }

    /* date hostel */
    function date_hostel_function() {
      $('#date-start').val($("#hostel-date-in").val());
          $('#date-end').val($("#hostel-date-out").val());
          
          if ($("#hostel-date-in").datepicker("getDate"))       date=$("#hostel-date-in").datepicker("getDate");
          else  date=new Date();
          
      $('#hostel-date-in').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange, minDate: new Date() });
      $('#hostel-date-out').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, beforeShow: customRange, minDate: date});
          
                $('#date-start').val($("#hostel-date-in").val());
                $('#date-end').val($("#hostel-date-out").val());
          
      $("#hostel-date-in").change( function() {
        $('#date-start').val($("#hostel-date-in").val());
      });
      $("#hostel-date-out").change( function() {
        $('#date-end').val($("#hostel-date-out").val());
      });
         
      $('.modal-date .button a').click(function (e) {
        e.preventDefault();
        $.modal.close();
        $('#simplemodal-overlay').fadeOut('normal');
        $('html, body').animate({scrollTop: $(".single-hostel-prices").offset().top - 100}, 200);
        
                date_search();
                
      });
    }
     
    $('.hostel-date-count').click(function (e) {
      e.preventDefault();
          
          var href = $(this).attr('href');
          //'modal/modal_date.php'
          //alert(href);
      $.get(href, function(data){
        $.modal(data, {
          opacity: 90,
          autoPosition: false,
          onOpen: modalOnOpen,
          onClose: modalOnClose,
          onShow: function(dialog){date_hostel_function()}
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });

    /* tour prices */
    $('.single-hostel-prices .price-type a').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          //alert(href);
      var block_height = $('.single-hostel-prices .ajax-content').height();
          
      $('.single-hostel-prices .price-type').fadeOut("fast");
      $('.single-hostel-prices > p').fadeOut("fast");
      $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
        $('.single-hostel-prices .ajax-content').html("<div class=\"preloader\"></div>");
        $('.single-hostel-prices .ajax-content .preloader').height(block_height + 35);
        $('.single-hostel-prices .ajax-content').fadeIn('fast', function() {
          $.get(href, function(data){
            $('.single-hostel-prices .ajax-content').fadeOut('fast', function() {
              $('.single-hostel-prices .price-type').fadeIn("fast");
              $('.single-hostel-prices > p').fadeIn("fast");
              $('.single-hostel-prices .ajax-content').fadeIn("fast");
              $('.single-hostel-prices .ajax-content').html(data);
              tour_order_js();
            });
          });
        });
      });
      $('.single-hostel-prices .price-type a').show();
      $('.single-hostel-prices .price-type h2').hide();
      $(this).prev().show();
      $(this).hide();
    });

    /* ajax search */
        
    /*$('.hostels-search form.hostel-search-form .button').click(function (e) {
      e.preventDefault();
      var block_height = 100;
      $('.hostel-search-box').fadeOut('fast', function() {
        $('.hostel-search-box .paginator').remove();
        $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
        $('.hostel-search-box .preloader').height(block_height);
        $('.hostel-search-box').fadeIn('fast', function() {
          $.post("modal/modal_search_result.php", $(".hostels-search form.hostel-search-form").serialize(),
            function(data){
              $('.hostel-search-box').fadeOut('fast', function() {
                text = $('.hostel-search-box').html(data);
                $('.hostel-search-box').fadeIn('fast');
                hostel_order_js();
                ajax_search_prev();
                ajax_search_next();
              });
            });
        });
      });
    });

    function ajax_search_prev() {
      $('.hostel-search-box .paginator .paginator-prev').click(function (e) {
        e.preventDefault();
        var block_height = 100;
        $('.hostel-search-box').fadeOut('fast', function() {
          $('.hostel-search-box .paginator').remove();
          $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
          $('.hostel-search-box .preloader').height(block_height);
          $('.hostel-search-box').fadeIn('fast', function() {
            $.post("modal/modal_search_result.php?page=prev", $(".hostels-search form.hostel-search-form").serialize(),
              function(data){
                $('.hostel-search-box').fadeOut('fast', function() {
                  text = $('.hostel-search-box').html(data);
                  $('.hostel-search-box').fadeIn('fast');
                  hostel_order_js();
                  ajax_search_prev();
                  ajax_search_next();
                });
              });
          });
        });
      });
    }
    ajax_search_prev();

    function ajax_search_next() {
      $('.hostel-search-box .paginator .paginator-next').click(function (e) {
        e.preventDefault();
        var block_height = 100;
        $('.hostel-search-box').fadeOut('fast', function() {
          $('.hostel-search-box .paginator').remove();
          $('.hostel-search-box').html('<div class="innerw-box "><span class="ibox-top"><span class="tr"></span><span class="tl"></span></span><div class="preloader"></div><span class="ibox-bottom"><span class="br"></span><span class="bl"></span></span></div>');
          $('.hostel-search-box .preloader').height(block_height);
          $('.hostel-search-box').fadeIn('fast', function() {
            $.post("modal/modal_search_result.php?page=next", $(".hostels-search form.hostel-search-form").serialize(),
              function(data){
                $('.hostel-search-box').fadeOut('fast', function() {
                  text = $('.hostel-search-box').html(data);
                  $('.hostel-search-box').fadeIn('fast');
                  hostel_order_js();
                  ajax_search_prev();
                  ajax_search_next();
                });
              });
          });
        });
      });
    }
    ajax_search_next();*/

    /* excursion description */
    $('.excursion-table table tr.closed .excursion a').click(function (e) {
      e.preventDefault();
      var base = $(this).parents('tr');
      var href = $(this).attr('href');
          
      if ($(base).hasClass('active1')) {
        $('.excursion-table table tr.active2 td div.slide').slideUp('slow', function() {
          $('.excursion-table table tr.active2').remove();
          $('.excursion-table table tr.active1').addClass('closed').removeClass('active1');
        });
      }
      else {
          $('.excursion-table table tr.active2').remove();
          $('.excursion-table table tr.active1').addClass('closed').removeClass('active1');
          $(base).addClass('active1').removeClass('closed');
                  
          $.get(href, function(data){
            $(base).after(data);
            $('.excursion-table table tr.active2 td div.slide').slideDown("slow");
            order_callback_js();
          });
      }
    });

    /* best offers ajax */
    $('.best-offers .more a').click(function (e) {
      e.preventDefault();
      var str = $(this).text();
      var href = "modal/bestoffers.php";
          var this_id=$(this).attr('id');
          
      var block_height = $('#offers-list').height();
      $('.best-offers h3 span').text(str);
      $('#offers-list').fadeOut('fast', function() {
        $('#offers-list').html("<div class=\"preloader\"></div>");
        $('#offers-list .preloader').height(block_height);
        $('#offers-list').fadeIn('slow', function() {
          
                  $.post(href, { id:this_id }, function(data){
            $('#offers-list').fadeOut('slow', function() {
              $('#offers-list').html(data);
              $('#offers-list').fadeIn(data);
              mainBoxHeighEqual();
              //alert("Data Loaded: " + data);
            });
          });
        });
      });
      mainBoxHeighEqual();
    });

    /* contest vote */
    $('.contest-sidebar a.vote-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
      $.get(href, function(data){
        $('.contest-sidebar .rating span').html(data);
        $('.contest-sidebar a.vote-js').hide();
      });
    });
    $('.custom-box a.vote-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
      var data = $.ajax({url:href,type:"GET",async: false}).responseText;
      $(this).prev().html(data);
      $(this).hide();
    });

    /* metro map */
    function metromap_function() {
      map_markers();
      $('.metromap-modal .m').click(function (e) {
        e.preventDefault();
        var metro_id = $(this).attr('alt');
        $('#hostel-metro').val(metro_id);
        $("#hostel-metro").msDropDown();
        $.modal.close();
      });
    }
    $('.metro-map-js').click(function (e) {
      e.preventDefault();
      $.get( 'modal/modal_metromap.html', function(data){
        $.modal(data, {
          opacity: 90,
          autoPosition: false,
          onOpen: modalOnOpen,
          onClose: modalOnClose,
          onShow: function(dialog){metromap_function()}
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });

    /* callback */
    function callback_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
      $('.modal-callback .button input').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_callback.php", $(".modal-callback form").serialize(),
          function(data){
            $('.css-style').html(data);
        });
      });
    }
     
    function order_callback_js () {
    $('.order-callback-js').click(function (e) {
          //$.modal(data, {  opacity: 90  });
          //$.modal.opacity=90;
         // alert("test-callback");
      e.preventDefault();
        $.get( 'modal/modal_callback.php', function(data){
          $.modal(data, {
            autoPosition: false,
            opacity: 90,
            onClose: modalOnClose,
            onOpen: modalOnOpen,
            onShow: function(dialog){callback_function();}
          });
        });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
    }
    order_callback_js();
        
    /* login */
    function login_function() {
	   service_info();
		
      $(".modal-registration select").msDropDown();
          
      $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          //$('#p-birthday').datepicker({minDate:});
          
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-login .button .go-registration').click(function (e) {
        e.preventDefault();
        //$('.modal-login').hide();
        //$('.modal-registration').show();
		window.location="/registration.html";
      });
         
          $('.modal-login a.go-passrecall').click(function (e) {
        e.preventDefault();
        $('.modal-login').hide();
        $('.modal-recall').show();
      });
         
      $('.modal-login .button .login-enter').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_login.php", $(".modal-login form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
          $('.modal-recall .button .recall-enter').click(function (e) {
        e.preventDefault();
        $.post("modal/modal_test_recall.php", $(".modal-recall form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
      $('.modal-registration .button a').click(function (e) {
        e.preventDefault();
                //alert("asd");
        $.post("modal/modal_registration.php", $(".modal-registration form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
    }
     
    $('.login-js').click(function (e) {
      e.preventDefault();
        $.get( 'modal/modal_login.html', function(data){
          $.modal(data, {
            autoPosition: false,
            opacity: 90,
            onClose: modalOnClose,
            onOpen: modalOnOpen,
            onShow: function(dialog){login_function();}
          });
        });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
       
    $('.registration-js').click(function (e) {
      e.preventDefault();
          
                  $(document).ready(function(){
                        $.get( 'modal/modal_login.html', function(data){
                          $.modal(data, {
                                autoPosition: false,
                                opacity: 90,
                                onClose: modalOnClose,
                                onOpen: modalOnOpen,
                                onShow: function(dialog){
                                  login_function();
                                  $('.modal-login').hide();
                                  $('.modal-registration').show();
                                }
                                
                          });
                        });
                });
                  
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
    });
       
        $('.logout').click(function (e) {
      e.preventDefault();
          
       $.post("modal/logout.php", { exit:1 },
          function(data){
                        $('.logout').html(data);
       });
    });
       

    /* response */
    function response_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-response .button a').click(function (e) {
        e.preventDefault();
		
		$('.modal-response .wrapper').attr("style","display:none");
		$('.modal-response .preload').html("<div class=\"preloader\"></div>");
		
        $.post("modal/modal_test_response.php", $(".modal-response form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
    }
     
    $('.new-response-js').click(function (e) {
      e.preventDefault();
        		
      var href = $(this).attr('href');
          //alert(href);
      $.get( href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            response_function();
            $(".hostel-response-bar", dialog.container[0]).slider({
              range: "min",
              value: 5,
              min: 1,
              max: 10,
              slide: function(event, ui) {
                var hostelval = ui.value;
                var showval = $(this).next('.hostel-response-val');
                $(showval).text(hostelval);
                $(showval).next('.hostel-val').val(hostelval);
              }
            });
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200)
        });
        
    /* tour-response */
    function resptour_function() {
      $('.modal-box form .captcha-num a').click(function (e) {
        e.preventDefault();
        $(".modal-box form .captcha-num img").replaceWith('<img src="img/photo/captcha.png" alt="" /');
      });
         
      $('.modal-response .button a').click(function (e) {
        e.preventDefault();
		
		$('.modal-response .wrapper').attr("style","display:none");
		$('.modal-response .preload').html("<div class=\"preloader\"></div>");
				
        $.post("modal/modal_test_resptour.php", $(".modal-response form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
      });
         
    }
     
    $('.new-resptour-js').click(function (e) {
      e.preventDefault();
         
      var href = $(this).attr('href');
          //alert(href);
      $.get( href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            resptour_function();
            $(".hostel-response-bar", dialog.container[0]).slider({
              range: "min",
              value: 5,
              min: 1,
              max: 10,
              slide: function(event, ui) {
                var hostelval = ui.value;
                var showval = $(this).next('.hostel-response-val');
                $(showval).text(hostelval);
                $(showval).next('.hostel-val').val(hostelval);
              }
            });
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200)
        });
        
        
    /* visa business */
    function visa_b_period() {
      visaduration = $('#visa-duration').val();
      if (visaduration.length > 0 && $('#visa-date-from').val().length > 0) {
          now = new Date();
          $('#visa-date-to').datepicker('setDate', visaduration);
          date_to = $('#visa-date-to').datepicker( 'getDate' ).getTime();
          date_from = $('#visa-date-from').datepicker( 'getDate' ).getTime();
          next_s = date_from - now.getTime() + date_to;
          next = new Date();
          next.setTime(next_s);
          $('#visa-date-to').datepicker('setDate', next);
          $('.visa-date-js').html($('#visa-date-to').val());
      }
      else {$('.visa-date-js').html(' ');}
    }
    function visa_b_function() {
      service_info();
      order_service_checkboxes();
      $(".modal-visa-business select").msDropDown();
          
          $('.modal-visa-business p.date input#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          
		  if ($(".passport-from").datepicker("getDate")) 
		  {
			  	new_date=$(".passport-from").datepicker("getDate");
				$('.passport-to').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate: new_date});
		  }
		  else
		  {
			  	$('.passport-to').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
		  }
          //else    date=new Date();		
		  // minDate: new_date
          $('.passport-from').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          
      $('.modal-visa-business p.date input#visa-date-from').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate: new Date()});
          
      $('#visa-date-to').datepicker();
      $("#visa-duration_child a").click(function () {visa_b_period();});
      $("#visa-date-from").change( function() {visa_b_period();});
      $("#children-count_child a").click(function () {
        needed_number = $('#children-count').val();
        current_children = $("form .children-info-item:visible");
        all_children = $("form .children-info-item");
        current_number = current_children.size();
        if (needed_number > 0) {
          if (needed_number < current_number) {
            $(current_children).each(function( intIndex){
              if (intIndex >= needed_number) {
                $(this).hide();
                $("form .children-info-item:hidden input").val("");}
            });
          }
          if (needed_number > current_number) {
            $(all_children).each(function(intIndex){
              if (intIndex < needed_number) {$(this).show();}});
          }
        }
        else {
          $("form .children-info-item input").val("");
          $(current_children).hide();
        }
      });
      $('.modal-visa-business .button a').click(function (e) {
        e.preventDefault();
                
        $.post("modal/modal_test_b_visa.php", $(".modal-visa-business form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }
     
    $('.visa-business-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
      $.get( href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            visa_b_function();
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
	  });


    /* visa tour */
    function visa_t_function() {
      service_info();
      order_service_checkboxes();
      $(".modal-visa-tour select").msDropDown();
          
      $('.modal-visa-tour p.date input#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('.modal-visa-tour p.date input#visa-date-from').datepicker({beforeShow:customRangeTTVisa, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
          $('.modal-visa-tour p.date input#visa-date-to').datepicker({beforeShow:customRangeTTVisa, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
      //$('#visa-date-from').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
          
          function customRangeTTVisa(input) {
                var input_id = input.id;
                //alert(input_id);
                if ($("#visa-date-from").datepicker("getDate")) date=$("#visa-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "visa-date-from"){return {maxDate: $("#visa-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "visa-date-to"){return {minDate: date, maxDate: null};}
      }
       
         $(".modal-visa-tour .next-js").click(function (e) {
        e.preventDefault();
        $(".modal-visa-tour").hide();
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
        $(".modal-finish-order").show();
      });
         
      $('.modal-visa-tour .button a').click(function (e) {
        e.preventDefault();
                
        $(".modal-finish-order form .hidden-data").html("");
        data = $(".modal-visa-tour form").html();
        $(".modal-finish-order form .hidden-data").html(data);
                
        $.post("modal/modal_test_t_visa.php", $(".modal-visa-tour form").serialize(),
          function(data){
            $('.css-style').html(data);
          });
             
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }
     
    $('.visa-tour-js').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          
      $.get( href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
                  
          onShow: function(dialog){
            visa_t_function();
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});


    /* order service checkboxes */
    function order_service_checkboxes() {
     
         /*$("input.service-visa").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-visa').val('1');
          $('input.service-visa').attr('checked', true);
          //$('.modal-breadcrumbs .visa').show();
          //$('.modal-breadcrumbs .finish b').html(3);
        }
        else {
          $('#hidden-service-visa').val('0');
          $('input.service-visa').attr('checked', false);
          $('.modal-breadcrumbs .visa').hide();
          $('.modal-breadcrumbs .finish b').html(2);
        }
      });*/
          
      $("input.service-tour").click( function() {
        if($(this).is(':checked')) {
          $('#hidden-service-tour').val('1');
          $('input.service-tour').attr('checked', true);
        }
        else {
          $('#hidden-service-tour').val('0');
          $('input.service-tour').attr('checked', false);
        }
      });
      $("input.service-hostel").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-hostel').val('1');
          $('input.service-hostel').attr('checked', true);
        }
        else {
          $('#hidden-service-hostel').val('0');
          $('input.service-hostel').attr('checked', false);
        }
      });
      $("input.service-ins").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-ins').val('1');
          $('input.service-ins').attr('checked', true);
        }
        else {
          $('#hidden-service-ins').val('0');
          $('input.service-ins').attr('checked', false);
        }
      });
      $("input.service-transport").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-transport').val('1');
          $('input.service-transport').attr('checked', true);
        }
        else {
          $('#hidden-service-transport').val('0');
          $('input.service-transport').attr('checked', false);
        }
      });
      $("input.service-ticket").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-ticket').val('1');
          $('input.service-ticket').attr('checked', true);
        }
        else {
          $('#hidden-service-ticket').val('0');
          $('input.service-ticket').attr('checked', false);
        }
      });
      $("input.service-excursion").click( function() {
        if($(this).is(':checked')){
          $('#hidden-service-excursion').val('1');
          $('input.service-excursion').attr('checked', true);
        }
        else {
          $('#hidden-service-excursion').val('0');
          $('input.service-excursion').attr('checked', false);
        }
      });
      $("#service-subscribe").click( function() {
        if($(this).is(':checked')){$('#hidden-service-subscribe').val('1');}
        else {$('#hidden-service-subscribe').val('0');}
      });
    }
     
    /* order links */
    function order_links(type) {
                
        $(".next-js").click( function(e) {
			 e.preventDefault();
			 
			if($('.service-visa').is(':checked')){
				$('.modal-box').hide();
				$('.modal-visa-tour').show();
				$('.modal-breadcrumbs .item').removeClass('active');
				$('.modal-breadcrumbs .visa').addClass('active');
			}
			else {
				$('.modal-box').hide();
				$('.modal-finish-order').show();
				$('.modal-breadcrumbs .item').removeClass('active');
				$('.modal-breadcrumbs .finish').addClass('active');
			}
      });
        
               /* $.post("modal/modal_order_"+type+"_test.php?order=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });*/
        
                 /* if ($('.service-visa').is(':checked'))
                  {
                        $.post("modal/modal_order_"+type+"_test.php?visa=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });
                  }
                  else
                  {
                   
                  }
          });*/
        
      $(".finish-js").click( function() {
                $.post("modal/modal_order_"+type+"_test.php?last=1&from_order=1", $(".wrapper form.used").serialize(),
                          function(data){
                                $('.css-style').html(data);
                });
      });
         
          $(".finish-js-visa").click( function() {
                                                  
                        $.post("modal/modal_order_"+type+"_test.php?last=1&from_visa=1", $(".wrapper form.visa").serialize(),
                          function(data){
                                $('.css-style').html(data);
                        });
          });
          
      $("a.go-hostel").click( function() {
            $('.modal-box').hide();
            $('.modal-hostel').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .hostel').addClass('active');
      });
         
      $("a.go-excursion").click( function() {
            $('.modal-box').hide();
            $('.modal-excursion').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .excursion').addClass('active');
      });
         
      $("a.go-transport").click( function() {
            $('.modal-box').hide();
            $('.modal-transport').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .transport').addClass('active');
      });
      $("a.go-tour").click( function() {
            $('.modal-box').hide();
            $('.modal-tour').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            $('.modal-breadcrumbs .tour').addClass('active');
      });
    /*  $("a.go-visa").click( function() {
            $('.modal-box').hide();
            //$('.modal-visa-tour').show();
            $('.modal-breadcrumbs .item').removeClass('active');
            //$('.modal-breadcrumbs .visa').addClass('active');
      });*/
    }
	
	if ($("div").hasClass("hostel-order")) {
		hostel_order_js() ;
	} else if ($("div").hasClass("tour-order")) {
		tour_order_js();
	} else if ($("div").hasClass("modal-transport")) {
		transport_order_js();
	} else if ($("div").hasClass("modal-excursion")) {
		excursion_order_js();
	} else if ($("div").hasClass("modal-visa-business")) {
		visa_b_function();
	} else if ($("div").hasClass("modal-visa-tour")) {
		visa_t_function();
	}
	
    /* order service list */
    function service_info() {
      $(".add-service label").click( function(e) {
          //e.preventDefault();
          if ($(this).hasClass('active')) {
            //$(this).removeClass('active');
            //$('.service-info').slideUp("fast");
			e.preventDefault();
			$('.add-service label.active').removeClass('active');
			$('.service-info').slideUp("fast");
          } else {
            var title = $(this).html();
            var text = $(this).next('small').html();
            $(".add-service label.active").removeClass('active');
            $(this).addClass('active');
            if($('.service-info').is(':hidden')) {
              $('.service-info strong').html(title);
              $('.service-info p.description').html(text);
              $('.service-info').slideDown("fast");
            } else {
              $('.service-info').slideUp('fast', function() {
                $('.service-info strong').html(title);
                $('.service-info p.description').html(text);
                $('.service-info').slideDown('fast');
              });
            }
          }
      });
     $(".service-info .link a").click( function(e) {
		
			e.preventDefault();
			$('.add-service label.active').removeClass('active');
			$('.service-info').slideUp("fast");
		
      });
    }
	service_info();
    
	/* order */
    function order_function(type) {
      order_service_checkboxes();
      order_links(type);
          //order_links();
      service_info();
          
      $(".modal-box select").msDropDown();
      $('#p-birthday').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
      $('#excursion-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#tour-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#tour-date-search').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#transport-date').datepicker({showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#visa-date-from').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
      $('#visa-date-to').datepicker({beforeShow: customRangeMVisa,showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true, minDate:new Date()});
          
      function customRangeMVisa(input) {
                var input_id = input.id;
                
                if ($("#visa-date-from").datepicker("getDate")) date=$("#visa-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "visa-date-from"){return {maxDate: $("#visa-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "visa-date-to"){return {minDate: date, maxDate: null};}
      }
       
      $('#hostel-date-from').datepicker({beforeShow: customRangeMHostel, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
      $('#hostel-date-to').datepicker({beforeShow: customRangeMHostel, showOn: 'both', buttonImage: 'img/common/calendar.png', buttonImageOnly: true});
      
          function customRangeMHostel(input) {
                var input_id = input.id;
                
                if ($("#hostel-date-from").datepicker("getDate"))       date=$("#hostel-date-from").datepicker("getDate");
                else    date=new Date();
                
        if (input_id == "hostel-date-from"){return {maxDate: $("#hostel-date-to").datepicker("getDate"), minDate:new Date()};}
        if (input_id == "hostel-date-to"){return {minDate: date, maxDate: null};}
      }
       
      $(".modal-box .count-number a").click(function () {
        needed_number = $('.modal-box:visible .count-number select').val();
        current_children = $(".modal-box:visible .counts .count-item:visible");
        all_children = $(".modal-box:visible .counts .count-item");
        current_number = current_children.size();
        if (needed_number > 0) {
          if (needed_number < current_number) {
            $(current_children).each(function( intIndex){
              if (intIndex >= needed_number) {$(this).hide();}
            });
          }
          if (needed_number > current_number) {
            $(all_children).each(function(intIndex){
              if (intIndex < needed_number) {$(this).show();}});
          }
        }
        else {$(current_children).hide();}
      });
         
      // finish order ajax
          //$('.modal')
          
      $('.modal-finish-order .button a').click(function (e) {
        e.preventDefault();
        //hui
		$('.modal-finish-order .wrapper').attr("style","display:none");
		$('.modal-finish-order .preload').html("<div class=\"preloader\"></div>");
		
        $('.hidden-data form').html("");
        visa = $('.modal-visa-tour form').html();
        $('.hidden-data form').append(visa);
        used = $('form.used').html();
        $('.hidden-data form').append(used);
        services = $('.services-box').html();
        $('.hidden-data form').append(services);
                                
                
         $.post("modal/modal_order_"+type+"_test.php?send=1", $(".wrapper form.form-last").serialize(),
          function(data){
            $('.css-style').html(data);
        });
           
        $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);
      });
    }
     
    function hostel_order_js() {
    
	/*$('.modal-hostel').show();
	$('.modal-visa-tour .prev-js').addClass('go-hostel');
	$('.modal-finish-order .prev-js').removeClass('go-hostel');
	$('.modal-finish-order .prev-js').addClass('go-visa');
	$('.modal-breadcrumbs .hostel').addClass('active');*/


	$('.hostel-order-js').click(function (e) {
      e.preventDefault();
      var href = $(this).attr('href');
          
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-visa-tour .prev-js').addClass('go-hostel');
            $('.modal-box').hide();
            $('.modal-hostel').show();
            $('.modal-breadcrumbs .hostel').show().addClass('active');
            $('.modal-hostel form').addClass('used');
            $('input.service-hostel').attr('checked', true);
            $('#hidden-service-hostel').val('1');
                        
            order_function("hostel");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    hostel_order_js();

    function excursion_order_js() {
    $('.excursion-order-js').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          //alert(href);
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-box').hide();
            $('.modal-excursion').show();
            $('.modal-breadcrumbs .excursion').show().addClass('active');
            $('.modal-excursion form').addClass('used');
            $('.modal-visa-tour .prev-js').addClass('go-excursion');
            $('.modal-breadcrumbs .excursion b').html(1);
            $('#hidden-service-excursion').val('1');
            $('input.service-excursion').attr('checked', true);
                        
            order_function("excursion");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    excursion_order_js();

    function tour_order_js() {
    $('.tour-order-js').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-box').hide();
            $('.modal-tour').show();
            $('.modal-breadcrumbs .tour').show().addClass('active');
            $('.modal-visa-tour .prev-js').addClass('go-tour');
            $('.modal-tour form').addClass('used');
            $('.modal-breadcrumbs .tour b').html(1);
            $('input.service-tour').attr('checked', true);
            $('#hidden-service-tour').val('1');
                        
            order_function("tour");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    tour_order_js();

    function transport_order_js() {
    $('.transport-order-js').click(function (e) {
      e.preventDefault();
          
      var href = $(this).attr('href');
          
      $.get(href, function(data){
        $.modal(data, {
          autoPosition: false,
          opacity: 90,
          onClose: modalOnClose,
          onOpen: modalOnOpen,
          onShow: function(dialog){
            $('.modal-visa-tour .prev-js').addClass('go-transport');
            $('.modal-box').hide();
            $('.modal-transport').show();
            $('.modal-breadcrumbs .transport').show().addClass('active');
            $('.modal-transport form').addClass('used');
            $('.modal-breadcrumbs .transport b').html(1);
            $('input.service-transport').attr('checked', true);
            $('#hidden-service-transport').val('1');
                        
            order_function("transport");
          }
        });
      });
      $('html, body').animate({scrollTop: $(".simplemodal-container").offset().top}, 200);});
    }
    transport_order_js();

	if ($("div").hasClass("hostel-order")) {
		//alert("test");
		hostel_order_js() ;
	} else if ($("div").hasClass("tour-order")) {
		tour_order_js();
	} else if ($("div").hasClass("modal-transport")) {
		transport_order_js();
	} else if ($("div").hasClass("modal-excursion")) {
		excursion_order_js();
	} else if ($("div").hasClass("modal-visa-business")) {
		visa_b_function();
	} else if ($("div").hasClass("modal-visa-tour")) {
		visa_t_function();
	}


    function modalOnOpen(dialog) {
        //Animate the open of the popup
        dialog.overlay.fadeIn('fast', function() {
            dialog.container.fadeIn('fast', function() {
                dialog.data.hide().slideDown('fast');
            });
        });
    }
    function modalOnClose(dialog) {
        //Animates the closing of the dialogs
       dialog.data.fadeOut('fast', function() {
           dialog.container.slideUp('fast', function() {
               dialog.overlay.fadeOut('fast', function() {
                   $.modal.close();
               });
           });
       });
    }

    if ($.browser.msie && $.browser.version.substr(0,1)<8) {
      $(".content-page .news-single ul li").prepend("<span class=\"marker\"> </span>");
    }


    //$("a[rel^='prettyPhoto']").prettyPhoto();
	//$("a[rel^='prettyPhoto[2]']").prettyPhoto();

});
/* jQuery.fx.off = true; */

