var user_agent = navigator.userAgent;
var isOpera = user_agent.indexOf("Opera") >= 0;
var isFirefox = user_agent.indexOf("Firefox") >= 0;
var isWin32up = user_agent.indexOf("Win32") >= 0 
	|| user_agent.indexOf("Win64") >= 0
	|| user_agent.indexOf("Windows NT") >= 0;

// disallow Opera faking IE
var isIE = !isOpera && user_agent.indexOf("MSIE") >= 0;
var isIE55up = isIE && isWin32up && user_agent.match(/MSIE ((5\.5)|[6789])/);
var isIE70up = isIE && isWin32up && user_agent.match(/MSIE ([789])/);
var isIE55dn = isIE && !isIE55up;
var browser = "other";

if (isFirefox)
	browser = "firefox";
else if (isOpera) 
	browser = "opera";
else if (isIE55up) 
	browser = "ie55p";
else if (isIE55dn) 
	browser = "ie55d";


// toplam dosya sayisi
var anaDosyaSayisi;
// en soldaki gorunen dosya
var anaDosyaFirst = 0;
// bir seferde gorunen dosya sayisi
var anaDosyaVisible = 11;
// dosyalarin yerlesim araligi
var anaDosyaPlacement = 80;
// dosyalarin araligi
var anaDosyaSeperator = 0;
// dosya resimleri ve resim yuklendi bilgisi
var anaDosyaImgs = new Array();
var anaDosyaImgObjects = new Array();
var anaDosyaImgLoaded = new Array();

// slide efekti timer
var anaDosyaTimer = null;
// silde efekti pozisyonu
var anaDosyaPosition = 0;
// silde efekti hedef pozisyonu
var anaDosyaTarget = 0;
// slide efekti icin timer ve her timer da gidilecek pixel
var anaDosyaStepMultiplier = 1.3;
var anaDosyaStepTime = 40;

// slide efekti timer
var slideContinuouslyTimer = null;
var lastOffset = -1;
var SlideContinuouslyStepTime = 3000;

function DosyaWidget(baslik, spot, header, link, bgcolor, fontcolor) {
	this.baslik = baslik;
	this.spot = spot;
	this.header = header;
	this.link = link;
	this.bgcolor = bgcolor;
	this.fontcolor = fontcolor;
}

function CreateDosya(list, index, isVisible) {
	var dosya = list[index];
	var left = anaDosyaPlacement * (index - anaDosyaFirst);
	
	var div = document.createElement("DIV");
	div.style.position = "absolute";
	div.style.left = left + "px";
	div.style.top = "0px";
	div.style.width = "107px";
	div.style.height = "119px";
	div.style.backgroundColor = dosya.bgcolor;
	
	var divImg = document.createElement("DIV");
	div.appendChild(divImg);

	// ust resim linki
	var lnkHeader = document.createElement("A");
	lnkHeader.href = dosya.link;
	lnkHeader.target = "altt";
	lnkHeader.onfocus = function() {
		this.blur();
	}
	
	// ust resim
	var imgHeader = document.createElement("IMG");
	anaDosyaImgs[index] = imgHeader;
	anaDosyaImgLoaded[index] = isVisible;
	if (isVisible)
		imgHeader.src = dosya.header;
	else
		imgHeader.src = I_URL + "sp.gif";
	imgHeader.width = 160;
	imgHeader.height = 108;
	imgHeader.border = 0;
	imgHeader.alt = dosya.baslik;
	imgHeader.title = dosya.baslik;
	lnkHeader.appendChild(imgHeader);
	divImg.appendChild(lnkHeader);

	// resim alti yazi blogu	
	var divYazi = document.createElement("DIV");
	divYazi.style.padding = "6px";
	div.appendChild(divYazi);
	
	var lnkBaslik = document.createElement("A");
	lnkBaslik.className = "ver11";
	lnkBaslik.href = dosya.link;
	lnkBaslik.target = "altt";
	lnkBaslik.style.color = dosya.fontcolor;
	lnkBaslik.style.fontWeight = "bold";
	lnkBaslik.appendChild(document.createTextNode(dosya.baslik));
	divYazi.appendChild(lnkBaslik);
	divYazi.appendChild(document.createElement("BR"));

	var lnkSpot = document.createElement("A");
	lnkSpot.className = "ver11";
	lnkSpot.href = dosya.link;
	lnkSpot.target = "altt";
	lnkSpot.style.color = dosya.fontcolor;
	// lnkSpot.innerHTML = dosya.spot;
	lnkSpot.appendChild(document.createTextNode(dosya.spot));
	divYazi.appendChild(lnkSpot);
	
	return div;
}

