TT.PP =
{
	flash : swfobject.getFlashPlayerVersion ( ).major >= 8,
	
	'products-category' : function ( )
	{
		var cinemas = TT.Select.byAttr ( 'class' , 'overviewcomponent' , 'div' , document.body );
		
		for ( var index = 0 , length = cinemas.length; index < length; index ++ )
		{
			var cinema = cinemas [ index ];			
			var screen = TT.Select.byAttr ( 'class' , 'media' , 'div' , cinema ) [ 0 ] . getElementsByTagName ( 'div' ) [ 0 ];
			var list =   TT.Select.byAttr ( 'class' , 'medialist' , 'ul' , screen.parentNode.parentNode ) [ 0 ];
			var links =  TT.Select.byAttr ( 'class' , 'feature-link-jsmanipulate' , 'a' , list );
			
			if ( links.length == 0 )
			{
				links = list.getElementsByTagName ( 'a' );
			}
			
			TT.PP.addMediaObservers ( links , screen );
		}
	},
	
	'product-features' : function ( )
	{
		TT.PP.addBlockObservers ( );
		TT.PP [ 'products-category' ] ( );
	},
	
	'product-experience' : function ( )
	{
		TT.PP.addBlockObservers ( );
		
		var cinemas = TT.Select.byAttr ( 'class' , 'info-blok' , 'div' , document.body );
		
		for ( var index = 0 , length = cinemas.length; index < length; index ++ )
		{
			var cinema = cinemas [ index ];			
			var screen = TT.Select.byAttr ( 'class' , 'flashvlak' , 'div' , cinema ) [ 0 ] . getElementsByTagName ( 'div' ) [ 0 ];
			var list =   TT.Select.byAttr ( 'class' , 'flash-thumbvlak' , 'div' , cinema ) [ 0 ];
			var links =  TT.Select.byAttr ( 'class' , 'thumb-border' , 'a' , list );		
			
			TT.PP.addMediaObservers ( links , screen );
		}
	},
	
	toggleBlock : function ( element , event , data )
	{
		if ( data.active ) 
		{
			TT.DOM.addClass ( data.active , 'info-blok-closed' );
		}
		
		data.active = element.parentNode;
	
		TT.DOM.removeClass ( data.active , 'info-blok-closed' );
	},
	
	addBlockObservers : function ( )
	{
		var segments = TT.Select.byAttr ( 'class' , 'info-blok' , 'div' , document.body );
		var options = { active : null };
		
		for( var index = 0, length = segments.length; index < length; index ++ )
		{
			var segment = segments [ index ];		
			TT.DOM.addClass ( segment , 'info-blok-closed' );
			var observer = TT.Event.observe( TT.DOM.first ( segment ) , 'click' , TT.PP.toggleBlock , null , options );
			
			if ( index == 0 ) observer (  );
		}
	},
	
	addMediaObservers : function ( links , screen )
	{
		var browser = TT.PP.Text.construct ( screen.parentNode );
		
		for ( var count = 0, size = links.length; count < size; count ++ )
		{
			var link = links [ count ];
			link.href = 'javascript:void(0);';
			
			var type = link.getAttribute ( 'type' );
			
			var options = 
			{
				text : link.getAttribute ( 'text' ) . split ( '|' ) ,
				swf : link.getAttribute ( 'swf' ) ,
				image : link.getAttribute ( 'image' ) ,
				screen : screen.id ,
				browser : browser
			};
			
			var observer = function ( ){ };
			
			if ( type == 'emulator' && TT.PP.flash && options.swf.indexOf ( '.lightbox' ) == -1 )
			{
				observer = TT.Event.observe ( link , 'click' , TT.PP.Emulator.observers.play , null , options );
			}
			else if ( ( type == 'hdvideo' || type == 'emulator' ) && TT.PP.flash )
			{
				observer = TT.Event.observe ( link , 'click' , TT.PP.HDVideo.observers.construct , null , options );
			}
			else if ( type == 'video' && TT.PP.flash )
			{
				observer = TT.Event.observe ( link , 'click' , TT.PP.Video.observers.play , null , options );
			}
			else if ( type == 'image' || TT.PP.flash == false )
			{
				observer = TT.Event.observe ( link , 'click' , TT.PP.Image.observers.play , null , options );
			}
			
			if ( count == 0 ) observer ( );
		}
	}
};

TT.PP.HDVideo =
{
	observers : 
	{
		construct : function ( element , event , data )
		{
			TT.PP.Image.observers.play ( null , null , data );
			TT.Event.observe ( document.getElementById ( data.screen ) , 'click' , TT.PP.HDVideo.observers.play , null , data );			
			document.getElementById ( data.screen ).style.cursor = 'pointer';
			
			data.browser.current = null;			
			data.browser.data = data.text;
			TT.PP.Text.observers.next ( null , null , data.browser );
		},
		
		play : function ( element , event , data )
		{
			var options = { vars : { xmlFile : encodeURIComponent ( data.swf ) } };
			
			if ( data.swf.indexOf ( '.lightbox' ) > -1 )
			{
				options.swf = '/lib/flash/milan/players/emulatorPlayer.swf';
			}
			
			TT.SWF.HDVideo.play ( Object.merge ( TT.PP.HDVideo.options , options ) );
		}
	},
	
	options :
	{
		swf        : '/lib/flash/milan/players/videoPlayerHD.swf',
		id         : 'swf-hdv-movie',
		width      : 480,
		height     : 272,
		version    :'9.0.0',
		express    : 'false',
		vars       : { },
		params     : { menu : 'false' , quality : 'high' , wmode : 'opaque' , allowscriptaccess : 'always' , allowfullscreen : 'true' },
		attributes : { }	
	}
};
				
