// JavaScript Document
//<!--
	function resetNextPrev( perpage, perline, page, pages ){
		$('#performances li#next').insertAfter('#performances li.shown:eq('+ (perpage-1) +')');
		$('#performances li#prev').insertAfter('#performances li.shown:eq('+ (perline-1) +')');
		$('#performances #next .pages a.selectedpage').removeClass('selectedpage').addClass('page');
		$('#performances #next .pages a:eq('+(page-1)+')').addClass('selectedpage').removeClass('page');
		
		
		if (page == 1) //deactive previous button if at first page
			$('#performances a#btprev').removeClass('movebutton').addClass('movebutton-off')
		else //active previous button if not at first page
			$('#performances a#btprev').removeClass('movebutton-off').addClass('movebutton');
			
		if (page == pages) //deactive next button if at last page
			$('#performances a#btnext').removeClass('movebutton').addClass('movebutton-off')
		else //active next button if not at last page
			$('#performances a#btnext').removeClass('movebutton-off').addClass('movebutton');
	}
	$(document).ready(function(){
							   
		$('div[id^="tab-"]').each(function(){
											$('a[rel="'+this.id+'"]')
												.removeClass('dimmed')
												.click(function(){
																	$('a[rel^="tab-"].selected').removeClass('selected');
																	$(this).addClass('selected');
																	$('div[id^="tab-"]')
																		.hide()
																		.filter('[id="'+this.rel+'"]')
																		.show();
																	return false;
																});
										   })
							.hide();
		$('a[rel^="tab-"]').each(function(){ if (!$('#' + this.rel ).length) $(this).hide().next('span.dash').hide();})
		$('span.dash:visible:last').hide();
		//$('a[rel^="tab-"]:not(.dimmed):first').click();
		$('a[rel^="tab-"]:visible:first').click();
		$('a.review-button').click(function(){
											var $content = $('#'+this.rel).html();
											$('#text-review').fadeOut(300, function(){$(this).html( $content ).fadeIn(300);});
											});
		var $perpage = 12; // how many items (visible) per page (should be the first row items x2)
		var $perline = ($perpage+2) / 2; // calculate how many on the first row ..
		var $page = 1; // starting page
		var $itemcount = $('#performances li.performance').length; // how many true elements in total
		var $pages = Math.ceil ( $itemcount / $perpage); // calculate the number of pages 
		if ($pages == 0 ) $pages=1;
		
		if (($pages * $perpage) > $itemcount )
				for (var i =0;i< ($pages * $perpage)-$itemcount;i++) 
						$('<li class="performance placeholder">test</li>').appendTo('#performances'); // create the ghost elements to ensure full pages
		
		$('#performances li.performance').slice(0,$perpage).addClass('shown'); // show the first page elements
		
		resetNextPrev( $perpage , $perline, $page, $pages ); //Position the buttons for the first time ..
		
		

		// define the next page action
		$('#next a#btnext').click(function(){
			if ($page < $pages)
				$('#performances li.performance').filter('.shown').removeClass('shown').end().slice($perpage * (++$page-1),$perpage * $page).addClass('shown');
			resetNextPrev( $perpage , $perline, $page, $pages );
			
		});
		// define the previous page action
		$('#prev a#btprev').click(function(){
			if ($page > 1)
				$('#performances li.performance').filter('.shown').removeClass('shown').end().slice($perpage * (--$page-1),$perpage * $page).addClass('shown');
			resetNextPrev( $perpage , $perline, $page, $pages );
			
		});
		// define the direct page action
		$('#next .pages a').click(function(){
			var $absolutePage = parseInt($(this).text()) ;
			$page = $absolutePage;
			$('#performances li.performance').filter('.shown').removeClass('shown').end().slice($perpage * ($absolutePage-1),$perpage * $absolutePage).addClass('shown');
			resetNextPrev( $perpage , $perline, $absolutePage, $pages );
		});

		$('#tab-videos a').click(
			function(){
				var $href = this.href;
				var plr = $('#player').get(0);
				plr.sendEvent('STOP');
				plr.sendEvent('LOAD',$href);
				plr.sendEvent('PLAY');
				return false;
			}
		);
	});
//-->
