var GCar = function (idBlock) {
	var cBlock = $("#" + idBlock);
	var self = this;
	this.carBlock = cBlock.find("div.carousel");
	this.botBlock = cBlock.find("div.bottom_blue");
	this.arrLeft = this.carBlock.find(".arrow_left");
	this.arrRight = this.carBlock.find(".arrow_right");
	this.carList = this.carBlock.find("ul");
	self.carList.css("position","relative");
	this.revers = (self.carBlock.attr('rel') == 'revers') ? true : false;
	this.speedScroll = 500;
	this.carListItems = this.carList.find("li");
	this.widthItem = 0;
	
	this.visiblity_items = 1;
	this.state = 0;
	
	if (self.revers){
		self.state = self.carListItems.length - self.visiblity_items;
	}
	
	this.showArr = function() {
				if(self.arrLeft.hasClass("noactive")) self.arrLeft.removeClass("noactive");
				if(self.arrRight.hasClass("noactive")) self.arrRight.removeClass("noactive");
		switch (self.state) {
			case 0: {self.arrLeft.addClass("noactive");
			break;}
			case self.carListItems.length - self.visiblity_items: {self.arrRight.addClass("noactive");
			break;}
			
		}
	};
	
	this.arrLeft.click(function() {
		if (self.widthItem == 0){
			self.widthItem = parseInt(self.carListItems.eq(0).css("width")) + parseInt(self.carListItems.eq(0).css("margin-left")) + parseInt(self.carListItems.eq(0).css("margin-right")) + parseInt(self.carListItems.eq(0).css("padding-left")) + parseInt(self.carListItems.eq(0).css("padding-right"));
			self.visiblity_items = Math.ceil(parseInt(self.carBlock.css("width"))/self.widthItem);
		}
		if (self.state != 0){
			self.state --;
			self.carList.animate({ 
		    	left: self.state*-self.widthItem + "px"
			    },self.speedScroll,function(){
		    	if (self.carListItems.eq(self.state).attr("rel") != ''){
					var itemText = eval('('+self.carListItems.eq(self.state).attr("rel")+')');
					for (var pole in itemText){
						switch(pole) {
							case 'online':
								self.botBlock.find("a.online_translation").attr('href', itemText[pole]);
								break;
							case 'tickets':
								var tick_link = self.botBlock.find("a.tickets_botlink");
								if (tick_link.lenght != 0)
								tick_link.next('em').remove();
								tick_link.remove();
								if(itemText[pole] != 0){
									self.botBlock.find('span.body').prepend('<a href="/ru/tickets/index.html#buy" class="tickets_botlink">' + lng.tickets + '</a><em class="link_separator"> / </em>');
								}
								break;
							default:
								cBlock.find("." + pole).text(itemText[pole])
						}
					}
		    	}
		    	});
		
			self.showArr();
			
		}return false;
	});
	this.arrRight.click(function() {
		if (self.widthItem == 0){
			self.widthItem = parseInt(self.carListItems.eq(0).css("width")) + parseInt(self.carListItems.eq(0).css("margin-left")) + parseInt(self.carListItems.eq(0).css("margin-right")) + parseInt(self.carListItems.eq(0).css("padding-left")) + parseInt(self.carListItems.eq(0).css("padding-right"));
			self.visiblity_items = Math.ceil(parseInt(self.carBlock.css("width"))/self.widthItem);
		}
		if (self.state < self.carListItems.length - self.visiblity_items){
			self.state ++;
			self.carList.animate({ 
		    	left: self.state*-self.widthItem + "px"
		    },self.speedScroll,function(){
		    	if (self.carListItems.eq(self.state).attr("rel") != ''){
					var itemText = eval('('+self.carListItems.eq(self.state).attr("rel")+')');
					for (var pole in itemText){
						switch(pole) {
							case 'online':
								self.botBlock.find("a.online_translation").attr('href', itemText[pole]);
								break;
							case 'tickets':
								var tick_link = self.botBlock.find("a.tickets_botlink");
								if (tick_link.lenght != 0)
								tick_link.next('em').remove();
								tick_link.remove();
								if(itemText[pole] != 0){
									self.botBlock.find('span.body').prepend('<a href="/ru/tickets/index.html#buy" class="tickets_botlink">' + lng.tickets + '</a><em class="link_separator"> / </em>');
								}
								break;
							default:
								cBlock.find("." + pole).text(itemText[pole])
						}
					}
		    	}
		    });
		
			self.showArr();
			
		}return false;
	});
	
	/*self.arrLeft.addClass('noactive');
	if (self.carListItems.length <= self.visiblity_items){
		self.arrRight.addClass('noactive');
	}*/
	
	self.showArr();
	
	this.init = function() {
	}
}
