/**
 * NM_YouTube.js
 *
 * @mootols		V 1.0
 * @swfobject	V 1.5
 * @author		Steffen Heinzelmann <shi@dmc.de>
 * @copyright   Copyright (c) dmc - digital media center GmbH
 * @version 	$Id: NM_YouTube.js 4169 2007-11-02 12:23:22Z lpetersohn $
 **/
var NM_LightBox = {

	/**
	 * inialization flag
	 **/
	blnInitialize: false,

	/**
	 * detection flag for old ie browsers
	 **
	blnOldIE: false,

	/**
	 * language id
	 **/
	strLangId: 'nl',

	/**
	 * parmeters: language
	 **/
	objLang: {
		nl: {
			close_window: 'Venster sluiten'
		},
		fr: {
			close_window: 'Fermer la fenêtre'
		}
	},

	/**
	 * SWFObject object
	 **/
	objSWF: null,

	/**
	 * parameters: background layer
	 **/
	objBGParam: {
		width: 	984,
		height: 700
	},

	/**
	 * parameters: content layer
	 **/
	objContentParam: {
		width: 	350,
		height: 180
	},

	/**
	 * element: background layer
	 **/
	objElmYouTubeBG: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					0,
			'left': 				0,
			'z-index':				'1001',
			'width':				0,
			'height':				0,
			'display': 				'none',
			'background-color': 	'#000000',
			'opacity': 				'0.6'
		} ).setProperty( 'id', 'YouTube' ),

	/**
	 * element: content layer
	 **/
