var caption = null;
var captionS = false;
var slides = null;
var strip = null;
var imgElm = null
var mainImg = null
var timeo = null;
var hnotice = null;
var backissues = null;
var hash = null;
var tabs = null;
var login = null;
var loginf = null;
var loginlvl = 2;
var tabs_array = null;
var tabs_active = 0;
var morelike = null;
var morelikes = true;
var morelikev = null;
var morelikevs = true;
var feedbt = null;
var subscribeform = null;

$(document).ready(function(){

	// subscription section
	subscribeform = $('div#subscribeForm');
	if (subscribeform.length > 0) {
		doSubscriptionSelection();
	}

	// clear newsletter signup
	var blogsign = $('form.blogsignup').find('#email');
	if (blogsign.length > 0) {
		blogsign.focus(function(){
			if (blogsign.attr('value') == 'Your email address') {
				blogsign.attr('value','');
			}
		});
	}
	


	// slideshow
	imgElm = $('.img_gallery_img');
	caption = $('.caption_panel');
	initCaption();
	
	slides = $('.gallery_thumbnails');
	if (slides.length > 0) {
		mainImg = $('.img_gallery_img img');
		initSlides();
	}


	// comments
	hnotice = $('p.hnotice');
	if (hnotice.length > 0) {
		hnotice.hide();
		hnotice.prev().find('a').click(function(me){
			me.preventDefault();
			hnotice.slideToggle(200);
			return false;
		});
	}
	
	backissues = $('div.years');
	if(backissues.length > 0){
		
		hash = location.hash;
		hash = hash.substring(1);
		
		initBackIssues();
		//console.log("--"+hash);
	}
	
	
	// locked content
	loginf = $('a#loginfunc');
	if (loginf.attr('rel') == 1) {
		loginlvl = 1;
	}
	if (loginf.length > 0) {
		login = $('li#usertype').attr('rel');
		loginf.parent().wrap('<div id="dynamicdiv"></div>');
		loginf = $('div#dynamicdiv');
		if (login == 2) {
			// normal user
				loginf.load('/dynamic.php?page_id=254',function(){
				hijackSubscription();
			});		
		} else if (login == 1) {
			// not logged in
			loginf.load('/dynamic.php?page_id=26',function(){
				hijackLogin();
			});			
		}
	}	
	
	// more like this
	morelike = $('a#morelike');
	if (morelike.length > 0) {
		morelike.click(function(me){
			me.preventDefault();
			if (morelikes) {
				var terms = $('p#morelikek').html();
				var id = $('p#morelikeid').html();
				var post = '"'+terms+'"';
				var url = '/home/helpers/more-like-this';
				if (morelike.hasClass('crtv')) {
					url = '/home/helpers/more-like-this-crtv';
				} 
				morelike.next().slideUp();
				$.post(url,{ keywords : terms, pageid : id },function(data) {
					morelike.next().find('ul').append(data);
					morelike.next().slideDown();
				});
				morelikes = false;
			} 
			return false;
		});
	}

	// blog tabs
	tabs = $('#statistic div.tab');
	if(tabs.length > 0){
		initTabs();
	}
	
	// feed button
	feedbt = $('div#feed_bar input');
	if (feedbt.length > 0) {
		feedbt.hide();
		$('div#feed_bar form').change(function(){
			$(this).submit();
		});
	}
	
	
	// new feed button for subjectFeed
	feedbtSubject = $('div.subjectFeed input');
	if (feedbtSubject.length > 0) {
		feedbtSubject.hide();
		$('div.subjectFeed select').change(function(){
			$('div.subjectFeed form').submit();
		});
	}
	
	// new feed button for monthFeed
	feedbtMonth = $('div.monthFeed input');
	if (feedbtMonth.length > 0) {
		feedbtMonth.hide();
		$('div.monthFeed select').change(function(){
			$('div.monthFeed form').submit();
		});
	}
		
	
	// soldout
	soldout = $('table.pbi span.soldout');
	if (soldout.length > 0) {
		soldout.each(function(){
			$(this).parent().parent().parent().remove();
		});
	}
	
});

