// JavaScript Document

var info = false;


$(document).ready(function() {
	scaleWrapper();		
	fitToWindow("#img-stage #placeholder", "#img-buffer", imgSrc, 1);	
	
	/*
	$('#info-btn').toggle(
		function() {
			$(this).html("HIDE INFO");
			$('#project-info').fadeIn();
		}, function() {
			$(this).html("SHOW INFO");
			$('#project-info').fadeOut();
	});
	*/
	
	
	
	
});


function closeLayer (aSelector)  {
	$(aSelector).fadeOut();
	//$("a#player").attr('href', '#');
}


function countUp () {
	if (cIndex<projectFiles.length-1) {
		cIndex++;	
	}
	drawImg();
}

function countDown () {
	if (cIndex>0) {
		cIndex--;	
	}
	drawImg();
}


function toggleInfo() {
	info = !info;
	
	if (info) {
		$('#info-btn').html("HIDE INFO");
		$('#project-info').fadeIn();
	} else {
		$('#info-btn').html("SHOW INFO");
		$('#project-info').fadeOut();
	}
	

}


	
	


$(window).resize(function() {
	scaleWrapper();

	imgSrc = "./"+imgURLs[cIndex];
	fitToWindow("#img-stage #placeholder", "#img-buffer", imgSrc, 1);
	centerClip();
	alignFlash();
});




function scaleWrapper() {
	var wrapperHeight = $(window).height();
	wrapperHeight-=120;
	$('.wrapper').css({					
		'height': wrapperHeight
	});
	
	$('#project-info').css({					
		'height': wrapperHeight
	});	
}





// --------------------------------- drawImage
function drawImg() {
	
	// ------- video or img
	
	if (projectFileExtensions[cIndex]=="flv") {
		$("#img-stage").css("display", "none");
		$("#video-stage").css("display", "block");
		$("#flash-box").detach();	
		$("#flash-stage").css("display", "none");
		
		videosrc =  "./"+projectFiles[cIndex];
		$("a#player").attr('href', videosrc);
		flowplayer("player", "functions/flowplayer-3.1.5.swf", {
			canvas: {backgroundColor: "lime"},
			plugins: { controls:null }		   
		});
		centerClip();
		
	} else if (projectFileExtensions[cIndex]=="swf") {
		$('<div id="flash-box"></div>').appendTo("#flash-stage");		

		$("#img-stage").css("display", "none");
		$("#video-stage").css("display", "none");	
		$("#flash-stage").css("display", "block");
		
		flashsrc =  "./"+projectFiles[cIndex];
		//alert (flashsrc);
   		
		$('#flash-box').flash({
			src: flashsrc,
          	width: 650,
          	height: 570 },
        	{ version: 8
		});
		alignFlash();

	} else {
		
		$("#img-stage").css({"display": "block"});
		$("#video-stage").css("display", "none");
		$("#flash-box").detach();	
		$("#flash-stage").css("display", "none");	
			
		imgSrc = "./"+projectFiles[cIndex];
		//alert (imgSrc);
		fitToWindow("#img-stage #placeholder", "#img-buffer", imgSrc, 1);
		
	}
	
	
	
	
	
	// ------ PFEILE TOGGELN
	
	if (cIndex == projectFiles.length-1) {
		$("#next-wrapper").attr("class", "a-wrapper disabled");
	} else {
		$("#next-wrapper").attr("class", "a-wrapper enabled");
	}
	
	if (cIndex == 0) {
		$("#prev-wrapper").attr("class", "a-wrapper disabled");
	} else {
		$("#prev-wrapper").attr("class", "a-wrapper enabled");
	}
	
	
} // end drawImg


function centerClip() {
	var cHeight = $("a#player").height();
	$("a#player").css('margin-top', ($(window).height()-cHeight)/2);
}


function alignFlash() {
	var cHeight = $("#flash-box").height();
	var cWidth = $("#flash-box").width();
	$("#flash-box").css('margin-top', ($(window).height()-cHeight)/2);	
	$("#flash-box").css('margin-left', ($(window).width()-cWidth)/2);	
}

