
$(document).ready(function(){


// Заклинаю этот сайт больше не ломаться!!!!
//captcha
$("#refreshCapt").click(function () {

//$(this).src='';
$("#imageToRefresh").attr("src",'/capcha.php?rnum='+ Math.random() * (1000000000 - 100000) + 100000);
return false;

});

//end captcha

var dp=$('[name=dp]');
var today_obj=new Date();

  $("[name=day]").find('option').eq(today_obj.getDate()-1).attr('selected','selected');
  $("[name=month]").find('option').eq(today_obj.getMonth()).attr('selected','selected');


//$(dp).datepicker();
function DPonShow()
{
//$(dp).datepicker({})//console.log('');
//$(dp).datepicker('setDate',(($("[name=month]").find('option:selected').index())+" "+$("[name=day]").find('option:selected').index()+1));
var ddate=($("[name=day]").find('option:selected').index()+1)+' '+($("[name=month]").find('option:selected').index()+1);
$(dp).datepicker('setDate', $.datepicker.parseDate('dd mm',ddate));
}

function DPchangeDate()
{
var date=$(dp).datepicker('getDate');
    $("[name=day]").find('option').eq(date.getDate()-1).attr('selected','selected');
  $("[name=month]").find('option').eq(date.getMonth()).attr('selected','selected');

//$(dp).datepicker({})
//console.log('');
}

//console.log($("[name=day]").find('option:selected').index());

$(dp).datepicker({beforeShow: DPonShow,
			onSelect: DPchangeDate});

//$(dp).datepicker()

//var ddate=($("[name=day]").find('option:selected').index()+1)+' '+($("[name=month]").find('option:selected').index()+1);
//console.log($.datepicker.parseDate('dd mm',ddate));

//$(dp).css('visibility','hidden');
                 //$(dp).css('display','none');
       //          $(dp).css('width','1px');
         //        $(dp).css('height','1px');
                $(dp).css('border','none');
$(dp).css('background','none');


//var today_date=today_obj.getDate()
//console.log();
//console.log(today_obj.getMonth());

//$(elem).find('option').eq($(this).data('pos')).attr('selected','selected');
               $("#square").bind('click', function () {

            //   console.log('click');
               $(dp).datepicker('show');
                //var el= $("<input >/");
                // $(el).hide();
                //$(this).append(el);
                //$(el).focus();

               });
//$("#square").bind('click', function () {//              console.log('click');
  //             var el= $("<input >/");
    //           //$(el).hide();
      //         $(this).append(el);
        //       $(el).datepicker('show');
                         //$(this).datepicker();
                         //$().datepicker("show");
                         //$(this).focus();//});

$('#menu table#minemenu td:not(".mitemll")').bind('mouseenter',function () {
  $("#menu div.mmme").hide();
  var elem=$(this).find('.mmme');
  $(elem).show();
  elem.data("open",1);
  //alert("td mouseenter");
});

$('#menu table td').bind('mouseleave',function () {
	//alert("td mouseleave");
  var elem=$(this).find('.mmme');
  (elem).data("open",0);
  //setTimeout(function(){ if($(elem).data("open") == 0 ){ $(elem).hide(); } } , 500) ;
});


$("div.mmme table").bind('mouseleave',function () {
            $(this).parent().hide();
});


$("div.mmme a").bind('mouseenter',function () {
	//open = 0;
	//alert("aaaaa");
	  $(this).parent().data("open",1);
});

//$("div.mmme, div.mmme a, div.mmme .submenu, div.mmme").bind('mousemove',function () {

//$(this).data("open",1);
//
//});

$("div.mmme").bind('mousemove',function () { $(this).data("open",1); });
$("div.mmme table").bind('mousemove',function () { $(this).parent().data("open",1); });
$("div.mmme ul.submenu li").bind('mousemove',function () { $(this).parent().parent().data("open",1); });
$("div.mmme ul.submenu li a").bind('mousemove',function () { $(this).parent().parent().parent().data("open",1); });



//$("#menu div.mmme").bind('mouseenter',function () {
//	open = 1;
//	alert("11");
//});



$('#menu div.mmme').bind('mouseleave',function(){
  open = 0;
  $(this).data("open",0);

  //alert("mmme mouse leave")
//  setTimeout(function(){ if($(this).data("open") == 0 ){ $(this).hide(); } } , 1000) ;
});

$('#menu div.mmme').bind('mouseenter',function(){
  $(this).data("open",1);
  //alert("mmme mouseenter");
});















$("#paddigbottom").bind('click', function () {
//var gdate=$(dp).datepicker('getDate');  //console.log(gdate.getMonth()+"/"+gdate.getDate()+"/"+gdate.getYear()+"/");
  myDate = new Date;
  ///newDate = new Date;
  //myDate.set
  myDate.setMonth($("[name=month]").find('option:selected').index()+1);
myDate.setDate($("[name=day]").find('option:selected').index()+1);
  var nights=($("[name=nights]").find('option:selected').index()+1);
  if(nights==8) { nights=10;}
  if(nights==9) { nights=14;}

  var childs=($("[name=childs]").find('option:selected').index()+1);
  var adults=($("[name=adults]").find('option:selected').index()+1);
var from = myDate.getMonth()+"/"+myDate.getDate()+"/"+myDate.getFullYear();
  myDate.setDate(myDate.getDate()+nights);
var to = myDate.getMonth()+"/"+myDate.getDate()+"/"+myDate.getFullYear();

//newDate = myDate;
  //  var day=($("[name=day]").find('option:selected').index()+1);
   // var month=($("[name=month]").find('option:selected').index()+1);
   // var year=today_obj.getFullYear();

  //  console.log(myDate.getMonth()+"/"+myDate.getDate()+"/"+myDate.getFullYear());
    //nights
   // newDate
//    console.log(newDate.getMonth()+"/"+newDate.getDate()+"/"+newDate.getFullYear());

window.open("https://secure.netbookerng.com/hotel/libra/aerostarhotelmoscow/moscow/ru/hseoptx_UZ/hseoid_5589700.html?mode=frame&begindate="+from+"&enddate="+to+"&adults="+adults+"&children="+childs+"&autosearch=true");
});



$(window).resize(function() {
		// onresize();
});
	onresize();
	if($.browser.msie && ($.browser.version == 6 || $.browser.version == 7)){
		$('.shadow').css('display', 'none');
		$('#minemenu a, #minemenu .a').css('position', 'static');
		$('#minemenu .active .here .a').css('padding-top','12px').css('display','block');
	}
	//$('img').load(function(){onresize();});
});


