$(document).ready(function() {

  //search
  $('.band_menu form input').each(function(){
    var value = $(this).attr('value');
    
    $(this).focus(function(){
      if($(this).attr('value') == value)
      {
        $(this).attr('value', '');
      }
    });

    $(this).blur(function(){
      if($(this).attr('value') == '')
      {
        $(this).attr('value', value);
      }
    });
  });

  //slideshow
  if($('#slideshow .image').size() > 1)
  {
    $('#slideshow')
    .before('<div id="slideshowNav" class="slideshow_nav">')
    .cycle({
      fx:     'fade',
      speed:   500,
      timeout: 5000,
      next:   '#slideshow',
      pause:   1,
      pager:  '#slideshowNav'
    });
  }
  $('#slideshow .image .text').css('display', 'block');

  //primary menu
  var duration = 200;

  //click for ipad
  if((navigator.userAgent.match(/iPhone|iPod|iPad/i)))
  {
    $('.band_menu .primary_menu>li>a, .band_menu .primary_menu>li>span').click(function(event){
      var element = $(this).parent('li').children('ul:eq(0)');
      if(element.length > 0)
      {
        event.preventDefault();
        $('.band_menu .primary_menu>li>ul').not($(element)).animate({height: '0'}, duration);

        if(element.height() != 220)
        {
          element.animate({height: '220'}, duration);
        }
        else
        {
          element.animate({height: '0'}, duration);
        }
      }
    });
  }
  else
  {
    //other support
    $('.band_menu .primary_menu>li').hover(
      function(){
        $(this).children('ul:eq(0)').animate({height: '220'}, duration);
      },
      function(){
        $(this).children('ul:eq(0)').animate({height: '0'}, duration)
      }
    );
  }

  $('a.popup:not(.edit)').click(function(event){
    event.preventDefault();

    var href = $(this).attr('href');

    window.open(href,"nom_popup","width=800, height=600, menubar=no, status=no, menubar=no, scrollbars=yes");
  });
});


