$.projectNamespace = 
{
	language: 'fr-ca',
	cookies:
	{
		selection:		null,
		classification:	null,
		page:			0,
		thumbnail:		0,
		captioning:		null,
		lowHighRes:		'high'
	},
	thumbnailsSlider:
	{
		divThumbnails: 'thumbnailsSlider',
		nbSubDivs: 2,
		deplacementX: 955,
		tempsDeplacement: 1000,
		styleContainerDiv:
		{
			position: 'absolute',
			top: '0',
			left: '0',
			width: '955',
			height: '450',
			margin: '0 0 0 98',
			overflow: 'hidden'
		},
		styleSubDivs:
		{
			position: 'absolute',
			top: '0',
			left: '0',
			width: '955',
			height: '450',
			margin: '0 0 0 0'
		},
		styleThumbnailDiv:
		{
			float: 'left',
			width: '166px',
			margin: '20px 0px 0px 15px'
		},
		styleThumbnailImg:
		{
			width: '166px',
			height: '93px',
			alt: ''
		},
		styleThumbnailImgSeries:
		{
			width: '166px',
			height: '142px',
			alt: ''
		},
		requeteThumbnails:
		{
			path: '',
			modules:
			{
				extras: 'modules/population.php',
				publicite: 'modules/population.php',
				collection: 'modules/population.php',
				series: 'modules/populationSeries.php'
			},
			videoPage: 'video.php',
			dataType: 'xml',
			type: 'POST',
			data: [ 'selection', 'classification' ]
		},
		selections:
		{
			selection:		[ 'collection', 'serie' ],
			classification:	[ 'date', 'vote' ]
		},
		selectionsActives:
		{
			selection:		0,
			classification:	0
		},
		selection:
		{
			collection:	{rangees: 3, colonnes: 5},
			serie:		{rangees: 1, colonnes: 5},
			video:		{rangees: 1, colonnes: 5}
		},
		navMethod: [ 'page', 'miniature' ],
		pageActive: 0,
		thumbnailsClickFunction: function(event)
		{
			var idProduit		=	event.target.id;
			var URLexecutable	=	$BK_ThumbnailsSlider.parametres.requeteThumbnails.path +
									$BK_ThumbnailsSlider.parametres.requeteThumbnails.videoPage +
									"?vid=" + idProduit + "&langue=" + this.data.language;
			$BK.process(['getNetPage', [URLexecutable]]);
		},
		thumbnailsSeriesClickFunction: function(event)
		{
			var idProduit		=	event.target.id;
			var arrIds			=	idProduit.split("_");
			var URLexecutable	=	$BK_ThumbnailsSlider.parametres.requeteThumbnails.path +
									$BK_ThumbnailsSlider.parametres.requeteThumbnails.videoPage +
									"?vid=" + arrIds[1] + "&serie=" + arrIds[0] + "&langue=" + this.data.language;
			$BK.process(['getNetPage', [URLexecutable]]);
		},
		thumbnailsOnloadFunction: function(event)
		{
		},
		thumbnailsErrorFunction: function(event)
		{
		},
		navClickFunction: function(event)
		{
			var e = event.target.id;
			
			switch(e)
			{
				case 'precedente':
					$BK.process(['thumbnailsPagePrecedente']);
					break;
					
				case 'suivante':
					$BK.process(['thumbnailsPageSuivante']);
					break;
					
				default:
					$BK.process(['thumbnailsPageSpecifique',[e]]);
					break;
			}
			var id = event.target.idNav;
		}
	},
	BtnFonctionalities:
	{
		mouseover: function(event)
		{
			var idBtn = event.target.id;

			switch(idBtn)
			{
				case 'btnCollection':
				case 'textCollection':
//					$BK.process(['mouseoverSelection',[idBtn]]);
					break;
					
				case 'btnSerie':
				case 'textSerie':
//					$BK.process(['mouseoverSelection',[idBtn]]);
					break;
					
				case 'btnDate1', 'btnVote1', 'btnDate2', 'btnVote2':
					$BK.process(['mouseoverClassification',[idBtn]]);
					break;
			}
		},
		mouseout: function(event)
		{
			var idBtn = event.target.id;
			
			switch(idBtn)
			{
				case 'btnCollection':
					$BK.process(['mouseoutSelection',['collection', idBtn]]);
					break;
					
				case 'btnSerie':
					$BK.process(['mouseoutSelection',['serie', idBtn]]);
					break;
					
				case 'btnDate1':
				case 'btnDate2':
					$BK.process(['mouseoutClassification',['date', idBtn]]);
					break;
				
				case 'btnVote1':
				case 'btnVote2':
					$BK.process(['mouseoutClassification',['vote', idBtn]]);
					break;
			}
		},
		click: function(event)
		{
			var idBtn = event.target.id;
			
			switch(idBtn)
			{
				case 'btnCollection':
				case 'textCollection':
//					$BK.process(['changeSelection',['collection', idBtn]]);
					break;
					
				case 'btnSerie':
				case 'textSerie':
//					$BK.process(['changeSelection',['serie', idBtn]]);
					break;
					
				case 'btnDate1':
				case 'btnDate2':
					$BK.process(['changeClassification',['date', idBtn]]);
					break;
					
				case 'btnVote1':
				case 'btnVote2':
					$BK.process(['changeClassification',['vote', idBtn]]);
					break;
			}
		},
		css: function(btn)
		{
			btn.css("cursor", "pointer");
		}
	},
	activePage: null,
	sendVideoFilenameToFlashAfterReceivingXML: false
}

