/*
	Class: site
		Performs different action to the product.
		
	Usage:
		For instant, use to manage product variation
		
	Parameters:
		productClass - Product target (the product container)
		targetPrice - Product price target 
		targetVariation - Product variations target (all)
		separator - The char who separe thousand 
		formatPrice - Choose if the price must be formated // 0 : no format price (ex:1200) / 1 : format (ex:1'200.00)
		
	Exemple:
	
	About:
		product.js v.1.0 for mootools v1.1 05 / 2007
		
		by Floor SA (http://www.floor.ch) MIT-style license
		
		modified by Denis Schneiter 18.09.2007
		modified by sb 10.05.2010
*/
var site = {
	options: {
		server: 'fribowling',
		defaultLang: 'fr',
		
		cs2	: '/floor/cs',
		cs3	: '/cgi/app',
		server	: 'fribowling',
		slide : {
			fx:  {
				transition: Fx.Transitions.Quad.easeOut,
				duration: 400
			}	
		},
		CommentsTarget	: '.addcomment'
	},
	
	start: function() {
		
		Cufon.replace('h2');
		Cufon.replace('h1');
		Cufon.replace('.highlight');
		Cufon.replace('a.title');
		Cufon.replace('.side .menu li', { fontFamily: 'Vitesse Medium' });
		Cufon.replace('#calendar .controls .header');
		Cufon.replace('.monthWeek .monthDay div div');
		Cufon.replace('#calendar .dowRow td');
		
		Cufon.replace('table tr th');
		
		if (typeof(IFInterface) == 'undefined' && $(document.body).getElement('.footer .mainmenu')) {
			
		} else {
			this.handleGridMenu();	
			
		}
		
		if ($('monthly-score')){
			this.initTable($('monthly-score'));	
		}
		
		if ($(document.body).id == 'page32'){
			this.initCalendar();
		}
		
		if ($(document.body).id == 'page35'){
			//console.log($(document.body).id);
			this.initScores();
		}
		
		if ($(document.body).id == 'page1'){
			//console.log($(document.body).id);
			this.initWallOfFame();
		}
		
		if ($(document.body).getElement('form.reservation'))	{
			new Reservation($(document.body).getElement('form.reservation'));
		}
		
		this.initComments();
		this.initSlideItMoo();
	},
	
	initComments : function()	{
		var elements = $(document.body).getElements(this.options.CommentsTarget);
		if (elements)	{
			elements.each(function(el){
				new Comment(el);
			},this);
		}
	},
	
	initSlideItMoo: function() {
		//document.body.getElement('.wrapper').setStyle('width',document.body.getElement('.wrapper').getSize().x+'px');
			if ($('SlideItMoo_items')) {
				/* thumbnails example , div containers */
				new SlideItMoo({
					overallContainer: 'SlideItMoo_outer',
					elementScrolled: 'SlideItMoo_inner',
					thumbsContainer: 'SlideItMoo_items',		
					itemsVisible:1,
					elemsSlide:1,
					itemsSelector: '.SlideItMoo_element',
					transition: this.options.slide.fx.transition,
					duration:this.options.slide.fx.duration,
					itemWidth: 950,
					showControls:1,
					startIndex:1,
					autoSlide:5000,
					onChange: function(index){
						//console.log('next');
					}
				});
			}
			if ($('SlideItMooGallery_outer')) {
				/* thumbnails example , div containers */
				new SlideItMoo({
					overallContainer: 'SlideItMooGallery_outer',
					elementScrolled: 'SlideItMooGallery_inner',
					thumbsContainer: 'SlideItMooGallery_items',
					navs:{ /* starting this version, you'll need to put your back/forward navigators in your HTML */
						fwd:'.SlideItMooGallery_forward', /* forward button CSS selector */
						bk:'.SlideItMooGallery_back' /* back button CSS selector */
					},		
					itemsVisible:2,
					elemsSlide:1,
					duration:300,
					itemsSelector: '.SlideItMoo_element',
					transition: Fx.Transitions.Quad.easeOut,
					itemWidth: 81,
					showControls:1,
					startIndex:1,
					autoSlide:5000,
					onChange: function(index){
						//console.log('next');
					}
				});
			}
	},
	
	initTable: function(container) {
		var table = container.getElement('table');
		
		var myTable = new HtmlTable(table,{
			paginate:true,
			paginateRows:12,
			paginationControlPages:10
		});
		
		myTable.updatePagination();
		
	},
	
	handleGridMenu: function() {
		var self = this;
		if (!$('IFInterfaceMenu')) return;
		
		var ul = $('IFInterfaceMenu').getElement('ul');
		
		ul.getChildren().each(function(li) {
			if (li.get('html') == 'Canvas') {
				li.destroy();
			}
			
			if (li.get('html') == 'Context') {
				new Element('li',{ html: 'Grid'}).addEvent('click',function() {
					self.toggleGrid();	
				}).addClass('IFBlue').inject(li,'after');
			}
		});
		
		
	},
	
	handleGrid: function() {
		
	},
	
	toggleGrid: function() {
		if ($(document.body).getElement('.container').hasClass('showgrid'))
			this.hideGrid();
		else 
			this.showGrid();
	},
	
	showGrid: function() {
		$(document.body).getElements('.container').each(function(el){
			el.addClass('showgrid')	
		})
	},
	
	hideGrid: function() {
		$(document.body).getElements('.container').each(function(el){
			el.removeClass('showgrid');
		})
	},
	
	initCalendar: function() {
		// read events
		var eventlist = [];
		var title = '';
		$('eventlist').getChildren().each(function(el) {
			//var title = el.getElement('a.title').get('html');
			
			if (el.getElement('a.title').get('html'))
			eventlist.push({
				title:el.getElement('a.title').get('html'),
				start:el.getElement('div.date').get('html'),
				end:el.getElement('div.date').get('html')
			});
			//console.log(title);
		});
		
		//console.log(eventlist);
		/*
		new Calendar({
			calContainer:'calendar',
			newDate:'11/17/2011',
			cEvents: [ 
				{ 
					title:title,
					start:'2009-11-05',
					end:'2009-11-05'
				},
				{ 
					title:'yoyoyo',
					start:'2009-11-06',
					end:'2009-11-06'
				},
				{ 
					title:'lonely tunes',
					start:'2009-12-06',
					end:'2009-12-06'
				}
			]	
		});*/
		
		var date = new Date();
		
		new Calendar({
			calContainer:'calendar',
			newDate:date,
			cEvents: eventlist
		});
	},
	
	initScores: function(){
		
		annual = new Request.HTML({
			url: '/data/score-annual.htm',
			method: 'get',
			update: $('results'),
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
				var table = $('results').getElement('table');
				var myTable = new HtmlTable(table,{
					paginate:true,
					paginateRows:10,
					paginationControlPages:12
				});
	
				myTable.updatePagination();
			}
		}).get();	
		
		hebdo = new Request.HTML({
			url: '/data/score.htm',
			method: 'get',
			update: $('hebdo'),
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
				var table = $('hebdo').getElement('table');
				var myTable = new HtmlTable(table,{
					paginate:true,
					paginateRows:10,
					paginationControlPages:12
				});
	
				myTable.updatePagination();
			}
		}).get();	
	},
	
	initWallOfFame: function(){
		
		hebdo = new Request.HTML({
			url: '/data/score.htm',
			method: 'get',
			update: $('hebdo'),
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
				var table = $('hebdo').getElement('table');
				var myTable = new HtmlTable(table,{
					paginate:true,
					paginateRows:10,
					paginationControlPages:12
				});
	
				myTable.updatePagination();
			}
		}).get();	
	}
};


window.addEvent('domready', function()	{
	site.start();
});