$(window).load(function() {
	// panel rollovers
	// looks for hilite, videoh classes
	// structure of panel needs to be <div><a class="header"></a><a class="desc"></a></div>
	// current row classes for adjusting heights cases bg_hpcen, bg_hptop
	hpanels = $('div.hilite');
	if (hpanels.length > 0) {
		hpanels.each(function() {
			var obj = $(this);
			var desc = obj.find('a.desc');
			var parent = obj.parent();
			var h = desc.find('img').height()+desc.find('div.text').height()+30;
			if (parent.hasClass('bg_hpcen') || parent.hasClass('bg_hptop') || parent.hasClass('bb1') || parent.hasClass('bg_issuec') || parent.hasClass('bt1') || parent.hasClass('crtvrow')) {
				h = parent.height() - obj.find('a.header').height();
			}
			if (parent.hasClass('fl') && !(parent.parent().parent().hasClass('col_right')) && !(parent.hasClass('w760')) && !(parent.hasClass('w189'))) {
				h = parent.parent().height() - obj.find('a.header').height();
			}
			desc.wrap('<a href="'+desc.attr('href')+'" class="hilitewrap" style="height:'+h+'px;position:relative;display:block;overflow:hidden"></a>');
			
			if ($.browser.msie && $.browser.version <= 6 ) $(".hilitewrap").css("display", "inline" );

			var w = desc.width();
			var v = '';
			var clss = 'largepanel';
			if (obj.hasClass('videoh')) {v = 'v';} 
			if (w < 300) {clss='smallpanel';}
			obj.find('a.hilitewrap').hover(function(){
				desc.after('<div class="'+clss+v+'" style="height:'+h+'px;width:'+w+'px">&nbsp;</div>');
			},function() {
				obj.find('div.'+clss+v).remove();
			});
		});
	}
	
	fpanels = $('div.feedhilite');
	if (fpanels.length > 0) {
		fpanels.each(function(){
			var obj = $(this);
			var desc = obj.find('a.desc');
			var h = obj.find('a.cl').height() + obj.find('a.desc').height()+20;
			obj.css('position','relative');
			obj.hover(function(){
				obj.append('<div class="smallpanel" style="height:'+h+'px;">&nbsp;</div>');
			},function(){
				obj.find('div.smallpanel').remove();
			});
			obj.click(function(me){
				me.preventDefault();
				window.location.href = (desc.attr('href'));
				return false;
			});
			
			
		});
	
	}
});


function doSubscriptionSelection() {

	var cells = subscribeform.find('td.default');
	subscribeform.find('input.proceed').before('<input type="hidden" name="type" class="hdntype" value="" />');
	var lastactive = null;
	var counter = 0;
	cells.each(function(){
		var inp = $(this).find('input#type');
		var lbl = inp.next();
		var value = inp.val();
		var prices = lbl.attr('rel');
		var text = lbl.text();
		var btn = null;
		if (inp.is(':checked')) {
			var triggerflag = true;
		} else {
			var triggerflag = false;
		}
		
		if ($(this).parent().next().hasClass('toggleBox')) {
			inp.before('<button class="toggle" rel="'+prices+'" value="'+value+'"><span rel="'+value+'"><em>'+text+'</em></span></button>');
			$(this).parent().next().hide();
		} else {
			inp.before('<button rel="'+prices+'" value="'+value+'"><span rel="'+value+'"><em>'+text+'</em></span></button>');
		}
		btn = $(this).find('button');
		inp.remove();lbl.remove();
		var hdninput = $('input.hdntype');
		
		$(this).removeClass('default');
		btn.click(function(me){
			me.preventDefault();
			var istoggle = $(this).hasClass('toggle');
			if (lastactive != null) {
				lastactive.removeClass('active');
				if (lastactive.hasClass('toggle')) {
					lastactive.parent().parent().next().hide();
				}
			}
			var labeltemp = $(this).html();
			$(this).html('');
			hdninput.val($(this).attr('value'));
			$(this).html(labeltemp);
			
			$(this).addClass('active');
			lastactive = $(this);
			if (istoggle) {
				$(this).parent().parent().next().show();
			}
			
			return false;
		});
		if (triggerflag) {
			btn.trigger('click');
		}
		counter++;
	
	});


	var select = subscribeform.find('select#country');
	var curr_region = subscribeform.find(':selected').attr('rel');
	showRegionPrices(curr_region);
	select.change(function(me){
		curr_region = subscribeform.find(':selected').attr('rel');
		showRegionPrices(curr_region)
	});

	// find td with class default
	// find input id type and label read out values
	// replace label and input with button
	//	<button class="toggle active">
	//		<span><em>1 year subscription</em>&pound;64.00 (Save 7%)</span>
	//	</button>
	// change class on td to toggleBox if there are gifts, remove default class



}



