;(function($) {

		function recuf() {
		Cufon.replace('h3');
		}
		

									 									
		// Player

			function demoInstanceInfo(myPlayer, myInfo) {
				var jPlayerInfo = "<p>This jPlayer instance is running in your browser using ";
				if(myPlayer.jPlayerGetInfo("html5")) {
					jPlayerInfo += "<strong>HTML5</strong> with ";
					if(myPlayer.jPlayerGetInfo("canPlayOGG")) {
						jPlayerInfo += "<strong>OGG</strong>";
					} else {
						jPlayerInfo += "<strong>MP3</strong>";
					}
				} else {
					jPlayerInfo += "<strong>Flash</strong> with <strong>MP3</strong>";
				}
				jPlayerInfo += " files.<br />This instance has the constructor option ";
				if(myPlayer.jPlayerGetInfo("oggSupport")) {
					jPlayerInfo += "set to <code>$(\"#jpId\").jPlayer({oggSupport: true})</code>";
				} else {
					jPlayerInfo += "defaulting to <code>$(\"#jpId\").jPlayer({oggSupport: false})</code>";
				}
				jPlayerInfo += "</p>";
				myInfo.html(jPlayerInfo);
			}

			var playItem = 0;

			var myPlayList = [
			    {name:"Hold Your Tongue (War To Head)",mp3:"http://apemachine.com/m/HoldYourTongue.mp3"},
				{name:"All Times",mp3:"http://apemachine.com/m/AllTimes.mp3"},
				{name:"Wear Me Out",mp3:"http://apemachine.com/m/WearMeOut.mp3"},
				{name:"Monte Malady",mp3:"http://apemachine.com/m/MonteMalady.mp3"}

			];

			$("#jquery_jplayer").jPlayer({
				ready: function() {
					displayPlayList();
					playListInit(false); // Parameter is a boolean for autoplay.
					demoInstanceInfo($(this), $("#jplayer_info"));
				},
				swfPath:"../m",
				oggSupport: false
			})
			.jPlayerId("play", "player_play")
			.jPlayerId("pause", "player_pause")
			.jPlayerId("stop", "player_stop")
			.jPlayerId("loadBar", "player_progress_load_bar")
			.jPlayerId("playBar", "player_progress_play_bar")
			.jPlayerId("volumeMin", "player_volume_min")
			.jPlayerId("volumeMax", "player_volume_max")
			.jPlayerId("volumeBar", "player_volume_bar")
			.jPlayerId("volumeBarValue", "player_volume_bar_value")
			.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
				var myPlayedTime = new Date(playedTime);
				var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
				var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
				$("#play_time").text(ptMin+":"+ptSec);

				var myTotalTime = new Date(totalTime);
				var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
				var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
				$("#total_time").text(ttMin+":"+ttSec);
			})
			.onSoundComplete( function() {
				playListNext();
			});

			$("#ctrl_prev").click( function() {
				playListPrev();
				return false;
			});

			$("#ctrl_next").click( function() {
				playListNext();
				return false;
			});

			function displayPlayList() {
				for (i=0; i < myPlayList.length; i++) {
					$("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
					$("#playlist_item_"+i).data( "index", i ).hover(
						function() {
							if (playItem != $(this).data("index")) {
								$(this).addClass("playlist_hover");
							}
						},
						function() {
							$(this).removeClass("playlist_hover");
						}
					).click( function() {
						var index = $(this).data("index");
						if (playItem != index) {
							playListChange( index );
						}
					});
				}
			}

			function playListInit(autoplay) {
				if(autoplay) {
					playListChange( playItem );
				} else {
					playListConfig( playItem );
				}
			}

			function playListConfig( index ) {
				$("#playlist_item_"+playItem).removeClass("playlist_current");
				$("#playlist_item_"+index).addClass("playlist_current");
				playItem = index;
				$("#jquery_jplayer").setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
			}

			function playListChange( index ) {
				playListConfig( index );
				$("#jquery_jplayer").play();
			}

			function playListNext() {
				var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
				playListChange( index );
			}

			function playListPrev() {
				var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
				playListChange( index );
			}

            // Twitter
            
            function reTweet() {
            			$(".tweet").tweet({
            			loading_text: "loading tweets..."
            							  });
            			};
            			
            
//            Gallery			
			
			
			
 $(document).ready(function() {
 
 var galTitle = $("body.gallery");
   if (galTitle === "gallery") {
  flickStart();
   };
 

 	
//         function liteboxCallback(el){
//           $(el).litebox({nz:'0.8em',lu:'http://www.projectatomic.com/wordpress/wp-includes/js/thickbox/loadingAnimation.gif'});
//         }
 
	$("a[title='Tweet this']").attr('href', "http://www.twitter.com/apemachine").attr('title', "Check out Ape Machine on Twitter!");
	$("a[title='Share it on Facebook']").attr('href', "http://www.facebook.com/pages/Ape-Machine/119898274035").attr('title', "Check out Ape Machine on Facebook!");
	$("a[title='Share it on Myspace']").attr('href', "http://www.myspace.com/apemachinemusic").attr('title', "Check out Ape Machine on MySpace!");
 
			
			// this initialises the demo scollpanes on the page.
							$('.scroll-box').jScrollPane();
			
							reinitialiseScrollPane = function()
							{
								$('.scroll-box').jScrollPane();
							}
			
							reTweet();
//			Colorbox
			
			$(".example8").colorbox({width:"450px", height:"600px", inline:true, href:"#inline_example1"});

						$("#click").click(function(){ 
							$('#click').css({"background-color":"#51463D", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
							return false;
						});
			
			var content = $("#content");
			var load = '<div id="load"></div>';
			var body = $('body');
			var bodyClass = 'welcome blog who-we-are videos gallery shop tours contact press-kit';
			var jqLinks =  $('.pagenav li a,.logo a,.five a,.four a');
			var galLinks = $("body.welcome .flk-wrap .cb");
			var galLinks2 = $("body.gallery .flk-wrap a");

			
//				galLinks.live('click',  
//				  function(e) {
//					e.preventDefault();
//					$("body").append(load);
//						var url = "http://apemachine.com/gallery";
//						var title = "gallery";
//				     content.hide('fast', function() {
//					 content.load(url + ' .post', function() {
//					  $('body').removeClass(bodyClass).addClass(title);
//					  flickStart();
//					   $('#load').remove();
//					  	  content.show('slow');
//				            });
//				   });
//				  });

			function flickStart() {
			$.each(galLinks2, function(i, data) {
			data.attr('href', 'http://www.flickr.com/photos/apemachine/');			
			});
			};
				  
				 			
			jqLinks.live('click',
			function(event) {
				event.preventDefault();
				
				$("body").append(load);
				var url = $(this).attr('href');
				var title = $(this).attr('title');
				
			  content.hide('fast', 
			   function() {
				content.load(url + ' .post', 
				 function(){
				 body.removeClass(bodyClass)
				  .addClass(title);
				  recuf();
				  
				  $('#load').remove();
				  content.show('slow', function() {
				  if (title === "welcome") {
				  reinitialiseScrollPane();
				  reTweet();
				  }
				  else if (title === "gallery") {
				 flickStart();
				  }
				  else if (title === "videos"){
				  TubePress.init("#tubepress_gallery_50116897");
				  };
				  });	  
			  	});
			   });
			 });
			

			
 });
})(jQuery);



