// video_community.js Alle für die Video Community benötigten Funktionen
var v_filterWoOpen = false;
var v_filterWasOpen=false; 
var updateTeasers = false; // Leider keine Teaser per Ajax updaten

//Video Community spezifische Init Methode
$(document).ready(function(){
	//Fuer noscript ausgeblendetes wieder einblenden
	$('.video_hitlist .video_thumb,.video_hitlist .iconshided,.#video_tipp a,.video_link,#hit_table .hit_link ').show();
	
	if($('#selection_text_was_video').html() !== 'bitte w&auml;hlen' && $('#selection_text_was_video').html().length > 23){
		$('#selection_text_was_video').html($('#selection_text_was_video').html().substring(0,21)+"...");	
	} else {
		$('#selection_text_was_video').html($('#selection_text_was_video').html());
	}
	if($('#selection_text_wo_video').html() !== 'bitte w&auml;hlen' && $('#selection_text_wo_video').html().length > 23){
		$('#selection_text_wo_video').html($('#selection_text_wo_video').html().substring(0,21)+"...");	
	} else {
		$('#selection_text_wo_video').html($('#selection_text_wo_video').html());
	}
	
	//aktuellen Gegenueber-Index verlinken
   	$('#top_20_wo_video .active').html('<a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick="v_activate_toplist(this,\'wo_video\');return false;">'+ $('#top_20_wo_video .active').html() +'</a>');
    $('#top_20_wo_video .active').removeAttr('class');	
	
   	$('#top_20_was_video .active').html('<a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick="v_activate_toplist(this,\'was_video\');return false;">'+ $('#top_20_was_video .active').html() +'</a>');
    $('#top_20_was_video .active').removeAttr('class');	
	
	if($('.video_detail_page').size()>0){
		//alert('VideoDetail');
	}
});



//Backend Funktion: Check ob Vorschaubilder vorhanden sind und bei false default bild laden

function v_handleBrokenImages(dies,src){
	if(src==="result"){
		dies.src = "../../static/img/videoportal/default_preview_180x135.jpg";
	}
	else if(src==="teaser1"){
		dies.src = "../../static/img/videoportal/default_preview_400x300.jpg";
	}
	else if(src==="teaser2" || src==="teaser3"){
		dies.src = "../../static/img/videoportal/default_preview_100x75.jpg";
	}
}

// loading GIF Verarbeitung
function v_hide_small_loading_gif(which){
	$("#loading_"+which+"_video").hide();
	$("#toggler_"+which+"_video").show();
}
function v_show_small_loading_gif(which){
	$("#toggler_"+which+"_video").hide();
	$("#loading_"+which+"_video").show();
}

function v_hide_big_loading_gif(which){
	$("#loading_big_"+which+"_video").hide();
	$("#delimiter_list_"+which+"_video").show();
}
function v_show_big_loading_gif(which){
	//hoehe des loading GIF feststellen
	var lg_height = $("#loading_big_"+which+"_video").height();
	//Y-Position fuer das loading GIF berechnen soll mittig sitzen
	var f_height = $("#search_delimiter_scroll_"+which+"_video").height();
	var y_pos = (f_height/2)-(16);
	$("#loading_big_"+which+"_video").css('top', y_pos+"px");
	if($("#search_delimiter_scroll_"+which+"_video").height() > 30){ //wenn mehr als eine zeile im filter stehen dann loading gif auf normalgröße setzen
		$("#loading_big_"+which+"_video").attr('height', '32').
										  css('margin-top','0px').
										  css("overflow-y","auto");
	}
	$("#delimiter_list_"+which+"_video").hide();
	$("#loading_big_"+which+"_video").show();
}

function v_hover_slider(dies){
	dies.firstChild.src = dies.firstChild.src.replace(/\.png/,"_on.png");
}

function v_dehover_slider(dies){
	dies.firstChild.src = dies.firstChild.src.replace(/_on\.png/,".png");
}

function v_closeFilter(which){
	$('#search_delimiter_'+which).hide();
	FilterKeyHandler.stopKeyListener(which);
	ge('toggler_'+which).src = ge('toggler_'+which).src.replace(/close/,"open");
}

function v_closeFilters(){
	v_closeFilter('wo_video');
	v_closeFilter('was_video');
}

function v_openFilter(which){
    v_closeFilter('was_video');
    v_closeFilter('wo_video');
    FilterKeyHandler.startKeyListener( which );
	//Hoehe vorher bestimmen
	var height = $('#delimiter_list_wo_video').height();
	$('#search_delimiter_'+which).css("visibility","hidden").
								  show();
	v_resizeFilter(which);
	$('#search_delimiter_'+which).css("visibility","visible").
								  bgiframe();
	ge('toggler_'+which).src = ge('toggler_'+which).src.replace(/open/,"close");
}

function v_toggleFilter(which){
	if(which==="was_video"){
		if(v_filterWasOpen){
			v_closeFilter("was_video");
			v_filterWasOpen=false;
		}
		else{
			v_openFilter("was_video");
			v_filterWasOpen=true;
			v_filterWoOpen=false;
		}
	}
	else if(which==="wo_video"){
		if(v_filterWoOpen){
			v_closeFilter("wo_video");
			v_filterWoOpen=false;
		}
		else{
			v_openFilter("wo_video");
			v_filterWoOpen=true;
			v_filterWasOpen=false;
		}
	}
}

