function onStartVideo( id )
{
	var blocks = new Array();
	blocks[0]   = new Array( "title", "title", false, false );
	blocks[1]   = new Array( "#cc_css", "css", false, false );
	blocks[2]   = new Array( "#video_description", "video_description", "<div style=\"text-align: center; padding-top: 30px;\"><img src=\"images/loader.gif\"></div>", "initContentActions()" );
	blocks[3]   = new Array( "#left-col", "left_col", "<div style=\"text-align: center;  padding-top: 100px;\"><img src=\"images/loader.gif\"></div>", "initComments(); commentsFormIncreace = false; addCommentFormClose();" );
	blocks[4]   = new Array( "#label_block", "label_block", "<div style=\"text-align: center;  padding-top: 30px;\"><img src=\"images/loader.gif\"></div>", false );
	blocks[5]   = new Array( "#channel_header", "channel_header", "<div style=\"text-align: center;  padding-top: 5px;\"><img src=\"images/loader.gif\"></div>", false );
	blocks[6]   = new Array( "#movie_advert", "movie_advert", "<div style=\"text-align: center;  padding-top: 45px;\"><img src=\"images/loader.gif\"></div>", false );        

	for( var cB = 0; cB < blocks.length; cB++)
	{
		if( blocks[cB][2] )
		{
			$(  blocks[cB][0] ).html( blocks[cB][2] );
		}
	}	

	//set up locatio bar
	var url  = location.href.replace( location.hash, '' );

	location.href = url + "#load" + id;

	params = "upd=cont&ajx=1";

	jQuery.get( "play_" + id + ".html", params, function( data )
		{
			    $(data).find( "data" ).each( function()
			    {
			        if( $( "redir",this ).text() != "false" )
				{

					location.href = $( "redir", this ).text();
					return;
				}
			        
			    	for( var cB = 0; cB < blocks.length; cB++)
				{
					if( cB == 0 )
					{
					       document.title = $( blocks[cB][1], this ).text();
					}
					else if( cB == 1 )
					{
						var css    = $( blocks[cB][1], this ).text() ;
						var style  = document.getElementById( 'cc_css' );
						
						if( !style )
						{
							style = document.createElement( 'link' );
							style.id = "cc_css";
							style.setAttribute( "type", "text/css" );    
							style.setAttribute( "rel", "stylesheet" );							
							document.getElementsByTagName( "head" ).item( 0 ).appendChild( style );
						}
						
						if( css )
						{
							style.href = css;
							style.disabled = false;
						}	
						else
						{
							style.disabled = true;
						}
					}
					else
					{
						$(  blocks[cB][0] ).html( $( blocks[cB][1], this ).text() ) ;
					}	
					
					if( blocks[cB][3] )
					{
						eval( blocks[cB][3] );
					}
				}
		
			    });
		} 
	);

};

function loadHash( id )
{
	var hash = location.hash.slice( 1 );

	hash = Number( hash.replace( "load", "" ) );

	if( ( hash > 0 ) && ( hash != "NaN" ) && ( hash != id ) )
	{
		location.href = "/play_" + hash + ".html#load" + hash;
	}

};
function ajx_submit( form_id, update )
{
	var form = $( "#" + form_id );

	var params = form.serialize();

	var method = form.attr( "method" );

	var action = form.attr( "action" );

	if( action.indexOf( '?' ) != -1 )
	      action = action + '&ajx=1';
	else
	      action = action + '?ajx=1';

	if( update )
	{
		params = params + "&upd=" + update;
	}

	if( method == "get")
	{
		jQuery.get( action + "&" + params, function( data ){ $( "#" + update ).html( data ); } );
	}
	else
	{
		jQuery.post( action , params, function( data ){ $( "#" + update ).html( data ); } );
	}

	return false;
};

function email_submit()
{
	var update = "video_description";

	var form = $( "#decription_actions"  );

	var params = form.serialize();

	var method = form.attr( "method" );

	var action = form.attr( "action" );

	if( action.indexOf( '?' ) != -1 )
	      action = action + '&ajx=1';
	else
	      action = action + '?ajx=1';

	if( update )
	{
		params = params + "&upd=" + update;
	}

	if( method == "get")
	{
		jQuery.get( action + "&" + params, function( data ){ $( "#" + update ).html( data ); initContentActions(); toggleActionsPanel( "send_field" ); } );
	}
	else
	{
		jQuery.post( action , params, function( data ){ $( "#" + update ).html( data ); initContentActions(); toggleActionsPanel( "send_field" ); } );
	}


	return false;
}

