$(document).ready(function(){

	var Playlist = function(instance, playlist, options) {
		var self = this;

		this.instance = instance; // String: To associate specific HTML with this playlist
		this.playlist = playlist; // Array of Objects: The playlist
		this.options = options; // Object: The jPlayer constructor options for this playlist

		this.current = 0;

		this.cssId = {
			jPlayer: "jquery_jplayer_",
			interface: "jp_interface_",
			playlist: "jp_playlist_"
		};
		this.cssSelector = {};

		$.each(this.cssId, function(entity, id) {
			self.cssSelector[entity] = "#" + id + self.instance;
		});

		if(!this.options.cssSelectorAncestor) {
			this.options.cssSelectorAncestor = this.cssSelector.interface;
		}

		$(this.cssSelector.jPlayer).jPlayer(this.options);

		$(this.cssSelector.interface + " .jp-previous").click(function() {
			self.playlistPrev();
			$(this).blur();
			return false;
		});

		$(this.cssSelector.interface + " .jp-next").click(function() {
			self.playlistNext();
			$(this).blur();
			return false;
		});
		
		self.playlistInfo(self.playlist[0].name, 'Client:' + self.playlist[0].client, self.playlist[0].desc);
		//$('.info h1').text(self.playlist[0].name);
		//$('.info h2').text('Client:' + self.playlist[0].client);
		//$('.info p').text(self.playlist[0].desc);
	};

	Playlist.prototype = {
		displayPlaylist: function() {
			var self = this;
			$(this.cssSelector.playlist + " ul").empty();
			for (i=0; i < this.playlist.length; i++) {
				var listItem = (i === this.playlist.length-1) ? "<li class='jp-playlist-last'>" : "<li>";
				listItem += "<a href='#' id='" + this.cssId.playlist + this.instance + "_item_" + i +"' tabindex='1'>"+ this.playlist[i].name +"</a><br> <span>" + this.playlist[i].client + " </span>";

				// Create links to free media
				/*if(this.playlist[i].free) {
					var first = true;
					listItem += "<div class='jp-free-media'>(";
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							if(first) {
								first = false;
							} else {
								listItem += " | ";
							}
							listItem += "<a id='" + self.cssId.playlist + self.instance + "_item_" + i + "_" + property + "' href='" + value + "' tabindex='1'>" + property + "</a>";
						}
					});
					listItem += ")";
				}*/

				listItem += "</li>";

				// Associate playlist items with their media
				$(this.cssSelector.playlist + " ul").append(listItem);
				$(this.cssSelector.playlist + "_item_" + i).data("index", i).click(function() {
					var index = $(this).data("index");
					if(self.current !== index) {
						self.playlistChange(index);
					} else {
						$(self.cssSelector.jPlayer).jPlayer("play");
					}
					$(this).blur();
					
					//Display the song info in the box at the right
					self.playlistInfo(self.playlist[index].name, 'Client: ' + self.playlist[index].client, self.playlist[index].desc);
					//$('.info h1').text(self.playlist[index].name);
					//$('.info h2').text('Client: ' + self.playlist[index].client);
					//$('.info p').text(self.playlist[index].desc);
					return false;
				});

				// Disable free media links to force access via right click
				/*if(this.playlist[i].free) {
					$.each(this.playlist[i], function(property,value) {
						if($.jPlayer.prototype.format[property]) { // Check property is a media format.
							$(self.cssSelector.playlist + "_item_" + i + "_" + property).data("index", i).click(function() {
								var index = $(this).data("index");
								$(self.cssSelector.playlist + "_item_" + index).click();
								$(this).blur();
								return false;
							});
						}
					});
				}*/
			}
		},
		playlistInit: function(autoplay) {
			if(autoplay) {
				this.playlistChange(this.current);
			} else {
				this.playlistConfig(this.current);
			}
		},
		playlistConfig: function(index) {
			$(this.cssSelector.playlist + "_item_" + this.current).removeClass("jp-playlist-current").parent().removeClass("jp-playlist-current");
			$(this.cssSelector.playlist + "_item_" + index).addClass("jp-playlist-current").parent().addClass("jp-playlist-current");
			this.current = index;
			this.playlistInfo(this.playlist[this.current].name, 'Client: ' + this.playlist[this.current].client, this.playlist[this.current].desc);
			$(this.cssSelector.jPlayer).jPlayer("setMedia", this.playlist[this.current]);
		},
		playlistChange: function(index) {
			this.playlistConfig(index);
			$(this.cssSelector.jPlayer).jPlayer("play");
		},
		playlistNext: function() {
			var index = (this.current + 1 < this.playlist.length) ? this.current + 1 : 0;
			this.playlistChange(index);
		},
		playlistPrev: function() {
			var index = (this.current - 1 >= 0) ? this.current - 1 : this.playlist.length - 1;
			this.playlistChange(index);
		},
		playlistInfo: function(name,client,desc) {
			//Display the song info in the box at the right
			$('.info h1').text(name);
			$('.info h2').text(client);
			$('.info p').text(desc);
		}
	};
	var audioPlaylist = new Playlist("2", [
	
			{
				name:"A Beautiful World",
				mp3:"/music/a_beautiful_world.mp3",
				oga:"/music/a_beautiful_world.ogg",
				client: "Grossnickle Eye Center",
				desc: "A carefully composed acoustic guitar and a heartfelt female vocal bring Grossnickle's sense of personal involvement with each patient to life.  The lyric doesn't sell eye care, it sells vision, and relates it to the things we love most in life."
			},
			{
				name:"Battleheart 1",
				mp3:"/music/battleheart_1.mp3",
				oga:"/music/battleheart_1.ogg",
				client: "Mika Mobile",
				desc: "First of three main battlefield themes from Mika Mobile's hit 2011 game for iPhone, iPod Touch and iPad.  This one sets the sweeping, heroic tone for the game and establishes the chamber orchestra instrumentation."
			},
			{
				name:"Battleheart 2",
				mp3:"/music/battleheart_2.mp3",
				oga:"/music/battleheart_2.ogg",
				client: "Mika Mobile",
				desc: "Second of three main battlefield themes from Mika Mobile's hit game for iPhone, iPod Touch and iPad.  Here we evoke distant armies, a chill wind, and a long slog through caverns of ice and snow, but not without sense of triumph."
			},
			{
				name:"Battleheart 3",
				mp3:"/music/battleheart_3.mp3",
				oga:"/music/battleheart_3.ogg",
				client: "Mika Mobile",
				desc: "Third of three main battlefield themes from Mika Mobile's hit game for iPhone, iPod Touch and iPad.  The party moves slowly through a dense forest, while carefully controlled half- and whole-tone dissonances create tension."
			},
			{
				name:"Battleheart Boss Level",
				mp3:"/music/battleheart_boss_level.mp3",
				oga:"/music/battleheart_boss_level.ogg",
				client: "Mika Mobile",
				desc: "Every video game has enemies  that define the end of a game segment by being tougher, meaner and harder to kill.  They're known as bosses and this frenzied metal orchestra helps the gamer's heart race when they encounter one."
			},
			{
				name:"Belongs To You",
				mp3:"/music/belongs_to_you.mp3",
				oga:"/music/belongs_to_you.ogg",
				client: "Midwest America Federal Credit",
				desc: "One of the Fort Wayne area's best known musical ID's.  A perfect example of the old-school group vocal, this tune gives new life to the standard credit union pitch that you aren't just a customer, you're a stockholder."
			},
			{
				name:"Big Food, L'il Money",
				mp3:"/music/big_food_lil_money.mp3",
				oga:"/music/big_food_lil_money.ogg",
				client: "Hacienda Mexican Restaurants",
				desc: "The cheeky advertising for Hacienda took a lot of risks, and the radio campaign was no exception:  this intro audaciously announces that you are about to hear a commercial.  Looney Tunes, 50's vocal groups, lo-fi, hit blend."
			},
			{
				name:"Buy One Get One",
				mp3:"/music/buy_one_get_one.mp3",
				oga:"/music/buy_one_get_one.ogg",
				client: "ProFed Credit Union",
				desc: "A clever switcheroo on the low interest car loan, ProFed offered a low rate plus a second low at zero percent.  This snappy tune with its highly visual lyric drove the TV and radio with the good humor the campaign required. "
			},
			{
				name:"City Streets",
				mp3:"/music/city_streets.mp3",
				oga:"/music/city_streets.ogg",
				client: "Lincoln Financial Group",
				desc: "Lincoln's video producers knew what they wanted:  modern, driving music, with elements that felt both sophisticated and trustworthy.  Dance music, mixed with acid jazz and classical.  This excerpt from the resulting score makes it work."
			},
			{
				name:"Convergence",
				mp3:"/music/convergence.mp3",
				oga:"/music/convergence.ogg",
				client: "ASPN",
				desc: "Score for a meeting opening video (set in the Arizona desert) for a company that provided umbrella marketing services for a group of specialty underwriters.  The highlight here is the arpeggiator and drum programming."
			},
			{
				name:"Dot Com!",
				mp3:"/music/dot_com.mp3",
				oga:"/music/dot_com.ogg",
				client: "Restorative Remedies",
				desc: "We collaborated with the marketing people at this San Diego-based dietary supplement company to flesh out this 1940's inspired musical ID and help drive people to their website.  Andrews Sisters, small combo jazz. "
			},
			{
				name:"Every Sandwich A Star",
				mp3:"/music/every_sandwich_a_star.mp3",
				oga:"/music/every_sandwich_a_star.ogg",
				client: "Carolina Turkey Deli",
				desc: "Sure, the song is great, the lyric clever, the 30-piece pit orchestra and 8 singers all on their A-game.  But the big news is the 79% unaided recall score it got in mall intercepts.  Coke and McDonald's would kill for that number."
			},
			{
				name:"Get Happy",
				mp3:"/music/get_happy.mp3",
				oga:"/music/get_happy.ogg",
				client: "Star Financial Bank",
				desc: "Star Financial wanted to tell the world that Star Power would make them happy.  We put together an all-star band of local horn guys to nail down the sound on this arrangement of the song made popular by Judy Garland.  "
			},
			{
				name:"Great Things, Female",
				mp3:"/music/great_things_female.mp3",
				oga:"/music/great_things_female.ogg",
				client: "First Bank of Carmi",
				desc: "They said, not a jingle, a song about someone's pride in their hometown.  We wrote this, in a female and male version.  The tune proved so popular that local DJ's had to turn down phone requests to play it."
			},
			{
				name:"Great Things, Male",
				mp3:"/music/great_things_male.mp3",
				oga:"/music/great_things_male.ogg",
				client: "First Bank of Carmi",
				desc: "The female version of this song had a more heartfelt lyric. This straight ahead, classic-rock male version reflects on the singer's connection to his hometown through work and honor.  A huge hit in southern Indiana."
			},
			{
				name:"Hook Barrage",
				mp3:"/music/hook_barrage.mp3",
				oga:"/music/hook_barrage.ogg",
				client: "Various",
				desc: "Don't have time to root through Gravity's greatest Hits?  Here's an under-two-minute compilation of all the hook lines from some of our best known musical IDs.  It's like a time machine, only you don't actually travel through time."
			},
			{
				name:"It's Festival Time!",
				mp3:"/music/its_festival_time.mp3",
				oga:"/music/its_festival_time.ogg",
				client: "Three Rivers Festival",
				desc: "Jim wrote and produced the original version circa 1985, long before there was a Gravity Music.  This version was a 2008 donation to the Festival.  Straight-up Dixieland fun, with a hook that most city residents know by heart."
			},
			{
				name:"Mindscape",
				mp3:"/music/mindscape.mp3",
				oga:"/music/mindscape.ogg",
				client: "Optima Systems",
				desc: "This company creates training videos for psychiatrists.  We created a set of themes, bumpers and interstitial pieces, all based on this main video theme.  The mystery of synaptic activity.   Neurochemistry meets Incredible Voyage."
			},
			{
				name:"Old Timey",
				mp3:"/music/old_timey.mp3",
				oga:"/music/old_timey.ogg",
				client: "Gravity Library",
				desc: "We have lots of original instrumental tracks for use as library music.  This example is understated, warm and personal, perfect for laid-back radio underscore or telephone on-hold.  Ask us about the Gravity Library."
			},
			{
				name:"OMG! Pirates! Level 1",
				mp3:"/music/omg_pirates_level_1.mp3",
				oga:"/music/omg_pirates_level_1.ogg",
				client: "Mika Mobile",
				desc: "The follow-up to Mika's smash hit Zombieville USA was a classic beat-'em-up based on the Internet meme about ninjas vs. pirates.  So the score jokingly blends Celtic chanties with shamisen and koto in traditional Asian melodies."
			},
			{
				name:"OMG! Pirates! Level 2",
				mp3:"/music/omg_pirates_level_2.mp3",
				oga:"/music/omg_pirates_level_2.ogg",
				client: "Mika Mobile",
				desc: "Part two of the OMG! Score continues the tongue-in-cheek blending of pirate tunes with Japanese dojo music.  In this section, the player is aboard a pirate ship, so we go a little heavier on the yo-ho-ho."
			},
			{
				name:"OMG! Pirates! Level 3",
				mp3:"/music/omg_pirates_level_3.mp3",
				oga:"/music/omg_pirates_level_3.ogg",
				client: "Mika Mobile",
				desc: "The level three action takes place in a volcano, so what better to communicate the searing heat than jazz flute?  Herbie Mann and Yo Yo Ma jam with Frank Zappa on an iceberg floating in red-hot magma.  Yeah, that's about right."
			},
			{
				name:"Playing To Win",
				mp3:"/music/playing_to_win.mp3",
				oga:"/music/playing_to_win.ogg",
				client: "Discover Card",
				desc: "Created as the theme for a Discover Card annual sales meeting, this was the basis for an entire suite of scoring beds and interstitial pieces.  The client asked for an arena rock feel, and as a child of the 70s, Jim is always ready to deliver on that."
			},
			{
				name:"Radio Montage",
				mp3:"/music/radio_montage.mp3",
				oga:"/music/radio_montage.ogg",
				client: "Various",
				desc: "We make real good radio at Gravity Music:  Jim is an award-winning radio writer, and has a peculiar love for the medium.  This 7-minute montage contains some of our favorite spots."
			},
			{
				name:"Rockin' Is My Business",
				mp3:"/music/rockin_is_my_business.mp3",
				oga:"/music/rockin_is_my_business.ogg",
				client: "Lincoln Financial Group",
				desc: "The theme for an audio newsletter Windshield Wisdom.  Its creator and host wanted a classic rock song but couldn't afford the license.  Our original theme is as classic as it gets.  I got a fever, and the only prescription is more cowbell."
			},
			{
				name:"Scoring Montage",
				mp3:"/music/scoring_montage.mp3",
				oga:"/music/scoring_montage.ogg",
				client: "Various",
				desc: "Jim really enjoys scoring long form video, because it gives him a chance to stretch and take a more filmic approach, playing with mood, and with techniques for building and releasing tension.  Here is 7 minutes of some cool exceprts."
			},
			{
				name:"Simmering",
				mp3:"/music/simmering.mp3",
				oga:"/music/simmering.ogg",
				client: "Charles Ng, Inc.",
				desc: "A lively import from Japan, cooking games are simple time management puzzles based on a virtual kitchen where one cooks a meal.  This track is part of the score for such a game from Hong Kong.  Synthy, 8-bit fun on a bun."
			},
			{
				name:"Smarter From the Ground Up",
				mp3:"/music/smarter_from_the_ground_up.mp3",
				oga:"/music/smarter_from_the_ground_up.ogg",
				client: "Water Furnace",
				desc: "A world leader in geothermal heating, Water Furnace created the tag line for this piece in-house.  This tune went out to dealers as part of a franchise co-op package, and is written in that jingly style that fits any radio format."
			},
			{
				name:"Snuffles",
				mp3:"/music/snuffles.mp3",
				oga:"/music/snuffles.ogg",
				client: "Gravity Library",
				desc: "Snuffy Walden is a rare bird:  an in-demand Hollywood music guy whose primary instrument is acoustic guitar.  This is our version of Snuffy's highly recognizable style.  When you need needle-drop, we've got it in house."
			},
			{
				name:"Spirit of Rock And Roll",
				mp3:"/music/spirit_of_rock_and_roll.mp3",
				oga:"/music/spirit_of_rock_and_roll.ogg",
				client: "Arnold's Drive-In",
				desc: "A NE Indiana landmark, Arnold's is an unselfconscious reproduction of a '50s diner.  We decided to let the music carry the retro vibe and sell the food hard.  Justly famous since 1997 is a line painted on an awning at Arnold's. "
			},
			{
				name:"Summer Dream",
				mp3:"/music/summer_dream.mp3",
				oga:"/music/summer_dream.ogg",
				client: "Kirsch Window Dressing",
				desc: "Reminiscent of Sleepwalk, what really makes this track is the period guitar sound.  The agency rejected our first shot, calling it too polished. A borrowed '63 Gretsch Country Gentleman with dead strings was just the ticket."
			},
			{
				name:"Surf Faster",
				mp3:"/music/surf_faster.mp3",
				oga:"/music/surf_faster.ogg",
				client: "Time-Warner Cable",
				desc: "TV underscore for a high-speed Internet promo. A good example of how we will research a genre to get just the right feel, Jim dug up the Ventures' deep cut Diamond Head as inspiration."
			},
			{
				name:"The Giving Season",
				mp3:"/music/the_giving_season.mp3",
				oga:"/music/the_giving_season.ogg",
				client: "MC Sports",
				desc: "We produced the national jingle package for MC Sports and created the signature line At MC Sports, you're ahead of the game. There's a rock version, a country version and this holiday version. This is one of our most favorite vocal arrangements ever."
			},
			{
				name:"The Right Direction",
				mp3:"/music/the_right_direction.mp3",
				oga:"/music/the_right_direction.ogg",
				client: "Ossian State Bank",
				desc: "Lots of small town banks want the same thing from a musical ID:  to sound modern but   old-fashioned, hip but warm, big enough/serve you but small enough/care. This smoov jazz with female vocal hits the bullseye."
			},
			{
				name:"Three For The Money",
				mp3:"/music/three_for_the_money.mp3",
				oga:"/music/three_for_the_money.ogg",
				client: "Iowa Lottery",
				desc: "The soundtrack for an animated TV spot featuring a N'orleans band of singing numbers, this track won a National Addy for Commercial Music, coming in one place behind Chevy's The Heartbeat of America."
			},
			{
				name:"Today, Tomorrow, Together",
				mp3:"/music/today_tomorrow_together.mp3",
				oga:"/music/today_tomorrow_together.ogg",
				client: "Merillat Cabinets",
				desc: "The theme for a crucial dealer meeting, Merillat asked for a 5-minute corporate baby come back song (like something Sting might do), and gave us five days from green light to finished track.  It was a smash at the show. "
			},
			{
				name:"Travel Better",
				mp3:"/music/travel_better.mp3",
				oga:"/music/travel_better.ogg",
				client: "Travel Leaders",
				desc: "Used in their national TV and radio buy and distributed to Travel Leaders franchise office, this jaunty fusion piece captures the excitement and fun of travel without going all steel-drum on ya.  Tom Scott & The LA Express meets Anita Kerr."
			},
			{
				name:"Voice Over Demo",
				mp3:"/music/voice_over_demo.mp3",
				oga:"/music/voice_over_demo.ogg",
				client: "Jim Bordner",
				desc: "Owner, composer and producer Jim Bordner also has a good set of regular guy pipes and 30 years of radio production experience.   Looking for an announcer who doesn't sound like one?  Hear here."
			},
			{
				name:"We're On A Roll",
				mp3:"/music/were_on_a_roll.mp3",
				oga:"/music/were_on_a_roll.ogg",
				client: "International Truck",
				desc: "The producer of International's annual show asked us to go Midwest rootsy and wrap the show's theme in a cozy, John-Mellancamp influenced blanket.  No problem, I mean, we ARE from Indiana, you know."
			},
			{
				name:"What If?",
				mp3:"/music/what_if.mp3",
				oga:"/music/what_if.ogg",
				client: "Parkview Hospital",
				desc: "Driving dance music with a sense of hopeful possibility is what Parkview asked us for this meeting opener score.  Our house-n-trance expert DJ Aiden Michael laid down the beat law, while Jim spruced it up modelically."
			},
			{
				name:"What’s Your Story?",
				mp3:"/music/whats_your_story.mp3",
				oga:"/music/whats_your_story.ogg",
				client: "ProFed Credit Union",
				desc: "Credit unions from coast to coast are trying to figure out how to attract younger depositors, and Fort Wayne agency Patterson-Riegel figured out a novel approach:  low-key, slice of life TVC’s (with accompanying radio) that depict the day in the life of a 20-something, with this song the only audio.  The sparse arrangement, slightly out of tune upright piano and unprocessed vocal give the track an “indie” authenticity.  This is the :60 radio version."
			},
			{
				name:"Workhorse",
				mp3:"/music/workhorse.mp3",
				oga:"/music/workhorse.ogg",
				client: "International Truck",
				desc: "Video score for a product introduction video featuring a light panel truck doing, well, doing everything a panel truck can do.  The acoustic guitar gives it a personal feel aimed at the target:  small business owners."
			},
			{
				name:"You Know Us",
				mp3:"/music/you_know_us.mp3",
				oga:"/music/you_know_us.ogg",
				client: "Lee Brothers Paint",
				desc: "The Lee Brothers they always wanted a jingle that sang the phone number like the legendary Empire Carpet song.  We said we could go one better, and encapsulate their market position as the local paint experts in just six words."
			},
			{
				name:"You Never Know What You'll Find",
				mp3:"/music/you_never_know_what_youll_find.mp3",
				oga:"/music/you_never_know_what_youll_find.ogg",
				client: "The Bookmark",
				desc: "One of the city's most successful independent bookstores used this bouncy song to help them create an image and grab a top-of-mind position among their demo.  Two versions exist, but The Bookmark still prefers this original."
			},
			{
				name:"Your Bank, Your Life",
				mp3:"/music/your_bank_your_life.mp3",
				oga:"/music/your_bank_your_life.ogg",
				client: "Crossroads Bank",
				desc: "Which came first, the slogan or the bank name?  No matter.  Once again an acoustic guitar marries up with some college chords to give a small-town bank a big-town feel without losing that friendly touch."
			},
			{
				name:"Zombieville USA",
				mp3:"/music/zombieville_usa.mp3",
				oga:"/music/zombieville_usa.ogg",
				client: "Mika Mobile",
				desc: "Haven't played smash hit iDevice game Zombieville USA? You probably know someone who has.  This darkly comic (or humorously terrifying) track loops endlessly as The Survivor turns the living dead into the totally dead."
			}	], {
		ready: function() {
			audioPlaylist.displayPlaylist();
			audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
		},
		ended: function() {
			audioPlaylist.playlistNext();
		},
		play: function() {
			$(this).jPlayer("pauseOthers");
		},
		swfPath: "js",
		supplied: "oga, mp3"
	});
	
	if ($.client.browser == "Explorer" ) {
		$('#posts ul li .news').css('position', 'relative');
		$('#posts a.read').css('position', 'absolute');
		$('#posts a.read').css('bottom', '30px');
		$('#posts a.read').css('left', '75px');
	}
	
});
