/* ----------------------------------------------------
Title		: Alex Nelson Music
Version		: V1.0.1
Author		: Alex Nelson
URL 		: http://www.alexnelsonmusic.com/

Description	: 
Note(s)		: 

Created		: December 01, 2010
Modified	: 

Table of 
Contents	: * - Master JQuery Control
			  A - Container Toggle, Small Containers Only
			  B - Main Navigation Tool Tip
			  C - Toggle Twitter Feed Count
			  D - Navigation Tool Tip
			  E - Page Pagination Fade
			  F - HTML5 Form Support

			  * - Bad Browser, No Internet Explorer 6 Support

---------------------------------------------------- */
/* ----------------------------------------------------
* - Master JQuery Control
---------------------------------------------------- */
var touchDevice = ((navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1));

$(function() {
  
  

	$('#twitterFeed').getTwitter(); 	// Requires "jquery.twitter.js"

	containerToggle(); 
	promoBar(); 
	badBrowser(); 
	twitterToggle(); 
	navToolTip(); 
	signUpForm();
	jplayer(); 
	
	
	//if submit button is clicked  
  //  $('#submit').click(function () { 
      
  //    alert("submit");
      
  //  });

	if ( !touchDevice ) {
		paginationFade(); 
	};
	
	
	
	
 
});


/* ----------------------------------------------------
 *  jPlayer
 */

function jplayer(){
  
    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("2", [
    {
      name:"1. Relaxing in Public",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/relaxingInPublic.mp3"
    },
    {
      name:"2. Mistake",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/mistake.mp3"
    },
    {
      name:"3. Said Too Much",
      // free:true,
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/saidTooMuch.mp3"
    },
    {
      name:"4. St. Petersburg",
      free:true,
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/stPetersburg.mp3"
    },
    {
      name:"5. This Way",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/thisWay.mp3"
    },
    {
      name:"6. She Said",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/sheSaid.mp3"
    },
    {
      name:"7. Tired",
      //free:true,
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/tired.mp3"
    },
    {
      name:"8. Wonder",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/wonder.mp3"
    },
    {
      name:"9. Ask",
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/ask.mp3"
    },
    {
      name:"10. Again",
      //free:true,
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/again.mp3"
    },
    {
      name:"11. Beautiful",
      //free:true,
      mp3:"http://019789a.netsolhost.com/alexnelsonmusic1/wp-content/themes/default/audio/beautiful.mp3"
    }

  ], {
    ready: function() {
      audioPlaylist.displayPlaylist();
      audioPlaylist.playlistInit(false); // Parameter is a boolean for autoplay.
    },
    ended: function() {
      audioPlaylist.playlistNext();
    },
    play: function() {
      $(this).jPlayer("pauseOthers");
    },
    supplied: "oga, mp3"
  });

  
};

/* ----------------------------------------------------
 A - Container Toggle, Small Containers Only
---------------------------------------------------- */
function containerToggle() {
	var slideUpSpeed = 300;
	var slideDownSpeed = 300;
	var showSlideDelay = 1000;
	
	$('.infoContainer.small .title').each(function () {
		var $this = $(this);
		
		if ( $this.hasClass('expand') ) { 
			$this.next('.containerMiddle').delay(showSlideDelay).slideDown(slideDownSpeed);
			$this.addClass('toggleArrow');
		};
	});

	$('.infoContainer.small h2').click(function() {
		var $thisParent = $(this).parent();
		var $thisParentNext = $(this).parent().next('.containerMiddle');
	
		if ( $thisParent.hasClass('toggleArrow') ) { 
			$thisParentNext.slideUp(slideUpSpeed, function(){
				$thisParent.removeClass('toggleArrow');
			});
		} else {
			$thisParentNext.slideDown(slideDownSpeed, function(){
				$thisParent.addClass('toggleArrow');
			});
		}
		return false; 
	});
}

/* ----------------------------------------------------
B - Promotional Bar Adjustment
---------------------------------------------------- */
function promoBar() {
	var showSpeed = 300;
	var hideSpeed = 300;
	var promoHeight = 31;

	if ( $('#promoBar').length ) {

		$('#promoBar').slideDown(showSpeed, function(){
			$('<div class="promoBar_Button" id="promoBar_Close" />').insertBefore('#promoBar').fadeIn(showSpeed);
			$('<div class="promoBar_Button" id="promoBar_Info" />').insertBefore('#titleBar');
		});
		$('#titleBar').animate({'top':'+=' + promoHeight + 'px'}, showSpeed);
		$('#site').animate({'top':'+=' + promoHeight + 'px'}, showSpeed);
	};

	$('#promoBar_Close').live('click', function() {
		$(this).fadeOut(hideSpeed, function() {
			$('#promoBar').slideUp(hideSpeed);
			$('#titleBar').animate({'top':'-=' + promoHeight + 'px'}, hideSpeed);
			$('#site').animate({'top':'-=' + promoHeight + 'px'}, hideSpeed, function(){
				$('#promoBar_Info').fadeIn(showSpeed);
			});
		});
	});
	
	$('#promoBar_Info').live('click', function() {
		$(this).fadeOut(hideSpeed, function() {
			$('#promoBar').slideDown(showSpeed);
			$('#titleBar').animate({'top':'+=' + promoHeight + 'px'}, showSpeed);
			$('#site').animate({'top':'+=' + promoHeight + 'px'}, showSpeed, function(){
				$('#promoBar_Close').fadeIn(showSpeed);
			});
		});
	});
}