function TAC()
{
	//this.data = $.projectNamespace;
	//this.data.playerTexts = $.languagesForPlayer[this.data.language];
}

function TAC_process(msg)
{
	var result = null;
	
	switch(msg[0])
	{
		case 'setLowHighResCookie':
			this.setLowHighResCookie(msg[1]);
			break;
			
		case 'setCaptioningCookie':
			this.setCaptioningCookie(msg[1]);
			break;
				
		case 'initTAC':
			this.init();
			break;
			
		case 'sendTextsToPlayer':
			this.sendTextsToPlayer();
			break;
			
		case 'activateCorrectStyle':
			this.activateCorrectStyle(msg[1]);
			break;
			
		case 'Begin':
			//$BK.process(['FlashReady']);
			$BK.process(['createThumbnailsSlider', [$.projectNamespace.thumbnailsSlider, 'video']]);
			$BK.process(['sendVideoFilenameToFlashAfterReceivingXML']);
			//this.actions($.projectNamespace.actions[msg[0]]);
			break;
			
		case 'assignBtnFonctionalities':
			this.assignBtnFonctionalities(msg[1]);
			break;
			
		case 'assignPage':
			this.assignPage(msg[1]);
			break;
			
		case 'changeSelection':
			this.changeSelection(msg[1]);
			break;
			
		case 'changeClassification':
			this.changeClassification(msg[1]);
			break;
			
		case 'setLanguage':
			this.setLanguage(msg[1]);
			break;
			
		case 'getActivePage':
			result = $TAC.data.thumbnailsSlider.pageActive;
			break;
		
		case 'setActivePage':
			this.data.thumbnailsSlider.pageActive = msg[1][0];
			break;
			
		case 'mouseoverSelection':
			this.mouseoverSelection(msg[1][0]);
			break;
		
		case 'mouseoutSelection':
			this.mouseoutSelection(msg[1]);
			break;
			
		case 'mouseoverClassification':
			this.mouseoverClassification(msg[1][0]);
			break;
			
		case 'sendFlashThumbnailsXML':
			this.sendFlashThumbnailsXML();
			break;
			
		case 'XMLThumbnailsLoaded':
			break;
			
		case 'needFlashThumbnailsXML':
			$BK.process(['sendFlashThumbnailsXML']);
			break;
			
		default:
			break;
	}
	
	return result;
}

function TAC_init()
{
	var cookiesNamesList	= $BK.process(['getKeysInObject', [this.data.cookies]]);
	var cookies				= $BK.process(['getCookies', cookiesNamesList]);
	
	for(i in cookies)
	{
		if(cookies[i] != null)
		{
			switch(i)
			{
				case 'selection':
					this.data.thumbnailsSlider.selectionsActives[i] =
					$BK.process(['findIndex', [cookies[i], this.data.thumbnailsSlider.selections[i]]]);
					break;
					
				case 'classification':
					this.data.thumbnailsSlider.selectionsActives[i] =
					$BK.process(['findIndex', [cookies[i], this.data.thumbnailsSlider.selections[i]]]);
					break;
					
				case 'page':
//					this.data.thumbnailsSlider.pageActive = parseInt(cookies[i]);
					this.data.thumbnailsSlider.pageActive = 1;
					break;
					
				case 'thumbnail':
					break;
					
				case 'pageSerie':
					this.data.thumbnailsSlider.pageActiveSerie = parseInt(cookies[i]);
					break;
			}
		}
	}

	$BK.process(['activateCorrectStyle', [cookies['selection'], cookies['classification']]]);

}

