var slideshow = new Array;
var captions = new Array;
var caption;
var current = 0;
var previous;
var frame;
var fadeFrame;
var opacity = 1;
var trigger;
var timer;
var auto;
var switcher;
var shower;

function loadFrame(){

	if(slideshow.length > 0){	
		frame = document.getElementById("frame");
		caption = document.getElementById("caption");
		fadeFrame = document.getElementById("secondary_frame");
		frame.style.display = "block";
		frame.style.opacity = 1;
		if(slideshow.length > 0){
			frame.src = slideshow[current];
			caption.innerHTML = captions[current];
			$("#point"+(current + 1)).css('color', '#ff6600');
		}
	}
	
	//auto_slide();
}

function cycleSlides(){
	if(current == (slideshow.length - 1)){
		current = 0;
	}
	
	opacity = 1
	if(current + 1 < slideshow.length){
		fadeFrame.src = slideshow[++current];
		fadeFrame.style.display = "block";
		trigger = setTimeout(startFade, 500);
		setTimeout(fadeOutCaption, 800);
	}
}

function nextSlide(){
	clearInterval(auto);
	clearTimeout(switcher);
	opacity = 1
	if(current + 1 < slideshow.length){
		$("#point"+(current + 2)).css('color', '#ff6600');
		$("#point"+(current + 1)).css('color', '#fff');
		fadeFrame.src = slideshow[++current];
		fadeFrame.style.display = "block";
		trigger = setTimeout(startFade, 500);
	}
	
	//switcher = setTimeout(auto_slide, 4000);
}

function prevSlide(){
	clearInterval(auto);
	clearTimeout(switcher);
	opacity = 1;
	if(current > 0){
		$("#point"+current).css('color', '#ff6600');
		$("#point"+(current + 1)).css('color', '#fff');
		fadeFrame.src = slideshow[--current];
		fadeFrame.style.display = "block";
		trigger = setTimeout(startFade, 800);
	}

	//switcher = setTimeout(auto_slide, 4000);
}

function jumpToSlide(page){
	$("#point"+(current + 1)).css('color', '#fff');
	$("#point"+page).css('color', '#ff6600');
	previous = current;
	current = --page;
	fadeFrame.src = slideshow[current];
	fadeFrame.style.display = "block";
	trigger = setTimeout(startFade, 500);
}

function fadeOutCaption(){
	$("#caption").fadeTo(1000, 0, null);
}

function startFade(){
	$("#frame").fadeTo(2000, 0, function(){
		frame.style.display = "none";
		frame.src = slideshow[current];
		$("#caption").fadeTo(0, 0, null);
		caption.innerHTML = captions[current];
		$("#caption").fadeTo(1000, 1, function(){
			setTimeout(fadeOutCaption, 1000);
		});
		$('#frame').fadeTo(0,1);
	});
}

function fadeOut(picture){
	clearTimeout(trigger);	
	if(opacity > 0){
		opacity -= 0.03;
		try{
			picture.style.opacity = opacity;
		}catch(e){
			//adjust opacity levels for internet explorer
			//picture.filter = "alpha(opacity=" + opacity + ")";
		}
	}else{
		opacity = 0;
		clearInterval(timer);
		frame.style.display = "none";
		frame.src = slideshow[current];
		frame.style.display = "block";
		try{
			frame.style.opacity = 1;
		}catch(e){
			//adjust opacity levels for internet explorer
			//picture.filter = "alpha(opacity=" + opacity + ")";
		}
		opacity = 1;
	}
}

function auto_slide(){
	auto = setInterval(cycleSlides, 4000);
}

function fadeIn(fadeInObj){
	try{
		opacity = 0;
		fadeInObj.style.opacity = 0;
		fadeInObj.style.display = "block";
		shower = setInterval(showObj, 100, fadeInObj);
	}catch(e){
		fadeInObj.style.display = "block";
	}
		
}

function showObj(fadeInObj){
	if(opacity < 1){
		opacity += 0.05;
		try{
			fadeInObj.style.opacity = opacity;
		}catch(e){
			//adjust opacity levels for internet explorer
		}
	}else{
		opacity = 1;
		clearInterval(shower);
		try{
			fadeInObj.style.opacity = opacity;
		}catch(e){
			//adjust opacity levels for internet explorer
		}
	}
}

function hoverLeft(){
	$("#left_button").css('color', '#ff6600');
}

function hoverRight(){
	$("#left_button").css('color', '#ff6600');
}

function restoreLBtn(){
	$("#left_button").css('color', '#fff');
}

function restoreRBtn(){
	$("#left_button").css('color', '#fff');
}
