$(document).ready(function(){
	
	// install flowplayer inside a#player 
	$f("player", "/images/js/flowplayer/flowplayer-3.1.1.swf", {
	
		// clip does start automatically
		clip: {
			url: '/pictures/gralvilaga/video/KimAronson-TwentySeconds73213.flv',
			autoPlay: true,
			scaling: 'fit'
		},
		// don't use default controls 
		plugins: {
			controls: {
				url: '/images/js/flowplayer/flowplayer.controls-tube-3.1.1.swf'
			},
			audio: { 
				url: '/images/js/flowplayer/plugins/flowplayer.audio-3.1.0.swf' 
        	}
		}
	});
	
	// get all links that are inside div#clips 
	var links = $("#fp-playlist").find(".play");
	
	// loop those links and alter their click behaviour 
	for (var i = 0; i < links.length; i++) {
		links[i].onclick = function(){
		
			$.scrollTo(0, 200);
			
			// play the clip specified in href- attribute with Flowplayer 
			$f().play([{
				url: this.getAttribute("href", 2)
			}]);
			
			// update infobox
			$("#fp-video_infobox-head").html($(this).children('span').html());
			$("#fp-video_infobox-p").html($(this).next('p').html()).css('display', 'none').show("slow", function callback(){
			
				if ($('#fp-video_infobox').hasClass('big')) {
					$('#fp-video_infobox').animate({
						height: $('#fp-video_infobox').find('p').height() + $('#fp-video_infobox').find('h1').height() + 15
					}, 500);
				}
			});
			
			$("#fp-videoid").val($(this).attr('id'));
			$("#fp-videotitle").val($(this).next('h1').children('a').html());
			
			$('.pl-item').removeClass('playing');
			$(this).parent('div').addClass('playing');
			
			// by returning false normal link behaviour is skipped 
			return false;
		}
	}
	
	var uri = document.URL;
	var splituri = uri.split('=');
	
	if (splituri.length > 2) {
		var videoid = splituri[2];
		$f().play($('#' + videoid).attr("href"));
	}
	
	
	$("#fp-video_infobox-plus").click(function(){
		var item = $('#fp-video_infobox');
		item.addClass("big");
		item.animate({
			height: $('#fp-video_infobox').find('p').height() + $('#fp-video_infobox').find('h1').height() + 15
		}, 500);
		
	});
	
	$("#fp-video_infobox-minus").click(function(){
	
		var item = $('#fp-video_infobox');
		item.removeClass("big");
		item.animate({
			height: 73
		}, 500);
		
	});
	
	// Hyphenator


});

Hyphenator.run();