function showRegionPrices(curr_region) {
	var labels = subscribeform.find('button');
	var curr_region_no = 0;
	if (curr_region == 'UK') curr_region_no = 0;
	if (curr_region == 'EU' || curr_region == 'USA') curr_region_no = 1;
	if (curr_region == 'ROW') curr_region_no = 2;
	labels.each(function(){
		curr_label = $(this);
		//if (curr_label.attr('for') == 'type') {
			var prices = curr_label.attr('rel').split(',');
			curr_label.html('<span><em>'+curr_label.find('em').text()+'</em>'+'&#xA3;' + prices[curr_region_no]+'</span>');
		//}
	
	});
}


function hijackSubscription() {
	if (loginlvl == 1) {
		// we're only on the feed so we don't really need this info... add a link to bypass this
		loginf.find('.login').after('<a class="header" href="/feed/submit-work"><span>Continue to feed submission without adding the subscription details.</span>');	
	}
	loginf.find('form').submit(function(me){
		me.preventDefault();
		var theform = $(this);
		var target = theform.attr('action');
		temp = target.split('?');
		target = '/dynamic.php?'+temp[1];
		var u = theform.find('#sid').val();
		var p = theform.find('#postcode').val();
		var params = {submit:'Add subscription',sid:u,postcode:p}
		params = $.param(params);	

		loginf.slideUp('slow',function(){
			$.post(target,params,function(data){
				if (data.length == 0) {
					// we've got the subscription information correct we can reload the page
					var sURL = unescape(window.location.pathname);
					window.location.replace(sURL);
				} else {
					loginf.html(data);
					loginf.slideDown();
					hijackSubscription();
				}
			});
		});
		return false;
	});
}

function hijackLogin() {
	loginf.find('form').submit(function(me){
		me.preventDefault();
		var theform = $(this);
		var target = theform.attr('action');
		temp = target.split('?');
		target = '/dynamic.php?'+temp[1];
		var u = theform.find('#username').val();
		var p = theform.find('#password').val();
		var pc = theform.find('#postcode').val();
		var sd = theform.find('#sid').val();
		var sm = theform.find('#submit').val();
		var params = {submit:sm,username:u,password:p,postcode:pc,sid:sd}
		params = $.param(params);
		loginf.slideUp('slow',function(){
			$.post(target,params,function(data){
			// here we need to see what happend and either hijack again or reload the page
				//if (data.length == 0) {
				if (data.indexOf('id="loggedin"') != -1) {
				// we've logged in... get the status by calling any page for example the home page with just the user value output
					var lstatus = null;
					$.get('/dynamic.php?page_id=3',function(data){
						lstatus = data.substr(data.indexOf('rel="')+5,1);
						if (loginlvl == 1) {
							if (lstatus > 0) {
								var sURL = unescape(window.location.pathname);
								sURL = sURL.substr(0,sURL.indexOf('/actions'));
								//console.log(sURL);
								window.location.replace(sURL);
							} else {
								// we haven't confirmed our email address yet
								$.get('/dynamic.php?page_id=276',function(data){
									loginf.html(data);
									loginf.slideDown();
									
								});
							}
						} else {
							if (lstatus > 1) {
								var sURL = unescape(window.location.pathname);
								window.location.replace(sURL);
							} else {
								// we haven't confirmed our email address yet
								$.get('/dynamic.php?page_id=276',function(data){
									loginf.html(data);
									loginf.slideDown();
									
								});
							}
						}
					});
	
				} else {
					// check if we are having a subscription form but are only logging into  the feed
					if (loginlvl == 1 && data.indexOf('id="sid"') != -1) {
						// we're only on the feed so we don't really need this info... add a link to bypass this
						//loginf.after('<a class="header" href="/feed/submit-work"><span>Continue to Feed submission without adding the subscription details.</span>');	
						// actually just refresh the page
						var sURL = unescape(window.location.pathname);
						sURL = sURL.substr(0,sURL.indexOf('/actions'));
						window.location.replace(sURL);		
					} else {
					
						// we have an error... we need to hijack the form again and go through the same process
						loginf.html(data);
						loginf.slideDown();
						hijackLogin();
					}
				}
			});
		});
	
		return false;
	});
}



