/* HTML5 Video */

function makeHtml5Video(poster,video) {
	
	if (supports_h264_baseline_video()) {
		var myVideo = "<video width=\"491\" height=\"272\" controls preload poster=\""+poster+"\">";
		myVideo += "<source src=\""+video+"\" type=\'video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"\' />";
		myVideo += "</video>";
		//console.log(video);
		$("#flashcontainer").append(myVideo);
		
	} else {
		var myPoster = "<a href='"+video+"' target='_blank'><img width='491' height='272' src='"+poster+"' /></a>";
		$("#flashcontainer").append(myPoster);
	}
}

function supports_video() {
  return !!document.createElement('video').canPlayType;
}
function supports_h264_baseline_video() {
  if (!supports_video()) { return false; }
  var v = document.createElement("video");
  return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}

/* Coverflip */

function makeCoverflip() {
	var coverflipWrapper = "<div id=\"coverflip_wrapper\"></div>";
	$("#flashcontainer").append(coverflipWrapper);
	
	var ulContainer = "<ul id=\"coverflow_startseite\"></ul>";	
	$("#coverflip_wrapper").append(ulContainer);
	
	
	// XML auslesen	
	$.ajax({
		type: "GET",
		url: "/scripts/coverflow_home.xml",
		dataType: "xml",
		success: function(xml) {
			coverflow_xml = xml;
			var myAreas = $("#nf_map_karte area");
			
			// Elemente generieren
			$(coverflow_xml).find("albuminfo").each(function(index){				
	 			var theImage = $(this).find("artLocation").text();
				var theType = $(this).find("name").text();
				var theTitle = $(this).find("funktion").text();
				var theLink = $(this).find("link").text();
				
				var newElement = "<li><a href=\""+theLink+"\"><img src=\""+theImage+"\"><span class=\"title\"><span class=\"videotype\">"+theType+"</span>"+theTitle+"</span></a></li>";
				$("#coverflow_startseite").append(newElement);
			});
			
			var steppis = 100/$(coverflow_xml).find("albuminfo").length;
			var mitte = Math.round($(coverflow_xml).find("albuminfo").length/2);
			
			// Scrollbar
			var scrollbarContainer = "<div id=\"scrollbar_container\"></div>";
			$("#coverflip_wrapper").append(scrollbarContainer);
			
			var myScrollbar = "<div id=\"scrollbar\"></div>";
			$("#scrollbar_container").append(myScrollbar);
			
			jQuery('#scrollbar').slider({
				value: 50,
				stop: function(event, ui) {
					if(event.originalEvent) {
						var newVal = Math.round(ui.value/steppis);
						jQuery('#coverflow_startseite' ).jcoverflip( 'current', newVal );
						jQuery('#scrollbar').slider('value', newVal*steppis);
					}
				}
			});
			
			// Coverflip initialisieren
			$("#coverflow_startseite").jcoverflip({
				current: flashvars.jumpto-1,
				change: function(event, ui){
					jQuery('#scrollbar').slider('value', (ui.to)*steppis);	
				},
				currentCss: function( el, container ){
					return [
						$.jcoverflip.animationElement( el, { left: ( container.width( )/2 - 93 )+'px', bottom: 0 }, { } ),
						$.jcoverflip.animationElement( el.find( 'img' ), { opacity: 1, width: '185px' }, { } )
					];
				}
			});
			
			addSwipeListener(document.getElementById("flashcontainer"), function(e) { 
				if (e.direction == "left") {
					//touchbarScroll(obj,"right");
					//alert("right");
					jQuery('#coverflow_startseite' ).jcoverflip( 'next' );
				} else if (e.direction == "right") {				
					//touchbarScroll(obj,"left");
					//alert("left");
					//alert(jQuery('#coverflow_startseite' ).jcoverflip( 'current' ));
					jQuery('#coverflow_startseite' ).jcoverflip( 'previous' );
				}
			});
		}
	});
	
}

function test() {
	addSwipeListener(document.getElementById(myName), function(e) { 
		if (e.direction == "left") {
			touchbarScroll(obj,"right");
		} else if (e.direction == "right") {				
			touchbarScroll(obj,"left");	
		}
	});	
}


