$(function(){
total_con=$("#total_con").text();
total_rows=$("#total_rows").text();
max_con=$("#max_con").text();
cat_id=$("#cat_id").attr("value");
cat_name=$("#cat_name").attr("value");
current_con=1;
i=0;







////////////////////////////next_search/////////////////////////////
////////////////////////////next_search/////////////////////////////


$("#next_num_search").bind("click",function(){

	
if(current_con<total_con){

current_con++;
table=$(this).attr("lang");sort_by=$(this).attr("sort_by");
num_rows=$(this).attr("max");sort=$(this).attr("sort");
search=$(this).attr("search");search_type=$(this).attr("search_type");
end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);

var_encrypt='';
$('.encrypt_var').each(function(){
var_encrypt+=$(this).attr('name')+","+$(this).val()+"####";
	
});

//alert(var_encrypt);


current_mod=(current_con-1)%max_con;

//فى حالة عدم وجود الرقم التالى
if(current_mod!=0){
$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");
$("#next_num_search").attr("alt",Math.round((eval($("#next_num_search").attr("alt"))))+1);	
$("#prev_num_search").attr("alt",Math.round((eval($("#prev_num_search").attr("alt"))))+1);

}else{


from=Math.round((eval((current_con))))-1 + Math.round((eval((max_con)))) ;
to=(Math.round((eval(from)))-Math.round((eval(max_con))))+1;	

//alert(from);
//alert(to);
$(".num_con_search").show();
for(i=from;i>=to;i--){
before=i-max_con;

$("#num_con_search"+before).attr("alt",i);
$("#num_con_search"+before).text(i);
$("#num_con_search"+before).attr("id","num_con_search"+i);	

if(i>total_con){ $("#num_con_search"+i).hide(); }
}

$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");

}

page=$("#load_page").html();
page=page+".php";
$("#load_wait").show();

$("#news_cont").load(page,{
"cat":'',
'search':search ,'search_type':search_type ,'sort':sort ,'sort_by':sort_by ,
"table":table ,
"start":start ,
"var_encrypt":var_encrypt,
"end":end ,
"num_rows":num_rows ,
"cat_id":cat_id ,
"cat_name":cat_name 
},function(){

if (end>total_rows){ end=total_rows	}
$("#rows_range").html((end+1)+"-"+(start+1));

$("#load_wait").hide();


	
});
}

});









////////////////////////////prev_search/////////////////////////////
////////////////////////////prev_search/////////////////////////////



$("#prev_num_search").on("click",function(){	
//alert(current_con);

if(current_con>1){
current_con--;
table=$(this).attr("lang");sort_by=$(this).attr("sort_by");
num_rows=$(this).attr("max");sort=$(this).attr("sort");
search=$(this).attr("search");search_type=$(this).attr("search_type");
end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);

current_mod=(current_con)%max_con;

var_encrypt='';
$('.encrypt_var').each(function(){
var_encrypt+=$(this).attr('name')+","+$(this).val()+"####";
	
});

//فى حالة عدم وجود الرقم التالى
if(current_mod!=0){
$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");
$("#next_num_search").attr("alt",Math.round((eval($("#next_num_search").attr("alt"))))-1);	
$("#prev_num_search").attr("alt",Math.round((eval($("#prev_num_search").attr("alt"))))-1);

//alert(current_con);
}else{

from=current_con ;
to=Math.round((eval((current_con))))-Math.round((eval((max_con))))+1;	
//alert(from);
//alert(to);
$(".num_con_search").show();
for(i=from;i>=to;i--){
before=Math.round((eval(i)))+Math.round((eval(max_con)));

$("#num_con_search"+before).attr("alt",i);
$("#num_con_search"+before).text(i);
$("#num_con_search"+before).attr("id","num_con_search"+i);	

if(i>total_con){ $("#num_con_search"+i).hide(); }
}

$(".num_con_search").removeClass("num_active");
$("#num_con_search"+current_con).addClass("num_active");

}

page=$("#load_page").html();
page=page+".php";
$("#load_wait").show();

$("#news_cont").load(page,{
"cat":'',
'search':search ,'search_type':search_type ,'sort':sort ,'sort_by':sort_by ,
"table":table ,
"start":start ,"var_encrypt":var_encrypt,
"end":end ,
"num_rows":num_rows ,
"cat_id":cat_id ,
"cat_name":cat_name
},function(){

if (end>total_rows){ end=total_rows	}
$("#rows_range").html((end+1)+"-"+(start+1));
$("#load_wait").hide();


	
});
}

});







////////////////////////////num_con_search/////////////////////////////
////////////////////////////num_con_search/////////////////////////////

$(".num_con_search").not('#next_num_search , #prev_num_search').bind("click",function(){
total_con=$("#total_con").text();
if ($(this).attr("class")!='num_con_search num_active'){

$(".num_con_search").removeClass("num_active");
$(this).addClass("num_active");

current_con=$(this).attr("alt");
table=$(this).attr("lang");
sort_by=$(this).attr("sort_by");
num_rows=$(this).attr("max");
sort=$(this).attr("sort");
search=$(this).attr("search");
search_type=$(this).attr("search_type");

var_encrypt='';
$('.encrypt_var').each(function(){
var_encrypt+=$(this).attr('name')+","+$(this).val()+"####";
	
});


page=$("#load_page").html();
page=page+".php";
$("#load_wait").show();

end=(Math.round((eval(current_con)))* Math.round((eval(num_rows))))-1;
start=Math.round((eval(end)))-(Math.round((eval(num_rows)))-1);


var_encrypt='';
$('.encrypt_var').each(function(){
var_encrypt+=$(this).attr('name')+","+$(this).val()+"####";
	
});

//alert(current_con);
//alert(table);
//alert(num_rows);
//alert(search_type);
//alert(page);
//alert(end);
//alert(start);
//alert(cat_id);


$("#next_num").attr("alt",Math.round((eval(current_con)))+1);
$("#prev_num").attr("alt",Math.round((eval(current_con)))-1);

$("#load_wait").show();

$("#news_cont").load(page,{
"cat":'',
'search':search ,'search_type':search_type ,'sort':sort ,'sort_by':sort_by ,
"table":table ,
"start":start ,"var_encrypt":var_encrypt,
"end":end ,
"num_rows":num_rows ,
"cat_id":cat_id ,
"cat_name":cat_name
},function(){
$("#load_wait").hide();

});	

}
//alert("S");
});



















	
});