function TAC_activateCorrectStyle(msg)
{
	
	var selectionActive 		= msg[0];
	var classificationActive	= msg[1];
	
	// on change seulement si "serie" car par défaut: "collection" dans le code PHP
	if(selectionActive=='serie') {
		$("div#btnCollection").addClass("popTartTabCollectionOff").removeClass("popTartTabCollectionOn");
		//$("div#btnCollection").removeClass("popTartTabCollectionOn");
		$("div#btnSerie").addClass("popTartTabSerieOn").removeClass("popTartTabSerieOff");
		//$("div#btnSerie").removeClass("popTartTabSerieOff");
		$("div#popTartNavigationClassementTop").css("display","none");
		$("div#popTartNavigationClassementBottom").css("display","none");
	}
	
	// on change seulement si "date" car par défaut: "vote" dans le code PHP
	if(classificationActive=='vote') {
		$("span[id^=btnDate]").addClass("popTartNavigationClassementOff").removeClass("popTartNavigationClassementON");
		//$("span[id^=btnDate]").removeClass("popTartNavigationClassementON");
		$("span[id^=btnVote]").addClass("popTartNavigationClassementON").removeClass("popTartNavigationClassementOff");
		//$("span[id^=btnVote]").removeClass("popTartNavigationClassementOff");
	}
	
}

function TAC_actions(msg)
{
	//msg();
}

function TAC_assignBtnFonctionalities(msg)
{
	for(var i = 0; i < msg.length; i++)
	{
		var btn = "#" + msg[i];
		
		for(j in this.data.BtnFonctionalities)
		{
			switch(j)
			{
				case 'css':
					this.data.BtnFonctionalities[j]($(btn));
					break;
				
				default:
					$(btn).bind(j, this.data.BtnFonctionalities[j]);
					break;
			}
		}
	}
}

function TAC_assignPage(msg)
{
	this.data.activePage = msg[0];
	
	switch(this.data.activePage)
	{
		case 'video':
			this.data.navMethod = 'miniature';
			break;
			
		default:
			this.data.navMethod = 'page';
			break;
	}
}

function TAC_changeSelection(msg)
{
	var ordre		= msg[0];
	var bouton		= msg[1];
	var indexOld	= this.data.thumbnailsSlider.selectionsActives['selection'];
	var indexNew	= $BK.process(['findIndex', [ordre, this.data.thumbnailsSlider.selections.selection]]);

	switch(bouton)
	{
		case 'btnCollection':
		case 'textCollection':
			var btnClicked = $("div#btnCollection");
			break;
			
		case 'btnSerie':
		case 'textSerie':
			var btnClicked = $("div#btnSerie");
			break;
	}
	// on liste manuellement les boutons de cette navigation-là
	var btnCollection	= $("div#btnCollection");
	var btnSerie		= $("div#btnSerie");
	
	// on met tous les boutons à Off
	btnCollection.addClass("popTartTabCollectionOff").removeClass("popTartTabCollectionOn");
	//btnCollection.removeClass("popTartTabCollectionOn");
	btnSerie.addClass("popTartTabSerieOff").removeClass("popTartTabSerieOn");
	//btnSerie.removeClass("popTartTabSerieOn");
	
	ordreFirstLetterCap = ordre.substring(0,1).toUpperCase()+ordre.substring(1,ordre.length);
	// puis on active seulement le bouton cliqué
	btnClicked.addClass("popTartTab"+ordreFirstLetterCap+"On").removeClass("popTartTab"+ordreFirstLetterCap+"Off");
	//btnClicked.removeClass("popTartTab"+ordreFirstLetterCap+"Off");

	var o =
	{
		selection:
		{
			value: ordre,
			options:
			{
				path: '/',
				expires: 1
			}
		}
	};
	
	$BK.process(['setCookies', o]);

	if(indexOld != indexNew)
	{
		this.data.thumbnailsSlider.selectionsActives['selection'] = indexNew;
		this.data.navMethod = this.data.thumbnailsSlider.navMethod[indexNew];
		if(bouton == 'btnCollection' || bouton == 'textCollection')
		{
			if($(document).getUrlParam('vid') == null) {
				BK_ajax_populerSlider($(document).getUrlParam('serie'), $(document).getUrlParam('vid'), $(document).getUrlParam('vid'), $(document).getUrlParam('vid'), true);
//				$BK.process(['newSetOfThumbnails']);
//				$BK.process(['dataRequest', [this.data.thumbnailsSlider]]);
			} else {
				BK_ajax_populerSlider($(document).getUrlParam('serie'), $(document).getUrlParam('vid'), $(document).getUrlParam('vid'), $(document).getUrlParam('vid'), true);
			}
		} else {
			$BK.process(['newSetOfThumbnails']);
			$BK.process(['dataRequest', [this.data.thumbnailsSlider]]);
		}
	}
	
	// en mode Serie, on ne voit pas de classement
	if(ordre=="serie")
	{
		$("div#popTartNavigationClassementTop").css("display","none");
		$("div#popTartNavigationClassementBottom").css("display","none");
	} else {
		$("div#popTartNavigationClassementTop").css("display","block");
		$("div#popTartNavigationClassementBottom").css("display","block");
	}
	
	this.mouseoverSelection(bouton);
}

