/* 	ObjectSingle
 *	Nice calendar navigation
 */

var ObjectSingle = function( action )	{

	Object.extend( obj = $$( '.ObjectSingle' ).pop(), ObjectSingle.proto );
	Object.extend( obj, ObjectSingle[ "proto_" + action ]);
	
	obj.init();	
	return obj;
}


ObjectSingle.proto = {
	
	current		: 0,
	
	bubble		: function() {}

}

ObjectSingle.proto_extended = {
	
	init		: function() {
		
		this.select( "img" ).invoke( "observe", "click", this.bubble.bind( this ) ).invoke( "observe", "mouseover", this.hover.bind( this ) ).invoke( "observe", "mouseout", this.blur.bind( this ) );
		this.up(0).observe( "mouseout", this.toggle );
	},
	
	active_img	: function( ref ) {
		
		this.select( "img" ).invoke( "setOpacity", 1 );
		
		this.img = (typeof ref == "number" )? this.select( "img" )[ ref ] : ref;
		this.img.setOpacity( 0.6 );
	},
	
	bubble		: function( e ) {
		img = e.element( e ); //e.currentTarget;
		$( 'photo' ).src = "/public.img?id=" + img.readAttribute( 'rel' ) + "&sze=980.664";
		this.active_img( img );
		//this.up(0).setOpacity( 0.12 );
	},
	
	hover		: function( e ) {
		img = e.element( e ); //e.currentTarget;
		img.setOpacity( (img == this.img )? 0.5 : 0.9 );
	},
	
	blur		: function( e ) {
		img = e.element( e ); //e.currentTarget;
		img.setOpacity( (img == this.img )? 0.6 : 1 );
	},
	
	toggle		: function() {
	
		this.setOpacity( 0.12 );
		this.observe( "mouseover", function() { this.setOpacity(1); } );
	}
}


/*
SVN Error:

ObjectSingle.proto_extended = {
	
	init		: function() {
		
		this.select( "img" ).invoke( "observe", "click", this.bubble.bind( this ) ).invoke( "observe", "mouseover", this.hover.bind( this ) ).invoke( "observe", "mouseout", this.blur.bind( this ) );
		this.up(0).observe( "mouseout", this.toggle );
	},
	
	active_img	: function( ref ) {
		
		this.select( "img" ).invoke( "setOpacity", 1 );
		
		this.img = (typeof ref == "number" )? this.select( "img" )[ ref ] : ref;
		this.img.setOpacity( 0.6 );
	},
	
	bubble		: function( e ) {
<<<<<<< .mine
		img = Event.element( e ); //e.currentTarget;
		$( 'photo' ).src = "/public.img?id=" + img.readAttribute( 'rel' ) + "&sze=980.664";
=======
		img = e.element( e ); //e.currentTarget;
		$( 'photo' ).src = "/public.img?id=" + img.readAttribute( 'rel' ) + "&sze=980.664";
>>>>>>> .r118
		this.active_img( img );
		//this.up(0).setOpacity( 0.12 );
	},
	
	hover		: function( e ) {
<<<<<<< .mine
		img = Event.element( e ); //e.currentTarget;
=======
		img = e.element( e ); //e.currentTarget;
>>>>>>> .r118
		img.setOpacity( (img == this.img )? 0.5 : 0.9 );
	},
	
	blur		: function( e ) {
<<<<<<< .mine
		img = Event.element( e ); //e.currentTarget; 
=======
		img = e.element( e ); //e.currentTarget;
>>>>>>> .r118
		img.setOpacity( (img == this.img )? 0.6 : 1 );
	},
	
	toggle		: function() {
	
		this.setOpacity( 0.12 );
		this.observe( "mouseover", function() { this.setOpacity(1); } );
	}
}*/


var SocialLastfm = function( type ) {
	
	Object.extend ( obj = $$('.SocialLastfm').pop(), SocialLastfm_proto );
	obj.type = type;
	
	obj.childs = obj.select( "li.tag" );
	obj[ "init_" + type ]();

	return obj;
}


var SocialLastfm_proto	= {
	
	init_toptracks	: function() {
		
		this.movie = this.select('.movie')[0].hide();
		this.player = this.movie.firstChild.remove();
		this.childs.each( this.childobserve.bind( this ) );
	},
	
	childobserve	: function( el ) {
		
		el.observe( "click", this.toptracks_load_src.bind( this ) );
	},
	
	toptracks_load_src	: function( e ) {

		this.childs.invoke( "removeClassName", "active" );
		li = e.currentTarget.addClassName( "active" );
	
		ref = li.attributes.getNamedItem("ref").value;
		
		this.player.src = this.source + ref;
		this.movie.update( this.player );
		this.select('.movie')[0].show();
	}
}