/* ----------------------------------------------------
C - Toggle Twitter Feed Count
---------------------------------------------------- */
function twitterToggle() {
	var $twitterList = $('ul#twitter_update_list');
	var $heightAdjust = $('#twitterToggle, #btn_followOnTwitter');

	var tweetUpSpeed = 300;
	var tweetDownSpeed = 300;
	var tweetDelaySpeed = 250;
	
	$('#twitterToggle').click(function() {
		var $this = $(this);

		if ( $twitterList.hasClass('showTweets') ) {
			$('ul#twitter_update_list li:not(:first)').slideUp(tweetUpSpeed, function() {
				i=1000;
				$twitterList.removeClass('showTweets');
			});
			$this.removeClass('active');
		} else {
			i=1;
			$twitterList.addClass('showTweets');
			$this.addClass('active');
			showNext();
		}
		return false; 
		
		function showNext() {
			if ( i < 11 ) {
				$('ul#twitter_update_list').find('li:nth-child(' + i + ')').delay(tweetDelaySpeed).slideDown(tweetDownSpeed, function() {
					i++;
					showNext();
				});
			}
		}
	});
}

/* ----------------------------------------------------
D - Navigation Tool Tip
---------------------------------------------------- */
function navToolTip() {
	$('nav a').each(function () {
		$('<span>' + $(this).attr('title') + '</span>').insertBefore(this);
	});
	
	var animateSpeed = 200;
	$('nav a').hover(function() {
		$(this).prev('span').stop(true, true).animate({
			'top':'-27px',
			'opacity':'1.0'
		}, animateSpeed);
		$('#signUp_Response').stop(true, true).animate({
			'opacity':'0.20'
		}, animateSpeed);
	}, function() {
		$(this).prev('span').stop(true, true).animate({
			'top':'-22px',
			'opacity':'0.0'
		}, animateSpeed);
		$('#signUp_Response').stop(true, true).delay(1000).animate({
			'opacity':'1.0'
		}, animateSpeed);
	});
}

/* ----------------------------------------------------
E - Page Pagination Fade
---------------------------------------------------- */
function paginationFade() {
	$('#pagination').css({'opacity':0.0});
	
	$('#pageSelection').hover(function() {
		$('#pagination').stop(true, true).animate({
			'opacity':'1.0'
		});
	}, function() {
		$('#pagination').stop(true, true).animate({
			'opacity':'0.0'
		});
	});
}

/* ----------------------------------------------------
F - HTML5 Form Support
---------------------------------------------------- */

	
	
function signUpForm() {
  $('#signUp').html5form({
    allBrowsers   : true,
    labels      : 'hide',
    colorOn     : '#fff',
    colorOff    : '#999',
    messages    : 'en',
    emailMessage  : 'This email address is not valid, please try again',
    emptyMessage  : 'This is a required field',
    method        : 'POST',
    //action        :'http://www.fanbridge.com/signup/fansignup_form.php?userid=128705',
    action        : 'http://www.alexnelsonmusic.com/wp-content/themes/default/utils/joinMailingList.php',
    responseDiv   : '#signUp_Response'
  });
}
	

	
	



/* ----------------------------------------------------
 - Bad Browser, No Internet Explorer 6 Support
---------------------------------------------------- */
function badBrowser() {
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
	//var firefox = (navigator.userAgent.indexOf("Firefox")!=-1) ? true : false;

	if (IE6) {
		var browserWarning = '<div id="browserWarning">This website is not supported by the web browser you are currently using. <br />Please upgrade to <a href="http://getfirefox.com/" target="_blank">Mozilla FireFox</a>, <a href="http://www.google.com/chrome/" target="_blank">Google Chrome</a> or <a href="http://www.apple.com/safari/" target="_blank">Apple Safari</a>.</div>.<div id="browserBlackOut" />';
		var barPosition = (($(window).height() / 2) - ($('#browserWarning').height() / 2));
		
		$(browserWarning).prependTo('body');
			
		$('html').css({'overflow':'hidden'});
		$('#browserWarning').css({'position':'absolute', 'top':barPosition + 'px', 'left':'0px'});
		$('#browserBlackOut').css({'width':'100%', 'height':$(document).height(), 'opacity':'0.85'});
	}
}