function TAC_changeClassification(msg)
{
	var ordre		= msg[0];
	var bouton		= msg[1];
	var indexOld = this.data.thumbnailsSlider.selectionsActives['classification'];
	var indexNew = $BK.process(['findIndex', [ordre, this.data.thumbnailsSlider.selections.classification]]);
	
	// on détecte le bouton actuellement cliqué
	var btnClicked	= $("span[id^="+bouton.substring(0,bouton.length-1)+"]");
	// on liste manuellement les boutons de cette navigation-là
	var arrBtns	= new Array($("span#btnDate1"), $("span#btnVote1"), $("span#btnDate2"), $("span#btnVote2"));
	
	// on boucle tous les boutons et on les met tous à Off
	for(x=0; x<arrBtns.length; x++)
	{
		arrBtns[x].addClass("popTartNavigationClassementOff").removeClass("popTartNavigationClassementON");
		//arrBtns[x].removeClass("popTartNavigationClassementON");
	}
	// puis on active seulement le bouton cliqué
	btnClicked.addClass("popTartNavigationClassementON").removeClass("popTartNavigationClassementOff");
	//btnClicked.removeClass("popTartNavigationClassementOff");
	
	if(indexOld != indexNew)
	{
		this.data.thumbnailsSlider.selectionsActives['classification'] = indexNew;
		$BK.process(['newSetOfThumbnails']);
		$BK.process(['dataRequest', [this.data.thumbnailsSlider]]);
	}
	
	var o =
	{
		classification:
		{
			value: ordre,
			options:
			{
				path: '/',
				expires: 365
			}
		}
	};
	
	$BK.process(['setCookies', o]);
}


function TAC_setLanguage(msg)
{
	this.data.language = msg;
	
	//this.data.playerTexts	= $.languagesForPlayer[this.data.language];
	//$.languagesForPlayer	= null;
}


function TAC_mouseoverSelection(idBtn)
{
	var selection = $TAC.data.thumbnailsSlider.selections.selection[$TAC.data.thumbnailsSlider.selectionsActives.selection];
	
	switch(idBtn)
	{
		case 'btnCollection':
		case 'textCollection':
			var btn = $("div#btnCollection");
			
			if(selection == 'collection')
			{
				$("#btnCollection").css("cursor", "default");
				$("#textCollection").css("cursor", "default");
				//$("#textCollection").css("cursor", "default").css("text-decoration", "none");
			} else {
				$("#btnCollection").css("cursor", "pointer");
				$("#textCollection").css("cursor", "pointer");
				//$("#textCollection").css("cursor", "pointer").css("text-decoration", "underline");
			}

			btn.addClass("popTartTabCollectionOn").removeClass("popTartTabCollectionOff");
			break;
			
		case 'btnSerie':
		case 'textSerie':
			var btn = $("div#btnSerie");
			
			if(selection == 'serie')
			{
				$("#btnSerie").css("cursor", "default");
				$("#textSerie").css("cursor", "default");
				//$("#textSerie").css("cursor", "default").css("text-decoration", "none");
			} else {
				$("#btnSerie").css("cursor", "pointer");
				$("#textSerie").css("cursor", "pointer");
				//$("#textSerie").css("cursor", "pointer").css("text-decoration", "underline");
			}
			
			btn.addClass("popTartTabSerieOn").removeClass("popTartTabSerieOff");
			break;
	}
}

