var daf_fenster;
function daf_win(url,breit,hoch){
	var props="width="+breit+",height="+hoch+",status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
 	if(url != ""){
	 	if (!daf_fenster || daf_fenster.closed){
	    daf_fenster = window.open('','daf_fenster',props);
	 	}
	 	daf_fenster.document.location.href=url;
	 	daf_fenster.focus();
 	}
}

/*** suggest ***/
$(function() {
	$('#suggestinput').autocomplete({
		source: '/ajax/search.php',
		minLength: 2,
		select: function(event, ui) {
			window.location.href = ui.item.url;
		}
	}).data('autocomplete')._renderItem = function( ul, item ) {
		return $('<li></li>')
		.data('item.autocomplete', item)
		.append('<a class="clearfix"><span class="fL" style="margin-right:5px;color:#004276;font-size:11px;"><b>'+item.label+'</b></span><span class="fR" style="font-size:11px;">'+item.category+'</span></a>')
		.appendTo(ul);
	};
});

/*** Dialog ***/
function showWindow(width, height, title, content) {
	//$('<iframe src="'+content+'" width="'+width+'" height="'+height+'" style="padding:0px;" style="overflow:hidden;" />').dialog({
	$('<iframe src="'+content+'" width="100%" height="'+height+'" style="padding:0px;" frameborder="0" />').dialog({
		title: '<div class="icon iconBoxTop"></div> '+title,
		width: width+20,
		height: height+20,
		resizable: true
	}).width(width+20).height(height+20);
}

/*** VoD ***/
var bannerLayerID = "#box_banner";
var interfaceURL = "http://test.tmt.de/anleger-fernsehen/demo/_AJAX/interface.php";

VoDBC = function() {
	this.Refresh = function(type, index) {
		$.post(interfaceURL, {
			action: "refesh",
			entity: "vod",
			type: type,
			index: index
		}, function(data) {
			  $(bannerLayerID).html(data);
		});
	};
}
var VoDBC = new VoDBC();

/*** Videoband ***/
var videobandAnimation = false;
var partnerWidth = 127;
$(function() {
	$('.partneritems').css('width', $('.partneritems').children('.item').size() * partnerWidth);
	$('.prevpartner').click(function() {
		if(videobandAnimation) return;
		
		var left = $('.partneritems').css('left').replace('px', '');
		if(left >= -10) return;
		videobandAnimtaion = true;
		$('.partneritems').animate({left: '+=' + partnerWidth }, 800, function() { 
			videobandAnimation = false;  
        });
	});
	$('.morepartner').click(function() {
		if(videobandAnimation) return;
		var left = $('.partneritems').css('left').replace('px', '');
		var children = $('.partneritems').children('.item').size();
		if(left <= ((children - 4) * partnerWidth - 10)*-1) return;
		videobandAnimation = true;
		$('.partneritems').animate({left: '-=' + partnerWidth}, 800, function() {
			videobandAnimation = false;  
        });
	});
});

/*** Köpfe ***/
var index = 0;
function switchKoepfe() {
	if($.browser.msie) {
		$('#koepfe').children('div:eq(' + index + ')').addClass('hidden');
		index++;
		if(index >= $('#koepfe').children().size())
			index = 0;
			
		$('#koepfe').children('div:eq(' + index + ')').removeClass('hidden');
		setTimeout('switchKoepfe()', 5000);
	} else {
		$('#koepfe').children('div:eq(' + index + ')').fadeOut(1000, function() {
			index++;
			if(index >= $('#koepfe').children().size())
				index = 0;
			
			$('#koepfe').children('div:eq(' + index + ')').fadeIn(1000, function() { setTimeout('switchKoepfe()', 5000); });
		});
	}
}
$(function() { setTimeout('switchKoepfe()', 5000); });

/*** Ticker ***/
function animateTicker() {
	$('.tickercontainer').animate({'left': '-205px'}, 5000, 'linear', function() {
		var first = $('.tickercontainer .tickeritem:first').html();
		$('.tickercontainer .tickeritem:first').remove();
		$('.tickercontainer').css('left', 0);
		$('.tickercontainer').append('<div class="fL clearfix tickeritem">' + first + '</div>');
		animateTicker();
	});	
}
function updateTicker() {
	$.getJSON('/ajax/ticker.php?' + Math.random(), function(data) {
		var count = data.length;
		for(var i = 0; i < count; i++) {
			$('#last' + data[i]['wkn']).html(data[i]['last']);
			$('#diff' + data[i]['wkn']).html(data[i]['diff']);
			$('#diff' + data[i]['wkn']).removeClass('red');
			$('#diff' + data[i]['wkn']).removeClass('green');
			$('#diff' + data[i]['wkn']).addClass(data[i]['class']);
			$('#icon' + data[i]['wkn']).removeClass('iconTop');
			$('#icon' + data[i]['wkn']).removeClass('iconFlop');
			$('#icon' + data[i]['wkn']).addClass(data[i]['icon']);
		}
		setTimeout('updateTicker()', 60000);
	});
}
$(function() { animateTicker();	$(document).ready(function() { setTimeout('updateTicker()', 60000); }); });

/*** Teaser ***/
function SwitchTeaser(item, target) {
	$('.teaseritem').each(function() { $(this).removeClass('aktiv'); });
	item.addClass('aktiv');
	$('.itemteaser').each(function() { $(this).fadeOut(); });
	$('.item' + target).fadeIn();
}
function AutoSwitch() {
	if(!autoSwitch)
		return;
	
	item++;
	if(item > 15)
		item = 1;
	
	SwitchTeaser($('.teaser' + item), item);
	if(autoSwitch) autoSwitchTimer = setTimeout('AutoSwitch()', 5000);
}

function goToCategorie() {
	if($('#categorieList').val() == '') return;
	window.document.location = $('#categorieList').val();
}

