var nowOnload = window.onload;
boxno = 1
slideto = 0
var gen
var yuk
var boxcount
window.onload = function () {
	pushslide();
	if(nowOnload != null && typeof(nowOnload) == 'function') {
		nowOnload();
		}
}

pushslide = function() {
	//elementlerimizi alalim
	var masker = document.getElementById("pushslidemask");//kutucuklarin gozukecegi pencere
	var film = document.getElementById("pushslide");//kutucuklari tasiyan $erit
	var boxes = document.getElementById("pushslide").getElementsByTagName("DIV")//herbir ozel kutucuk
	
	//kutu navigasyonunun elementleri
	// bu 3 span dan 1.si geri butonu. 2.si hangi sayfa oldugunu gosterir 3.su ileri butonu
	var slidenav = document.getElementById("pushnav").getElementsByTagName("SPAN")
	
	//kare sayisini bulalim

	for (var i=1; i<boxes.length; i++) {boxcount=i+1}

	//boyutlari ogrenelim
	yuk = masker.offsetHeight;//kayacak elementin yuksekligini alalim
	gen = masker.offsetWidth;//kayacak elementin geni$ligini alalim
	
	
	//filmin geni$ligini kutu sayisina gore arttiralim
	film.style.width = (boxcount)*gen+"px"
	film.style.marginLeft = 0+"px";
	slidenav[1].innerHTML = boxno
	//ileri butonu
	slidenav[2].onmousedown=function() {clearInterval(clockcounter)
					if(boxno==boxcount) {
				
				
				slideee(film, true, true);
				boxno=1
				}else {
			
			slideee(film, true, false);}
			slidenav[1].innerHTML = boxno;
			}	


	//geri butonu
	slidenav[0].onmousedown=function() {clearInterval(clockcounter)
			if(boxno==1) {
				return;
				}
			
			slideee(film, false, false);
			slidenav[1].innerHTML = boxno
			}

		
		
		

	
	film.slider = 0
	clockcounter = window.setInterval(function(){ 
											   if(boxno==boxcount) {
				
				
				slideee(film, true, true);
				boxno=1
				}else {
			
			slideee(film, true, false);}
			slidenav[1].innerHTML = boxno;
											
										
									}
									,5000)
	
	
	
}

function slideee(wind, where, firstbox){
		clearInterval(wind.playit)
		if (where) {
						if (firstbox){slideto=0;}
			else {
			slideto = slideto-gen

		boxno++
			}
		wind.playit = window.setInterval(
										function(){
											wind.slider += (slideto-(wind.slider))/5
												if (!firstbox && slideto+1 >= wind.slider ){
												wind.slider = slideto
												clearInterval(wind.playit)
												
											
											}
											if (firstbox && slideto-1 <= wind.slider ){
												wind.slider = slideto
												clearInterval(wind.playit)
											
											}
											wind.style.marginLeft = wind.slider+"px";
									}
									,33)
		
		}
		
		
		
		
		
		
		if (!where) {

			slideto = slideto+gen
			boxno--
		
		wind.playit = window.setInterval(
										function(){
											wind.slider += (slideto-(wind.slider))/5		
											
											if (slideto-1 <= wind.slider ){
													wind.slider = slideto
													clearInterval(wind.playit)
												
											}
											wind.style.marginLeft = wind.slider+"px";
									}
									,33)
		
		}
		
			
}

	
	
