function extend(Child, Parent) {
    var F = function() { };
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child.superclass = Parent.prototype;
}
function Slider() {
	this.items=[];
	this.items_count=0;
	this.cur_index=0;
	this.display_count=3;
};
Slider.prototype.AddItem = function(id,url,name,price,img) {
	this.items[this.items_count++] = {id:id,url:url,name:name,price:price,img:img}; 
};
Slider.prototype.MoveLeft = function() {
	//console.log('MoveLeft');
	if (this.cur_index ==0) {
		this.cur_index=this.items_count-1;
	} else {
		this.cur_index--;
	}
	this.Paint();
};
Slider.prototype.MoveRight = function() {
	//console.log('MoveRight');
	this.cur_index++;
	if (this.cur_index >= this.items_count) {
		this.cur_index=0;
	}
	this.Paint();
};
Slider.prototype.Paint = function() {
	//console.log('Slider.prototype.Paint');
};
function NISlider () {
	NISlider.superclass.constructor.call(this);
}
extend(NISlider, Slider)
NISlider.prototype.Paint = function() {
	//console.log('NISlider.prototype.Paint');
	var index = this.cur_index;
	var total = this.items_count;
	var items = this.items;
	$('.new_prod_con .new_product').each(function(){
		//console.log(index);
		//console.log(this);
		if (items[index].img) {
			$(this).find('img').attr('src','/img/catalog/item_'+items[index].id+'_m.'+items[index].img).removeAttr('width').attr('title',items[index].name).attr('alt',items[index].name);
		} else {
			$(this).find('img').attr('width','100').attr('src','/images/nophoto.jpg').attr('title',items[index].name).attr('alt',items[index].name);
		}
		$(this).find('.price').html(items[index].price);
		$(this).find('.new_product_lnk a').html(items[index].name);
		$(this).find('a').attr('href','/catalog/i/'+items[index].url+'.html');
		$(this).find('button.kor_p').unbind();
		$(this).find('button.kor_p').attr('onclick','');
		var id = items[index].id;
		$(this).find('button.kor_p').click(function(){return AddItemToCart(id);});
		index++;
		if (index >=total) {
			index=0;
		}
	});
};
function PISlider () {
	PISlider.superclass.constructor.call(this);
}
extend(PISlider, Slider)
PISlider.prototype.Paint = function() {
	//console.log('PISlider.prototype.Paint');
	var index = this.cur_index;
	var total = this.items_count;
	var items = this.items;
	$('.pop_prod .pop_product').each(function(){
		//console.log(index);
		//console.log(this);
		if (items[index].img) {
			$(this).find('img').attr('src','/img/catalog/item_'+items[index].id+'_m.'+items[index].img).removeAttr('width').attr('title',items[index].name).attr('alt',items[index].name);
		} else {
			$(this).find('img').attr('width','100').attr('src','/images/nophoto.jpg').attr('title',items[index].name).attr('alt',items[index].name);
		}
		$(this).find('.price').html(items[index].price);
		$(this).find('.pop_product_lnk a').html(items[index].name);
		$(this).find('a').attr('href','/catalog/i/'+items[index].url+'.html');
		$(this).find('button.kor_p').unbind();
		$(this).find('button.kor_p').attr('onclick','');
		var id = items[index].id;
		$(this).find('button.kor_p').click(function(){return AddItemToCart(id);});
		index++;
		if (index >=total) {
			index=0;
		}
	});
};
function SimSlider () {
	SimSlider.superclass.constructor.call(this);
}
extend(SimSlider, Slider)
SimSlider.prototype.AddItem = function(id,url,name,price,img,id_img) {
	this.items[this.items_count++] = {id:id,url:url,name:name,price:price,img:img,id_img:id_img}; 
};
SimSlider.prototype.Paint = function() {
	//console.log('SimSlider.prototype.Paint');
	var index = this.cur_index;
	var total = this.items_count;
	var items = this.items;
	$('.sim_prod_con .pop_product').each(function(){
		//console.log(items);
		//console.log(index);
		//console.log(this);
		if (items[index].img) {
			$(this).find('img#img_t').attr('src','/img/catalog/item_'+items[index].id_img+'_m.'+items[index].img).removeAttr('width').attr('title',items[index].name).attr('alt',items[index].name);
		} else {
			$(this).find('img#img_t').attr('width','100').attr('src','/images/nophoto.jpg').attr('title',items[index].name).attr('alt',items[index].name);
		}
		$(this).find('.price').html(items[index].price);
		$(this).find('.pop_product_lnk a').html(items[index].name);
		$(this).find('a').attr('href','/catalog/i/'+items[index].url+'.html');
		$(this).find('img#kor').unbind();
		$(this).find('img#kor').attr('onclick','');
		var id = items[index].id;
		$(this).find('img#kor').click(function(){return AddItemToCart(id);});
		index++;
		if (index >=total) {
			index=0;
		}
	});
};

function ActionSlider () {
	NISlider.superclass.constructor.call(this);
}
extend(ActionSlider, Slider)
ActionSlider.prototype.Paint = function() {
	//console.log('PISlider.prototype.Paint');
	var index = this.cur_index;
	var total = this.items_count;
	var items = this.items;
	$('.action_prod .pop_product').each(function(){
		//console.log(index);
		//console.log(this);
		if (items[index].img) {
			$(this).find('img').attr('src','/img/catalog/item_'+items[index].id+'_m.'+items[index].img).removeAttr('width').attr('title',items[index].name).attr('alt',items[index].name);
		} else {
			$(this).find('img').attr('width','100').attr('src','/images/nophoto.jpg').attr('title',items[index].name).attr('alt',items[index].name);
		}
		$(this).find('.price').html(items[index].price);
		$(this).find('.oldprice').html(items[index].price_origin+' грн.');
		$(this).find('.pop_product_lnk a').html(items[index].name);
		$(this).find('a').attr('href','/catalog/i/'+items[index].url+'.html');
		$(this).find('button.kor_p').unbind();
		$(this).find('button.kor_p').attr('onclick','');
		var id = items[index].id;
		$(this).find('button.kor_p').click(function(){return AddItemToCart(id);});
		index++;
		if (index >=total) {
			index=0;
		}
	});
};
ActionSlider.prototype.AddItem = function(id,url,name,price,price_origin,img) {
	this.items[this.items_count++] = {id:id,url:url,name:name,price:price,price_origin:price_origin,img:img}; 
};
function AccSlider () {
	SimSlider.superclass.constructor.call(this);
}
extend(AccSlider, Slider)
AccSlider.prototype.Paint = function() {
	//console.log('SimSlider.prototype.Paint');
	var index = this.cur_index;
	var total = this.items_count;
	var items = this.items;
	$('.acc_prod_con .pop_product').each(function(){
		//console.log(index);
		//console.log(this);
		if (items[index].img) {
			$(this).find('img').attr('src','/img/catalog/item_'+items[index].id+'_m.'+items[index].img).removeAttr('width').attr('title',items[index].name).attr('alt',items[index].name);
		} else {
			$(this).find('img').attr('width','100').attr('src','/images/nophoto.jpg').attr('title',items[index].name).attr('alt',items[index].name);
		}
		$(this).find('.price').html(items[index].price);
		$(this).find('.pop_product_lnk a').html(items[index].name);
		$(this).find('a').attr('href','/catalog/i/'+items[index].url+'.html');
		$(this).find('button.kor_p').unbind();
		$(this).find('button.kor_p').attr('onclick','');
		var id = items[index].id;
		$(this).find('button.kor_p').click(function(){return AddItemToCart(id);});
		index++;
		if (index >=total) {
			index=0;
		}
	});
};