function CreateDosyalar() {
	var containerDiv = document.getElementById("divAnaDosyalar");
	anaDosyaSayisi = anaDosyalar.length;
	containerDiv.style.width = (anaDosyaPlacement * anaDosyaSayisi - anaDosyaSeperator) + "px";
	
	// clear
	while (containerDiv.firstChild != null) {
		containerDiv.removeChild(containerDiv.firstChild);
	}
	// create the new items
	for (var i = 0; i < anaDosyaSayisi; i++) {
		// load images of all visible ones and the first invisible one
		containerDiv.appendChild(CreateDosya(anaDosyalar, i, i <= anaDosyaVisible));
	}
	// if (isIE55up) containerDiv.style.filter = "progid:DXImageTransform.Microsoft.MotionBlur(direction=90,strength=10,enabled=false)";
}

function CreateDosyalarStatic() {
	var containerDiv = document.getElementById("divAnaDosyalar");
	anaDosyaSayisi = anaDosyalar.length;
	containerDiv.style.width = (anaDosyaPlacement * anaDosyaSayisi - anaDosyaSeperator) + "px";

	// create the new items
	for (var i = 0; i < anaDosyaSayisi; i++) {
		// load images of all visible ones and the first invisible one
		anaDosyaImgs[i] = document.getElementById("imgAnaDosya" + i);
		anaDosyaImgLoaded[i] = (i <= anaDosyaVisible);
	}
}

function clearDosyalarTimer() {
	if (anaDosyaTimer != null)
		clearTimeout(anaDosyaTimer);
	anaDosyaTimer = null;
}

function anaDosyaSlideStep() {
	var offset = anaDosyaTarget - anaDosyaPosition;
	var sign = (offset < 0) ? -1 : 1;
	
	if (Math.abs(offset) > 12) {
		offset /= anaDosyaStepMultiplier;
		anaDosyaPosition = anaDosyaTarget - offset;
	} else if (Math.abs(offset) > 4) {
		anaDosyaPosition += 4 * sign;
	} else {
		anaDosyaPosition = anaDosyaTarget;
	}
	
	var containerDiv = document.getElementById("divAnaDosyalar");
	containerDiv.style.left = parseInt(anaDosyaPosition) + "px";

	if (anaDosyaPosition != anaDosyaTarget)
		anaDosyaTimer = setTimeout("anaDosyaSlideStep();", anaDosyaStepTime);
	else 
		clearDosyalarTimer();
}

function anaDosyaGit(offset, automatic) {
	if (offset != -1) offset = 1;
	if (anaDosyaFirst<18)
	{
	if (automatic != null && automatic) {
		if (anaDosyaFirst + offset < 0) {
			lastOffset = 1;
		
//		} else if (anaDosyaFirst + offset + anaDosyaVisible > anaDosyaSayisi) { 
		} else if (anaDosyaFirst + offset + anaDosyaVisible > 30) { 

		lastOffset = -1;
		}
		
		
		offset = lastOffset;
		clearTimeout(anaDosyaTimer);
	} else {
		// Auto degilse kaydirma islemini durdur.
		clearSlideContinuouslyTimer();
		// check array boundaries
		if (anaDosyaFirst + offset < 0 || 
			anaDosyaFirst + offset + anaDosyaVisible > anaDosyaSayisi)
			return;		
	}
		
	clearDosyalarTimer();

	anaDosyaFirst += offset;
	// load images on demand
	for (var i = 0; i <= anaDosyaVisible; i++) {
		var index = anaDosyaFirst + i;
		if (index < anaDosyaSayisi) {
			if (!anaDosyaImgLoaded[index]) {
				anaDosyaImgLoaded[index] = true;
				// load new image
				anaDosyaImgObjects[index] = new Image();
				anaDosyaImgObjects[index].src = anaDosyalar[index].header;
				anaDosyaImgs[index].src = anaDosyaImgObjects[index].src;				
			}
		}
	}
	anaDosyaTarget = -anaDosyaFirst * anaDosyaPlacement;
	
	if (isIE55up) {
		/*
		var containerDiv = document.getElementById("divAnaDosyalar");
		var motionDirection = (offset == 1) ? 90 : 270
		if (!containerDiv.filters.MotionBlur)
			containerDiv.style.filter = "progid:DXImageTransform.Microsoft.MotionBlur(direction=" + motionDirection + ",strength=10)";
		containerDiv.filters.MotionBlur.direction = motionDirection;
		containerDiv.filters.MotionBlur.enabled = true;
		*/	
	}
	
	anaDosyaSlideStep();
	}
}

function clearSlideContinuouslyTimer() {
	if (slideContinuouslyTimer != null)
		clearTimeout(slideContinuouslyTimer);
	slideContinuouslyTimer = null;
}

function SlideContinuously() {
	anaDosyaGit(lastOffset, false);
	slideContinuouslyTimer = setTimeout("SlideContinuously();", SlideContinuouslyStepTime);
}
setTimeout("SlideContinuously();", SlideContinuouslyStepTime);