//==================================[Specials helper class]========================================================
//-------------------[if we have multiple specials (new,used) we will use this class]--------------------
function Specials() {
	var SPECIALS_CONTAINER;//<-id of container holding specials
	var SPECIALS_TEMPLATE;//template holder for specials
	var data=new Array();
	var qty=0;
	var cars_perpage=0;
	var next=0;
	var btn_left;//id of prev button
	var btn_right;//id of next button
	
	this.add=function(car_name,img_link,price,link){
		var img=new Image();
		img.src=img_link;
		data[qty++]=new Array(car_name,img,price,link);
	}
	this.setCarsPerPage=function(cpp){
		cars_perpage=cpp;
	}
	this.doNext=function(){
		next+=cars_perpage;
	}
	this.doPrev=function(){
		next-=cars_perpage;
		if(next<0) next=0;
	}
	this.getSpecials=function(){
		//we are defining these vars directly name.var=val so we need to reassign them so they will be available inside dataParser
		if(SPECIALS_CONTAINER==null) SPECIALS_CONTAINER=this.SPECIALS_CONTAINER
		if(SPECIALS_TEMPLATE==null) SPECIALS_TEMPLATE=this.SPECIALS_TEMPLATE;
		var specials_box='';
		for(var i=next;i<(cars_perpage+next);i++){
			if(i<qty){
				//Array(car_name,img_link,price,link);
				var car_name=data[i][0];
				var car_price=data[i][2];
				var car_url=data[i][3];
				var car_image=data[i][1].src;
				var special_item=eval(SPECIALS_TEMPLATE);
				specials_box+=special_item;
			}
		}
		document.getElementById(SPECIALS_CONTAINER).innerHTML=specials_box;
		
		if(qty<=(next+cars_perpage))
			document.getElementById(btn_right).style.display="none";
		else document.getElementById(btn_right).style.display="inline";
	}
	this.unhideButton=function(){
		if(next>0){
			document.getElementById(btn_left).style.display="inline";
		}else{
			if(next==0) document.getElementById(btn_left).style.display="none";
			document.getElementById(btn_right).style.display="inline";
		}
	}
	this.defineButtons=function(btn_left_id,btn_right_id){
		btn_left=btn_left_id;
		btn_right=btn_right_id;
	}
}
//=================================================================================================
function getNextSpecials(specobj){
	specobj.doNext();
	specobj.getSpecials();
	specobj.unhideButton();
}
function getPreviousSpecials(specobj){
	specobj.doPrev();
	specobj.unhideButton();
	specobj.getSpecials();
}