TT.PP.Video =
{
	observers : 
	{
		play : function ( element , event , data )
		{
			var options = { id : data.screen, vars : { xmlFile : encodeURIComponent ( data.swf ) } };
			
			data.browser.current = null;			
			data.browser.data = data.text;
			TT.PP.Text.observers.next ( null , null , data.browser );			
			TT.SWF.play ( Object.merge ( TT.PP.Video.options , options ) );
		}
	},
	
	options :
	{
		swf        : '/lib/flash/milan/players/videoPlayer.swf',
		id         : null,
		width      : 323,
		height     : 240,
		version    :'8.0.0',
		express    : 'false',
		vars       : { },
		params     : { menu : 'false' , quality : 'high' , wmode : 'opaque' , allowscriptaccess : 'always' , allowfullscreen : 'true' },
		attributes : { }
	}
};

TT.PP.Emulator =
{
	observers : 
	{
		play : function ( element , event , data )
		{
			var options = { id : data.screen, vars : { xmlFile : encodeURIComponent ( data.swf ) } };

			data.browser.current = null;			
			data.browser.data = data.text;
			TT.PP.Text.observers.next ( null , null , data.browser );
			TT.SWF.play ( Object.merge ( TT.PP.Emulator.options , options ) );
		}
	},
	
	options :
	{
		swf        : '/lib/flash/milan/players/emulatorPlayer.swf',
		id         : null,
		width      : 323,
		height     : 244,
		version    :'9.0.0',
		express    : 'false',
		vars       : { },
		params     : { menu : 'false' , quality : 'high' , wmode : 'opaque' , allowscriptaccess : 'always' , allowfullscreen : 'true' },
		attributes : { }
	}
};
	
TT.PP.Image =
{
	observers : 
	{
		play : function ( element , event , data )
		{
			var screen = document.createElement ( 'div' );
			screen.id = data.screen;		
			
			var image = document.createElement ( 'img' );		
			image.src = data.image;
			image.style.height = '240px';
			image.style.width = '323px';
			image.style.display = 'block';
			
			var overlay = document.createElement ( 'div' );
			overlay.className = "image-overlay";
			
			screen.appendChild ( image );
			screen.appendChild ( overlay );	
						
			document.getElementById ( data.screen ) .parentNode.replaceChild( screen, document.getElementById ( data.screen ) );
			
			data.browser.current = null;			
			data.browser.data = data.text;
			TT.PP.Text.observers.next ( null , null , data.browser );	
		}
	}
};

TT.PP.Text =
{
	construct : function ( theater )
	{	
		var browser = document.createElement ( 'div' );
		browser.className = 'textbrowser';
		
		var text = document.createElement( 'p' );		
		
		var prev = document.createElement ( 'a' );
		prev.href = 'javascript:void(0);';
		prev.className = 'prev';
		prev.style.display = 'none';		
		
		var next = document.createElement ( 'a' );
		next.href = 'javascript:void(0);';
		next.className = "next";
		next.style.display = 'none';		
		
		theater.appendChild ( browser );
		browser.appendChild ( text );
		browser.appendChild ( prev );
		browser.appendChild ( next );
		
		var options = 
		{
			text : text,
			next : next,
			prev : prev,
			data : null,
			current : null
		};
		
		TT.Event.observe ( prev , 'click' , TT.PP.Text.observers.prev , null , options );
		TT.Event.observe ( next , 'click' , TT.PP.Text.observers.next , null , options );
		
		return options;	
	},
	
	observers :
	{
		prev : function ( element , event , data )
		{
			var current = data.current;
			
			if ( current == null )
			{
				current = 0;
			}
			else
			{
				current -= 1; 
			}
			
			TT.PP.Text.toggleNavigation ( data , current );
		},
		
		next : function ( element , event , data )
		{
			var current = data.current;
			
			if ( current == null )
			{
				current = 0;
			}
			else
			{
				current += 1; 
			}
			
			TT.PP.Text.toggleNavigation ( data , current );
		}
	},

	toggleNavigation : function ( data , current )
	{
		if ( data.data [ current ] )
		{
			data.current = current;
			data.text.innerHTML = data.data [ current ];
		}
		
		if ( data.data [ data.current - 1 ] )
		{
			data.prev.style.display = 'block';
		}
		else
		{
			data.prev.style.display = 'none';
		}
		
		if ( data.data [ data.current + 1 ] )
		{
			data.next.style.display = 'block';
		}
		else
		{
			data.next.style.display = 'none';
		}
	}	
};

var stopBanner = function ( ){ };
TT.DOM.Load.observe ( function ( ) 
{ 
	if ( typeof ( TT.PP [ document.body.id ] ) == 'function' ) 
	{ 
		TT.PP [ document.body.id ] ( ) 
	}
});