function TAC_mouseoutSelection(msg)
{
	var btnCollection	= $("div#btnCollection");
	var btnSerie		= $("div#btnSerie");
	
	var cookiesNamesList	= $BK.process(['getKeysInObject', [this.data.cookies]]);
	var cookies				= $BK.process(['getCookies', cookiesNamesList]);
	var selectionActive 	= "collection";
	if(cookies['selection']!=null)
	{
		selectionActive = cookies['selection'];
	}
	
	if(selectionActive!=msg[0])
	{
		if(msg[1]=='btnCollection')
		{
				btnCollection.addClass("popTartTabCollectionOff").removeClass("popTartTabCollectionOn").css("text-decoration", "none");
				//btnCollection.removeClass("popTartTabCollectionOn");
		}
		if(msg[1]=='btnSerie')
		{
				btnSerie.addClass("popTartTabSerieOff").removeClass("popTartTabSerieOn").css("text-decoration", "none");
				//btnSerie.removeClass("popTartTabSerieOn");
		}
	}

}

function TAC_mouseoverClassification(idBtn)
{
}

function TAC_mouseoutClassification(idBtn)
{
}


function TAC_sendFlashThumbnailsXML()
{
	var o = $BK_ThumbnailsSlider.composeRequest([$TAC.data.thumbnailsSlider]);
	
	var file = o.URL + "?" + o.data;
	
	$BK.process(['callToActionScript', ['BK_player', ['loadXMLThumbnails', 'xml/testUn.xml']]]);
}

function TAC_sendTextsToPlayer()
{
	//$BK.process(['callToActionScript', ['BK_player', ['receiveTexts', this.data.playerTexts]]]);
}

function TAC_setCaptioningCookie(msg)
{
	var o =
	{
		captioning:
		{
			value: msg,
			options:
			{
				path: '/',
				expires: 365
			}
		}
	};
	
	var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 60 * 1000));
	
	for(i in o){
		$.cookie(i, o[i].value, { path:'/', expires:date });
	}
}

function TAC_setLowHighResCookie(msg)
{
	var o =
	{
		lowHighRes:
		{
			value: msg,
			options:
			{
				path: '/',
				expires: 365
			}
		}
	};
	
	var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 60 * 1000));
	
	for(i in o){
		$.cookie(i, o[i].value, { path:'/', expires:date });
	}
}

TAC.prototype.process					= TAC_process;
TAC.prototype.init						= TAC_init;
TAC.prototype.activateCorrectStyle		= TAC_activateCorrectStyle;
TAC.prototype.actions					= TAC_actions;
TAC.prototype.assignBtnFonctionalities	= TAC_assignBtnFonctionalities;
TAC.prototype.assignPage				= TAC_assignPage;
TAC.prototype.changeSelection			= TAC_changeSelection;
TAC.prototype.changeClassification		= TAC_changeClassification;
TAC.prototype.setLanguage				= TAC_setLanguage;
TAC.prototype.mouseoverSelection		= TAC_mouseoverSelection;
TAC.prototype.mouseoverClassification	= TAC_mouseoverClassification;
TAC.prototype.mouseoutSelection			= TAC_mouseoutSelection;
TAC.prototype.mouseoutClassification	= TAC_mouseoutClassification;
TAC.prototype.sendFlashThumbnailsXML	= TAC_sendFlashThumbnailsXML;
TAC.prototype.sendTextsToPlayer			= TAC_sendTextsToPlayer;
TAC.prototype.setCaptioningCookie		= TAC_setCaptioningCookie;
TAC.prototype.setLowHighResCookie		= TAC_setLowHighResCookie;

$TAC = new TAC();

/**
if($BK !== undefined)
{
	$BK.registerObject($TAC);
}
*/