function v_resizeFilter(which){
	var height = $('#delimiter_list_'+which).height();
    //256 ist die maximale Hoehe der Box im Filter. muss leider hart rein
	if(height>256){
	
		//uebnerm START - scroll container scroll bar setzen
		$('#scroll_container_'+which).css("overflow-y","auto");
		//uebnerm END
    
        height = 256;
    }
    $('#scroll_container_'+which).height(height);
	$('#search_delimiter_scroll_'+which).height(height);
}

function v_refreshFilter(which,data){
	
	var jsonDataResponseObject = data;
	var htmlSelection = new Array();
	var htmlIndex 	  = new Array();
	
    var even_odd = new Array("even","odd");
    $('#delimiter_list_'+which).html('');
	var topLimit = jsonDataResponseObject.list.length;
    for(var i=0;i<topLimit;i++){
   		htmlSelection.push('<li class="'+even_odd[i%2]+'"><a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);"  onclick="v_applyFilterSelection(\''+which+'\',this.firstChild.innerHTML,\''+jsonDataResponseObject.list[i].code+'\');return false;"><span>'+jsonDataResponseObject.list[i].name+'</span></a></li>');
    }
    $('#top_20_'+which).html('');
    
	var indexLimit = jsonDataResponseObject.index.length;
	if(indexLimit == null || indexLimit == undefined || indexLimit == 0) {
	} else {
	    for(var i=0;i<indexLimit;i++){
	    	if(jsonDataResponseObject.index[i].linked == true) {
				htmlIndex.push('<li><a href="#" onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick="v_activate_toplist(this,\''+which+'\');return false;">'+jsonDataResponseObject.index[i].letter+'</a></li>');
	    	} else {
	        	htmlIndex.push('<li>'+jsonDataResponseObject.index[i].letter+'</li>');
	        }	
	    }
	} 
    if(data.length === 0){
    	if(which==="was_video"){
    		htmlSelection.push('<li class="'+even_odd[i%2]+'"><span>keine weiteren Branchen Verf&uuml;gbar</span>	</li>');
    	}
    	else if(which==="wo_video"){
    		htmlSelection.push('<li class="'+even_odd[i%2]+'"><span>keine weiteren Orte Verf&uuml;gbar</span>	</li>');
    	}
    }
    $('#delimiter_list_'+which).html(htmlSelection.join(""));
    $('#top_20_'+which).html(htmlIndex.join(""));  
	v_resizeFilter(which);
}

function v_updateTeasers(){
	v_updateMainTeaser($('#selection_text_was_video').html(),$('#selection_text_wo_video').html());
    v_updateRightTeaser($('#selection_text_was_video').html(),$('#selection_text_wo_video').html());
    v_updateBottomTeaser($('#selection_text_was_video').html(),$('#selection_text_wo_video').html());
}

function v_resetFilterOnError(){
	//Funktion nur im Body onload der InseratseiteVideo aufrufen
	//wenn mindestens einer der Filterwerte  == -1 dann kann man nur ueber 
	//Teaser auf Inseratseite gelangt sein -> Auswahlboxen resetten
	if(ge('filter_wo').value==-1 || ge('filter_was').value==-1){
		v_resetFilter('wo_video');
		v_resetFilter('was_video');
	}
}

function v_resetFilter(which){
	$('#selection_text_was_video').html('bitte w&auml;hlen');
	$('#selection_text_wo_video').html('bitte w&auml;hlen');
	
	//uebnerm START - hidden values resetten
	ge('filter_wo').value=-1;
	ge('filter_was').value=-1;
	ge('fullTradeNameText').value=-1;
	//uebnerm END
	
	v_closeFilter(which);	
	//aktuelle active wieder mit Link versehen
	$('#top_20_'+which+' .active').each(function(){
	   	var myname = $(this).text();
	    $(this).html('').
	    	    prepend('<a href="#" onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick=v_activate_toplist(this,"'+which+'");return 0;>'+ myname +'</a>').
	    	    removeAttr('class');
	});
	
	if(which==="was_video"){
		$('#top_20_was_video li.active').removeAttr('class');
		$('#was_a_link').show().
							  attr('class','active').
							  html('A');
		v_filterWasOpen = false;
	}
	else if(which==="wo_video"){
		$('#top_20_wo_video li.active').removeAttr('class');
		$('#wo_a_link').show().
							 attr('class','active').
							 html('A');
		v_filterWoOpen = false;
	}
	
	if(which==="was_video"){
		$.getJSON(PATH_TO_VIDEO_FILTER,{mode:1,val:"reset"},function(data){
	        v_refreshFilter("was_video",data);
	        if(updateTeasers){
	            v_updateTeasers();
	        }
	    });
    } else if(which==="wo_video"){
	    $.getJSON(PATH_TO_VIDEO_FILTER,{mode:2,val:"reset"},function(data){
	        v_refreshFilter("wo_video",data);
	        if(updateTeasers){
	            v_updateTeasers();
	        }
	    });
	}
}

