
jQuery(document).ready(function() {


/* ACCORDION */

	jQuery('.accordion_typ1').accordion({
		active: false,
		header: '.head',
		navigation: false,
		active: '.selected',
		event: 'click',
		//animated: 'easeslide'
		autoHeight: true,
		change: function(event, ui) {
			reloadCounterPixel();
		}

	});

	jQuery('.accordion_typ2').accordion({
		active: false,
		header: '.head',
		navigation: false,
		active: '.selected',
		event: 'click',
		//animated: 'easeslide',
		alwaysOpen: false,
		autoHeight: false,
		change: function(event, ui) {
			reloadCounterPixel();
		}
	});
	
	


/* CAROUSEL */

	function formatText(index, panel) {
	  return index + "";
	}

	jQuery(function () {
	
		jQuery('.anythingSlider_typ1, .anythingSlider_typ2').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 500,             // How long the slide transition takes
			hashTags: false,                // Should links change the hashtag in the URL?
			buildNavigation: false,         // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,            // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             	// Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});

		jQuery('.anythingSlider_typ3, .anythingSlider_typ4, .anythingSlider_typ5').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 500,             // How long the slide transition takes
			hashTags: false,                // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,            // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             	// Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});

		jQuery('.anythingSlider_typ_search').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 5000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 10,             // How long the slide transition takes
			hashTags: false,                // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: false,            // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             	// Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText // Details at the top of the file on this use (advanced use)
		});


		//klick auf link aus dem accordion setzt entsprechendes element im slider (buehne)
		jQuery(".accordion_typ1 #link1").click(function(e){
			jQuery('.anythingSlider_typ1').anythingSlider(1);
			e.preventDefault();
		});
		jQuery(".accordion_typ1 #link2").click(function(e){
			jQuery('.anythingSlider_typ1').anythingSlider(2);
			e.preventDefault();
		});
		jQuery(".accordion_typ1 #link3").click(function(e){
			jQuery('.anythingSlider_typ1').anythingSlider(3);
			e.preventDefault();
		});
		
	});

	


	/*carousels - breite fuer ul setzen*/
	jQuery('.anythingSlider ul').each(function() {
		var li_count 	= jQuery(this).find('li').length;
		var li_width 	= parseInt( jQuery(this).find('li').width() );

		var ul_sum		= li_count*li_width;
		jQuery(this).css('width', ul_sum);
	});


	
	/* prev-link im carouselpager flexibel machen */
	/* gezählt wird die pager-link-anzahl, nicht die li's, wegen der cloned li's */
	jQuery('.workspace .anythingSlider').each(function() {
		var pL_count 	= jQuery(this).find('#thumbNav a').length;
		var pL_width 	= parseInt( jQuery(this).find('#thumbNav a').css('width') );
		var pL_margin	= parseInt( jQuery(this).find('#thumbNav a').css('margin-right') );
		var thNav_right	= parseInt( jQuery(this).find('#thumbNav').css('right') );

		var pl_sum		= pL_count*(pL_width+pL_margin)+thNav_right+pL_margin;
		jQuery(this).find('.back').css('right', (pl_sum+'px'));
	});



	





/* ALLGEMEIN */

	jQuery('.submit, .formElement input.button').hover(function() {
		jQuery(this).addClass('active');
	}, function() {
		jQuery(this).removeClass('active');
	});


	//jQuery('.pic a img, .anythingSlider_typ3 .pic img, .anythingSlider_typ4 .pic img, .anythingSlider_typ5 .pic img, .contenTeaser_typ1 .pic img').hover(function() {
	jQuery('.pic a img').hover(function() {
		jQuery(this).addClass('active');
	}, function() {
		jQuery(this).removeClass('active');
	});

	jQuery('.anythingSlider .button img, .pic_tagesvideo .button img').hover(function() {
		jQuery(this).parent().next().children().addClass('active');
	}, function() {
		jQuery(this).parent().next().children().removeClass('active');
	});


	



/* Rote Specialnavigation Headline holen */
	
	jQuery('.specialnaviDiv h4').each(function() {
		specialHeadline = jQuery(this).parent().prev('h2').html();
		jQuery(this).html(specialHeadline);
	});





});



/* VIDEOS */

/* Updated Text auf der Seite bei Player mit Playliste */
function refreshVideoContent(videoID) {
	jQuery.ajax({
		url: 'index.php',
		type: "GET",
		data: 'eID=ff_tiertv_refreshVideoContent&videoID=' + videoID,
		success: function(xml){
		 	//alert(jQuery("dateDaten",xml).text());
		 	
		 	jQuery(".text H1").html(jQuery("name",xml).text());
		 	jQuery(".text H2").html(jQuery("shortDescription",xml).text());
		 	jQuery(".text p").html(jQuery("longDescription",xml).text());
		 	//jQuery("#menue_programm_content").html(jQuery("programmDaten",xml).text());

			//start_navi_prog();
			
			updateLink(videoID);
		}
	});
}


/* Updated den Videolink im Player mit Playliste */
function updateLink(videoId) {
  
	var currentLink = social.getLink();
	
    newLink = currentLink.replace(/videoID\]=([0-9]+)&/g, "videoID\]=" + videoId + "&");

      
    //alert(newLink);
	social.setLink(newLink);
 
}


/* Init API des Players */
function onTemplateLoaded(pPlayer) {
	//alert("templateLoaded");

	player = bcPlayer.getPlayer(pPlayer);

	video 	= player.getModule(APIModules.VIDEO_PLAYER);
	content = player.getModule(APIModules.CONTENT);
	exp 	= player.getModule(APIModules.EXPERIENCE);
	menu 	= player.getModule(APIModules.MENU);
	ads 	= player.getModule(APIModules.ADVERTISING);
	social 	= player.getModule(APIModules.SOCIAL);


	//exp.addEventListener(BCExperienceEvent.CONTENT_LOAD, onContentLoad);
	//exp.addEventListener(BCExperienceEvent.TEMPLATE_READY, onTemplateReady);
	video.addEventListener(BCVideoEvent.VIDEO_CHANGE, onVideoChange);
	
	//menu.addEventListener(BCMenuEvent.SEND_EMAIL_CLICK, onEmailSent);

}	
	

function onVideoChange(e){
	
	var currentVideo = video.getCurrentVideo();

	refreshVideoContent(currentVideo.id);
}

