;function shipClass(options){
	var self = this;

	this.port = options.port; // Сохраняем ссылку порта

	this.cargoShipped = true; // Судно груженое?

	this.unprocessedCargos = 12;

	this.finish = screen.width+300;

	this.speed = 80;
	
	this.stack = [];

	this.offsetLeft = 30;

	this.init(options.callback);
}

shipClass.prototype = {
	start: 0,
	cargosCreated: 0, // Количество созданных грузов
	cargosPocessed: 0, // Количество обработанных грузов
	init: function(callback){ // Инициализация крана
//		log('shipClass.prototype.init();',1);

		if($('#ship').length < 1) this.createShip(); // Если корабль не создан - создаем его

		this.start = 0 - this.port.globalOffset - this.$ship.width();

		if(typeof callback == 'function') callback();

		return this.$ship;
	},
	show: function(equipData,callback){ // Подводим корабль к причалу
		var _this = this;
		
		if(typeof equipData == 'function'){
			callback = equipData;
			equipData = [];
		}

		this.unprocessedCargos = 12; // Обуляем счетчик необработанных грузов

		this.offsetLeft = Math.randomFromTo(30,160);
		this.offsetLeft = 162;
		
		this.equip(equipData); // Загружаем корабль

		this.$ship.show().css({left: this.offsetLeft, top:-200, opacity:0}).rotate(90) // Устанавливаем корабль на позиццию для выхода
		
		this.$ship.animate({top:96, opacity:1}, this.port.getSpeed( this.offsetLeft - this.start , this.speed) ,'easeOutSine', callback); // Анимируем выход корабля
		this.$ship.rotate({animateTo:0, duration: 4500 });
			
		// ;
	},
	hide: function(callback){ // Отводим корабль от причала
		var _this = this;
		var speed = this.port.getSpeed(this.finish - this.offsetLeft , this.speed);
//		this.port.hideAllTrucks(); // Скрываем все грузовики
		this.$ship.animate({top: -200, opacity:0}, speed, 'easeInSine', callback);
		
		
		setTimeout(function(){
			_this.$ship.rotate({animateTo:-90, duration: speed });
		},4000);
		
	},
	createShip: function(){ // Создаем DOM и jQuery объекы нового грузовика
//		log('shipClass.prototype.createShip();',1);
		this.$ship = $("<div/>", {'class': 'ship', 'id': 'ship'}).hide();
		this.$cargoArea = {
				0: $("<div/>", {'id': 'shipCargoArea', 'class':'shipCargoArea size4'}).appendTo(this.$ship)
			};

		// Подготавливаем места для грузов
		for(var i=1; i <= 9; i++){
			this.$cargoArea[0].append(this.$cargoArea[i] = this.createCargoPlace(4,i));
		}

		this.$ship
			.data('class',this)
			.appendTo('#port-sea');

		return this.$ship; // Возвращаем ссылку на грузовик
	},
	createCargoPlace: function(size, index){
//		log('shipClass.prototype.createCargoPlace('+size+')');
		return $("<div/>", {'class': 'ship-cargo-place cargo-holder', 'id':'ship-cargo-place-'+index});
	},
	equip: function(equipData){
//		log('shipClass.prototype.equipCargo();',1);
		var _this = this;
		
		if(equipData.length < 1) return;

		for(var i in equipData) {
		    if (!equipData.hasOwnProperty(i)) continue;
		    var c = equipData[i];
		    if (typeof c[0] != 'number') continue;

		    var c_type = (typeof c[0] == 'number') ? c[0] : false ;
		    var c_position = (typeof c[1] == 'number') ? c[1] : false ;
		    var c_target_id = (typeof c[2] == 'number') ? c[2] : false ;

			var target = false;

			if(c_target_id && c_target_id !== 0 && typeof this.port.targets[c_target_id] != 'undefined'){
				target = this.port.targets[c_target_id];
			}

			var $cargo = _this.port.createCargo(c_type,target);
			if(c_type == 4) $cargo.addClass('position'+this.$cargoArea[c_position].find('.cargo').length);
			if(typeof target == 'string') this.port.crane.stack.push($cargo); // Набираем стек
			if(typeof this.$cargoArea[c_position] == 'object' && this.$cargoArea[c_position] instanceof jQuery) this.$cargoArea[c_position].append($cargo);
//			$cargoHolder.append($cargo); // Добавляем новый груз в держатель на корабле
		}

		return;
	},
	dropCargo: function($cargo){
		log('shipClass.prototype.dropCargo();',1);
	}
};
