
	
	$(document).ready( function() {
		build_search_show( page_show );
		build_search_video( page_video );
	});
	function build_search_tag(p, cm)
	{
		build_search_show(p,cm)
	}
	// S H O W S
	function build_search_show( p , cm)
	{
		if ( !p ) p = page_show;
			else page_show = p;

		before_server_call_show();

		if ( cm && cm == 1 )
			_click_made = true;
		
		// call the server.
		server_post( { m : 'build_search_tag' , act : 'show' , page : p , tag_id : tag_id , filter:filter_show } , server_callback_show );
	}
	
	function after_search_load_show()
	{
		$('#forScriptShow > #filter_d > #filter').change(function() {
			t = document.location.href.split('#');
			v = $(this).val();
			v = v.split('/');
			filter_show = v[1];
			build_search_show( page_show );
		});
	}
	
	function before_server_call_show()
	{
		// show loader
		$('#forScriptShow').empty().append( loader() );
	}
	
	function before_server_call(){};
	function server_callback(){};
	
	function server_callback_show( data ) {
			
			if ( data['err'] ) {
				// display_error can be found in the utils.js ; for start it alerts the error text
				display_error( data['err'] );
			}else if ( data['server'] &&  data['server']['data'] ){
				// we got the html from the server. now let us build the page.
				// clearer() retunr a div with style clear:both with height as parameter. found in utils.js
				$('#forScriptShow').empty().append( data['server']['data'] );
				$('#forScriptShow').append( clearer(1) ).append( data['server']['pagination'] );
				$('#forScriptShow > #simple_pagination').clone().prependTo('#forScriptShow').after( clearer(5) );
				$('#forScriptShow').prepend( data['server']['filter'] );
			}
			after_search_load_show();
	}
	
	
	// V I D E O
	function build_search_video( p , cm)
	{
		if ( !p )	p = page_video;
			else	page_video = p;

		$('#forScriptVideo').empty().append( loader() );

		// call the server.
		no_history_server_post( { m : 'build_search_tag' , act : 'video' , page : p , tag_id : tag_id , filter:filter_video  } , server_callback_video );
	}
	
	function server_callback_video( data ) {
		if ( data['err'] ) {
			// display_error can be found in the utils.js ; for start it alerts the error text
			display_error( data['err'] );
		}else if ( data['server'] &&  data['server']['data'] ){
			// we got the html from the server. now let us build the page.
			// clearer() retunr a div with style clear:both with height as parameter. found in utils.js
			$('#forScriptVideo').empty().append( data['server']['data'] ).after( clearer() );
			$('#forScriptVideo').append( clearer(1) ).append( data['server']['pagination'] );
			$('#forScriptVideo > #simple_pagination').clone().prependTo('#forScriptVideo').after( clearer(5) );
			
			$('#forScriptVideo').prepend( data['server']['filter'] );
		}
		
		$('#forScriptVideo > #filter_d > #filter').change( function() {
			t = document.location.href.split('#');
			v = $(this).val();
			v = v.split('/');
			filter_video = v[1];
			build_search_video( page_video );
		});
	}