$(document).ready(function(){	
	
	//-------------------------------------------------------------------------------------------------
	//--- EMBED MOVIES - flv/flash ---
	
	//replace all html editor inserted movies with swfobject
	//needed for accessibility options
	var cnt = 1;
	var next_img = null;
	//find all embed objects
	$('div.flash-movie').each(function()
	{								   
		flash_preview_img = '/content/images/flash-default.gif';
		var next_img = $(this).siblings('img');
		var flash_preview_img = null;
		var flash_div = $(this).children("a");
		var flash_href = flash_div.attr('href');
		var flash_extension = flash_div.attr('href').substring(flash_div.attr('href').lastIndexOf(".")+1,flash_div.attr('href').length);
		var flash_preview_img = '/content/images/flash-default.gif';
		
		//
		switch (flash_extension)
		{
			case "flv":
			//case "swf":
				if (next_img.length > 0 && next_img.attr('src').length > 0)
				{
					flash_preview_img = next_img.attr('src');
					//remove the image from the page
					next_img.remove();
				}
				flash_href = flash_href + '&image=' + flash_preview_img;
				flash_div.attr('href',flash_href);	
				//alert(flash_href);
			break;
		}
		
		flash_div.media();				
		//if there is an img next to the flash video then use that image as the image preview
		/*
		if(next_img.length > 0 && next_img.attr('src').length > 0){
			flash_preview_img = next_img.attr('src');
			//remove the image from the page
			next_img.remove();
		}
		*/
							
		//set default player location
		//$.fn.media.defaults.flvPlayer = '/css/skins/default/flash/player.swf';
		//run media plugin on all a links with media class
		//$('#'+flash_div+' a').media();
	});
	

	//replace all fck inserted movies with swfobject
	//needed for accessibility options
	var cnt = 1;
	//find all embed objects
	$('embed').each(function(){
			//if they are flash movies
			if ($(this).attr('type') == 'application/x-shockwave-flash')
			{				
				//get the source fo the flash movie
				if ($(this).attr('src'))
				{	
					//get width and height of movie to use for replacement below
					flash_width = $(this).attr('width');
					flash_height = $(this).attr('height');
					//alert(flash_width+":"+flash_height);
					
					embed_type = $(this).attr('type');
					flash_src = $(this).attr('src');
					flash_div = 'flash-'+cnt;
					flash_extension = $(this).attr('src').substring($(this).attr('src').lastIndexOf(".")+1,$(this).attr('src').length);
					flash_preview_img = '/content/images/flash-default.gif';
					//alert("type:"+embed_type+"ext:"+flash_extension+"flash_src:"+flash_src);
	
					//give the element an id
					$(this).attr('id','embed-'+cnt);	

					switch (flash_extension)
					{						
						/*case "flv":
							alert(flash_height);
							
							if (jQuery.fn.media)
							{	
								//replace the embed obect with a holding div
								$(this).replaceWith('<div id="'+flash_div+'"></div>');

								//use swfobject to embded the flash movie
								$('#'+flash_div).flash({ 
									// test.swf is the flash document 
									swf: flash_src,
									play: false,
									width : flash_width,
									height : flash_height
									//width : 425,
									//height : 344
								});
								
								//alert(flash_height);
								
								//set default player location
								$.fn.media.defaults.flvPlayer = '/css/skins/default/flash/mediaplayer.swf';
								//run media plugin on all a links with media class
								//$('#'+flash_div+' a').media();
							}
							else
							{
								alert('You need to have the media and meta plugins installed.');
							}
						break;*/
						case "swf":
							if (jQuery.fn.flash)
							{
								//alert("swf");	
									
								//replace the embed obect with a holding div
								$(this).replaceWith('<div class="flash-movie"><div id="'+flash_div+'"></div></div>');
								//use swfobject to embded the flash movie
								$('#'+flash_div).flash({ 
									// test.swf is the flash document 
									swf: flash_src,
									width : flash_width,
									height : flash_height									
									//width : 425,
									//height : 344
								}); 
							}
							else
							{
								alert('You need to have the swfobject plugins installed.');
							}
						break;
						default:
						break;
					}
				}
			}
		cnt++;
	});
	//--- EMBED MOVIES - flv/flash ---
	//-------------------------------------------------------------------------------------------------


	//-------------------------------------------------------------------------------------------------
	/* EMBED MEDIA */
	if (jQuery.fn.media){
		//set default player location
		$.fn.media.defaults.flvPlayer = '/css/skins/default/flash/mediaplayer.swf';
		//run media plugin on all a links with media class
		$('a.media').media();
	}
	//-------------------------------------------------------------------------------------------------


	/*!
	 * unwrap - v0.1 - 7/18/2009
	 * http://benalman.com/projects/jquery-unwrap-plugin/
	 * 
	 * Copyright (c) 2009 "Cowboy" Ben Alman
	 * Licensed under the MIT license
	 * http://benalman.com/about/license/
	 */

	if(jQuery.fn.showhide){
		//apply show hide plugin for use in gallery
		if($('a.showhide').length > 0 ){
			$('a.showhide').showhide({
				animate:true,
				event:'click',
				target:'#large_img',
				animate_type:'custom'
			});
		}
	}
	



});