function initTabs(){
	tabs_array = new Array();
	var topbar = '<table id="tabs"><tr>';
	var count = 0;
	tabs.each(function(){
		
		var obj = $(this);
		
		if(count == tabs.length-1){
			var title = '<td><a href="#" style="margin-right:0px" rel="'+count+'">'+obj.find('a.header span').text()+'</a></td>';
		}else if (count == 0){
			var title = '<td><a href="#" class="active" rel="'+count+'">'+obj.find('a.header span').text()+'</a></td>';		
		} else {
			var title = '<td><a href="#" rel="'+count+'">'+obj.find('a.header span').text()+'</a></td>';
		}
		obj.find('a.header span').remove();
		var content = obj.find('table');
		tabs_array[count] = [content,null];
		content.css('width','379px');
		if (count != 0) {
			content.hide();
		}
		topbar += title;
		
		count++;
	});
	topbar += "</tr></table>";
	
	$('#statistic').before(topbar);
	
	count = 0;
	$('table#tabs').find('a').each(function(){
		tabs_array[count][1] = $(this);
		$(this).click(function(me){
			me.preventDefault();
			var content = tabs_array[tabs_active][0];
			tabs_array[tabs_active][1].removeClass('active');
			tabs_active = parseInt($(this).attr('rel'));
			content.slideUp('fast',function(){
				tabs_array[tabs_active][1].addClass('active');
				tabs_array[tabs_active][0].slideDown('slow');			
			});
			return false;
		});
		count++;
	});
	

	
}
function initBackIssues(){
	backissues.each(function(){
		var obj = $(this);
		var table = obj.find('table.pbi');
		var link = obj.find('a.header');
		var anchor = link.attr('name');
		//console.log(anchor);
		if(hash != "" && hash == anchor){
			openTable(table);
		}else{
			closeTable(table);
		}
	
		link.click(function(me){
			me.preventDefault();
			if(table.attr("rel") == "open"){
				closeTable(table);
			}else{
				//console.log(anchor);
				openTable(table);
			}
		});
		
	});
}

function openTable(t){
	t.slideDown('fast');
	t.attr("rel","open");
}
function closeTable(t){
	t.slideUp('fast');
	t.attr("rel","close");
}

function initCaption() {
	caption.hide();
	imgElm.hover(function(){
		if (captionS) {
			caption.slideDown(function(){
				captionS = false;
			});
			
		}
	},function(){
		if (!captionS) {
			var c1 = caption.find('h3').html();
			var c2 = caption.find('p').html();
			if (c1 == '' && c2 == '') {
				// do nothing
			} else {
				caption.slideUp(function(){
					captionS = true;
				});
			}							
		}
	});

}

function initSlides() {
	strip = new iStrip(slides);
}


function iStrip(slides) {
	this.me = slides;
	this.strip = $(slides).find('div.thumbswrapper');
	this.container = $(slides).find('div.thumbs');
	this.imgs = new Array();
	this.btn = new Array();
	this.lngth = 0;
	this.cpos = 0;
	this.max = null;
	this.maxp = null;
	this.act = [true,true];
	this.slngth = this.strip.width();
	this.crrImg = null;
	this.init();
	this.firstImg();
	this.time = 650;
	this.mode = false;
	this.busy = false;
	return this;
}