function onresize(){
	//r = (($('body').width()-$('#content').width())/2-20)%2; никто всеравно не заметит разницы в 1 пиксель, глаза же режет.  А ие дохнет.
	//$('body').css('background', ' url("/images/bg.gif") '+r+'px 0');
	if($('#leftbuttomperl.mine').size() > 0){
		/* if($('body').width() < 1160){    // да и косяки верски исправлять кривым js тоже не дело
			$('#minetable').css('width', '1160px');
			$('#body').css('width', '1160px');
		}else{
	     $('#minetable').css('width', '100%');
			$('#body').css('width', 'auto');

    }
       */

	}else{
		//$('#body').css('width', ($('#minetable').width()+25)+"px");
	}
//		lleft = (1160 - $('body').width())/2;
//		$('#flashin').css('left', '-'+lleft+'px').css('position','relative');  это не мое


  /* а это было, но я убрал эту херь
  	if($("#submenu").html()){
		hsub = 17;
	}else{
		hsub = 0;
	}

	if($.browser.msie){
		if($.browser.version == 8){
			$('#topperl.in').css('height', (194-hsub)+"px");
			h = $('#content').height()-194-135-hsub;
			$('#leftbuttomperl').css('height', h+"px");
			$('#leftbuttomperl.mine').css('height', (h+43+17)+"px");
		}else{
			if($.browser.version == 6 || $.browser.version == 7){
				hb = $('#minecontent').height()-270;
				$('#bronbtn').css('height', hb+'px');
				h = $('#content').height()-198-135-hsub;
				$('#leftbuttomperl').css('height', h+"px");
				$('#leftbuttomperl.mine').css('height', (h+35+17)+"px");
				$('#topperl.in').css('height', "198px");
			}
		}
	}else{
		$('#topperl.in').css('height', 196-hsub+"px");
	}
*/

$(".mmme:last").css({"left":"auto","right":"2px"});

}


