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')
		.find('a').css({ textDecoration: 'underline' })
	},function(){
		$(this)
		.find('h3').removeClass('hover')
		.find('a').css({ textDecoration: 'none' })
	})
	.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('h3 a').css({ textDecoration: 'underline' })
		.find('span:eq(0)').css({ textIndent: '0' })
	})
	.blur(function(){
		$(this).parents('div.wsTeaser')
		.find('h3 a').css({ textDecoration: 'none' })
		.find('span:eq(0)').css({ textIndent: '-10.0em' })
	});
	
	
	
	/* Medieneinbindung */
    /* Check Medialinks */    
    if($('.videoLink').length > 0 || $('.audioLink').length > 0) {
    	var $activePlayer = $('<a></a>'); /* Temporary LinkObject for CSS-Reset */  
    }
    
    /* Videoeinbindung per AJAX */
  	if($('.videoLink').length > 0) { 
  		
  		$('.videoLink a').each(function(pIdx) {
		
  			$(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+
                              ((videoObjArr[pIdx].untertitelurl != undefined  
                                && videoObjArr[pIdx].untertitelurl != null
                                && videoObjArr[pIdx].untertitelurl != '' 
                                )?('&untertitelurl='+ videoObjArr[pIdx].untertitelurl):'');  	     
  	      }
  	      
  	      $(this).after('<span id="videoPlayer"></span>')
  	      .parent().parent().find('img:eq(0)').css({ visibility: 'hidden'});
  	     
  	      $('#videoPlayer').load('/mediathek/codebase/intern/player.jsp'
  	                           + $tmpQuery

                                   + '&offset=' + ((videoObjArr[pIdx].timeCode)?videoObjArr[pIdx].timeCode:0)
+ ' #insideContainer')
  		  .ajaxStop(function(){
          	//location.hash('#flashPlayer');
          });
          
          return false;
  	  		})
  	  });
  	} // End of Videolink
  	
  	/* Audioeinbindung per AJAX */
  	if($('.audioLink').length > 0) { 

  		$('.audioLink a').each(function(pIdx) {
  		
  		$(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(audioObjArr.length > 0) {
  	      	$tmpQuery = '?mid=' + audioObjArr[pIdx].mid+'&size='+audioObjArr[pIdx].size;
  	      }
  	      
  	      $(this).after('<span id="audioPlayer"></span>')
  	      .css({ visibility: 'hidden'})
  	      .parent().parent().find('img:eq(0)').css({ visibility: 'hidden'});

  	      $('#audioPlayer').load('/mediathek/codebase/intern/player.jsp'
  	                           + $tmpQuery
                               + '&offset=' + ((audioObjArr[pIdx].timeCode)?audioObjArr[pIdx].timeCode:0)  	                           
+ ' #insideContainer')
  	      .ajaxStop(function(){
          	//location.hash = '#flashPlayer';
          }); 	      
  	      return false;
  	  })
  	  
  	});
  	} // End of Audiolink

  	$('#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($('.videoLink').length > 0) { 
          		videoObjArr[0].timeCode = pOffset;
          		$('.videoLink a:eq(0)').click();
          	}
          	else if($('.audioLink').length > 0) {
          		audioObjArr[0].timeCode = pOffset;
          		$('.audioLink a:eq(0)').click();          		
          	}          		
        }
      } catch(pError) { 
    	  //alert('Error');    	  
      }
}

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