iStrip.prototype.init = function() {
	
	// append the main image as an additional image to the strip
	if (!mainImg.hasClass('placeholder')) {
		this.container.prepend('<a href="'+mainImg.attr('src')+'" sheight="'+mainImg.attr('height')+'" swidth="'+mainImg.attr('width')+'"><img src="'+mainImg.attr('src')+'" height="49" /></a>');
	}
	// do the same scaling here as for the other images: 388px
	
	var newHeight = mainImg.attr('height');
	var imgElmHeight = 388;
	if (newHeight > 388) {
		ImgTopMargin = 0;
		
		// image needs to be scaled down
		scalefactor = (388/newHeight);
		newHeight = Math.round(newHeight * scalefactor);
		newWidth = Math.round(569 * scalefactor);
		ImgRightMargin = Math.round((569 - newWidth)/2);
		//console.log(newHeight);
	} else if (newHeight < 388) {
		ImgTopMargin = Math.round((388 - newHeight)/2);
		ImgRightMargin = 0;
		//	scalefactor = (388/newHeight);
		//	console.log(scalefactor);
		//	newHeight = Math.round(newHeight * scalefactor);
		newWidth = mainImg.attr('width');
	
	} else {
		newWidth = mainImg.attr('width');
		ImgTopMargin = 0;
		ImgRightMargin = 0;
	}

	imgElm.css('height',imgElmHeight+'px');
	mainImg.attr('width',newWidth);
	mainImg.attr('height',newHeight);
	mainImg.attr('style','margin-top:'+ImgTopMargin+'px;margin-left:'+ImgRightMargin+'px');
		
	
	
	
	
	// find all images and set container length
	var obj = this;
	this.container.find('a').each(function(){
		obj.addImg($(this));
	});
	this.container.css('width',this.lngth+10);
	this.max = -((this.lngth-10) - this.slngth);
	this.maxp = 0;
	var l = this.imgs.length;
	for(this.maxp=0;this.maxp<l;this.maxp++) {
		if (this.max >= this.imgs[this.maxp][1]) {
			break;
		}
	}

	// set up buttons
	this.btn[0] = this.me.find('a.prev');
	this.btn[1] = this.me.find('a.next');
	this.btn[0].click(function(me){me.preventDefault();obj.move(-1);return false;});
	this.btn[1].click(function(me){me.preventDefault();obj.move(1);return false;});
	this.ckB();
	
	// mode button
	this.me.find('a.mode').click(function(me) {
		me.preventDefault();
		if (obj.mode) {
			$(this).removeClass('active');
			obj.mode = false;
			
			// scale the current image
			obj.thumbClick(obj.crrImg);
		} else {
			$(this).addClass('active');
			obj.mode = true;
			
			// scale the current image 
			obj.thumbClick(obj.crrImg);
		}
		return false;
	});
	if (mainImg.hasClass('placeholder')) {
		this.thumbClick(0);
	}
}

iStrip.prototype.firstImg = function() {
	imgElm.css('cursor','pointer');
	obj = this;
	if (this.imgs[0][3] == "") {
		imgElm.click(function(me){
			me.preventDefault();
			obj.move(1);
			return false;
		});
	} else {
		var url = this.imgs[0][2];
		imgElm.css('cursor','pointer');
		imgElm.click(function(me){
			me.preventDefault();
			document.location.href = url;
			return false;
		});
	}
	this.activateImg(0);

}