//Ueberkreuz, da sich die Filter gegenseitig beeinflussen
// @var val: gewaehlter "Select Ausdruck" im was filter
// @var oppositeVal: gewaehlter "Select Ausdruck" im wo filter 
// @var source: wurde in der Liste oder unten in der Buchstabenreihe geklickt?
function v_buildWhatFilter(val,updateTeasers,oppositeVal,source){
	if(source === "toplist"){
		if($("#search_delimiter_scroll_wo_video").height() < 30){ //wenn nur eine zeile im filter dann loading gif kleiner machen
			$("#scroll_container_wo_video").css("overflow-y","hidden");
			$("#loading_big_wo_video").attr('height', '22').css('margin-top','5px');
		}
		v_show_big_loading_gif("wo");
	}
	else if(source === "selection"){
		v_show_small_loading_gif("wo");
	}
	$.getJSON(PATH_TO_VIDEO_FILTER,{mode:2,val:val,oppositeVal:oppositeVal},function(data){
		v_refreshFilter("wo_video",data);
		if(source === "toplist"){
			v_hide_big_loading_gif("wo");
		}
		else if(source === "selection"){
			v_hide_small_loading_gif("wo");
		}
		//nach Aktualisierung der Filter die Videos aktualisieren
		if(updateTeasers) {
			v_updateTeasers();
		}	
	});
}

//Ueberkreuz, da sich die Filter gegenseitig beeinflussen
//@var val: gewaehlter "Select Ausdruck" im wo filter
//@var oppositeVal: gewaehlter "Select Ausdruck" im was filter 
//@var source: wurde in der Liste oder unten in der Buchstabenreihe geklickt?
function v_buildWhereFilter(val,updateTeasers,oppositeVal,source){
	if(source === "toplist"){
		if($("#search_delimiter_scroll_was_video").height() < 30){ //wenn nur eine zeile im filter dann loading gif kleiner machen
			$("#scroll_container_was_video").css("overflow-y","hidden");
			$("#loading_big_was_video").attr('height', '22').
									    css('margin-top','5px');
		}
		v_show_big_loading_gif("was");
	}
	else if(source === "selection"){
		v_show_small_loading_gif("was");
	}
	$.getJSON(PATH_TO_VIDEO_FILTER,{mode:1,val:val,oppositeVal:oppositeVal},function(data){
		v_refreshFilter("was_video",data);
		if(source === "toplist"){
			v_hide_big_loading_gif("was");
		}
		else if(source === "selection"){
			v_hide_small_loading_gif("was");
		}
		if(updateTeasers) {
			v_updateTeasers();
		}	
	});
}

