(function($){

$.fn.caseStudies_function=function(){ 

ranked_arrayIndex=0;
recent_arrayIndex=0;

nosRecent=$('.recent_caseStudy_element').length-1;
nosRanked=$('.ranked_caseStudy_element').length-1;
//alert($('.recent_caseStudy_element').length);
//alert(nosRecent);

$('.recent_caseStudy_element').click(function(){
$('.recent_caseStudy_element').css({'background-position':'top'});
$(this).css({'background-position':'bottom'});
$('.recent_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$(this).attr('defaultImage'));
recent_arrayIndex=$(this).attr('arrayIndex');
//alert(recent_arrayIndex);
})

$('.ranked_caseStudy_element').click(function(){
$('.ranked_caseStudy_element').css({'background-position':'top'});
$(this).css({'background-position':'bottom'});											  
$('.ranked_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$(this).attr('defaultImage'));
ranked_arrayIndex=$(this).attr('arrayIndex');
//alert(ranked_arrayIndex);
})




$('.caseStudiesNextBtn').click(function(){

if($(this).attr('rankedRecent')=='ranked'){
if(ranked_arrayIndex==nosRanked){
ranked_arrayIndex=0}
else{ranked_arrayIndex++;}
$('.ranked_caseStudy_element').css({'background-position':'top'});
$('#ranked_caseStudy_element_'+ranked_arrayIndex).css({'background-position':'bottom'});											  
$('.ranked_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$('#ranked_caseStudy_element_'+ranked_arrayIndex).attr('defaultImage'));
}

if($(this).attr('rankedRecent')=='recent'){
if(recent_arrayIndex==nosRecent){
recent_arrayIndex=0}
else{recent_arrayIndex++;}
$('.recent_caseStudy_element').css({'background-position':'top'});
$('#recent_caseStudy_element_'+recent_arrayIndex).css({'background-position':'bottom'});											  
$('.recent_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$('#recent_caseStudy_element_'+recent_arrayIndex).attr('defaultImage'));
}



})



$('.caseStudiesPreviousBtn').click(function(){

if($(this).attr('rankedRecent')=='ranked'){
if(ranked_arrayIndex==0){
ranked_arrayIndex=nosRanked;}
else{ranked_arrayIndex--;}
$('.ranked_caseStudy_element').css({'background-position':'top'});
$('#ranked_caseStudy_element_'+ranked_arrayIndex).css({'background-position':'bottom'});										  
$('.ranked_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$('#ranked_caseStudy_element_'+ranked_arrayIndex).attr('defaultImage'));
}

if($(this).attr('rankedRecent')=='recent'){
if(recent_arrayIndex==0){
recent_arrayIndex=nosRecent;}
else{recent_arrayIndex--;}
$('.recent_caseStudy_element').css({'background-position':'top'});
$('#recent_caseStudy_element_'+recent_arrayIndex).css({'background-position':'bottom'});										  
$('.recent_caseStudy_thumbnail').attr('src','CMS/files/medium/'+$('#recent_caseStudy_element_'+recent_arrayIndex).attr('defaultImage'));
}



})








$('.readMore').click(function(event){
event.stopPropagation();
//alert('readmore');
loadPage=$(this).attr('linkTo');											   
window.location=loadPage;	
})


//CLOSE CASE STUDIES FUNCTION
}
				
	
// CLOSE FUNCTION
})(jQuery);		