/* bak orig
	objElmYouTubeContent: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					0,
			'left': 				0,
			'z-index':				'1002',
			'width':				0,
			'height':				0,
			'visibility': 			'visible',
			'display': 				'block',
			'border':				'1px solid #555555',
			'background-color':		'#FFFFFF',
			'background-image':		'url(/img/youtube/nm_logo.gif)',
			'background-position':	'5px 5px',
			'background-repeat': 	'no-repeat'
		} ).setProperty( 'id', 'YouTubeContent' ),
*/


	/**
	 * element: content layer
	 **/
	objElmYouTubeContent: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					0,
			'left': 				0,
			'z-index':				'1002',
			'width':				0,
			'height':				0,
			'visibility': 			'visible',
			'display': 				'block',
			'border':				'1px solid #555555',
			'background-color':		'#FFFFFF',
			'background-image':		'url(/img/youtube/nm_logo.gif)',
			'background-position':	'5px 5px',
			'background-repeat': 	'no-repeat'
		} ).setProperty( 'id', 'YouTubeContent' ),



	/**
	 * element: title
	 **/
	objElmYouTubeContentTitle: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					'6px',
			'left': 				'25px',
			'z-index':				'1003',
			'visibility': 			'visible',
			'display': 				'block',
			'width':				'300px',
			'height':				'20px',
			'text-align':			'left'
		} ).setProperty( 'id', 'YouTubeContentTitle' ),

	/**
	 * element: text
	 **/
	objElmYouTubeContentText: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					'45px',
			'left': 				'25px',
			'z-index':				'1003',
			'visibility': 			'visible',
			'display': 				'block',
			'width':				'300px',
			'height':				'20px',
			'text-align':			'left'
		} ).setProperty( 'id', 'YouTubeContentText' ),

	/**
	 * element: close button
	 **/
	objElmYouTubeContentCloseTop: new Element( 'div' ).setStyles( {
			'position':				'absolute',
			'top': 					'5px',
			'right': 				'5px',
			'z-index':				'1003',
			'width':				'20px',
			'height':				'20px',
			'background-image':		'url(/img/youtube/close.gif)',
			'background-position': 	'top right',
			'background-repeat': 	'no-repeat',
			'cursor':			 	'pointer'
		} ).setProperty( 'id', 'YouTubeContentCloseTop' ),

	/**
	 * form elements to hide in "opener"
	 **/
	arrFormElmListToHidden: [
		'lhAdviserBox',
		'NM_CrossSellingProduct',
		'NM_ComBasketBox'
	],

	objEffectFadeInContent: null,

	/**
	 * initialize
 	 **/
	initialize: function( objParam ) {

		this.blnInitialize = true;

		this.blnOldIE = this.detectOldIE();

		//init effect
		this.objEffectFadeInContent = this.objElmYouTubeContent.effects( {duration: 1500, transition: Fx.Transitions.quintOut } );

		//init language
		if( objParam.langId != '' && objParam.langId != undefined ) {
			this.strLangId = objParam.langId;
		}
		this.objLang = this.objLang[ this.strLangId ];

		//init bg layer
		var intBGHeight = this.getWindowHeight();
		if( intBGHeight < this.objBGParam.height ) {
			intBGHeight = this.objBGParam.height;
		}

		var intBGWidth = this.getWindowWidth();
		if( intBGWidth < this.objBGParam.width ) {
			intBGWidth = this.objBGParam.width;
		}

		this.objElmYouTubeBG.setStyles( {
			'width': 	intBGWidth+'px',
			'height': 	intBGHeight+'px'
		} );

		window.addEvent( 'domready', function() {
			//workaround: firefox need a little more time ;-)
			this.objElmYouTubeBG.setStyle( 'height', this.getWindowHeight() + 'px' );
		}.bind( this ) );

		//init content layer
		this.objElmYouTubeContent.setStyles( {

///bak			'left':  ( ( this.objBGParam.width /2 ) - ( this.objContentParam.width / 2 )  ) + 'px',
			'left':  '169px',
			'width': this.objContentParam.width + 'px'
		} );

		this.objElmYouTubeContent.setProperty( 'defaultTop', ( parseInt( this.objElmYouTubeContent.getStyle( 'top' ) ) + 10 ) + 'px' );
		this.objElmYouTubeContent.setProperty( 'defaultLeft', this.objElmYouTubeContent.getStyle( 'left' ) );

		//register event handler
		this.objElmYouTubeBG.addEvent( 'click', this.close.bind( this ) );
		this.objElmYouTubeContentCloseTop.addEvent( 'click', this.close.bind( this ) );

		/*
		this.objElmYouTubeContent.makeDraggable( {
			onDrag: function() {
				this.setOpacity( 0.7 );
			}.bind( this.objElmYouTubeContent ),
			onComplete: function() {
				this.setOpacity( 1.0 );
			}.bind( this.objElmYouTubeContent )
		} );

		this.objElmYouTubeContentTitle.addEvent( 'dblclick', function() {
			this.setStyles( { left: this.getProperty( 'defaultLeft' ) , top: this.getProperty( 'defaultTop' ) } );
		}.bind( this.objElmYouTubeContent ) );
		*/
		//set close button title
		this.objElmYouTubeContentCloseTop.setProperty( 'title', this.objLang.close_window );

		//insert in dom tree
		this.objElmYouTubeBG.injectInside( document.body );
		this.objElmYouTubeContentTitle.injectInside( this.objElmYouTubeContent );
		this.objElmYouTubeContentCloseTop.injectInside( this.objElmYouTubeContent );
		this.objElmYouTubeContentText.injectInside( this.objElmYouTubeContent );
		this.objElmYouTubeContent.injectInside(  document.body )

	},

	/**
	 * playVideo
	 **/
	open: function( objParam ) {

		//if not initialize, initalize
		if( false == this.blnInitialize ) {
			this.initialize( objParam );
		}

		this.objElmYouTubeContentTitle.setHTML( decodeURIComponent( objParam.title ) );

		//hide form elements in "opener"
		if( true == this.blnOldIE ) {
			try {
				for( var intIdCnt=0; intIdCnt < this.arrFormElmListToHidden.length; intIdCnt++ ) {
					if( $type( $( this.arrFormElmListToHidden[ intIdCnt ] ) ) == 'element' ) {
						$( this.arrFormElmListToHidden[ intIdCnt ] ).setStyle( 'display', 'none' );
					}
				}
			}
			catch( e ) {
				//
			}
		}

		if( objParam.langId == "nl" ) {
			this.objElmYouTubeContentText.setHTML( '<b><font style="color: rgb(255,0,0);">EEN EXTRA NEXBONUS : 300* nex</font></b><br /><br />+ 1 euro = 1 nexpunt<br />Ook op rode en gele prijsvignetten<br /><font style="color: rgb(255,0,0);">Met uw voordeelcode 5BL2</font> t/m 6/12<br /><br />* Geldig bij minimaal €70,- aan behouden artikelen op hele assortiment, ook rode en gele prijsvignetten t/m 6/12' );
		} else {
			this.objElmYouTubeContentText.setHTML( '<b><font style="color: rgb(255,0,0);">UN BONUS NEX SUPPLEMENTAIRE : 300* nex</font></b><br /><br />+ 1 euro = 1 point nex<br />Même valable sur vignettes rouges et jaunes<br /><font style="color: rgb(255,0,0);">Avec votre code-avantage 5BL2</font> jusqu’au 6/12<br /><br />* valable à partir d’un montant min. de € 70,- d’articles conservés. Valable sur tout l’assortiment,  vignettes rouges et jaunes comprises jusqu’au 6/12' );
		}


		//display elements
		this.objElmYouTubeBG.setStyles( { 'display': 'block' } );
		this.objElmYouTubeContent.setStyles( { 'top': 		(window.getScrollTop()+19)+'px',
											   'display': 	'block'
											    } );
/*bak
		this.objElmYouTubeContent.setStyles( { 'top': 		(window.getScrollTop()+10)+'px',
											   'display': 	'block'
											    } );
*/


		this.objEffectFadeInContent.start( { 'opacity': [0, 1], 'height': [ 0, this.objContentParam.height ] } ).chain( function() {


		}.bind( this ) );


	},

	/**
	 * closeVideo
	 **/
	close: function( objParam ) {

		//fade out content layer
		this.objElmYouTubeContent.effects( { duration: 500 } ).custom( { 'opacity': [1, 0] } ).chain( function() {

			this.objElmYouTubeContent.setStyles( { 	'display': 'none',
													'visibility': 'hidden' } );
			this.objElmYouTubeBG.setStyle( 'display', 'none' );
			this.objSWF = null;

			//redisplay hidden form elements in "opener"
			if( true == this.blnOldIE ) {
				try {
					for( var intIdCnt=0; intIdCnt < this.arrFormElmListToHidden.length; intIdCnt++ ) {
						$( this.arrFormElmListToHidden[ intIdCnt ] ).setStyle( 'display', 'block' );
					}
				}
				catch( e ) {
					//
				}
			}

		}.bind( this ) );

	},


	/**
	 * getWindowHeight
	 **/
	getWindowHeight: function()	{
		if( document.body && document.body.offsetHeight )
		{
			return document.body.offsetHeight;
		}
		else if( window.innerHeight > 0 )
		{
			return window.innerHeight;
		}
		else
		{
			return 0;
		}
	},

	/**
	 * getWindowWidth
	 **/
	getWindowWidth: function()	{
		if( document.body && document.body.offsetWidth )
		{
			return document.body.offsetWidth;
		}
		else if( window.innerWidth > 0 )
		{
			return window.innerWidth;
		}
		else
		{
			return 0;
		}
	},

	detectOldIE: function() {
		if( true == window.ie && window.ie7 == undefined ) {
			return true;
		}
		else
		{
			return false;
		}

	},

	/**
	* log
	**/
	log: function( mixMsg ) {

		if( window.gecko == true )
		{
		//	console.log( mixMsg ) ;
		}
	}

};