iStrip.prototype.activateImg = function(which) {
	if (this.crrImg != null) {
		this.imgs[this.crrImg][0].removeClass('active');
	}
	this.crrImg = which;
	this.imgs[which][0].addClass('active');
}
iStrip.prototype.addImg = function(img) {

	var w = 92;
	var h = $(img).attr('href');
	var r = $(img).attr('rel');
	var sh = $(img).attr('sheight');
	var sw = $(img).attr('swidth');
	var c = $(img).find('span');
	if (c.length > 0) {
		var c1 = c.eq(0).html();
		var c2 = c.eq(1).html();
	} else {
		// get caption from existing one
		var c1 = caption.find('h3').html();
		var c2 = caption.find('p').html();
	}
	var l = this.imgs.length;
	var obj = this;
	this.imgs.push([img,-this.lngth,h,r,sh,c1,c2,sw]);
	this.lngth +=  w;
	img.mouseover(function(me){
		imgElm.trigger('mouseout');
	});
	img.click(function(me){
		me.preventDefault();
		obj.thumbClick(l);
		return false;
	});
}
iStrip.prototype.thumbClick = function(which) {
	if (this.imgs[which] != null) {
		this.busy = true;
		//console.log($('#largeplayersb'));
		$('#largeplayersb').remove();
		var clickable = false;
		var newImg = null;
		var newHeight = this.imgs[which][4];
		var newWidth = 569;
		if (this.imgs[which][3] == "") {
			newImg = this.imgs[which][2];
		} else {
			// we have a video or slide show
			clickable = true;
			newImg = this.imgs[which][3];
		}
		caption.find('h3').html(this.imgs[which][5]);
		caption.find('p').html(this.imgs[which][6]);
		
		// here we need to work out wich mode we are in and display either the original height (4) or the 
		// newly calculated height / width (7)
		if (this.mode) {
			imgElmHeight = newHeight;
			newWidth = this.imgs[which][7];
			ImgTopMargin = 0;
			if (newWidth < 569) {
				ImgRightMargin = Math.round((569 - newWidth)/2);
			} else {
				ImgRightMargin = 0;
			}
		} else {
			imgElmHeight = 388;
			if (newHeight > 388) {
				ImgTopMargin = 0;
				
				// image needs to be scaled down
				scalefactor = (388/newHeight);
				newHeight = Math.round(newHeight * scalefactor);
				newWidth = this.imgs[which][7];
				newWidth = Math.round(newWidth * scalefactor);
				ImgRightMargin = Math.round((569 - newWidth)/2);
				
			} else if (newHeight < 388) {
				ImgTopMargin = Math.round((388 - newHeight)/2);
				newWidth = this.imgs[which][7];
				ImgRightMargin = 0;
				if (newWidth < 569) {
					ImgRightMargin = Math.round((569 - newWidth)/2);
				} else {
					ImgRightMargin = 0;
				}
				//	scalefactor = (388/newHeight);
				//	console.log(scalefactor);
				//	newHeight = Math.round(newHeight * scalefactor);
				//	newWidth = Math.round(569 * scalefactor);
			
			} else {
				ImgTopMargin = 0;
				ImgRightMargin = 0;
			}
		}
		
		obj = this;
		mainImg.fadeOut('slow',function(){
			imgElm.css('height',imgElmHeight+'px');
			var targetOffset = imgElm.offset().top;
			var bodyOffset = $('html').scrollTop() == 0 ? $('body').scrollTop() : $('html').scrollTop();
			if ((bodyOffset - targetOffset) > 1) {
				$('html,body').animate({scrollTop: targetOffset}, 500);
			}
			//console.log(mainImg);
			mainImg.after('<img width="'+newWidth+'" height="'+newHeight+'" src="'+newImg+'" style="margin-top:'+ImgTopMargin+'px;margin-left:'+ImgRightMargin+'px" />');
			mainImg.remove();
			mainImg = $('.img_gallery_img img').not('#largeplayersb');
			mainImg.hide();
			var nh = newHeight;
			mainImg.load(function(){
				var newHeight = nh;
				mainImg.fadeIn('slow',function(){
					if (clickable) {
						var h = parseInt((nh - 74) / 2);
						imgElm.prepend('<img id="largeplayersb" style="position: absolute; top: '+h+'px; left: 247px; display: inline;" src="/layout/img/largeplayer.png"/>');
					}
				});
			});
			obj.busy = false;
		});	
		this.activateImg(which);
		imgElm.unbind('click');
		imgElm.css('cursor','auto');
		var obj = this;
		if (clickable) {
			var url = this.imgs[which][2];
			imgElm.css('cursor','pointer');
			imgElm.click(function(me){
				me.preventDefault();
				document.location.href = url;
				return false;
			});
		} else {
			imgElm.css('cursor','pointer');
			imgElm.click(function(me){
				me.preventDefault();
				obj.move(1);
				return false;
			});
		
		}
	}
}
iStrip.prototype.getW = function() {
	return this.lngth+10;
}

iStrip.prototype.move = function(dir) {
	//alert('move');
	if (!this.busy) {
		imgElm.trigger('mouseout');
		if (dir == 1) {
			if (this.cpos < this.maxp && this.act[1]) {
				this.cpos++;
				var npos = this.imgs[this.cpos][1];
				if (-(npos) > (this.lngth-this.slngth)) {
					npos = -(this.lngth-this.slngth)+1;	
				}
				this.container.animate({marginLeft:npos},this.time);
			}
			this.thumbClick(this.crrImg+1);
		} else {
			if (this.cpos > 0 && this.act[0]) {
				this.cpos--;
				var npos = this.imgs[this.cpos][1];
				this.container.animate({marginLeft:npos},this.time);
				
			}
			this.thumbClick(this.crrImg-1);
		}	
		this.ckB();
	}
}
iStrip.prototype.ckB = function() {
	if (this.cpos == 0) {
		this.btn[0].addClass('inactive');
		this.act[0] = false;
		if (this.lngth+10 > 459) {
			this.act[1] = true;
			this.btn[1].removeClass('inactive');
		} else {
			this.act[0] = false;
			this.btn[0].addClass('inactive');		
		}
	} else if (this.cpos == this.maxp) {
		this.btn[1].addClass('inactive');
		this.act[1] = false;
		this.act[0] = true;
		this.btn[0].removeClass('inactive');
	} else {
		this.btn[0].removeClass('inactive');
		this.btn[1].removeClass('inactive');
		this.act[0] = true;
		this.act[1] = true;
	}
}
