/**
 * @author Roman Schmid
 */
// ensure that Prototype and Scriptaculous are indeed loaded
if(typeof Scriptaculous == "undefined"){
	alert("ERROR: scriptaculous.js must be loaded prior to this File");
}

if(typeof Prototype == "undefined"){
	alert("ERROR: prototype.js must be loaded prior to this File");
}

var iConcerts = {
	Version:"0.1.1",
	init: function() {
		//this.initSubNav();
		this.initMainNav();
		//this.initPlayList();
//		this.initRelated();
		//this.initContent();
		
		var loading = $('loading');
		if(loading)
			loading.remove();
	},
	
	initSubNav: function(artistMenuOpen){
		var subnav = new iConcerts.UI.SubNav('subNav',artistMenuOpen);
		
	},
	
	initMainNav: function(){
		var mainnav = new iConcerts.UI.MainNav('mainNav');
	},
	
	initPlayList: function(){
		this.playlists = new iConcerts.UI.TabbedArea('playlists', {titleTag:'h3', addScroll:true, addViewOptions:false});
//		var myconc = new iConcerts.UI.TabbedArea('myConcerts', {addViewOptions:false});
	},
	
	initUserPlayList: function(uplID){
		this.playlists = new iConcerts.UI.TabbedArea('playlists', {titleTag:'h3', showIndex: uplID, addScroll:true, addViewOptions:false});
//		this.droppable = new iConcerts.UI.UserPlaylist('upWrapper');
	},
	
	initRelated: function(){
		var related = new iConcerts.UI.TabbedArea('relatedArea', {titleTag:'h3', addScroll:true});
	},
	
	initContent:function(){
/*		if($('flashPlayer')){ 
			// only prepare fader if flashPlayer element exists
			this.fader = new iConcerts.UI.ScreenFader('flashPlayer');
		}
*/		
//		var draggable = new iConcerts.UI.UnitTrack('unittrack_container', '.upWrapper');

		if($('TrackUpPage')){ 
			this.userPlaylistPage = new iConcerts.UI.UserPlaylistPage('TrackUpPage');
		}
//		var grid = $$('.grid');
//		if(grid.length > 0){
//			new iConcerts.UI.DisplayOptions($('titlebox'), $('content'));
//		}
		
//		var pager = document.select('.pager');
/*		var pager = $$('.pager');
		if(pager.length > 0)
			{
			pager.each(function(s) {
  				$('gridpager').replace(s.innerHTML);
  				s.replace('');
			});

			
			}
*/		$$('.addScrollBar').each(function(elem){
//			alert('coucou scrollbar');
			elem.addScrollBar();
		}.bind(this));

		if($('TrackUpPage')){ 
			this.userPlaylistPage = new iConcerts.UI.UserPlaylistPage('TrackUpPage');
		}
	
	},
	
	darkScreen: function(callback){
		var darken = function(){
			if(this.fader)
				this.fader.fadeIn(callback);
		}.bind(this);
		
		iConcerts.UI.MainNav.closeAll(darken);
		return false;
	},
	
	brightScreen: function(callback){
		if(this.fader)
			this.fader.fadeOut(callback);
		return false;
	}
}

function toggleEPG(epgblock, plus) {
	if (iConcerts.EPGEffect != null) {
		return;
	}
	var b = $(epgblock);
	if (b.visible()) {
		if ($(plus + '1') != null) {
			$(plus + '1').setStyle({backgroundPosition: '0px 0px'});
		}
		if ($(plus + '2') != null) {
			$(plus + '2').setStyle({backgroundPosition: '0px 0px'});
		}
		if ($(plus + '3') != null) {
			$(plus + '3').setStyle({backgroundPosition: '0px 0px'});
		}
		if ($(plus + '4') != null) {
			$(plus + '4').setStyle({backgroundPosition: '0px 0px'});
		}
		iConcerts.EPGEffect = new Effect.SlideUp(epgblock, {duration: 1.0, afterFinish:function(obj) {
			iConcerts.EPGEffect = null;
		}});
	}
	else {
		if ($(plus + '1') != null) {
			$(plus + '1').setStyle({ backgroundPosition: '0px -10px' });
		}
		if ($(plus + '2') != null) {
			$(plus + '2').setStyle({ backgroundPosition: '0px -10px' });
		}
		if ($(plus + '3') != null) {
			$(plus + '3').setStyle({ backgroundPosition: '0px -10px' });
		}
		if ($(plus + '4') != null) {
			$(plus + '4').setStyle({ backgroundPosition: '0px -10px' });
		}
		iConcerts.EPGEffect = new Effect.SlideDown(epgblock, {duration: 1.5, afterFinish:function(obj) {
			iConcerts.EPGEffect = null;
		}});
	}
}
	
