// -----------------------------------------------------------------------------
// File:    custom.js
// Author:  Paul Norgaard
// Create the style array for the available shoe styles.

//<script src="stylesarray.js" type="text/javascript"></script>

var selected = "frdmBlk";
var mf_sel = "mf_go_fish";
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

jQuery(document).ready(function() {

  $("#show_newsletter").click(function() {
    $("#newsletter").toggle("slide");
  });
  
  $("#sexSelector input").click(function() {
    
    var sex = $("#sexSelector input[name='sex']:checked").val();
    var color = $("#sexSelector input[name='color']:checked").val();

    $(".sel").css("display", "none");
    $("." + sex + "." + color).css("display", "block");
 
  });

  // Enhancements to the main menus
  // Create a box shadow for the menus.
  $(" #navbar ul ").css({display: "none"}); // Opera Fix
  $(" #navbar li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
  },function(){
    $(this).find('ul:first').css({visibility: "hidden"});
  });

  // Set the first element in the shoeMenu to be active!
  $("#" + selected).addClass("selected");

  // Code to change the display when a style is selected from the
  // menu.
  $('.sel').click(function() {

    var id = $(this).attr("id");
    // Get the index # of the style selected.
    var index = styleArray.findID(id);
    
    $('#mainHeader').text(styleArray[index][STYLE_HEADING]);

    $('#mainPicture').attr("src", styleArray[index][STYLE_MAIN_IMAGE]);
    var textName = "#" + styleArray[styleArray.findID(selected)][STYLE_FEATURES];
    $("#" + styleArray[styleArray.findID(selected)][STYLE_FEATURES]).css("display", "none");
    $("#" + styleArray[index][STYLE_FEATURES]).css("display", "inline");

    selected = id;
  });

  $('#faq').find('dd').hide().end().find('dt').click(function() {
     $(this).next().slideToggle();
  });
   
  $('.handbag').click(function() {
    $("#" + mf_sel + "_div").hide();
    $("#" + $(this).attr("id") + "_div").show();
    mf_sel = $(this).attr("id");
  });
  
  $('.mf_acc_thmb img').click(function() {
    var imgsrc = $(this).attr("src");
    var newimg = imgsrc.substring(0, imgsrc.indexOf("thmb") - 1)
    var idname = "mf_" + imgsrc.substring(imgsrc.lastIndexOf("/") + 1, imgsrc.indexOf("-")) + "_pic"
    $("#" + idname).attr("src", newimg + ".jpg");
  });
  
  $('li.sel').click(function() {
    $(this).addClass("selected");
    $(this).prevAll().removeClass("selected");
    $(this).nextAll().removeClass("selected");
  });
  
  $("a.amber_images").fancybox({
    'zoomSpeedIn'     : 500,
    'zoomSpeedOut'    : 500
  });

  $("#testimonial_form").validate({
    rules: {
      timage: {
        accept: "jpg|jpeg|gif"
      }
     },
     messages: {
      timage: {
        accept: "Only jpg &amp; gif files accepted."
      }
    }
  });
  $("#cus").validate();

  // Code for the scrolling events box.
  $.ajax({
    url: "./include/events.txt",
    cache: false,
    success: function(data) {
      var events = new Array();
      var detail = new Array();
      events = data.split("\n");
      for (var i = 0; i < events.length; i++)
      {
        detail = events[i].split("|");
        $("#scrollup").append('<div class="headline"><a href="index.php?page=events#' + detail[2] + '"><span class="headline_date">' + detail[0] + '</span><br /><span class="headline_text">' + detail[1] + '</span></a></div>');
      }
      headline_count = $(".headline").size();
      $("div.headline:eq("+current_headline+")").css('top','.3em');
      headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
    }
  });


  $('#scrollup').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setInterval(headline_rotate,5000); //time in milliseconds
    headline_rotate();
  });
  
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; 
  $("div.headline:eq(" + old_headline + ")").animate({top: -205},"slow", function() {
    $(this).css('top','3.1em');
  });
  $("div.headline:eq(" + current_headline + ")").show().animate({top: 5},"slow");  
  old_headline = current_headline;
}

