var audioObjArr = [];
var videoObjArr = [];

jQuery('document').ready(function($) {

  $('#socialBookmarks a').click(function(){$(this).blur();});

  $('body').addClass('js');
	
  if(navigator.userAgent.toLowerCase().indexOf('opera/9.80') != -1
  && navigator.userAgent.toLowerCase().indexOf('version/10') != -1) { $('body').addClass('opera'); }
	
	$('#words')
	.attr('aria-required','true')
	.val('Suchbegriff eingeben')
	.focus(function() {
		$(this).val(($(this).val() === 'Suchbegriff eingeben')?'':$(this).val());
  })
	.blur(function() {
		$(this).val(($(this).val() === '')?'Suchbegriff eingeben':$(this).val());
	})
	.parents('form')
	.submit(function() {
	  if($('#words').val() === 'Suchbegriff eingeben' || $('#words').val() === '') {
		  alert('Bitte geben Sie einen Suchbegriff ein');
			$('#words').focus();
			return false;
		}
		else { return true; }
	});

	$('#wsContent div.wsContentBox div.wsTeaser')
	.addClass('hover')
	.hover(function(){
		$(this)
		.find('h3').addClass('hover')
	},function(){
		$(this)
		.find('h3').removeClass('hover')
	})
	.click(function(){
		//location.href = $(this).find('h3 a').attr('href');
	})
	.each(function() {
		//$(this).attr('title',$(this).find('h3 a').text());
	})
	.find('h3 a')
	.focus(function(){
		$(this).parents('div.wsTeaser')
		//.find('span:eq(0)').css({ textIndent: '0' })
	})
	.blur(function(){
		$(this).parents('div.wsTeaser')
		//.find('span:eq(0)').css({ textIndent: '-10.0em' })
	});
	
	
	
	/* Medieneinbindung */
    /* Check Medialinks */    
    if($('p.videoLink').length > 0 || $('p.audioLink').length > 0) {
    	var $activePlayer = $('<a></a>'); /* Temporary LinkObject for CSS-Reset */  
    }
    
    /* Videoeinbindung per AJAX */
  	if($('p.videoLink').length > 0) { 

  		$('p.videoLink a').each(function(pIdx) {
  			//alert(videoObjArr[pIdx].mid);
	  
  			$(this).click(function() {
  				
  	      $activePlayer.css({ visibility: 'visible'})
  	    	.parent().parent().find('img:eq(0)').css({ visibility: 'visible'});
  	      
  	      $('#flashPlayer').remove();
  	      $('#audioPlayer').remove();
  	      $('#videoPlayer').remove();
  	    	
  	    	$activePlayer = $(this);

  	      var $tmpQuery = '';
  	      if(videoObjArr.length > 0) {
  	    	$tmpQuery = '?mid=' + videoObjArr[pIdx].mid+'&size='+videoObjArr[pIdx].size;
  	      }

  	      $(this).after('<span id="videoPlayer"></span>')
  	      .parent().parent().find('img:eq(0)').css({ visibility: 'hidden'});
  	     
  	      $('#videoPlayer').load('/medien/codebase/intern/player_einslive.jsp'
  	                           + $tmpQuery

                                   + '&offset=' + ((videoObjArr[pIdx].timeCode)?videoObjArr[pIdx].timeCode:0)
+ ' #insideContainer')
  		  .ajaxStop(function(){
          	//location.hash('#flashPlayer');
          });
          
          return false;
  	  		})
  	  });
  	} // End of Videolink
  	

  	$('#wsOnlyAnker a').each(function(pIdx){
  		$(this)
  		.click(function(){
  			var tmpLinkStr = $(this).attr('href');
  			var tmpOffset = (tmpLinkStr.indexOf('offset=') != -1)?parseFloat(tmpLinkStr.split('offset=')[1]):0;
  			tmpOffset = (!isNaN(tmpOffset))?tmpOffset:0;
                        $goToOffset(tmpOffset);
  			return false;
  		});
  	});
  	
  	var $goToOffset = function(pOffset) {  		
  		try {
        if(document.getElementById('flashPlayer')
        && !($('#flashPlayer').parents().hasClass('wsPreview'))
        ) {
        	// Player schon eingebunden
        	document.getElementById('flashPlayer').jumpTo(pOffset);
        	//location.hash = '#flashPlayer';        	
        }
        else {
        	// Player noch nicht eingebunden
          	if($('p.videoLink').length > 0) { 
          		videoObjArr[0].timeCode = pOffset;
          		$('p.videoLink a:eq(0)').click();
          	}
          	else if($('p.audioLink').length > 0) {
          		audioObjArr[0].timeCode = pOffset;
          		$('p.audioLink a:eq(0)').click();          		
          	}          		
        }
      } catch(pError) { 
    	  //alert('Error');    	  
      }
}

}); // End jQuery('document').ready
 

