$(document).ready(function() {
  $('#node-45 .pane-2 h2').click(function () {
    $('.jshide').fadeIn('slow');
  });

  $('#block-menu-primary-links .menu a.active').addClass('init');
  $('#block-menu-primary-links .menu a').hover(
    function () {
      $('#block-menu-primary-links .menu a.active').removeClass('active');
    },
    function () {
      $('#block-menu-primary-links .menu a.init').addClass('active');
    }
  );
  
  
  $("#webform-client-form-3 .webform-component-textfield label").inFieldLabels();
  $("#webform-client-form-3 .webform-component-email label").inFieldLabels();
  $("#webform-client-form-3 .webform-component-textarea label").inFieldLabels();
  
  $("#webform-client-form-8 .webform-component-textfield label").inFieldLabels();
  $("#webform-client-form-8 .webform-component-email label").inFieldLabels();
  

  $("#audio").jPlayer({
		ready: function () {
			this.element.jPlayer("setFile", Drupal.settings.basePath + "sites/default/files/audio/mmm_2010_jingle.mp3").jPlayer("play");
		},
		swfPath: Drupal.settings.basePath + "sites/all/themes/mmm2010/js",
		customCssIds: true
	});
	
	$("#audio-n98").jPlayer({
		ready: function () {
			this.element.jPlayer("setFile", Drupal.settings.basePath + "sites/default/files/audio/mmm_2010_jingle.mp3");
		},
		swfPath: Drupal.settings.basePath + "sites/all/themes/mmm2010/js",
		customCssIds: true
	});
	
	$('#n98').hover(
    function () {
	    $("#audio-n98").jPlayer("play");
     },
     function () {
  });
  
  $(".audio-n98-play").click(function () {
    $("#audio-n98").jPlayer("play");
  });

  $('#player').jwplayer({
    flashplayer: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/player.swf',
    skin: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/five/five.xml'
  });
  
  $('.videoplayer','.videoplayer-playlist').jwplayer({
    flashplayer: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/player.swf',
    skin: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/five/five.xml'
  });


		$('.videofoo').flash(
			{
				// test_flashvars.swf is the flash document
                // 338 + playlist
				swf: 'http://www.medien-meeting-mannheim.de/2010/sites/all/themes/mmm2010/js/player.swf',
				width:  600,
				height: 782,
                
                allowfullscreen:    true,
                allowscriptaccess:  'always',
                bgcolor:            '#000000',
				
				// these arguments will be passed into the flash document
				flashvars: {
					file : 'http://www.medien-meeting-mannheim.de/2010/sites/default/files/playlist.xml',
					playlist: 'bottom',
                    playlistsize: 420,
                    dock: true,
                    fullscreen: true,
                    showdownload: true
				}
			}
		);
	


  
  /*
  var audio = $('.audioplayer').jwplayer({
    flashplayer: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/player.swf',
    skin: Drupal.settings.basePath + 'sites/all/themes/mmm2010/js/five/five.xml',
    height: 24
  });
  */
  
  $('#edit-submitted-kino').change(function() {
    if ($(this).val() == '' && $('#edit-submitted-aktionscode').val() == '') {
      refreshprice('165 €');
    } else {
      cinemahandler();
    }
  });
  
  $('#edit-submitted-aktionscode').keyup(function(e) {
    switch (e.keyCode) {
      case 27: //KEY_ESC:
      case 9: //KEY_TAB:
      case 13: //KEY_RETURN:
      case 38: //KEY_UP:
      case 40: //KEY_DOWN:
        return;
        break;
    }
    
    pricehandler();
  });
  
  function cinemahandler() {
    if ($('#edit-submitted-aktionscode').val() == '') {
      refreshprice('115 €');
    }
  }
  
  function pricehandler() {
    $.getJSON(Drupal.settings.basePath + 'mmm/price', { code: $('#edit-submitted-aktionscode').val() }, function(json){
      if (json.valid) {
        refreshprice(json.price);
      }
    });
  }
 
 function refreshprice(price) {
    $('#webform-component-preis p').fadeOut('fast', function () {
      $('#webform-component-preis p').text('Ihr Eintrittspreis: ' + price);
      $('#webform-component-preis p').fadeIn();
    });
  }

  /*
  $('.personen a').each(function () {
      $(this).addClass('thickbox');
      href = $(this).attr('href') + '?height=220&width=400';
      $(this).attr('href', href);
  });
  
  tb_init('.personen a.thickbox'); //pass where to apply thickbox
  */
  
  $('ul.personen a').each(function () {
    $(this).attr('href', '#' + $(this).attr('href'));
  });

  $(function(){

  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('.bbq-default')
  };

  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  $(window).bind( 'hashchange', function(e) {

    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();
    if (url.length > 10) {

    // Remove .bbq-current class from any previously "current" link(s).
    $( 'a.bbq-current' ).removeClass( 'bbq-current' );

    // Hide any visible ajax content.
    $( '.bbq-content' ).children( ':visible' ).hide();

    // Add .bbq-current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="#' + url + '"]' ).addClass( 'bbq-current' );

    if ( cache[ url ] ) {
      // Since the element is already in the cache, it doesn't need to be
      // created, so instead of creating it again, let's just show it!
      if (url != '') {
        cache[ url ].show();
        $('.bbq-content-trans').fadeIn('fast');
        $('#overlay').show().fadeIn('fast');
        Cufon.replace('h1');
        $.scrollTo(0, 0, {easing:'swing'});
      }
    } else {
      // Show "loading" content while AJAX content loads.
      $( '.bbq-loading' ).show();

      // Create container for this url's content and store a reference to it in
      // the cache.
      request = jQuery.param.querystring(url, 'content-only');
      cache[ url ] = $( '<div class="bbq-item"/>' )

        // Append the content container to the parent container.
        .appendTo( '.bbq-content' )

        // Load external content via AJAX. Note that in order to keep this
        // example streamlined, only the content in .infobox is shown. You'll
        // want to change this based on your needs.

        .load( request, function(){
          // Content loaded, hide "loading" content.
          $( '.bbq-loading' ).hide();
          $('.bbq-content-trans').fadeIn('fast');
          $('#overlay').fadeIn('fast');
          Cufon.replace('h1');
          $.scrollTo(0, 0, {easing:'swing'});
        });
    }
  }
  });

  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger('hashchange');
});

  function closeOverlay() {
    $('#overlay').hide().fadeOut('fast');
    $('.bbq-content-trans').fadeOut('fast');
    window.location = Drupal.settings.currentUrl + '#';
  }

  $('#overlay,.bbq-content-trans').click(function (e) {
    closeOverlay();
  });
  
  $('#overlay a').click(function () {
    return FALSE;
  });
  
});