//uebnerm zusaetzliche Function
function trim(s){
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] === ' ')
	{	l++; }
	while(r > l && s[r] === ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function v_applyFilterSelection(which,val,valcode){
	//$('#top_20_wo_link').hide();
	//$('#top_20_was_link').hide();
	
	if($('#start_page').size()<1){
		updateTeasers = false;
	}

	//uebnerm START - nicht den Wert cutten da für die Suche in der 
	//DB verwendet
	if(val.length>23){
		$('#selection_text_'+which).html(val.substring(0,21)+"...");	
	} else {
		$('#selection_text_'+which).html(val);
	}
	
	// CR5199 Volle Branchenbezeichnung sichern
	if(which==="was_video") {
		ge('fullTradeNameText').value=val;
	}

	// uebnerm END
	
	v_toggleFilter(which);
	
	if(which==="was_video"){
		//aktuellen Gegenueber-Index verlinken
	   	$('#top_20_wo_video .active').html('<a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick="v_activate_toplist(this,\'wo_video\');return false;">'+ $('#top_20_wo_video .active').html() +'</a>');
	    $('#top_20_wo_video .active').removeAttr('class');	
	
		v_buildWhatFilter(val,updateTeasers,$('#selection_text_wo_video').html(),'selection');
		//uebnerm START - nicht den val sondern den ValCode benutzen (DB)
		ge('filter_was').value=valcode;//in hidden value schreiben (hier Branchen-ID)
		//uebnerm END
	}
	else if(which==="wo_video"){
		//aktuellen Gegenueber-Index verlinken
	   	$('#top_20_was_video .active').html('<a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick="v_activate_toplist(this,\'was_video\');return false;">'+ $('#top_20_was_video .active').html() +'</a>');
	    $('#top_20_was_video .active').removeAttr('class');	
	
		v_buildWhereFilter(val,updateTeasers,$('#selection_text_was_video').html(),'selection');
		ge('filter_wo').value=val;//in hidden value schreiben (hier Ortsbezeichnung)
	}
	
	if (ge('filter_wo').value != -1 && ge('filter_was').value != -1) {
		executeSubmit();
	}
}

function v_applyFilterSelectionOnError(which){
	if(which==="was_video"){
		v_applyFilterSelection(which, ge('selection_text_was_video').innerHTML, ge('filter_was').value);
		v_toggleFilter('was_video');
		//ge('top_20_was_video').innerHTML = 'Index nicht verf\uumlgbar';
	} else {
		v_applyFilterSelection(which, ge('selection_text_wo_video').innerHTML, ge('filter_wo').value);
		v_toggleFilter('wo_video');
		//ge('top_20_wo_video').innerHTML = 'Index nicht verf\uumlgbar';
	}
}
// ############# IE6 BEGIN ##################
function v_applyFilterSelection_ie(which,val,oppositeVal){
	if(which==="was_video"){
		ge('filter_was').value=val;//in hidden value schreiben
		window.location.href= PATH_TO_VIDEO_HOME+"?was_video="+encodeURI(val)+"&wo_video="+encodeURI(oppositeVal);
	}
	else if(which==="wo_video"){
		ge('filter_wo').value=val;//in hidden value schreiben
		window.location.href= PATH_TO_VIDEO_HOME+"?wo_video="+encodeURI(val)+"&was_video="+encodeURI(oppositeVal);
	}
}
// ############### IE6 END #####################

function v_updateMainTeaser(what,where){
	$.getJSON(PATH_TO_VIDEO_COMMUNITY,{mode:1,what:what,where:where},function(data){
		v_callBack_updateMainTeaser(data);
	});
}


function v_updateRightTeaser(what,where){
	$.getJSON(PATH_TO_VIDEO_COMMUNITY,{mode:2,what:what,where:where},function(data){
		v_callBack_updateRightTeaser(data);
	});
}

function v_updateBottomTeaser(what,where){
	$.getJSON(PATH_TO_VIDEO_COMMUNITY,{mode:3,what:what,where:where},function(data){
		v_callBack_updateBottomTeaser(data);
		initMoveMediaVideo();
	});	
}

/*
 * data[i][0]: img src
 * data[i][1]: id
 * data[i][2]: headline
 * data[i][3]: subline
 * data[i][4]: link zu detailseite
 */
function v_callBack_updateBottomTeaser(data){
	var tableContent = "";
	var singleVideo = "";
	var topLimit = data.length;
	for(var i=0;i<topLimit;i++){
		if(i+1===data.length){
			singleVideo = singleVideo.concat('<td class="last_right">');
		}	
		else{
			singleVideo = singleVideo.concat('<td>');
		}			
		singleVideo = singleVideo.concat('  <div class="hit">');
		singleVideo = singleVideo.concat('     <a href="#" onclick="v_openPlayerTB_startpage_bottom(\'video_marginal'+i+'\',\'flash_url\',this);return false;"><img id="video_more_b'+data[i][1]+'_image" class="video_more_b" src="'+data[i][0]+'" width="100" height="75" alt="video_more_b'+data[i][1]+'_image" title="video_more_b'+data[i][1]+'_image" />');
		singleVideo = singleVideo.concat('     <img class="btn_play" id="video_more_b'+data[i][1]+'_button" src="../../static/img/videoportal/btn_play_small.png" width="33" height="32" alt="Play Knopf" title="Play Knopf" /></a>');
		singleVideo = singleVideo.concat('     <p><a href="'+data[i][4]+'" class="underline bold">'+data[i][2]+'</a></p>');
		singleVideo = singleVideo.concat('  </div>');
		singleVideo = singleVideo.concat('</td>');
		tableContent = singleVideo;
	}
	$('div#hit_table tr').empty().
						  append(tableContent);
	$('.btn_play').show();
}

function v_callBack_updateRightTeaser(data){
	var Content = "";
	var singleVideo = "";
	var topLimit = data.length;
    for(var i=0;i<topLimit;i++){
 		if(i===0){
 			singleVideo = singleVideo.concat('<div class="hit_first clearfix">');
 		}
 		else if(i+1===data.length){
				singleVideo = singleVideo.concat('<div class="hit_last clearfix">');
 		}
 		else{
			singleVideo = singleVideo.concat('<div class="hit clearfix">');
 		}
		singleVideo = singleVideo.concat(' <a href="#" onclick="v_openPlayerTB_startpage_right(\'video_marginal'+i+'\',\'flash_url\',this);return false;" class="video_link"><img id="video_marginal'+i+'_image" src="'+data[i][0]+'" width="100" height="75" alt="video_marginal'+i+'_image" title="video_marginal'+i+'_image" />');
		singleVideo = singleVideo.concat(' <img class="btn_play" src="../../static/img/videoportal/btn_play_small.png" width="34" height="34" alt="Play Knopf" title="Play Knopf" /></a><div id="video_marginal'+i+'_text" class="desc">');
		singleVideo = singleVideo.concat('  <p><a href="'+data[i][4]+'" class="bold underline">'+data[i][2]+'</a></p>');
		singleVideo = singleVideo.concat('  <p>'+data[i][3]+'</p>');
		singleVideo = singleVideo.concat(' </div>');
		singleVideo = singleVideo.concat(' <br class="clearall" />');
		singleVideo = singleVideo.concat('</div>');
		Content = singleVideo;
	}
	$('div#marginal_content').empty().
							  append(Content);
	$('.btn_play').show();
}

function v_callBack_updateMainTeaser(data){
	ge('video_tipp_image').src = data[0][0];
	var p = $('#video_tipp_subtitle p').empty();
	ge('video_tipp_button').href = "#";//data[0][4]+"?id="+data[0][1];
	$('#video_tipp_button').click(function(){v_openPlayerTB_startpage_main('video_tipp','flash_url',this);return false;});
	p.append(data[0][2]+"<br />"+data[0][3]);
}


// Video-Community Top-20-List Active setzen
function v_activate_toplist(elem,which){ 
	var ul = $(elem).parent().parent().attr('id');
	var parent = elem.parentNode;
	var name = $(elem).text();
	//aktuelle active wieder mit Link versehen
	$('#'+ul+' .active').each(function(){
	   	var myname = $(this).text();
	   	$(this).html('<a href="#"  onmouseover="add_hover(this);" onmouseout="remove_hover(this);" onclick=\'v_activate_toplist(this,"'+which+'");return false; \'>'+ myname +'</a>');
	    $(this).removeAttr('class');
	});
	// neue active: Links löschen
	$(parent).attr('class', 'active')
	parent.innerHTML = name; //IE7
	
	// CR5199 
	// Fall das Branchenbezeichnungen zu lang sind und im Index der Ortssuche als Opposite verwendet werden
	if (which==="wo_video") {
		if(ge('fullTradeNameText').value != -1) {
			v_buildWhatFilter(name,false,ge('fullTradeNameText').value,'toplist');
		} else {
			v_buildWhatFilter(name,false,$('#selection_text_was_video')[0].innerHTML,'toplist');
		}
	} else if(which==="was_video"){
		v_buildWhereFilter(name,false,$('#selection_text_wo_video')[0].innerHTML,'toplist');
	}
}

//uebnerm START - in den Functions auf GS - Standard Player angepasst
//gilt fuer alle openPlayer Functionen

function v_openPlayerTB(result_id,flash_url,dies, subId){
	//Filter schliessen
	v_closeFilters();

	var urlString = new String(flash_url);
	
	if(urlString.lastIndexOf('.htm') != -1) {
		document.getElementById('TB_video').innerHTML="<iframe name='iframeMicrosite' id='iframeMicrosite' marginheight='0' marginwidth='0' height='350' width='440' src='" + flash_url + "' frameborder='0' scrolling='no' class='bordered margin_t_10'><ilayer src='http://www.bfbnet.de/images/0003/1126/index.html'></ilayer></iframe>";
	} else if (urlString.lastIndexOf('.flv') != -1) {
		//flashplayer
		var object=getHtmlFlashObject(flash_url, 'true');		
		document.getElementById('TB_video').innerHTML=object;	    
	} else {
		//v4all Player
		//Link fuer Video versenden
		var emailLink=  dies.replace(/&/g, "%26")+"%26showVideoVersenden=true"; //result_id kann hier nicht genommen werden. Nicht wie auf Startseite
		document.getElementById('TB_video').innerHTML="<embed width=\"470\" height=\"370\" align=\"middle\" type=\"application/x-shockwave-flash\" salign=\"\" allowscriptaccess=\"sameDomain\" allowfullscreen=\"true\" menu=\"true\" name=\"vPlayer\" bgcolor=\"#ffffff\" devicefont=\"false\" wmode=\"window\" scale=\"noscale\" loop=\"true\" play=\"true\" pluginspage=\"http://www.adobe.com/go/getflashplayer_de\" quality=\"high\" src=\"http://gelbeseiten.v4all.de/vPlayer.swf\"flashVars=\"clipID="+urlString+"&TAF="+emailLink+"&linkURL=http://www.gelbeseiten.de/"+subId+"\" />";
	}
	
	disable_result_sorts();
	
	var text = $('#'+result_id+' h2 a').html();
    text       = text.concat("<br />");
    text     = text.concat($("#"+result_id+" p:first").html().replace(/<br>/,"").replace(/underline/,""));
    $('#TB_video_text h3').html(text);
	$('#TB_show_video .more').attr('href',dies);
	
	
	//$('#TB_video_text h3').html($('#'+result_id+' h2 a').html());
	//$('#TB_show_video .more').attr('href',dies);
	//position:fixed emulieren
	if($.browser.msie && $.browser.version === "6.0"){
		$('#TB_show_video').css({"top":document.documentElement.scrollTop+"px","position":"absolute"});
	}	
	$('#TB_merk_link').click(function(){
		addToBookmarking(result_id,1);
		return false;
	});
	
	/*
	//uebnerm zusaetzlich Icon verlinken
	$('#TB_merk_link_icon').click(function(){
		addToBookmarking(result_id,1);
		return false;
	});
	*/
	 
	if(in_BookmarkArray(result_id)){
        $('#TB_video_merker img.disabledIcon').fadeTo("slow",0.5); // Ausgrauen des Ikons 		
        $('#TB_video_merker img.enabledIcon').parent().
        									  hide();
    	$('#TB_video_merker img.enabledIcon').hide(); 
	}
	else{
		$('#TB_video_merker img.disabledIcon').hide();
		$('#TB_video_merker img.enabledIcon').parent().
											  show();
    	//BM DEL $('#TB_video_merker img.enabledIcon').show();     
	}	
	if(!dragging){
		$('#TB_show_video').show();
	}
	applyIVW('VThick');
}

function v_openPlayerTB_startpage(result_id,flash_url,dies,title){
	//Filter schliessen
	v_closeFilters();
}
function v_openPlayerTB_startpage_main(result_id,flash_url,dies, subId){
	//Filter schliessen
	v_closeFilters();
	
	var urlString = new String(flash_url);
	
	if(urlString.lastIndexOf('.htm') != -1) {
		document.getElementById('TB_video').innerHTML="<iframe name='iframeMicrosite' id='iframeMicrosite' marginheight='0' marginwidth='0' height='350' width='440' src='" + flash_url + "' frameborder='0' scrolling='no' class='bordered margin_t_10'><ilayer src='http://www.bfbnet.de/images/0003/1126/index.html'></ilayer></iframe>";
	} else if (urlString.lastIndexOf('.flv') != -1) {
		//flashplayer
		var object=getHtmlFlashObject(flash_url, 'true');		
		document.getElementById('TB_video').innerHTML=object;	 
	} else {
		//v4all Player
		//Link fuer Video versenden
		var emailLink=  result_id.replace(/&/g, "%26")+"%26showVideoVersenden=true";
		document.getElementById('TB_video').innerHTML="<embed width=\"470\" height=\"370\" align=\"middle\" type=\"application/x-shockwave-flash\" salign=\"\" allowscriptaccess=\"sameDomain\" allowfullscreen=\"true\" menu=\"true\" name=\"vPlayer\" bgcolor=\"#ffffff\" devicefont=\"false\" wmode=\"window\" scale=\"noscale\" loop=\"true\" play=\"true\" pluginspage=\"http://www.adobe.com/go/getflashplayer_de\" quality=\"high\" src=\"http://gelbeseiten.v4all.de/vPlayer.swf\"flashVars=\"clipID="+urlString+"&TAF="+emailLink+"&linkURL=http://www.gelbeseiten.de/"+subId+"\" />";
	}
		
	$('#TB_video_text h3').html($('#video_tipp_subtitle p').html());
	$('#TB_show_video .more').attr('href',result_id);
	//position:fixed emulieren
	if($.browser.msie && $.browser.version === "6.0"){
		$('#TB_show_video').css({"top":document.documentElement.scrollTop+"px","position":"absolute"});
	}	
	$('#TB_show_video').bgiframe().
						show();
	applyIVW('VThick');
}
function v_openPlayerTB_startpage_right(result_id,flash_url,dies, subId){
	//Filter schliessen
	v_closeFilters();
	
	//var urlString = new String(flash_url);
	var urlString = new String(flash_url);
	
	if(urlString.lastIndexOf('.htm') != -1) {
		document.getElementById('TB_video').innerHTML="<iframe name='iframeMicrosite' id='iframeMicrosite' marginheight='0' marginwidth='0' height='350' width='440' src='" + flash_url + "' frameborder='0' scrolling='no' class='bordered margin_t_10'><ilayer src='http://www.bfbnet.de/images/0003/1126/index.html'></ilayer></iframe>";
	} else if (urlString.lastIndexOf('.flv') != -1) { 
		//flashplayer
		var object=getHtmlFlashObject(flash_url, 'true');		
		document.getElementById('TB_video').innerHTML=object;	 
	} else {
		//v4all Player
		//Link fuer Video versenden
		var emailLink=  result_id.replace(/&/g, "%26")+"%26showVideoVersenden=true"; 
		document.getElementById('TB_video').innerHTML="<embed width=\"470\" height=\"370\" align=\"middle\" type=\"application/x-shockwave-flash\" salign=\"\" allowscriptaccess=\"sameDomain\" allowfullscreen=\"true\" menu=\"true\" name=\"vPlayer\" bgcolor=\"#ffffff\" devicefont=\"false\" wmode=\"window\" scale=\"noscale\" loop=\"true\" play=\"true\" pluginspage=\"http://www.adobe.com/go/getflashplayer_de\" quality=\"high\" src=\"http://gelbeseiten.v4all.de/vPlayer.swf\"flashVars=\"clipID="+urlString+"&TAF="+emailLink+"&linkURL=http://www.gelbeseiten.de/"+subId+"\" />";
	}
	
	var top_id = dies.parentNode.id;
	var text = $("#"+top_id+" .desc p:first").html().replace(/<br>/,"").replace(/underline/,"");
	text       = text.concat("<br />");
	text     = text.concat($("#"+top_id+" .desc p:last").html().replace(/<br>/,"").replace(/underline/,""));
	$('#TB_video_text h3').html(text);
	$('#TB_show_video .more').attr('href',result_id);
	//position:fixed emulieren
	if($.browser.msie && $.browser.version === "6.0"){
		$('#TB_show_video').css({"top":document.documentElement.scrollTop+"px","position":"absolute"});
	}	
	$('#TB_show_video').bgiframe().
						show();
	applyIVW('VThick');
}
function v_openPlayerTB_startpage_bottom(result_id,flash_url,dies, subId){
	//Filter schliessen
	v_closeFilters();
	
	//var urlString = new String(flash_url);
	var urlString = new String(flash_url);
	
	if(urlString.lastIndexOf('.htm') != -1) {
		document.getElementById('TB_video').innerHTML="<iframe name='iframeMicrosite' id='iframeMicrosite' marginheight='0' marginwidth='0' height='350' width='440' src='" + flash_url + "' frameborder='0' scrolling='no' class='bordered margin_t_10'><ilayer src='http://www.bfbnet.de/images/0003/1126/index.html'></ilayer></iframe>";
	} else if (urlString.lastIndexOf('.flv') != -1) {
		//flashplayer
		var object=getHtmlFlashObject(flash_url, 'true');		
		document.getElementById('TB_video').innerHTML=object;	 
	} else {
		//v4all Player
		//Link fuer Video versenden
		var emailLink=  result_id.replace(/&/g, "%26")+"%26showVideoVersenden=true";
		document.getElementById('TB_video').innerHTML="<embed width=\"470\" height=\"370\" align=\"middle\" type=\"application/x-shockwave-flash\" salign=\"\" allowscriptaccess=\"sameDomain\" allowfullscreen=\"true\" menu=\"true\" name=\"vPlayer\" bgcolor=\"#ffffff\" devicefont=\"false\" wmode=\"window\" scale=\"noscale\" loop=\"true\" play=\"true\" pluginspage=\"http://www.adobe.com/go/getflashplayer_de\" quality=\"high\" src=\"http://gelbeseiten.v4all.de/vPlayer.swf\"flashVars=\"clipID="+urlString+"&TAF="+emailLink+"&linkURL=http://www.gelbeseiten.de/"+subId+"\" />";
	}

	var top_id = dies.parentNode.id;
    var text = $("#"+top_id+"  p:first").html().replace(/<br>/,"").replace(/underline/,"");
    text       = text.concat("<br />");
    text     = text.concat($("#"+top_id+" p:last").html().replace(/<br>/,"").replace(/underline/,""));
    $('#TB_video_text h3').html(text);
	$('#TB_show_video .more').attr('href',result_id);
	//position:fixed emulieren
	if($.browser.msie && $.browser.version === "6.0"){
		$('#TB_show_video').css({"top":document.documentElement.scrollTop+"px","position":"absolute"});
	}	
	$('#TB_show_video').bgiframe().
						show();
	applyIVW('VThick');
}


function v_closePlayerTB(){
	$('#TB_show_video').hide();
	document.getElementById('TB_video').innerHTML='';
	//uebnerm18022009: write empty object to TB_video div cause IE doesnt stop the video / sound on thickbox close
	//var so = new SWFObject('../../static/flvplayer/player.swf','mpl',470,370,'9');
	//so.addParam('flashvars','&amp;file=');
	//so.write('TB_video');
}

function forwardToInserat(url){
	window.location.href=url;
}

//Pfeil Navi fŸr die Dropdowns
var v_arrowCounter = 0;

function v_listenTo(which){
	//commented out
	return;
	//.....
	ge('tf_'+which+'_video').focus();
	$('#tf_'+which+'_video').keyup(function(event){
		v_triggerKeyEvent(which,event.keyCode);
	});
}

function v_triggerKeyEvent(which,keyCode){
	v_handleArrow(which,keyCode);
}

/** Implementiert die Pfeil Tasten Navigation 
 * Keycodes
 * 13: Return
 * 37: left
 * 38: top
 * 39: right
 * 40: bottom
 */
function v_handleArrow(which,keyCode){
    var entries = $('#delimiter_list_'+which+'_video li').length;
    if(keyCode==40 && v_arrowCounter<entries-1){
        v_arrowCounter++;
        v_dehighlightArrow(v_arrowCounter-1,which);          
    }
    else if(keyCode==38 && v_arrowCounter>-1){
    	v_arrowCounter--;
    	v_dehighlightArrow(v_arrowCounter+1,which);
    }
    else if(keyCode==13 && $('#'+openSuggest+' div.suggest_inner li.hover').size()>0){
        SUBMIT_CLICK =false;
        if($('#suggest_town').size()>0){  //Spezialfall Kartensuche, da anderes Format
        	v_applyTag($('#'+openSuggest+' .suggest_inner ul .hover span.suggest_town_list_02').text());
        }
        else{
        	v_applyTag($('#'+openSuggest+' div.suggest_inner ul li.hover a').text());
        }
    }
    v_highlightArrow(v_arrowCounter,which);
}

function v_applyTag(tag){
    if(openSuggest == "suggest_what"){
        $('#what_search').val(tag);
        hideSuggest(openSuggest);
    }
    else if(openSuggest == "suggest_where" ){
        $('#where_search').val(tag);
        hideSuggest(openSuggest);
    }
    else if(openSuggest == "suggest_town"){
        if(tag.indexOf('suggest_what_tag')!=-1){ //tag ist hier kein tag, sondern die ID des Parent Links
            $('#where_search').val($('#'+tag+' span.suggest_town_list_02').html());
        }
        else{
            $('#where_search').val(tag);
        }
        saveMapSearchEntry(tag);
        
        hideMapSuggest();
        openSuggest = "";
    }
}

// Highlightet ein Tag
function v_highlightArrow(counter,which){
    $('#delimiter_list_'+which+'_video .entry_'+counter).addClass('hover');
}
//Dehighlightet ein Tag
function v_dehighlightArrow(counter,which){
    $('#delimiter_list_'+which+'_video .entry_'+counter).removeClass('hover');
}


/**
 * FilterKeyHandler
 * FÃ¼r die Tastatursteuerung der Was/Wo Filter
 */
var FilterKeyHandler = {};
FilterKeyHandler = {
	// some constants
	KEYCODE_Top: 38,
	KEYCODE_Right: 39,
	KEYCODE_Bottom: 40,
	KEYCODE_Left: 37,
	
	KEYCODE_Return: 13,
	KEYCODE_Escape: 27,
	KEYCODE_Tab: 9,
	KEYCODE_Space: 32,
	
	// array of events which should be listened to
	KEYEVENT: $.browser.mozilla ? ['keypress'] : ['keydown'],
	

	
	/**
	 * @var {string} currentFilter [was_video|wo_video]
	 */
	currentFilter: null,
	
		
	inti: function() {
	// search_delimiter_was_video
	},
	
	/**
	 * stop listening key press, called when filter get closed
	 * @param {string} which the current filter
	 */
	stopKeyListener: function ( which ) {
		this.currentFilter = null;
		this.currentSelectionId = null;
		for(var i=0;i<this.KEYEVENT.length;i++) {
			$(document).unbind(this.KEYEVENT[i]);
		}
	},
	
	/**
	 * start listening to keypressevents, called on opening a filter
	 * @param {string} the current filter
	 */
	startKeyListener: function ( which ) {	
		var ref = this;
		this.currentFilter = which;
		$('#delimiter_list_'+which+' li').removeClass('hover');
		for(var i=0;i<this.KEYEVENT.length;i++) {
			$(document).bind( 
				this.KEYEVENT[i], 
				function( event ) {
					ref.keyAction(event.keyCode);
					return false;
				}
			);
		}
	},
	
	/**
	 * get the count index of the current selected item and returns it
	 * @return {int} the index
	 */
	getIndexOfCurrentSelection: function() {
		var which = this.currentFilter;
		var index = 0;
		var current = this.getCurrentSelection();
		if(current != null) {
			$('#delimiter_list_'+which+' li').each(function(i) {
				if($(this).is('.hover')) {
					index = i;
				}
			});
		}
		return index;
	},
	
	/**
	 * checks which list item is current selected and returns it
	 * @return {JQuery HTML Object}
	 */
	getCurrentSelection: function() {
		var which = this.currentFilter;
		var currentSelection = null;
		if($('#delimiter_list_'+which+' li.hover').size() > 0) {
			currentSelection = $('#delimiter_list_'+which+' li.hover');
		}
		return currentSelection;
	},
	
	/**
	 * checks if scroller must be moved
	 * @return {int}
	 * -1: must scroll up
	 *  0: no need to scroll
	 *  1: must scroll down 
	 */
	checkScrollDirection: function( keyCode ) {
		var scrollDir = 0;
		var which = this.currentFilter;
		var currScrollTop = ge('scroll_container_'+which).scrollTop;
		var heightOfElement = parseInt( $('#delimiter_list_'+which+' li:first').height() );
		var currSelectPos = this.getIndexOfCurrentSelection() * heightOfElement;
		var scrollDivHeight = $('#scroll_container_'+which).height();
		var scrollContentHeight = $('#scroll_content_'+which).height();
		if(currSelectPos > (scrollDivHeight+currScrollTop-heightOfElement)) {
			scrollDir = -1;
		}
		if(currSelectPos < currScrollTop) {
			scrollDir = 1;
		}
		/*console.log('_____________');
		console.log('currScrollTop='+currScrollTop);
		console.log('heightOfElement='+heightOfElement);
		console.log('currSelectPos='+currSelectPos);
		console.log('scrollDivHeight='+scrollDivHeight);
		console.log('scrollContentHeight='+scrollContentHeight);
		console.log('_____________');*/
		return scrollDir;
	},
	
	
	/**
	 * 
	 */
	scroll: function( keyCode ) {
		var which = this.currentFilter;
		var heightOfElement = parseInt( $('#delimiter_list_'+which+' li:first').height() );
		var currSelectPos = this.getIndexOfCurrentSelection() * heightOfElement;
		if(this.checkScrollDirection(keyCode) < 0) {
			ge('scroll_container_'+which).scrollTop += heightOfElement;
		} else if(this.checkScrollDirection(keyCode) > 0) {
			ge('scroll_container_'+which).scrollTop -= heightOfElement;
		} 	
	},
	
	keyAction: function( keyCode ) {
		var which = this.currentFilter;
		var entries = $('#delimiter_list_'+which+' li').length;
	    if(keyCode == this.KEYCODE_Bottom){
	    	if(this.getCurrentSelection() != null) {
	    		var next = this.getCurrentSelection().next(); 
	    		if(next.size()) {
	    			$('#delimiter_list_'+which+' li').removeClass('hover');
	    			next.addClass('hover');
	    			this.scroll(keyCode);
	    		}
	    	} else {
	    		$('#delimiter_list_'+which+' li:first').addClass('hover');
	    	}
	    } 
	    if(keyCode == this.KEYCODE_Top){
	    	if(this.getCurrentSelection() != null) {
	    		var prev = this.getCurrentSelection().prev();
	    		if(prev.size()) {
	    			$('#delimiter_list_'+which+' li').removeClass('hover');
	    			prev.addClass('hover');
	    			this.scroll(keyCode);
	    		}
	    	} else {
	    		$('#delimiter_list_'+which+' li:last').addClass('hover');
	    	}
	    }
	    if(keyCode == this.KEYCODE_Escape){
	    	v_closeFilters();
	    }
	    if(keyCode == this.KEYCODE_Return || keyCode == this.KEYCODE_Space){
	    	// console.log(this.currentFilter);
	    	if( this.getCurrentSelection() != null ) {
	    		if($.browser.msie) {
	    			// IE fÃ¼hrt onclick nicht aus, get(0).click(); fÃ¼hrt javascripts eigenes all.click() aus
		    		this.getCurrentSelection().children(':first').get(0).click();
	    		} else {
	    			this.getCurrentSelection().children(':first').click();
	    		}
	    	}
	    }
    	if(keyCode == this.KEYCODE_Tab)  {
    		if(this.currentFilter == 'was_video') {
    			v_toggleFilter('wo_video');
    		} else if(this.currentFilter == 'wo_video') {
    			v_toggleFilter('was_video');
    		}
    	}

	},
	end: 0
};