// Toogle

$(document).ready(function(){
	$(".toggle_container").show(); 
	$("h3.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("fast");
	});
});

// -------------------------
// Duyuru
$(document).ready(function(){
	$(".toggle_duyuru").hide(); 
	$("span.trigger_duyuru").click(function(){
		$(this).toggleClass("active").next().slideToggle("fast");
	});
});
// -------------------------

// Duyuru .load
function load_duyuru(dv, cid) {
		$(this).toggleClass("active");
		$("#"+dv).slideToggle("fast");
			jqload(dv, "load_duyuru.php?aid="+cid, "");
}
// -------------------------

/** 
	Pagination
**/
$(document).ready(function(){  
//how much items per page to show  
var show_per_page = 10;  
//getting the amount of elements inside content div  
var number_of_items = $('#paginate').children().size();  
//calculate the number of pages we are going to have  
var number_of_pages = Math.ceil(number_of_items/show_per_page);  

//set the value of our hidden input fields  
$('#current_page').val(0);  
$('#show_per_page').val(show_per_page);  

//now when we got all we need for the navigation let's make it '  

/* 
what are we going to have in the navigation? 
   - link to previous page 
   - links to specific pages 
   - link to next page 
*/
var navigation_html = '';
if(number_of_pages >1) {
 navigation_html += '<a class="previous_link" href="javascript:previous();">Önceki</a>';  
}
var current_link = 0;  
while(number_of_pages > current_link){  
   navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';  
   current_link++;  
}  
if(number_of_pages >1) {
navigation_html += '<a class="next_link" href="javascript:next();">Sonraki</a>';
}
// ***************
navigation_html += '<span>Toplam <b>'+ number_of_items +'</b> kayıt.</span>';   
$('#page_navigation').html(navigation_html);  
//add active_page class to the first page link  
$('#page_navigation .page_link:first').addClass('active_page');  
//hide all the elements inside content div  
$('#paginate').children().css('display', 'none');  
//and show the first n (show_per_page) elements  
$('#paginate').children().slice(0, show_per_page).css('display', 'block');  
});  
function previous(){  
new_page = parseInt($('#current_page').val()) - 1;  
//if there is an item before the current active link run the function  
if($('.active_page').prev('.page_link').length==true){  
   go_to_page(new_page);  
}  
}  
function next(){  
new_page = parseInt($('#current_page').val()) + 1;  
//if there is an item after the current active link run the function  
if($('.active_page').next('.page_link').length==true){  
   go_to_page(new_page);  
}  
}  
function go_to_page(page_num){  
//get the number of items shown per page  
var show_per_page = parseInt($('#show_per_page').val());  
//get the element number where to start the slice from  
start_from = page_num * show_per_page;  
//get the element number where to end the slice  
end_on = start_from + show_per_page;  
//hide all children elements of content div, get specific items and show them  
$('#paginate').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');  
/*get the page link that has longdesc attribute of the current page and add active_page class to it 
and remove that class from previously active page link*/  
$('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');  
//update the current page input field  
$('#current_page').val(page_num);  
}  
// -------------------------

/** 
	JQ SimpleTabs
**/
$(document).ready(function() {
	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
});
// -------------------------

/* 
	Ajax Tabs
*/
var containerId = '#tab_content';
var tabsId = '#tabs';
$(document).ready(function(){
     // Preload tab on page load
     if($(tabsId + ' LI.active A').length > 0){
          loadTab($(tabsId + ' LI.active A'));
     }
     $(tabsId + ' A').click(function(){
          if($(this).parent().hasClass('active')){ return false; }
          $(tabsId + ' LI.active').removeClass('active');
          $(this).parent().addClass('active');
          loadTab($(this));
          return false;
     });
});
function loadTab(tabObj){
     if(!tabObj || !tabObj.length){ return; }
     // (containerId).addClass('loading');
	 $(containerId).hide();
     $(containerId).fadeOut('fast');
	 $("#preloader").show();
     $(containerId).load(tabObj.attr('href'), function(){
 	//  (containerId).removeClass('loading');
	 $("#preloader").hide();
	 $(containerId).show();
     $(containerId).fadeIn('fast');
     });
}
/* Sample HTML
	<ul id="tabs">
		<li><a href="./tabs/tab-1.html">Tab 1</a></li>
		<li><a href="./tabs/tab-2.html">Tab 2</a></li>
		<li><a href="./tabs/tab-3.html">Tab 3</a></li>
	</ul>
 <div id="tab_content">Loading. Please Wait...</div>
*/
// -------------------------

