var themeselection = (themeselection) ? themeselection : true;
jQuery(document).ready(function() {
	if(themeselection){
		$('#sidebar #channels a').click(function(){
			switchstyles($(this).attr('rel'));
			sspSetData($(this).attr('directorurl'));
			//sspSwitchStyles($(this).attr('rel'));
			return false;
		});	
	
		var liststylecnt = 5;

		$('#liststyle a').click(function(){
			var liststyle = $(this).attr('class');
			if(liststyle == ''){
				$(this).toggleClass('thumbnail');		
				$(this).attr("title","Switch to  Thumbnail View");
				$('#channels').trigger( 'goto', [ 0 ] );
				liststylecnt = 10;
			}
			else{
				$(this).removeClass();		
				$(this).attr("title","Switch to  Text View");
				$('#channels').trigger( 'goto', [ 0 ] );
			}
			
			$('#channels').toggleClass('textview');
	
			return false;
		});	
	
		var $prev = $('#prev'),//prev button
			$next = $('#next');//next button
	
		$('#channels').serialScroll({
			items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
			prev:'#prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
			next:'#next',// Selector to the 'next' button (absolute too)
			axis:'y',// The default is 'y' scroll on both ways
			duration:100,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
			force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
			
			//queue:false,// We scroll on both axes, scroll both at the same time.
			//event:'click',// On which event to react (click is the default, you probably won't need to specify it)
			//stop:false,// Each click will stop any previous animations of the target. (false by default)
			//lock:true, // Ignore events if already animating (true by default)		
			//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
			cycle:false,// Cycle endlessly ( constant velocity, true is the default )
			step:5, // How many items to scroll each time ( 1 is the default, no need to specify )
			//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
			//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
			//interval:1000, // It's the number of milliseconds to automatically go to the next
			//constant:true, // constant speed
			
			onBefore:function( e, elem, $pane, $items, pos ){
				$prev.add($next).fadeTo("fast", 1);
				$prev.add($next).css("cursor","pointer");
				if( pos == 0 ){
					$prev.fadeTo("fast", 0.33);
					$prev.css("cursor","default");
				}
				else if( pos >= $items.length-liststylecnt ){
					$next.fadeTo("fast", 0.33);
					$next.css("cursor","default");
					pos = $items.length;
				}
			}
		});
		
		$prev.fadeTo("fast", 0.33);
		$prev.css("cursor","default");
	}
});

// Video Events
function videoevent(type){
	//alert("Video Event:\n\n"+type); 
	switch(type)
	{
	case 'videoStart':
	  if(themeselection){
		  $('.remote').hide('slow');
		  createSidebarAd();	  
	  }
	  break;    
	case 'videoPause':	  
	  if(themeselection){
		  $('.remote').show('fast');
		  removeSidebarAd();	  
	  }
	  break;
	case 'videoResume':	  
	  if(themeselection){
		  $('.remote').hide('slow');
		  createSidebarAd();	  
	  }
	  break;
	case 'videoEnd':
	  if(themeselection){
		  $('.remote').show('fast');
		  removeSidebarAd();	  
	  }
	break;
	default:
		return false;
	}
}

function createSidebarAd(){
	if(!$('#inlinead').length){
		$('#sidebar').append("<iframe style='display:none' id='inlinead' name='inlinead' src='http://internetbrokers.ca/gssi/openx/www/delivery/afr.php?n=a0c79400&amp;zoneid=5&amp;target=_blank&amp;cb=035498964' framespacing='0' frameborder='no' scrolling='no' width='120' height='240'><a href='http://internetbrokers.ca/gssi/openx/www/delivery/ck.php?n=ae909b02&amp;cb=035498964' target='_blank'><img src='http://internetbrokers.ca/gssi/openx/www/delivery/avw.php?zoneid=5&amp;cb=035498964&amp;n=ae909b02' border='0' alt='' /></a></iframe>");
		$('#inlinead').fadeIn(3000);
	}
}
function removeSidebarAd(){
	if($('#inlinead').length){
		$('#inlinead').stop().remove();
	}
}

// Switch Style Sheet
function switchstyles(style){
 	$("link[rel*='alternate']").attr('disabled',true);
	if(style) $('link[title='+style+']').attr('disabled',false);
	return false;
}

// SSP PLAYER FUNCTION CALLBACKS
function sspToggleDisplayMode() {
  thisMovie("videoplayer").sspToggleDisplayMode(null);
  return false;
}
function sspLoadImageNumber(imageNumber) {
  thisMovie("videoplayer").sspLoadImageNumber(imageNumber);
  return false;
}
function sspSetData(path) {
  thisMovie("videoplayer").sspSetData(path,'Director');
  return false;
}
function sspSwitchStyles(style) {
  thisMovie("videoplayer").sspSwitchStyles(style);
  return false;
}
function thisMovie(movieName) {
   return swfobject.getObjectById(movieName);
}

// Permalinks
function flashPutHref(href) {
	//location.href = href;
	$("#bookmark").attr("href",href);
} 