// EZPZ Tooltip v1.0; Copyright (c) 2009 Mike Enriquez, http://theezpzway.com; Released under the MIT License
(function($){
	$.fn.ezpz_tooltip = function(options){
		var settings = $.extend({}, $.fn.ezpz_tooltip.defaults, options);
		
		return this.each(function(){
			var	content = $("div#tr-content");
			var targetMousedOver = $(this).mouseover(function(){
				settings.beforeShow(content, $(this));
			}).mousemove(function(e){
				contentInfo = getElementDimensionsAndPosition(content);
				targetInfo = getElementDimensionsAndPosition($(this));
				contentInfo = $.fn.ezpz_tooltip.positions[settings.contentPosition](contentInfo, e.pageX, e.pageY, settings.offset, targetInfo);
				contentInfo = keepInWindow(contentInfo);
				
				content.css('top', contentInfo['top']);
				content.css('left', contentInfo['left']);
				
				settings.showContent(content);
			});
			
			if (settings.stayOnContent && this.id != "") {
				$("#" + this.id + ", #" + getContentId(this.id)).mouseover(function(){
					content.css('display', 'block');
				}).mouseout(function(){
					content.css('display', 'none');
					settings.afterHide();
				});
			}
			else {
				targetMousedOver.mouseout(function(){
					settings.hideContent(content);
					settings.afterHide();
				})
			}
			
		});
		
		function getContentId(targetId){
			if (settings.contentId == "") {
				var name = targetId.split('-')[0];
				var id = targetId.split('-')[2];
				return 'content';
			}
			else {
				return settings.contentId;
			}
		};
		
		function getElementDimensionsAndPosition(element){
			var height = element.outerHeight(true);
			var width = element.outerWidth(true);
			var top = $(element).offset().top;
			var left = $(element).offset().left;
			var info = new Array();
			
			// Set dimensions
			info['height'] = height;
			info['width'] = width;
			
			// Set position
			info['top'] = top;
			info['left'] = left;
			
			return info;
		};
		
		function keepInWindow(contentInfo){
			var windowWidth = $(window).width();
			var windowTop = $(window).scrollTop();
			var output = new Array();
			
			output = contentInfo;
			
			if (contentInfo['top'] < windowTop) { // Top edge is too high
				output['top'] = windowTop;
			}
			if ((contentInfo['left'] + contentInfo['width']) > windowWidth) { // Right edge is past the window
				output['left'] = windowWidth - contentInfo['width'];
			}
			if (contentInfo['left'] < 0) { // Left edge is too far left
				output['left'] = 0;
			}
			
			return output;
		};
	};
	
	$.fn.ezpz_tooltip.positionContent = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY - offset - contentInfo['height'];
		contentInfo['left'] = mouseX + offset;
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions = {
		aboveRightFollow: function(contentInfo, mouseX, mouseY, offset, targetInfo) {
			contentInfo['top'] = mouseY - offset - contentInfo['height'];
			contentInfo['left'] = mouseX + offset;

			return contentInfo;
		}
	};
	
	$.fn.ezpz_tooltip.defaults = {
		contentPosition: 'aboveFollow',
		stayOnContent: false,
		offset: 10,
		contentId: "",
		beforeShow: function(content){},
		showContent: function(content){
			content.show();
		},
		hideContent: function(content){
			content.hide();
		},
		afterHide: function(){}
	};
	
})(jQuery);

// Plugin for different content positions. Keep what you need, remove what you don't need to reduce file size.

(function($){
	$.fn.ezpz_tooltip.positions.aboveFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY - offset - contentInfo['height'];
		contentInfo['left'] = mouseX - (contentInfo['width'] / 2) + 150;
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.rightFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY - (contentInfo['height'] / 2);
		contentInfo['left'] = mouseX + offset;

		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.belowRightFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY + offset;
		contentInfo['left'] = mouseX + offset;
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.belowFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = mouseY + offset;
		contentInfo['left'] = mouseX - (contentInfo['width'] / 2);
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.aboveStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = targetInfo['top'] - offset - contentInfo['height'];
		contentInfo['left'] = (targetInfo['left'] + (targetInfo['width'] / 2)) - (contentInfo['width'] / 2);
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.rightStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = (targetInfo['top'] + (targetInfo['height'] / 2)) - (contentInfo['height'] / 2);
		contentInfo['left'] = targetInfo['left'] + targetInfo['width'] + offset;
		
		return contentInfo;
	};
	
	$.fn.ezpz_tooltip.positions.belowStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
		contentInfo['top'] = targetInfo['top'] + targetInfo['height'] + offset;
		contentInfo['left'] = (targetInfo['left'] + (targetInfo['width'] / 2)) - (contentInfo['width'] / 2);
		
		return contentInfo;
	};
	
})(jQuery);

function sh_ttip(html_data, id_var){
	
	
	$("#tr-content").html('');
	
for (x in html_data)
  {
  $("#tr-content").append('<span style="font-family: arial; font-weight: bold; color: #ff5400; font-size: 15pt">'+html_data[x][0]+'</span><br><img src=/static/i/calendar_pop_up/lines.png style="padding-bottom:5px"><br>');
 
	for (y in html_data[x]){
		if (y!=0){
			if(html_data[x][y][3]=='None'){
				$("#tr-content").append('<span style="padding-left:35px;font-weight: bold; font-size:11pt; color: #565656">'+html_data[x][y][1]+'</span>&nbsp;<span style="color: #434343">'+html_data[x][y][2]+'</span><br>');
			}else if(html_data[x][y][3]=='1'){
				$("#tr-content").append('<span style="padding-left:35px;font-weight: bold; font-size:11pt; color: #565656">'+html_data[x][y][1]+'</span>&nbsp;<span style="color: #434343">'+html_data[x][y][2]+' <b>(мало мест)</b></span><br>');
			}else if(html_data[x][y][3]=='2'){
				$("#tr-content").append('<span style="padding-left:35px; font-size:11pt; color: #565656">'+html_data[x][y][1]+'</span>&nbsp;<span style="color: #434343">'+html_data[x][y][2]+' <b>(мест нет, только в резерв)</b></span><br>');
			}
		}
	}
  }
		
	
	$("div#"+id_var).ezpz_tooltip();

}



var waitTimeout = 1000;
var toID;
$(document).ready(function(){

    $("div#loading").bind("ajaxSend", function(){  
        $(this).show();
    }).bind("ajaxComplete", function(){
        $(this).hide();
    });

$.get('/calendar/', function(data){document.getElementById('calendar').innerHTML=data});

$("img.mypanorama").panorama({ speed: 200000});

})
var date = new Date();
var month = date.getMonth()+1;
var year = date.getFullYear();

function date_changer(action){
    if(action=="plus"){
    month=month+1
    if(month==13){
            month=1;
            year=year+1;
            }
    }else if(action=="minus"){
    month=month-1
        if(month==0){
            month=12;
            year=year-1;
            }
    }
       $.get('/calendar/date_changer/'+month+'/'+year+'/', function(data){document.getElementById('calendar').innerHTML=data});

}



