var Site = {
	
	start: function(){
		
		if ($('photoGallery')) Site.startGallery('photoGallery', false, true, true, 'Fotos', true);
		
		if ($('sitePhotoGallerySet')) Site.startGallerySet('sitePhotoGallerySet', false, true, true, 'Fotos', true);
		
		if ($('concertGalleryViewlet')) Site.startGallery('concertImages', false, true, true, 'Fotos', true);
		
		if ($('iblussomPromoGallery')) Site.startGallery('iblussomPromoGallery', true, false, false, '', false);
		
		if ($('historial')) {
			Site.startTips();
		} else {
			if ($('allRecordsNavBar')) Site.startTips();
		}
				
		// if ($('HomePageNavigationViewlet')) Site.startTips();
		
		if ($('playerRecordNavigation')) Site.startTips();
		
		if ($('kwick')) Site.parseKwicks('kwick', 50, 60, 185, '#kwick .kwick');
				
		if ($('bandkwick')) Site.parseKwicks('bandkwick', 94, 124, 240, '#bandkwick .kwick');
		
		if ($('guestkwick')) Site.parseKwicks('guestkwick', 94, 124, 240, '#guestkwick .kwick');
		
		if ($('allRecordsKwick')) Site.parseKwicks('allRecordsKwick', 75, 200, 450, '#allRecordsKwick .kwick');
		
		if ($('videokwick')) Site.parseKwicks('videokwick', 32, 100, 300, '#videokwick .kwick');
					
		if ($('download')) Download.start();
		
		if ($('recordSongs')){
			// Site.appearText();
			/*if (!window.ie6) Site.makeShadow();*/
		}
	},
	
	startGallery: function(galleryName, isTimed, arrowsVisible, carouselVisible, carouselText, infopaneVisible) {
		var myGallery = new gallery($(galleryName), {
			timed: isTimed,
			textShowCarousel: carouselText,
			showArrows: arrowsVisible,
			showCarousel: carouselVisible,
			showInfopane: infopaneVisible,
			delay: 5000
		});
	},
	
	startGallerySet: function(galleryName, isTimed, arrowsVisible, carouselVisible, carouselText, infopaneVisible) {
		var myGallerySet = new gallerySet($(galleryName), {
			timed: isTimed,
			textGallerySelector: 'Galerias',
			textShowGallerySelector: 'Outras Galerias',
			textGalleryInfo: '{0} Fotos',
			startWithSelector: true,
			/* Changing default options */
			textShowCarousel: '{0}/{1} Fotos'});
	},
	
	startTips: function() {
		var fastTips1 = new Tips($$('.fastTips'));
	},
	
	parseKwicks: function(kwickName, minWidth, standardWidth, maxWidth, elementName){
		var kwicks = $$(elementName);
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		var defaultWidth = standardWidth;
		var kwickInUse = kwickName;
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'display' : 'inline',
					'width': [kwick.getStyle('width').toInt(), maxWidth]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 105) obj[j] = {'width': [w, minWidth]};
					}
				});
				fx.start(obj);
			});
		});
		
		$(kwickInUse).addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), defaultWidth]};
			});
			fx.start(obj);
		});
	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#recordSongs li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			el.setStyle('margin-left', '-1000px');
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-left', {
				duration: 400,
				transition: Fx.Transitions.backOut,
				wait: false
				/*onComplete: Site.createOver.pass([el, i])*/
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 15);

		}, this);
	},
	
	createOver: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a') return;
		var overfxs = new Fx.Styles(first, {'duration': 200, 'wait': false});
		var tocolor, fromcolor;
		if (first.hasClass('big')){
			tocolor = '333';
			fromcolor = 'fff';
		} else {
			tocolor = 'faec8f';
			fromcolor = '595965';
		}
		el.mouseouted = true;
		el.addEvent('mouseenter', function(e){
			overfxs.start({
				'color': tocolor,
				'margin-left': 10
			});
		});
		el.addEvent('mouseleave', function(e){
			overfxs.start({
				'color': fromcolor,
				'margin-left': 0
			});
		});
	},
	
	makeShadow: function(){
		new Element('img').injectInside('container').setStyles({
			'position': 'absolute', 'top': '0', 'margin-top': '-30px', 'left': '644px', 'z-index': '999999'
		}).setProperties({
			'height': $('sidebar').offsetHeight + 70, 'width': '10', 'src': '/assets/images/menubig_shadow.png'
		});
	}
};

var Download = {

	start: function(){
		
		var compSlide = new Fx.Slide('compression', {duration: 500, transition: Fx.Transitions.quadOut, wait: false}).hide();
		
		$('compression-tog').addEvent('click', function(e){
			compSlide.toggle();
			new Event(e).stop();
		});
		
		Download.trs = $$('tr.option');
		
		Download.chks = $$('#download div.check');
		
		Download.radios = $$('#compression-options div.check');
		
		Download.prefs = $$('#preferences-options div.check');
		
		
		Download.fx = [];
		Download.parse();
		
		var allinputs = $$(Download.prefs, Download.chks, Download.radios);
		
		allinputs.each(function(chk){
			chk.inputElement = chk.getElement('input');
			chk.inputElement.setStyle('display', 'none');
		});
		
		allinputs.each(function(chk){
			if (chk.inputElement.checked) Download.select(chk);
		});
		
		Download.select(Download.chks[0]);
		
		Download.select(Download.radios[0]);
	},

	select: function(chk){
		
		chk.inputElement.checked = 'checked';
		
		Download.fx[chk.index].start({
			'background-color': '#161619',
			'color': '#FFF'
		});
		
		chk.addClass('selected');
		
		if (chk.deps){
			chk.deps.each(function(id){
				if (!$(id).hasClass('selected')) Download.select($(id));
			});
		} else if (chk.inputElement.type == 'radio'){
			Download.radios.each(function(other){
				if (other == chk) return;
				Download.deselect(other);
			});
		}
	},
	
	all: function(){
		Download.chks.each(function(chk){
			Download.select(chk);
		});
	},
	
	none: function(){
		Download.chks.each(function(chk){
			Download.deselect(chk);
		});
	},

	deselect: function(chk){
		chk.inputElement.checked = false;
		Download.fx[chk.index].start({
			'background-color': '#1d1d20',
			'color': '#595965'
		});
		chk.removeClass('selected');
		
		if (chk.deps){
			Download.chks.each(function(other){
				if (other == chk) return;
				if (other.deps.test(chk.id) && other.hasClass('selected')) Download.deselect(other);
			});
		}
	},

	parse: function(){
		Download.trs.each(function(tr, i){
			Download.fx[i] = new Fx.Styles(tr, {wait: false, duration: 300});

			var chk = tr.getElement('div.check');

			chk.index = i;
			var dp = chk.getProperty('deps');
			if (dp) chk.deps = dp.split(',');

			tr.addEvent('click', function(){
				
				if (!chk.hasClass('selected')) Download.select(chk);
				else if (tr.hasClass('check')) Download.deselect(chk);
			});
			
			tr.addEvent('mouseenter', function(){
				if (!chk.hasClass('selected')){
					Download.fx[i].start({
						'background-color': '#18181b',
						'color': '#b3b3bb'
					});
				}
			});
			
			tr.addEvent('mouseleave', function(){
				if (!chk.hasClass('selected')){
					Download.fx[i].start({
						'background-color': '#1d1d20',
						'color': '#595965'
					});
				}
			});

		});
	}

};

window.addEvent('load', Site.start);