if( !General ) var General = {};

/*SCRIPT TO RUN AFTER DOM IS LOADED*/
General.subscript = {
	init: function(){
		this.preparePng();
		this.prepareFlash();
		this.prepareTeasers();
		this.prepareMostRead();
		this.prepareGallery();
	},
	preparePng: function(){
		if( typeof( ddpngfix ) !== 'undefined' ){
			$( 'img[src$=.png]:not(.opaque)' ).each( function(){
				ddpngfix.fixPng( this );					
			} );			
		}
	},
	prepareFlash: function(){
		//General.flash.embedFlash( '/flash/filename.swf', 'main-container', '100%', '100%' );
	},
	prepareTeasers: function(){
		$( '.expandable-teaser h2 a' ).each( function(){
			$( this ).parent().next().hide();
			$( this ).parent().removeClass( 'expanded' );	
		} ).click( function(){
			$( this ).parent().next().slideToggle( $( this ).parent().next().height() * 2, function(){
				$( this ).prev().toggleClass( 'expanded' );										
			} ).end().blur();
			return false;
		} );
			
	},
	prepareMostRead: function() {
		if ($( '.js-mostread' ).length === 0) { return; }
		var listIndex;
		$('.js-mostread h2').addClass('inactive');
		$('.js-mostread h2:first').removeClass('inactive').addClass('active');
		$('.js-mostread ol').addClass('inactive');
		$('.js-mostread ol:first').removeClass('inactive').addClass('active');
		
		$( '.js-mostread h2 a' ).click( function() {
			if ( $( this ).parent().hasClass( 'inactive' ) ) {
				$('.js-mostread h2').removeClass('active').addClass('inactive');
				$( this ).parent().removeClass('inactive').addClass('active');
				listIndex = $('.js-mostread h2').index($( this ).parent());
				$('.js-mostread ol').removeClass('active').addClass('inactive');
				$('.js-mostread ol:eq(' + listIndex + ')').removeClass('inactive').addClass('active');
			}
			return false;
		} );	
	},
	prepareGallery: function(){			
		if( $( '.theme-gallery' ).length === 0 ){ return; }
		var slide = new AnimatedSlideShow( 
			'.theme-gallery ul',
			'.theme-gallery .nav-prev',
			'.theme-gallery .nav-next',
			'.theme-gallery li',
			'.theme-gallery li.selected',
			4
		);
	}
}
$( 'document' ).ready( function(){
	General.subscript.init();
} );