
	jQuery(function($){
		$.supersized({
			//Background image
			slides	:  [ { image : 'http://www.sound-bar.com/wp-content/themes/soundbar/images/backgroundmain.jpg' } ]					
		});
	});

	/* Drag and Drop boxes Awesome stuff! */
	 $(document).ready(function() {
		
		
		/* 3 */
		$( ".soundcard-header .ui-icon-plus " ).click(function() {
			$( this ).toggleClass( "ui-icon-plus" ).toggleClass( "ui-icon-minus" );
			$( this ).parents( ".soundcard:first" ).find( ".soundcard-contentclosed" ).slideToggle(100, 'linear');
		}); 
		
		/* 4 */
		$( ".soundcard-header .ui-icon-minus " ).click(function() {
			$( this ).toggleClass( "ui-icon-minus" ).toggleClass( "ui-icon-plus" );
			$( this ).parents( ".soundcard:first" ).find( ".soundcard-content" ).slideToggle(100, 'linear');
		});
		
		/* 5 */
		$( ".column" ).sortable({
			connectWith: ".column",
	handle: ".soundcard-header"
		});
		$( ".column" ).disableSelection();
	
		/* RSVP Hovers - !try to make those in pure CSS! */
		$('.hoverbutton').hover (function (){
			$(this).children('.front').stop(true).animate({

				left: '0px'}, 200);
		},function(){
			$(this).children('.front').stop(true).animate({

				left: '-55px'}, 200);
		});
		/* modal window */
		$('.hoverbutton').click (function(){
			var target = $(this).attr("rel");
			$( ".modal_frame" ).attr('src', target);
			$( ".modal_wrapper" ).fadeIn("1000");
			$( "#closewindow" ).click(function(){
				$( ".modal_frame" ).attr('src', 'http://sound-bar.com/loading/');
				$( ".modal_wrapper" ).delay(1000).fadeOut("600");
			});
		});


		/* start of PLAYER */
		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;
			});
		};

		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>";

					// 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 += ")</span>";
					}

					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();
						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.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);
			}
		};

		var audioPlaylist = new Playlist("1", [
			{

				name:"DeadMau5 - Ghosts and Stuff",
				mp3:"http://www.sound-bar.com/wp-content/themes/soundbar/songs/ghosts.mp3"
				
			},
			{
						name:"Swanky Tunes - XOXOXO (Original Mix)",
				mp3:"http://www.sound-bar.com/wp-content/themes/soundbar/songs/xoxo.mp3"	
				
	
			},
			{
				
			name:"Dada Life - Unleash The Fucking Dada",
				mp3:"http://www.sound-bar.com/wp-content/themes/soundbar/songs/unleash.mp3"	
				
			},
			{
	
			name:"Benny Benassi - Cinema",
				mp3:"http://www.sound-bar.com/wp-content/themes/soundbar/songs/cinema.mp3"

			}
			], {
			ready: function() {
				audioPlaylist.displayPlaylist();
				audioPlaylist.playlistInit(true); // Parameter is a boolean for autoplay.
			},
			ended: function() {
				audioPlaylist.playlistNext();
			},
			play: function() {
				$(this).jPlayer("pauseOthers");
			},
			swfPath: "http://www.sound-bar.com/wp-content/themes/soundbar/js",
			supplied: "mp3"
		});
		
		$("#jp-icon").toggle(function(){
			$('#jp_playlist_1').animate({height:'165px'});
			$('#playerpic').animate({height:'165px'});                                
			$('#playerpic').fadeIn();
			$(this).removeClass('ui-icon-plus');
			$(this).addClass('ui-icon-minus');

		},function(){
			$('#playerpic').fadeOut();				
			$('#playerpic').animate({height:'0'});
			$('#jp_playlist_1').animate({height:'0'});
			$(this).removeClass('ui-icon-minus');
			$(this).addClass('ui-icon-plus');
		});
		
		/* end of PLAYER */
		/* stylesheet and background switcher */
	

	}); /* end of $(document).ready() */
