﻿var divs = new Array('#news','#members','#dates','#media','#press');
var bodyWidth = '642px';  
var domain = "http://nonamekicker.com/";
var songList = new Array();
var currentSongNumber = 0;
var currentSongTitle = "";
var currentSongPath = "";
var mySound;
var curDiv = -1;
var loaded = false;
var anyShowing = true;


function hideAll(){
    $('#content').hide();
    loaded = true;
    anyShowing = false;
}

function showContent(contentId){
    if (contentId == 'null'){
        hideAll();
        return;
    }
    if (anyShowing && contentId == curDiv){
        hideAll();
    }else{
        loadContent(contentId);
        if (!anyShowing){
            $('#content').show();
            
        }
        $('html,body').animate({scrollTop:0}, 1000);
        anyShowing=true;
    }       
}

$(document).ready(function(){
    if (! loaded){
        hideAll();
    }
    $('#menu-news').click(function(){
         showContent(1);
    });
    $('#menu-members').click(function(){
        showContent(2);
    });
    $('#menu-dates').click(function(){
         showContent(3);
    });
    $('#menu-media').click(function(){
        showContent(4); 
    });
    $('#menu-press').click(function(){
        showContent(5);
    });
    $('#close').click(function(){
        hideAll();  
    });
    $('#join').click(function(){
        //$('#stupid-iframe').attr("src",'MailingList.aspx');
        $('#stupid-iframe').html('<iframe src="MailingList.aspx" runat="server" scrolling="no"></iframe>');
        $('#stupid-iframe').show();
    });
    
    $('#cancel').click(function(){
        $('#stupid-iframe',window.parent.document).hide();
    });
    
    $('#close-it').click(function(){
        $('#stupid-iframe',window.parent.document).hide();
    });

    $(function() {
		$('#homepage-pics-table a').lightBox({fixedNavigation:true}); 
	});

    var pgID = getParameter( 'id' );
    showContent(pgID);
});

function loadContent(contentId){

    $('#title').html("");
    $('#words').html('<img src="' + domain + 'styles/ajax-loader.gif" />');
    
    var params = '{"contentID":"' + contentId + '"}';

    $.ajax({
        type: "POST",
        url: "/_resources/services/NnkWebServices.asmx/getContent",
        data: params,
        async: true,
        timeout: 3000,
        contentType: "application/json",
        dataType: "json",
        success: function(msg) {
            $('#title').html("<h1>" + msg.d.title + "</h1>");
            $('#words').html(msg.d.body);
        },
        error: function(msg) {
//            alert('error');
            $('#title').html("Oops!");
            $('#words').html("There was a problem getting this stuff.");
        }
    });
}


function loadSongList(){
  try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e) 
    {
    //alert(e.message)
    }
  }
try
  {
      xmlDoc.async=false;
      xmlDoc.load(domain + "songs.xml");
      for (var i = 0; i < xmlDoc.getElementsByTagName("song").length;i++){
          var title = xmlDoc.getElementsByTagName("song")[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
          var path = xmlDoc.getElementsByTagName("song")[i].getElementsByTagName("path")[0].childNodes[0].nodeValue;
          songList[i] = title + "|" + path;
          //alert(path);
      }
  }
catch(e) 
    {
    //alert(e.message)
    }
}

function nextSong(){
    currentSongNumber++;
    if (currentSongNumber == songList.length){
        currentSongNumber = 0;
    }
    
    changeSong();
}

function prevSong(){
    currentSongNumber--;
    if (currentSongNumber == -1){
        currentSongNumber = songList.length-1;
    }
    changeSong();
}

function changeSong(){
    var s = songList[currentSongNumber];
    var spl = s.split("|");
    currentSongTitle=spl[0];
    currentSongPath=spl[1];
    soundManager.destroySound('aSound');
    mySound = soundManager.createSound({
        id: 'aSound',
        url: currentSongPath,
        onfinish: function() { nextSong(); }
    });
    mySound.play();
   
    $('#song-title').html(currentSongTitle);
}



function loadSM(){
    soundManager.url = '/_resources/Flash/SoundManager/swf/'; // directory where SM2 .SWFs live
    soundManager.onload = function() {
        var randomnumber=Math.floor(Math.random()*5);
        currentSongNumber = randomnumber;
        nextSong();
    }
    
    soundManager.onerror = function() {
    // SM2 could not start, no sound support, something broke etc. Handle gracefully.
    //disableSoundInMyApp(); // for example
    alert("Sorry, but you won't be able to listen to the tunes while you surf.");
    }
}

function getParameter( parameterName ) {
  var queryString = window.location.search.substring(1).toLowerCase();
  //alert(queryString);
  //if (queryString.length==0) {return "null";}
  var parameters = new Array();
  parameters = queryString.split('&');
  for(var i = 0; i < parameters.length; i++) {
    //alert(parameters[i]);
    //alert(parameters[i].indexOf(parameterName));
    if (parameters[i].indexOf(parameterName.toLowerCase())>=0) {
      //alert(parameters[i]);
      var parameterValue = new Array();
      parameterValue = parameters[i].split('=');
      return parameterValue[1];
    }
  }
  return "null";
}