                                                                /*
	BLOG JS FILE
	
		Contains following Code:
			Gallery Slide on the top of the page
			Blog Paginations
			
		Author: RR 
		Date: 9/22
		
		Last Update:
			Author:
			Date: 
			Update Description:


*/

// Gallery Slide

function slideSwitch() {
    try{
		var $active = $('#slideshow .active');

		if ( $active.length == 0 ) $active = $('#slideshow .slideShowContent:last');
	
		var $next =  $active.next().length ? $active.next()
			: $('#slideshow .slideShowContent:first');
	
	
		$active.animate({opacity: 0.0}, 2000, function(){
			$(this).removeClass('active').addClass('last-active');
		});
	
		$next.css({opacity: 0.0})
			.addClass('active').removeClass('last-active')
			.animate({opacity: 1.0}, 2000, function() {
				$active.animate({opacity: 0.0}, 2000).removeClass('active').addClass('last-active');
			});
	}catch(err){}
}

// ------------------- END Gallery Slide ------------------------- //




// Pagination

var pageSize = 4; // number of images displayed on page
var imagesParent = ".ct-container .blog-container"; // HTML container where the the image are found
var nextButton = ".next"; // class or id of the Next button
var previousButton = ".prev"; // class or id of the Previous button
var paginationNumberContainer = ".paginate"; // container for page numbers
var pageNumberAnchor = true; // this will create page number links inside "paginationNumberContainer" element. false will turn the function off



var numberOfImages = $(imagesParent).length; 

function dispPage(pageNum){	
try{
	var listItems = $(imagesParent);
	var pageMax = Math.ceil($(imagesParent).length / pageSize);
	
	
	// checks for images
	if(listItems.length > pageSize){
		$(listItems).hide();
		for(i=((pageSize*pageNum) - pageSize);i<pageSize*pageNum; i++){
			   if(listItems[i]!=undefined)
					$(listItems[i]).show();  
		}
		
		
		
		// functions next and previous buttons
			$(nextButton).unbind().click(function(){  
				pageNum = parseFloat(pageNum);								
				dispPage(pageNum+1);
				return false;
			});
			
			$(previousButton).unbind().click(function(){
				pageNum = parseFloat(pageNum);	
				dispPage((pageNum)-1);
				return false;
			});
			
			
		
		// display of next and previous buttons
	 	if(pageNum == 1){
			$(previousButton).hide();
			$(nextButton).show();

		}else if(pageNum == pageMax){
			$(nextButton).hide();
			$(previousButton).show();
			
		}else{					
			$(previousButton).show();
			$(nextButton).show();
		}

	}else{ // if no images listed
		
		$(nextButton).hide();
		$(previousButton).hide();
		$(".pagination").hide(); // RR
	}

	
	// creating pagination numbers links
	if(listItems.length > pageSize){
		if(!!pageNumberAnchor){
			for(x=1; x<pageMax+1;x++){
				$(paginationNumberContainer).append("<a href='javascript:;' rel='"+x+"'>"+x+"</a>");			
			}
			pageNumberAnchor = false;
		}	
		
		$(paginationNumberContainer+ " a").removeClass("pageSelect");
	$(paginationNumberContainer+ " a:eq("+(pageNum-1)+")").addClass("pageSelect");
	}else{
		$(".pagination").hide(); // RR
	}

	// pagination selected states and function
	$(paginationNumberContainer+ " a").unbind().click(function(){
				var pageNumberRel = $(this).attr('rel');
				var PageNumberRel = parseFloat(pageNumberRel);
				$(paginationNumberContainer+ " a").removeClass("pageSelect");
				
				dispPage(pageNumberRel);
				$(this).addClass("pageSelect");
				return false
				
		});

}catch(err){}
}


// ------------------- END Pagination ------------------- //




$(function(){

// runs gallery slides
$('#slideshow .slideShowContent:first').addClass("active");
setInterval( "slideSwitch()", 15000 );

// runs pagination
dispPage(1);


$('p.tags').each(function(){
    var x = $(this).html(); 
    lastComma = x.lastIndexOf(",");
    x = x.substring(0, lastComma);
    $(this).html(x+'</a>');
});
});

/*$(document).ready( function() {
	$("img").rightClick( function(e) {
		alert('hi');
	});
});*/