/**
 * @author Liviu Maftuleac
 * liviu.maftuleac@gmail.com
 */


CustomPager = {

	content:null,
	NextPage:null,
	needHeight :null,
	curentHeight :null,
	clicks :null,
	pages:null,
	btn:null,

	MovePage:function(){
		if(CustomPager.clicks<CustomPager.pages){
			CustomPager.content.css({
				'height':CustomPager.content.get(0).offsetHeight+CustomPager.needHeight+'px'
			})
			CustomPager.NextPage.css({
				'top':CustomPager.content.get(0).offsetHeight-28+'px'
			});
			
		}
		else{
			if (CustomPager.clicks == CustomPager.pages) {
				CustomPager.content.css({
					'height':'auto'
				});
				CustomPager.killPager();
			}
		}
	},
	
	killPager:function() {
		this.NextPage.hide();
	},
	
	getCurrentHeight: function() {
		return CustomPager.content.get(0).offsetHeight
	},
	
	initPager: function(measured,wrapper){
		CustomPager.content = $(wrapper);

		
		if (typeof(measured)=='number'){
			CustomPager.needHeight=measured;
		}
		if (typeof(measured)=='string'){
			CustomPager.needHeight = $(measured).get(0).offsetHeight;
		}
		CustomPager.curentHeight = CustomPager.content.get(0).offsetHeight;
		CustomPager.clicks = 0;
		
		if (CustomPager.needHeight < CustomPager.curentHeight) {

			CustomPager.content.css({'position':'relative'});
			CustomPager.content.get(0).innerHTML +='<div id="NextPage"><span class="default_button" href="/Steroids-Articles.php"><span>Read More</span></a></div>';
			CustomPager.NextPage = $('#NextPage');
			CustomPager.btn = CustomPager.NextPage.find('span');

			CustomPager.pages = Math.floor(CustomPager.curentHeight / CustomPager.needHeight);
			CustomPager.content.css({
				'height': CustomPager.needHeight + 'px',
				'overflow': 'hidden'
			});
			CustomPager.NextPage.css({'top':CustomPager.needHeight-28});
			CustomPager.btn.click(function(){
				CustomPager.clicks++;
				CustomPager.MovePage();
			});
			
			
		}
		else {
			return false;
		}		
	}
}












