// JavaScript Document

var isLoading = false ;


// function that show a subcategory div and hides the active one
function showItems( id, tp )
{
	
	obj1 = document.getElementById( 'subcat_'+id );
	if( activeItems != obj1 )
	{
		if ( activeItems )
		{
			activeItems.style.display='none';
		}
		obj1.style.display='block';
		activeItems = obj1;
	}
	else
	{
		obj1.style.display='none';
		activeItems = null;
	}
	total_pages = tp;
	
	
}

function activateCateg( id )
{
	activeItems = document.getElementById( 'subcat_'+id );	
}

function nextPage( ids )
{
	if( !isLoading )
	{
	page_number++;
	displayNav( ids ) ;
//	alert( ' next ');	
		isLoading = true ;	
	}
}

function prevPage( ids )
{
	if( !isLoading )
	{
	page_number--;
	displayNav( ids ) ;
//	alert( ' next ');	
		isLoading = true ;	
	}
}

function displayNav( ids )
{
	
	for( i=0; i<30; i++)
	{
		categoryItemContent = '<div class="popularItem">                    	<div class="pic90"></div>                        <div class="flft" style="width:110px;"><b><a href="#">Loading ..</a></b></div>                        <div class="flft" style="width:110px;font-size:10px;">0 views</div>                    </div>';
		eval( 'obj=document.getElementById( \'categoryItem_'+i+ '\' );');
		obj.innerHTML = categoryItemContent ;
		
	}
	
	document.getElementById('pgNav').innerHTML = '';
	if( page_number > 1 ) 
		document.getElementById('pgNav').innerHTML += '<div class="prevPage" onclick="javascript:prevPage(\''+ids+'\');"></div>';
	if( page_number < total_pages ) 
		document.getElementById('pgNav').innerHTML += '<div class="nextPage" onclick="javascript:nextPage(\''+ids+'\');"></div>';
	document.getElementById('pgNav').innerHTML += 'Page '+page_number+' / '+total_pages;
	
	categoryItemsCall( ids );
}

/***
 *	Functie ce afiseaza noile contenturi din featured additions
 **/
function categoryItemsShow()
{ 
	//alert( ajax.response );
	z = 0 ;
	eval( 'var ar = ' + ajax.response + ';' ) ;
	for ( x in ar )
	{
		y = ar[x] ;
		//alert(y.key );
		featureItemContent = '		<div class="popularItem">                    	<div class="pic90"><a href="'+root_path+'show/'+y.key+'/'+y.file+'"><img src="'+root_path+'data/thumbs/ff_'+y.key+'.jpg" width="90" height="67" border="0"></a></div>                        <div class="flft" style="width:110px;"><b><a href="'+root_path+'show/'+y.key+'/'+y.file+'">'+y.title+'</a></b></div>                        <div class="flft" style="width:110px;font-size:10px;">'+y.views+' views</div>                    </div>';
		eval( 'obj=document.getElementById( \'categoryItem_'+x+ '\' );');
//		alert( x );
		if ( x< 30 )
		{
			obj.innerHTML = featureItemContent ;
			z = x ;			
		}
	}
//	alert( z );
	if( z )
	for( i=++z; i<30; i++)
	{
		categoryItemContent = '<div class="popularItem"></div>';
		eval( 'obj=document.getElementById( \'categoryItem_'+i+ '\' );');
		obj.innerHTML = categoryItemContent ;
		
	}
		isLoading = false ;		
}


function categoryItemsCall( ids  )
{
	ajax.requestFile = '../../application/ajax/www/categoryItems.php?page='+page_number+'&ks=' + ids;	// Specifying which file to get
	ajax.onCompletion = categoryItemsShow;	// Specify function that will be executed after file has been found
	ajax.runAJAX();		// Execute AJAX function		
}

function initNav( pg_nr, total_pg )
{
	total_pages = total_pg     ;
	page_number = pg_nr ;
}

	var activeItems = null ;
	var page_number = 1 ;
	var total_pages = 0 ;