/******************************************************************/
/* Das Erste Templates Version 2.3.4							*/
/******************************************************************/
/* © DMC 01 Consulting & Development GmbH - gerald.urbas@dmc01.at */
/******************************************************************/
/* www.jquery.com based scripts for ARD Videoportal               */
/******************************************************************/
/* The script 1 U list, extracts hrefs and IDs and turn off       */
/* unesacary .letters in left coloum. teaser lists get loaded     */
/* into rigth coloum with scrollpanes. letters Left move centered */
/* coloum to the correct (calculated) position                    */
/******************************************************************/

$j(document).ready(function(){ // Page is ready
	var alphapane = $j('#alphapane'); // get Link container
	var alphapanetop = parseInt(alphapane.offset().top); // calculate Offsett
	$j('#alphapane ul').each(function(i) { // each UL gets an ID (axample(A, or D, to XZY)
		$j('#bt'+$j(this).attr('id')) // find the correspond button in Layout. (btA, or btD to btXZY)
			.attr({'href':'#', 'rel':$j(this).offset().top}) // rewrite the href to empty JS call and save Offset fot the object (for later use in anon click function
			.bind('click',function() { // bind the click for jumping to positions in the centered list to letters leftside
				//$j(this).parent().parent().children("li").removeClass('active') // remove all active states.
				//$j(this).parent().addClass('active') // add active state
				alphapane[0].scrollTo(parseInt($j(this).attr('rel')) - alphapanetop); // Scroll to Position... (function defined by scrollpane JS)
				return false;
			}); // cklick end
		}); // each UL end

	$j("#alphalist a").each(function(i){ // with letterlinks  replace href with spans, if no relation was found..
		if (!$j(this).attr("rel")) { // rel is generated above... only if the letter is is defined
			$j(this).parent().append("<span>"+$j(this).html()+"</span>") // add a Span with the eaxact content of the link...
			$j(this).remove();// so we can save claim heres no A tag allowed... remove it (the A Tag9
		}
	}); // each letter link
	$j('#alphapane li>a').each(function(i) { // each A- tag element (in centered list)
		$j(this) // Chainability!!
			.attr('url',$j(this).attr('href')) // remember orig. href to prop called url
			.attr({'href':'#', 'rel':$j(this).offset().top}) // rewrite the href to empty JS call, // calculate Offsett
			.bind('click',function() { // Bind click function
				$j('#alphapane li').removeClass('active'); // remove Active from all LI s
				$j(this).parent().addClass('active'); // add active to current parent LI				
				var obj = $j("#bluelist"); // teaser container				
				loading(obj); // generate loading anim
				obj.load($j(this).attr('url'),function() {  // Load URL, originl the href (saved in url). add scrollpane updater on result.					
					setScrollPane(obj.children(".jScrollPane"));
					setPaging();
				}); // Loading Teasercontainer
				return false;
			}); // Bind Click Function
	}); // each A- tag element
	
	//allow initial broadcast
	var scrollsendungenafterinit = false;
	if(typeof(initial_broadcast) != "undefined") {
		$j("#alphapane .title:contains("+initial_broadcast+")").each( function(i) {
			if($j(this).text().length == initial_broadcast.length) { //filter
				$j(this).parent().parent().addClass("active");
				scrollsendungenafterinit = (parseInt($j(this).parent().attr("rel")) - alphapanetop);
				//alphapane[0].scrollTo(parseInt($j(this).parent().attr("rel")) - alphapanetop);
				var obj = $j("#bluelist");	
				loading(obj); // generate loading anim
				obj.load($j(this).parent().attr('url'),function() {  				
					setScrollPane(obj.children(".jScrollPane"));
					setPaging();
					if (scrollsendungenafterinit) {
						alphapane[0].scrollTo(scrollsendungenafterinit)
					}
				});
				
			}
		});				
	}
}); // Page is ready
