// 
// 
//       **********           *****************               *         
//     **************         *****************              ***        
//   ******************       *****************             *****       
//  ********************      *****************            *******      
//  ********************      *****************           *********     
//  ********************      *****************          ***********    
//  ********************      *****************         *************   
//   ******************       *****************        ***************  
//     **************         *****************       ***************** 
//       **********           *****************      *******************
// 
// Created by DieNeueModern.com
// 
// (c) Copyright 2007 James Hicks. All Rights Reserved. 
// 
window.addEvent('domready', function() {
	
//
//		Links in new windows
//	

	var links = $$('.pieceDescription a');
	
	links.each(function(link){
	   link.setProperty('target', '_blank');
	});
	
//
//		Keys
//
		
	window.addEvent('keyup', function(event){
	    event = new Event(event);
	    if (event.key == 'g') {
			$('bodyId').className = "baselined";
		}		
	});
	
//
//		Lists
//

	var listHeads = $$("div.listHeader");
	
	listHeads.each(function(header){
		var arrow    = header.getElement('span');
		var thisList = $('list'+arrow.getText());
		
		
		header.$tmp.listFx  = new Fx.Slide(thisList, {duration:400, wait:true, transition: Fx.Transitions.cubicOut});
		header.$tmp.headFx  = new Fx.Styles(header,  {duration:400, wait:true, transition: Fx.Transitions.cubicOut});
		header.$tmp.arrowFx = new Fx.Styles(arrow,   {duration:400, wait:true, transition: Fx.Transitions.cubicOut});
		 
		if(window.ie){
			header.$tmp.arrowFx.set({ 'background-position-y': '-7' });				
		} else {
			header.$tmp.arrowFx.set({ 'background-position': '626, -7' });				
		}
		
		
//		Microfilter
		if(microFilter != ""){
			if(arrow.getText() != microFilter){
				header.$tmp.listFx.hide();
				header.$tmp.headFx.set({
					'opacity': 0.3
				});	
				if(window.ie){
					header.$tmp.arrowFx.set({ 'background-position-y': '-43' });
				} else {
					header.$tmp.arrowFx.set({ 'background-position': '626, -43' });
				}					
			}
		}
//
		
		header.addEvent('click', function(event){
			event = new Event(event);
			this.$tmp.listFx.toggle();
			this.$tmp.headFx.stop();
			if (this.$tmp.listFx.open == true) {
				this.$tmp.headFx.start({
					'opacity': 0.3
				});				
				if(window.ie){
					header.$tmp.arrowFx.start({ 'background-position-y': '-42' });				
				} else {
					header.$tmp.arrowFx.start({ 'background-position': '626, -42' });				
				}
			} else {
				this.$tmp.headFx.start({
					'opacity': 1
				});
				if(window.ie){
					header.$tmp.arrowFx.start({ 'background-position-y': '-7' });				
				} else {
					header.$tmp.arrowFx.start({ 'background-position': '626, -7' });				
				}
				
			}

		});
	});
	
//
//  Video Link
//

	if($('video')){
		var videoLink = $('videoLink');
		var videoFX			= new Fx.Styles($('video'), {duration:400, wait:true, transition: Fx.Transitions.cubicOut});
		var videoButtonFX	= new Fx.Styles(videoLink.getParent(), {duration:400, wait:true, transition: Fx.Transitions.cubicOut});
		videoLink.addEvent('click', function(event){
			event = new Event(event);
			var videoData = this.name.split(',');
			loadVideo(videoData[0],videoData[1],videoData[2]);
			
		
			
			videoButtonFX.start({
				'overflow': 'hidden',
				'height': 0,
				'opacity': 0
			}).chain(function() {
				videoLink.getParent().remove();
				
			});
			
		});
	}

	function loadVideo(url,width,height){
			
		videoFX.start({
			'height': height
		}).chain(function() {
			$('video').innerHTML = "<object width='"+width+"' height='"+height+"' classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab'> <param name='src' value='/mov/"+url+"'> <param name='controller' value='true'> <param name='autoplay' value='true'> <embed src='/mov/"+url+"' width='"+width+"' height='"+height+"' controller='true' autoplay='true' scale='tofit' cache='true' pluginspage='http://www.apple.com/quicktime/download/' > </object>";
		});
		
	}
	
	
});	
