﻿function ArabamAcilSatilikSlideShow(parentElement, listings)
{
	if (parentElement==null || !listings || listings.length == 0)
		return;
	
	var numSlides = listings.length;
	var aHrefElement = parentElement.getElementsByTagName('a')[0];
		
	var imageElem = aHrefElement.getElementsByTagName('img')[0]; 
	var priceElem = aHrefElement.getElementsByTagName('strong')[0];
	var titleElem = aHrefElement.getElementsByTagName('em')[0];
	var spanElem  = aHrefElement.getElementsByTagName('span')[0];
	
	var index = 1;	
	
	imageElem.src = listings[0].imgURL;
	imageElem.alt = listings[0].title;	
	
	aHrefElement.href = listings[0].linkURL;
	aHrefElement.title = listings[0].title;	
	
	priceElem.innerHTML = listings[0].price;
	titleElem.innerHTML = listings[0].shortTitle;
	spanElem.innerHTML = listings[0].modelAdi;
	
	this.showSlides = showSlides;
	
	function showSlides()
	{
		var num = index % numSlides;
		index++;

		setTimeout(function() { parentElement.style.opacity = 0.9; }, 50);
		setTimeout(function() { parentElement.style.opacity = 0.8; imageElem.style.filter = "alpha(opacity=80)"; }, 200);
		setTimeout(function() { parentElement.style.opacity = 0.7; }, 350);
		setTimeout(function() { parentElement.style.opacity = 0.6; imageElem.style.filter = "alpha(opacity=60)"; }, 500);
		setTimeout(function() { parentElement.style.opacity = 0.5; }, 650);
		setTimeout(function() { parentElement.style.opacity = 0.4; imageElem.style.filter = "alpha(opacity=40)"; }, 800);
		setTimeout(function() { parentElement.style.opacity = 0.3; }, 950);
		setTimeout(function() { parentElement.style.opacity = 0.2; imageElem.style.filter = "alpha(opacity=20)"; }, 1100);
		setTimeout(function() { parentElement.style.opacity = 0.1; }, 1250);
		
			
		setTimeout(function() { aHrefElement.href = listings[num].linkURL; }, 1250);
		setTimeout(function() { aHrefElement.title = listings[num].title; }, 1250);
		setTimeout(function() { imageElem.src = listings[num].imgURL; }, 1250);	
		setTimeout(function() { imageElem.alt = listings[num].title; }, 1250);
		setTimeout(function() { priceElem.innerHTML = listings[num].price; }, 1250);
		setTimeout(function() { titleElem.innerHTML = listings[num].shortTitle; }, 1250);	
		setTimeout(function() { spanElem.innerHTML = listings[num].modelAdi; }, 1250);	

		setTimeout(function() { parentElement.style.opacity = 0.1; }, 1300);
		setTimeout(function() { parentElement.style.opacity = 0.2; imageElem.style.filter = "alpha(opacity=20)"; }, 1450);
		setTimeout(function() { parentElement.style.opacity = 0.3; }, 1600);
		setTimeout(function() { parentElement.style.opacity = 0.4; imageElem.style.filter = "alpha(opacity=40)"; }, 1850);
		setTimeout(function() { parentElement.style.opacity = 0.5; }, 2000);
		setTimeout(function() { parentElement.style.opacity = 0.6; imageElem.style.filter = "alpha(opacity=60)"; }, 2150);
		setTimeout(function() { parentElement.style.opacity = 0.7; }, 2300);
		setTimeout(function() { parentElement.style.opacity = 0.8; imageElem.style.filter = "alpha(opacity=80)"; }, 2450);
		setTimeout(function() { parentElement.style.opacity = 0.9; }, 2600);
		setTimeout(function() { parentElement.style.opacity = 1.0; imageElem.style.filter = "alpha(opacity=100)"; }, 2750);
	}

	this.startShow = function(interval)
	{
		showSlides();
		setInterval(showSlides, interval);
	}
}

function startShowForElement(slideShow, timeStart, interval)			
{
	if(slideShow && slideShow.startShow)
	{
		setTimeout(
			function() 
				{
					slideShow.startShow(interval);
				}
			, timeStart);
	}
}

/*
 * Fisher-Yates shuffle from:
 * @http://jsfromhell.com/array/shuffle [v1.0]
 * Jonas Raoni Soares Silva
 */ 
shuffle = function(v){
	for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
	return v;
};

