$(document).ready(function(){


	var this_height = $(window).height()-40; // reducing the size to make some space around
	var this_width = $(window).width()-40;


// call the colour animation script
	animate_colors();




// MOVE THE LINK TO PLAY VIDEO INTO THE SIDEBAR

if($('#movie_link')) {
	var content_sidebar = $('#movie_link').html();
	$('#secondaryContent').append(content_sidebar);
	$('#movie_link').html('');
}

// MOVE THE CREDITS DOM into the sidebar
if($('#credits')) {
	var content_sidebar = $('#credits').html();
	if (content_sidebar) {
		$('#secondaryContent').append('<hr><span>'+content_sidebar+'</span>');
		$('#credits').html('');
	}
}



// INTEGRATING THE PLAYER IN THE PAGE - DETECTS LINKS WITH ID=background_movie

if ($('#background_movie').attr('href') != undefined) {

	var movie_href = $('#background_movie').attr('href');
	//alert(movie_href);
	$('body').append('<div id="bkgbkg_layer" style="width:100%; height:100%"><a href="#close" id="close_player" style="font-size:12px;color:#FFF; font-weight:bolder;">&lt;</a><br><div id="background_layer"></div></div>');
	//var url = movie_href;



	// using the method of the player to integrate it - should be easily converted into jQuery, works fine on whole browsers range on mac

	var so = new SWFObject('http://gaelledenis.com/wordpress/wp-content/themes/gaelle/mediaplayer/player.swf','flashmovie',this_width, this_height, '9', "#000000");
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','true');
		so.addParam('flashvars','&file='+movie_href+'&controlbar=over&caption=false&fullscreen=true');
		so.write('background_layer'); // not jQuery



	// defining basic css for the movie elements

	$('#background_layer').css({margin: '0 auto 0 auto', width: '100%', height:'100%'});
	$('#bkgbkg_layer').css({backgroundColor:"#FFF"});
	$('#bkgbkg_layer').css({position:'absolute', top:'0', left:'-'+(this_width+40)+'px', zIndex:'10'});
	$('#canvas').css({zIndex:'50'});


	// CLOSING THE PLAYER: the layer is scrolling out of the screen	
	
	$('#close_player').click(function(){
		$('#bkgbkg_layer').animate({
			left: "-"+(this_width+40)+"px",
			backgroundColor:'#FFF'
		}, 500);
		$('body').css({overflow:'auto'});
	});


}



	// OPEN THE PLAYER IN THE WINDOW: the layer is scrolling from outside the visible screen
	
	$('#background_movie').click(function() {
		$('#bkgbkg_layer').animate({
			left: "0px",
			backgroundColor:'#000'
		}, 3000);	
		$('body').css({overflow:'hidden'});
		return false;	
	});


	// LET'S SPARE SOME SPACE ON THE SCREEN:
	// if there are images remaining inside the post DOM, then we use the jQuery innerFade to display those as a slideshow


		$('#slideshow').css({height:this_height/2+'px'})

		if ($('#slideshow')) {
			$('#slideshow').innerfade({
				animationtype: 'fade',
				speed: 750,
				timeout: 5000,
				type: 'random',
				containerheight: this_height/2
			});
		}

});





function reset_colors() {
	$('body').css({color:'black'});
	$('a').css({color:'black'});
}


function animate_colors() {

	var anim_time= 20000;
	
	
	$('body').animate({color:'#FF0'}, 5000);
	$('body').animate({color:'#0FF'}, anim_time);
	$('body').animate({color:'#F0F'}, anim_time);
	$('body').animate({color:'#FFF'}, anim_time);


	$('a').animate({color:'#Fb0'}, 4000);
	$('a').animate({color:'#0bF'}, anim_time);
	$('a').animate({color:'#F0b'}, anim_time);
	$('a').animate({color:'#FFF'}, anim_time);


	$('a').animate({color:'#777'}, anim_time);

if($('#website_description')) {
	$('#website_description').animate({color:'#FF0'}, 500);
	$('#website_description').animate({color:'#000'}, 2000);
}
	
//animate_colors();

}

// Create innerHeight, innerWidth, outerHeight and outerWidth methods
$.each( [ 'Height', 'Width' ], function(i, name){
	
	// innerHeight and innerWidth
	$.fn[ 'inner' + name ] = function() {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		return this.css('display') != 'none' ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
	};
	
	// outerHeight and outerWidth
	$.fn[ 'outer' + name ] = function(options) {
		if (!this[0]) return;
		
		var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
		    borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
		
		options = $.extend({ margin: false }, options || {});
		
		var val = this.css('display') != 'none' ? 
				this[0]['offset' + name] : 
				num( this, name.toLowerCase() )
					+ num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
					+ num(this, 'padding' + torl) + num(this, 'padding' + borr);
		
		return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
	};
});