function fixElements(page) {
	if ((page == 'news') || (page == 'press')) {
		var content = $('content');
		var contentWidth = content.clientWidth;
	
		var posts = $$('.post');	
		
		
		if (page == 'news') {
			var postsWidth = (452 * posts.length);
		
			if (contentWidth < postsWidth) {
				content.style.width = postsWidth + 'px';
			}
		} else {
			var press = $$('.press');
			
			for (var i=0;i<press.length;i++) {
				new Effect.Appear(press[i],{
					duration: .08,
					delay: (i * .08)
				});
			}
			resizeImages();
		}
		
		for (var i=0;i<posts.length;i++) {
			if(page == 'news') {
				new Effect.Morph(posts[i],{
					duration: .18,
					delay: (i * .18),
					style: 'width: 400px; padding: 10px 20px 20px;'
				});
			} else {
				new Effect.Morph(posts[i],{
					duration: .18,
					delay: (i * .18),
					style: 'width: 650px; padding: 10px 20px 20px;'
				});
			}
		}
	}
	else if (page == 'blog') {
		var posts = $$('.post');	
		
		postCount = posts.length - 1;
		
		for (var i=postCount;i>(-1);i--) {
			new Effect.BlindDown(posts[i],{
				duration: .18,
				delay: (i * .18)
			});
		}
	}
	
	else if (page == 'live') {
		if ($('upcomingDatesTable')) {
			new Effect.BlindDown('upcomingDatesTable', {
				duration: .4,
				afterFinish: function() {
					Effect.BlindDown('pastDatesTable', { duration: .4 });
				}
			});
			new Effect.BlindDown('upcomingDates', {
				duration: .4,
				afterFinish: function() {
					Effect.BlindDown('pastDates', { duration: .4 });
				}
			});
		} else {
			new Effect.BlindDown('pastDatesTable', { duration: .4 });
			new Effect.BlindDown('pastDates', { duration: .4 });
		}
	}
	
	else if (page == 'links') {
		//if (navigator.appName != 'Microsoft Internet Explorer') {
		var boxes = $$('.shortBox');
		
			for (var i=0;i<boxes.length;i++) {
				new Effect.Morph(boxes[i], { style: 'fullBox' });
			}
		//}
	}
	
	else if (page == 'contact') {
		var boxes = $$('.shortBox');
		
		for (var i=0;i<boxes.length;i++) {
			new Effect.BlindDown(boxes[i]);
		}
	}
	
	else if (page == 'music') {
		var releases = $('releases');
		var tracklist = $('tracklist');
		var descr = $('releaseDescription');
		var press = $('releasePress');
		var allTracks = $('allTracks');
		
		if(releases) {
			new Effect.SlideDown(releases, {
				duration: .7,
				afterFinish: function() {
					if(tracklist) {
						tracklist.style.top = (releases.clientHeight + 2) + 'px';
						new Effect.Appear(tracklist, { 
							duration: .7,
							afterFinish: function() {
								new Effect.BlindDown('tracks');
								if (descr) {
									descr.style.height = releases.clientHeight + 'px';
									Effect.SlideDown(descr);
								}
								if (allTracks) {
									allTracks.style.top = (releases.clientHeight + 2) + 'px';
								}
								if (press) {
									press.style.top = (releases.clientHeight + 2) + 'px';
									Effect.SlideDown(press);
								}
							}
						});
					}
				}
			});
		}
	}
}

function canvasProcess(page) {
	if ($('header')) {
		var header = $('header');
	}
	if($('content')) {
		var content = $('content');
	}
	
	if (navigator.appName == 'Microsoft Internet Explorer') {
		resize();
		new Effect.Morph('header', {
			style: 'onscreen',
			duration: .5,
			afterFinish: function() {
				$('content').appear({ 
					from: 0.0,
					to: 1.0,
					duration: .5, 
					afterFinish: function() {
						fixElements(page);
					}
				});
			}
		});
	} else {
		var bg = $('page_bg');
		new Effect.Appear(bg, {
			afterFinish: function() {
				new Effect.Morph(header, {
					style: 'onscreen',
					duration: .5,
					afterFinish: function() {
						$('content').appear({ 
							from: 0.0,
							to: 1.0,
							duration: .5, 
							afterFinish: function() {
								fixElements(page);
							}
						});
					}
				});
			}
		});
	}
}

function createPlayer(file, placeholder, width, height) {
            var flashvars = {
                    file:file, 
                    autostart:"true",
										skin:"http://grizzly-bear.net/flash/overlay.swf"
            }
            var params = {
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
										wmode:"transparent"
            }
            var attributes = {
                    id:"player1",  
                    name:"player1"
            }
						if (file != '#') {
							swfobject.embedSWF("http://grizzly-bear.net/audio/player.swf", placeholder, width, height, "9.0.115", false, flashvars, params, attributes);
						}
}


function makeAudio(link, ID) {
	//if ($('player1')) { $('player1').sendEvent('STOP'); } 
	
	var press = $('releasePress');
	var file = $(link).readAttribute('href');
	var target = $('post-'+ID);
	var songs = $$('.trackInfo');
	
	if ((press) && (press.offsetLeft == '202')) {
		new Effect.Morph(press, {
			queue: 'front',
			style: 'pressMoved',
			afterFinish: function() {
				new Effect.Morph(press, {
					style: 'top: -10px'
				});
			}
		});
	}
	
	for (var i=0;i<songs.length;i++) {
		if (songs[i] == target) {
			new Effect.SlideDown(target, {
				duration: .8,
				queue: 'end',
				afterFinish: function() {
					if (file) {
						createPlayer(file,'track-'+ID, '480', '60');
					} else if ($('player1')) {
						$('player1').remove();
					}
				}
			});
		} else {
			new Effect.Fade(songs[i], { duration: .4 });
		}
	}
	
	if ($('playing')) { $('playing').writeAttribute('id', ''); }
	$(link).writeAttribute('id', 'playing');
	
	
}

function openVideo(ID, width, height) {
	var video = $('video-' + ID);
	var player = $('videoPlayer-' + ID);
	
	new Effect.Appear('lightsDown', {
		afterFinish: function() {
			$('lightsCont').innerHTML = video.innerHTML;
			new Effect.Appear('lightsCont');
			new Effect.Appear('closeVideo');
		}
	});
	
}

function closeVideo() {
	$('lightsDown').fade();
}

function reposition() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		
		var htmlEl = document.getElementsByTagName('body')[0];
	
		document.documentElement.onscroll = function() { 
			$('header').style.height = (document.documentElement.clientHeight + document.documentElement.scrollTop - 30) + 'px';
			//$('header').style.top = document.documentElement.scrollTop + 'px';
		}
	}
}

function resizeImages() {
	var imgs = $$('.pressThumbImg');
	
	for (var i=0;i<imgs.length;i++) {
		if ((imgs[i].height > 100) || (imgs[i].style.height > 100)) {
			imgs[i].style.height = '100px';
			var newWidth = (100 / imgs[i].height) * imgs[i].width;
			imgs[i].style.width = newWidth + 'px';
		
		}
	}
}

function bare() {
	window.status = ' ';
}