/**
 * Controller for kongresszentrum-stuttgart.de
 * (c) 2009, Benjamin Zaiser, info@benjamin-zaiser.de
 */
$(document).ready(function(){
	$('.gallery').cycle({ 
		speed: 6000,
		timeout: 1000
	});
	
	
  $('#pagerNavi').hide();
  //Blätternavigation
  $('#imagegallery_navi').html('<div id="back"></div><div id="next"></div>');

  // Pager
  $('#imagegallery').after('<div id="pagerNavi"></div>');
  $('#pagerNavi').fadeIn(2000);
  
  //Diashow-Animation
	$('#imagegallery').cycle({ 
      fx:     'fade', 
      speed: 1000,
      timeout: 3000, 
      next:   '#next, #imagegallery',
      fit: 1,
      fastOnEvent: 1, // Durchblättern ohne Animation
      pause: 1, // hält automatisch an, wenn Maus hover
      pager: '#pagerNavi'
  });
  
	
	//Raumfinder
	$("#map-container area").mouseover(function(){
		bgX = $(this).attr("class").replace('x', '');
		$('#map-container').css('background-position', '-' + bgX + 'px 0px');
	}).mouseout(function(){
		regionMap = "."+$(this).attr("class")+"-map";
		// Check if a click event has occured and only change the Region hover state accodringly
		if (!$(regionMap).hasClass("selected")) {
			$('#map-container').css('background-position', '0px 0px');
		}
	});
	
	//Flowplayer
	var player;
	$("a[rel]").overlay({
		// use the Apple effect for overlay
		//effect: 'apple',
		// some mask tweaks suitable for facebox-looking dialogs
		mask: {
			// you might also consider a "transparent" color for the mask
			color: '#000',
			// load mask a little faster
			loadSpeed: 300,
			// very transparent
			opacity: 0.5
		},
		// when overlay is opened, load our player
		onLoad: function() {
			videohref = this.getTrigger().attr('href');
			$('.video-overlay a#player').attr('href', videohref);
			player = $f("player", "fileadmin/sys/swf/flowplayer-3.2.7.swf", {
				clip: {
					autoStart: true,
					onStart: function(clip) {
						var wrap = jQuery(this.getParent());
						wrap.css({height: (clip.metaData.height/(clip.metaData.width/640)) });
					},
					scaling: 'fit'
				}
			});
			player.load();
		},
		// when overlay is closed, unload our player
		onClose: function() {
			player.stop();
			player.unload();
		}
	}); 
});
