(function( $ ){
	$.fn.discographyPost = function( settings ) {
	
		return this.each(function() {
							
			var zoom	 		= $(this).find('.header .zoom');
			var thumbnails 		= $(this).find('.header .thumbnail');
			var albumLinks 		= $(this).find('h3 a');
			var albumArticles 	= $(this).find('.article');
			var viewMoreLinks	= $(this).find('.view_more');
							
			var currentPost;

			albumLinks.add( viewMoreLinks )
				.attr('href', '#')	
				.click( function(e) {				
					if( currentPost && currentPost[0] == $(this).closest('.post')[0] ){
						currentPost.children('.article').slideUp( 500, 'easeOutExpo' );
						currentPost.find('.view_more').text( settings.viewMoreTxt );
						currentPost = undefined;
					} else {
						if( currentPost ){
							currentPost.children('.article').slideUp( 500, 'easeOutExpo' );
							currentPost.find('.view_more').text( settings.viewMoreTxt );
						}
						currentPost = $(this).closest('.post');
						currentPost.children('.article').slideDown( 1000, 'easeInOutExpo' );
						currentPost.find('.view_more').text( settings.viewLessTxt )
					}
					return false;
				});
		
			zoom
				.css({ opacity: 0 })
				.hover( 	
					function( e ){
						$(this).css({ opacity: 1 });
					},
					function( e ){
						$(this).css({ opacity: 0 });
					}
				)
				.click( function(e){
					$(this).next().click();
				});
				
			thumbnails	
				.colorbox();
									
			$(this).hover(	
				function( e ){
					$(this).find('.view_more').show();									
				},
				function( e ){
					$(this).find('.view_more').hide();
				}
			);
			
		});
							
	};
})( jQuery );


(function( $ ){
	$.fn.galleryTrigger = function( settings ) {	
		return this.each(function() {
			$(this).click( function(e) {			
				$('#body .gallery dl:first-child a').click();				
			});
		});							
	};
})( jQuery );


jQuery(document).ready(function() {

	//jQuery('#main-menu li ul').hide();
	
	jQuery('#main-menu').children('ul').children('li').hover(	
		function( e ){
			jQuery(this).children('a')
				.stop(true, true)
				.animate({'padding-right': 40}, 100 ); 
			var children = jQuery(this).children('ul');
			if( children.length ) children.show();
		},
		function( e ){
			jQuery(this).children('a')
				.stop(true, true)
				.animate({'padding-right': 20}, 100 ); 
			var children = jQuery(this).children('ul');
			if( children.length ) children.hide();
		}
	);

	jQuery('#body .contents .group img').css({ opacity: 0.6 });	
	jQuery('#body .contents .group').hover(	
		function( e ){
			jQuery(this)
				.addClass('group-hover');
			jQuery(this).find('img').stop(true, true).animate({ opacity: 1 }, 500);
		},
		function( e ){
			jQuery(this)
				.removeClass('group-hover');
			jQuery(this).find('img').stop(true, true).animate({ opacity: 0.6 }, 500);
		}
	);
	
	jQuery('#body .contents .post').hover(	
		function( e ){
			jQuery(this).addClass('post-hover')
		},
		function( e ){
			jQuery(this).removeClass('post-hover')
		}
	);
	/*
	jQuery('#body .contents .post').click( function(e){
		console.log('123');
	});
	*/
	
	function setCookie(name, value){
		//console.log('setCookie', name, value);
		jQuery.cookie( name, value, { expires: 7, path: '/site/', domain: 'www.ricardogallo.com' } );
	}
	
	jQuery('#audio-player').jPlayer({
		ready: function () {
			var command 	= ( jQuery.cookie( 'player-currently-playing' ) == 'true' ) ? 'play' : 'pause';
			var currentTime = parseFloat( jQuery.cookie( 'player-current-time' ) );			
			var currentSong = jQuery.cookie( 'player-current-song' );
			
			//console.log( '.--- ', command, currentTime, currentSong );			
			//if( currentSong ){
				//console.log('ni shit');	

			jQuery('#jp_playlist_1 div').html( jQuery.cookie( 'player-current-song-name' ) );	
				
			jQuery(this)
				.jPlayer('setMedia', {mp3: currentSong })
				.jPlayer(
					command,
					currentTime
				);				
			//}
		},		
		play: function (event) {
			setCookie('player-currently-playing', 'true');
		},
		pause: function (event) {
			setCookie('player-current-time', event.jPlayer.status.currentTime );
			setCookie('player-currently-playing', 'false');
		},
		ended: function (event) {
			setCookie('player-currently-playing', 'false');
		},
		timeupdate: function (event) {
			setCookie('player-current-time', event.jPlayer.status.currentTime );
		},
		swfPath: 'http://www.ricardogallo.com/site/wp-content/themes/ricardogallo/js',
		supplied: 'mp3'
	});	
	
	jQuery('.play-audio').each( function(e){
		jQuery(this)
			.attr('href1', jQuery(this).attr('href') )
			.attr('href', '#' );	
	});	

	jQuery('.play-audio').click( function(e){		
		setCookie('player-current-song', jQuery(this).attr('href1') );
		jQuery('#audio-player')
			.jPlayer('setMedia', {mp3: jQuery(this).attr('href1')})
			.jPlayer('play');

		var songName = '<strong>' + jQuery(this).attr('name') + '</strong>';
		if( jQuery(this).attr('group') ){
			songName += '<br/>';			
			if( jQuery(this).attr('group-permalink') )
				songName += '<a href="' + jQuery(this).attr('group-permalink') + '">' + jQuery(this).attr('group') + '</a>'
			else
				songName += jQuery(this).attr('group');
		}
		setCookie('player-current-song-name', songName );	

		jQuery('#jp_playlist_1 div').html( songName );	
		return false;
	});
});



