// overlay
// define function that opens the overlay
var api = '';

function openOverlay(movie, movieTitle, movieDescription, movieCity, isHTML5) {
	if(isHTML5) {
		// HTML 5
		var overlayHTML = movie + '<div id="movieTitle">'+movieTitle+'</div>'+
							'<div id="movieDesc">'+movieDescription+' | '+movieCity+'</div>';
		// alert(overlayHTML);
		$('#overLayMovie').html(overlayHTML);
	}else{
		// Normal FLV
		//fill overlay with given content
		
		var flashvars = {};		
		flashvars.file = movie;
		flashvars.title = movieTitle;
		flashvars.company = movieDescription;
		flashvars.city = movieCity;
		var params = {};
		params.play = "true";
		params.menu = "false";
		params.wmode = "transparent";
		swfobject.embedSWF(flashPath + "videoplayer.swf", "overLayMovie", "210", "168", "9.0.0", false, flashvars, params);	
			
		// $("#overLayTitle").html(movieTitle);
		// $("#overLayDescription").html(movieDescription);
	}
	
	// get access to the overlay API
	api = $("#overlay").overlay();
	// call it's open() method
	api.load();
}



function switchImageOverlay(image, text, content) {
	var imgObjects = Array();
	var prevImg;
	var nextImg;
	var html;
		
	$.each($('img','#imageNavigation'), function(k, v){
		var imgObject = $(v).parents('.imageContainer');
		
		var imgArray = ($.trim(($('a',$(imgObject))).attr('onclick')));
		if ($.browser.mozilla)
			imgArray = imgArray.split('\"');
		else
			imgArray = imgArray.split('\'')
		
		//alert(imgArray[0])
		
		if (imgArray[7] != '')
			//alert(imgArray[1]);
			imgObjects.push(imgArray);
		
		if ($(v).attr('alt') == text)
			currentImg = imgObjects.length-1;
	});
	
	//alert(imgObjects);
	
	prevImg = imgObjects[parseInt(currentImg)-1];
	nextImg = imgObjects[parseInt(currentImg)+1];
	
	
	html = '<img src="'+image+'" width="638">';
	if (parseInt(currentImg) > 0 && prevImg[7])
		html += '<a href="javascript:switchImageOverlay(\''+prevImg[7]+'\',\''+prevImg[3]+'\',\''+prevImg[5]+'\')"><div class="overlay-btn" id="overlay-prev"></div></a>';
	if (parseInt(currentImg) < imgObjects.length-1 && nextImg[7])
		html += '<a href="javascript:switchImageOverlay(\''+nextImg[7]+'\',\''+nextImg[3]+'\',\''+nextImg[5]+'\')"><div class="overlay-btn" id="overlay-next"></div></a>';
	
	html += '<span class="overlay-title">'+text+'</span>';
	
	if (content.length > 125){
		newContent = content.substr(0,125)+'...';
	}else{
		newContent = content;
	}
	
	html += '<span class="overlay-content">'+newContent+'</span>';
	
	$("#imageOverlayContent").html(html);
}


function openImageOverlay(image, text, content){
	
	switchImageOverlay(image, text, content);
	
	// get access to the overlay API
	api = $("#imageOverlay").overlay();
	// call it's open() method
	api.load();
}

/*
function openOverlay(movie1, movie2, movieTitle, movieDescription, movieCity, isHTML5) {
	if(isHTML5) {
		// HTML 5
		var overlayHTML = '<video id="movie" width="548" height="308" preload controls> '+
								'<source src="'+movie1+'" />'+
								'<source src="'+movie2+'" type=\'video/ogg; codecs="theora, vorbis"\'/>'+
							'</video>'+
							'<div id="movieTitle">'+movieTitle+'</div>'+
							'<div id="movieDesc">'+movieDescription+' | '+movieCity+'</div>';
		$('#overLayMovie').html(overlayHTML);
	}else{
		// Normal FLV
		//fill overlay with given content
		
		var flashvars = {};		
		flashvars.file = movie1;
		flashvars.title = movieTitle;
		flashvars.company = movieDescription;
		flashvars.city = movieCity;
		var params = {};
		params.play = "true";
		params.menu = "false";
		params.wmode = "transparent";
		swfobject.embedSWF(flashPath + "videoplayer.swf", "overLayMovie", "210", "168", "9.0.0", false, flashvars, params);	
			
		// $("#overLayTitle").html(movieTitle);
		// $("#overLayDescription").html(movieDescription);
	}
	
	// get access to the overlay API
	api = $("#overlay").overlay();
	// call it's open() method
	api.load();
}
*/

function extraClose(){
	api.close();
}
			
			Cufon.replace('span.slider-titel, span.slider-subtitel'); // Works without a selector engine
			Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above

$(function() {
	$("#overlay").overlay({
		// some expose tweaks suitable for facebox-looking dialogs
		expose: {
			// you might also consider a "transparent" color for the mask
			color: '#fff',
			// load mask a little faster
			loadSpeed: 200,
			// highly transparent
			opacity: 0.65,
			
			onClose: function() {
				//alert('test');
				$("#overlay").html('<div class="close" onclick="extraClose();"></div><div id="overLayMovie"></div>');
			}
		}
	});
	
	$("#imageOverlay").overlay({
		// some expose tweaks suitable for facebox-looking dialogs
		expose: {
			// you might also consider a "transparent" color for the mask
			color: '#fff',
			// load mask a little faster
			loadSpeed: 200,
			// highly transparent
			opacity: 0.65
		}
	});
	
	$("#downloadOverlay").overlay({
		// some expose tweaks suitable for facebox-looking dialogs
		expose: {
			// you might also consider a "transparent" color for the mask
			color: '#fff',
			// load mask a little faster
			loadSpeed: 200,
			// highly transparent
			opacity: 0.65
		}
	});
	
	$("#slides").slides({
			preload: true,
			preloadImage: imagePath + 'slider/loading.gif',
			play: 5000,
			pause: 1000,
			fadeSpeed: 250,
			hoverPause: true,
			effect: 'fade'
	});
});

function getDownloads(downloadId, downloadTitle){	
	// downloadForm
	$("#downloadForm").hide();	
	// set title
	if(downloadTitle != ''){
		$("#downloadTitle").html(downloadTitle);
	}
	
	// open download overlay
	openDownloadOverlay();
	
	//ajax it
	$.ajax({
		type: "GET",
		url: pagesPath+"functions.ajax.php",	
		data: "action=getDownloads&downloadId="+downloadId,		
		success: function(msg){
			$("#downloadOverlayContent").html(msg);
		}
	});
}

function showDownloadForm(fileId, downloadId){
	// clear overlayContent
	$("#downloadOverlayContent").html('');
	// downloadId
	$("#formDownloadId").val(downloadId);
	// fileId
	$("#formFileId").val(fileId);
	// downloadForm
	$("#downloadForm").show();	
}

function openDownloadOverlay(){
	// get access to the overlay API
	api = $("#downloadOverlay").overlay();
	// call it's open() method
	api.load();
}

function openDownloadForm(fileId, downloadId){

	openDownloadOverlay();
	showDownloadForm(fileId, downloadId);
}
