var xo=0;
var $j = jQuery.noConflict();
var mon = [];
mon['Jan']=0; mon['Feb']=1; mon['Mar']=2; mon['Apr']=3; mon['May']=4; mon['Jun']=5; mon['Jul']=6; mon['Aug']=7; mon['Sep']=8; mon['Oct']=9; mon['Nov']=10; mon['Dec']=11;


$j(document).bind('ready',function(){
	$j('#flash').html(VM_EmbedFlash( 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','wmode','transparent','width', '643', 'height', '266', 'src', 'http://www.lior.lv/kbhotel/template/kb.swf', 'quality', 'high', 'name', 'MyMovieName', 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ));
	$j('#bell').html(VM_EmbedFlash ( 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','wmode','transparent','width', '116', 'height', '111', 'src', 'http://www.lior.lv/kbhotel/template/dzinj.swf', 'quality', 'high', 'name', 'MyMovieName', 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ));
	$j('a').filter(function(){return $j(this).attr('href') == '#' ? true : false}).click(function(){return false});
	$j('#top_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).width(Math.round(($j('#top_navi').width()-$j('#top_navi ul li').filter(function(){return $j(this).children('span').size() > 0 ? true : false; }).size()*2)/($j('#top_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).size())));
	$j('#bot_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).width($j('#top_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).width());
	
	if($j('#content').height()<$j(document).height()-457) $j('#content').height($j(document).height()-457);
	getcoords();
	$j(window).bind('resize', function() {
		getcoords();
		});
	if($j('#content_center').height() < $j('#content').height()-5)
		$j('#content_center').css('min-height',$j('#content').height()-5);
	
	$j('#top_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).hover(function(){
		$j('#slider').stop().animate({left: $j(this).attr('rel')+'px'},400);
		},function(){$j('#slider').stop().animate({left: $j('#top_navi ul li.current').attr('rel')+'px'},500);});

	var sd = $j("input[name='min_date']").val().split('-');
	
	$j("input[name='date_in']").datepicker({altField: "input[name='start-date']", altFormat: 'yy-mm-dd', dateFormat: 'dd/M/yy', minDate: new Date(sd[0],parseInt(sd[1])-1,sd[2]),onClose: function(data){
		var date_in = data.split('/');
		var date = new Date(date_in[2],mon[date_in[1]],parseInt(date_in[0])+1)
		$j("input[name='date_out']").datepicker('setDate',date).datepicker('option','minDate',date);
		set_nights();
		}}).datepicker('setDate',new Date());
		
	$j("input[name='date_out']").datepicker({altField: "input[name='end-date']", altFormat: 'yy-mm-dd',minDate: new Date(sd[0],parseInt(sd[1])-1,parseInt(sd[2])+1),dateFormat: 'dd/M/yy',onClose: function(){set_nights();}}).datepicker('setDate' ,+1);
	
	$j("input[name='nights']").bind('keydown',function(e){
		if(!(e.keyCode>47 && e.keyCode<58) && !(e.keyCode>96 && e.keyCode<105) && e.keyCode!=8 && e.keyCode!=9 && e.keyCode!=46) return false;
		}).bind('paste',function(){return false}).bind('keyup',function(){
			if(parseInt($j(this).val()) > 0){
				var date_in = $j("input[name='date_in']").val().split('/');
				date_in = new Date(date_in[2],mon[date_in[1]],parseInt(date_in[0])+parseInt($j("input[name='nights']").val()));
				$j("input[name='date_out']").datepicker('setDate',date_in);
				}			
			});
	$j('img.calendar').click(function(){
		$j("input[name='"+$j(this).attr('rel')+"']").datepicker('show');
		});

	$j('.image_container div').bind('mouseover',function(){
		var tmp = $j(this);
		$j('#main_image').css('background-image',"url('./cms_andyou/galerijasm/"+tmp.attr('rel')+"')");
		$j('#main_image > div').animate({opacity:'0'},3000,function(){
			$j('#main_image > div').css({'background-image':"url('./cms_andyou/galerijasm/"+tmp.attr('rel')+"')"}).animate({opacity:'1'});
			});
		});
	});
function getcoords(){
	xo = $j('#top_navi').offset().left;
	$j('#top_navi ul li').filter(function(){return $j(this).children('a').size() > 0 ? true : false; }).each(function(){
		var obj = $j(this);
		$j(obj).attr('rel',Math.round($j(obj).offset().left+$j(obj).width()/2-xo-$j('#slider').width()/2));
		});
	$j('#slider').css('left',$j('#top_navi ul li.current').attr('rel')+'px');
	}
function set_nights(){
	var date_in = $j("input[name='date_in']").val().split('/');
	var date_out = $j("input[name='date_out']").val().split('/');
	
	date_in = new Date(date_in[2],mon[date_in[1]],date_in[0]).getTime();
	date_out = new Date(date_out[2],mon[date_out[1]],date_out[0]).getTime();
	
	var nights = ((date_out-date_in)/24/60/60/1000!='NaN') ? (date_out-date_in)/24/60/60/1000 : 0;
	
	$j("input[name='nights']").val(nights);
	}