function  initAddPlaylist( id )
{
	var playlistBlock = $( "#video_to_playlist" );


	if( playlistBlock )
	{
		//var openSaveLink  = $( "#lk_save_playlist" );
		var openSaveLink  = $( "#playlist-add" );
		var openAddLink   = $( "#lk_add_playlist" );
		var closeLink     = $( "#lk_close_playlist" );
		var saveForm      = $( "#form_save_playlist" );
		var addForm       = $( "#form_add_playlist" );
             if( saveForm[0] )
	     {
		saveForm[0].onsubmit =   function()
				  {
				  
				    	var form       = $( "#form_save_playlist" );

					var params = form.serialize();

					var method = form.attr( "method" );

					var action = form.attr( "action" );

					var update = "video_to_playlist";

					if( action.indexOf( '?' ) != -1 )
				    	      action = action + '&ajx=1';
					else
					      action = action + '?ajx=1';

					params = params + "&upd=" + update;



					if( method == "get")
					{
				    		jQuery.get( action + "&" + params, function( data ){ $( "#" + update ).html( data );  toggleActionsPanel( "playlist-add-field" ); initAddPlaylist( "save" ) } );
					}
				    	else
					{

						jQuery.post( action , params, function( data ){ $( "#" + update ).html( data );  
						         
							   toggleActionsPanel( "playlist-add-field" );
						           initAddPlaylist( "save" ) 
							 
							 } );
					}

					return false;
				  };

		};
	
		if( addForm[0] )
		{	

		addForm[0].onsubmit = function()
		               {

			    		var form       = $( "#form_add_playlist" );

					var params = form.serialize();

					var method = form.attr( "method" );

					var action = form.attr( "action" );

					var update = "video_to_playlist";

					if( action.indexOf( '?' ) != -1 )
				    	      action = action + '&ajx=1';
					else
					      action = action + '?ajx=1';

					params = params + "&upd=" + update;


					if( method == "get")
					{
				    		jQuery.get( action + "&" + params, function( data ){ $( "#" + update ).html( data ); toggleActionsPanel( "playlist-add-field" );  initAddPlaylist( "add" ) } );
					}
				    	else
					{
						jQuery.post( action , params, function( data ){ $( "#" + update ).html( data ); toggleActionsPanel( "playlist-add-field" );  initAddPlaylist( "add" ) } );
					}

 			       	         return false;
		               };
		};
		openSaveLink.click(  function()
		{
			    addForm.hide();
			    saveForm.show( 'slow' );
				contentActionsClose();
		});

		openAddLink.click(  function()
		{
			    saveForm.hide( );
			    addForm.show( 'slow' );
				contentActionsClose();
		});

		closeLink.click(  function()
		{
			    saveForm.hide( );
			    addForm.hide( );
			    saveForm.show( 'slow' );
				contentActionsClose();
		});


		switch( id )
		{
			case "save":
			    addForm.hide();
			    saveForm.show();
			break;
			case "add":
			    saveForm.hide( );
			    addForm.show( );
			break;

		}

	}



};

function initImageList()
{
	var imageClass = new Array();
	imageClass[0]  = ".playlist_img";
	imageClass[1]  = ".home_list_img";

	for( var cC = 0; cC < imageClass.length; cC++ )
	{

		$( imageClass[ cC ] ).css( "background-position", "top left");
		$( imageClass[ cC ] ).mouseover( function ()
		                                 {
							var index = 1;

							swapImage( this, index );
						 }
		                               );

		$( imageClass[ cC ] ).mouseout( function ()
		                                 {
							clearTimeout( window.imgTime );
							this.style.backgroundPosition = "top left";
						 }
		                               );

	}
}

function swapImage( image, index )
{
	var size = 74;

        try{
		clearTimeout( window.imgTime );
	}
	catch( e ){}

	if( index == 5 )
	{
	    index = 0;
	}

	image.style.backgroundPosition = "0px -" + index * size +  "px";

	window.imgTime = setTimeout( function(){ swapImage( image, index+1 ) }, 500 );
}

function fr_submit( form_id, frame_id, submit, load_id, update_id )
{
	var  form  = document.getElementById( form_id );
	var  frame = document.getElementById( frame_id );
	var  load  = document.getElementById( load_id );

	var action = form.action;



	form.action = action + "&" + submit + "=1&view=submit";

	form.target = frame.getAttribute( "name" );
	form.submit();
	form.reset();

	load.innerHTML = "uploading....";

	frame.onload = function()
	{
		params = "&upd=" + update_id + "&ajx=1";

		jQuery.get( action + params,  function( data ){ $( "#" + update_id ).html( data );  } );



	}


	return false;

}

function addToFavorites( id )
{
	var update_id = "add-fav-field";
	
	var action  = document.getElementById( id ).href;

	
	var params = "&upd=" + update_id + "&ajx=1";

	jQuery.get( action + params,  function( data ){ $( "#" + update_id ).html( data ); toggleActionsPanel("add-fav-field");} );

	return false;
}

function setInnerCode( parameters )
{

	var area = $( "#code" );
	
	if( !area || ( area[0].tagName.toLowerCase() != "textarea" ) )
	{
		return false;
	}
		
	var url = $( "#code_url" ).val();
	
	var params = { width: 450, height: 403 };
	
	for( p_value in parameters )
	{
		    params[ p_value ] = parameters[ p_value ];
	};
	
	if( params.bnColor )
	{
		url += "&bnColor=" + params.bnColor;
	};

	if( params.bnColor )
	{
		url += "&bgColor=" + params.bgColor;
	};
	
	var  code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"  width="' + params.width + '" height="' + params.height + '"><param name="movie"  value="' + url + '"><param name="quality" value="high"><embed src="' + url + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"  type="application/x-shockwave-flash" width="' + params.width + '" height="' + params.height + '"></embed></object>';
        
	area.val( code );
}