var General = {
	init: function(){
		this.preparePng();
		this.prepareFlash();
	},
	preparePng: function(){
		if( typeof( ddpngfix ) !== 'undefined' ){
			$( 'img[src$=.png]:not(.opaque)' ).each( function(){
				ddpngfix.fixPng( this );					
			} );			
		}
	},
	prepareFlash: function(){
		//FlashUtil.embed( 'path', 'container' );	
	}
}
var Ticker = {
	_container:'#ticker',
	_path:'/bazment/getxml.aspx',
	_delay:2000,
	_timer:null,	
	
	init: function( container, path, delay ){
		if( path ) this._path = path;
		if( delay ) this._delay = delay;	
		if( container ) this._container = container;
		
		this._container = $( this._container );
		if( this._container.length === 0 ) return;

		this.loadXML();
	},
	loadXML: function(){
		$.get( this._path, this.onResult );
	},
	onResult: function( data ){
		$( data ).find('ticker').children().each( function(){
			Ticker._container.append( $( '<a href="' + $( this ).find('link').text() + '" style="display:none;position:absolute;">' + $( this ).find('title').text() + '</a>' ) );
		} );
		Ticker.autoloop();
	},
	autoloop: function(){
		Ticker.next();
		setTimeout( Ticker.autoloop, Ticker._delay );
	},
	next: function(){
		var previous = this._container.find( 'a:visible' );
		if( previous.length === 0 ){
			$(this._container.children()[0]).fadeIn();
		}else
		if( !previous.is( ':last-child' ) ){
			previous.fadeOut();
			previous.next().fadeIn();
		}else{
			previous.fadeOut();
			$(this._container.children()[0]).fadeIn();
		}
	}
}
$( 'document' ).ready( function(){
	General.init();
	Ticker.init( '#ticker' );
} );
