var idx=0;
var splitarray = new Array();
var handle;

function swapimagesandtext()
{
	$('.more p:eq('+idx+')').removeClass('red').addClass('black');
	if (idx==2)
		{
		idx=-1;
		}
	idx++;
	para=idx+1;
	$('.more p:eq('+idx+')').removeClass('black').addClass('red');
	var topnews=splitarray[idx].split("###");
	var datum="<h6>"+topnews[0]+"</h6>";
	var header="<h4><a href='index.php?page=5&nfpara="+para+"'>"+topnews[1]+"</a></h4>";
	var subtitle="<p><strong>"+topnews[2]+"</strong></p>";
	var txt="<p>"+topnews[3]+"</p>";
	$('#topnews').empty();
	$('#topnews').html(datum+header+subtitle+txt);
	$('#topnews h6').css("background","url(images/t"+topnews[4]+".gif) no-repeat 97% 10px");	
	$('#topnews p').css('display','none');
	$('#pic img').css('display','none');
	$('#pic img').attr('src', pics[idx]);
	$('#topnews p').fadeIn(800);
	$('#pic img').fadeIn(400);
	}

$(document).ready(function()
{
$('#switchsx').click(function()
{
if ($('#slideshow').is(':visible'))
{
	$('#slideshow').fadeOut('slow',function()
	{
	$('#sxnavimg').attr('src','images/more.png');
	});
}
else
{
	$('#slideshow').fadeIn('slow', function()
	{
	$('#sxnavimg').attr('src', 'images/close.png');
	});
}
});

if ($('#suchpferd').val()=="")
{
 $('#suchpferd').val('Pferdename');
 $('#suchpferd').css('color','#999999');
}

if ($('#nfsearch').val()=="")
{
 $('#nfsearch').val('Suchbegriff');
 $('#nfsearch').css('color','#999999');
}

	$.ajax({
    type: "POST",
    url: "fetchnewsflash.php",
    data: "id=1",
    success: function(retData)
	{
	splitarray=retData.split("|||");
	$('<img src='+pics[idx]+'>').appendTo('#pic');
	handle=window.setInterval("swapimagesandtext()", 12000);
	}
});

$('.more p').mouseover(function(){
var el = ($('.more p').index(this));
	if (el == idx)
	{
	return;
	}
	window.clearInterval(handle);
	$('.more p:eq('+idx+')').removeClass('red').addClass('black');
	idx=el;
	para=idx+1;	
	$('.more p:eq('+el+')').removeClass('black').addClass('red');
	var topnews=splitarray[el].split("###");
	var datum="<h6>"+topnews[0]+"</h6>";
	var header="<h4><a href='index.php?page=5&nfpara="+para+"'>"+topnews[1]+"</a></h4>";
	var subtitle="<p><strong>"+topnews[2]+"</strong></p>";
	var txt="<p>"+topnews[3]+"</p>";
	$('#topnews').empty();
	$('#topnews').html(datum+header+subtitle+txt);
	$('#topnews h6').css("background","url(images/t"+topnews[4]+".gif) no-repeat 97% 10px");	

	$('#topnews p').css('display','none');

	$('#pic img').attr('src', pics[el]);
	$('#pic img').css('display','none');
	$('#topnews p').fadeIn(800);
	$('#pic img').fadeIn(400);

	handle=window.setInterval("swapimagesandtext()", 12000);	
});

$('.more p').click(function(){
	para=$('.more p').index(this)+1;
	self.location.href='index.php?page=5&nfpara='+para;
});
// ENDE TOPPICS

$('.pages p a').click(function(){
var anzahl=$('.pages p a').length;
var aktiv=$('.pages p a').index(this);
	$.ajax({
        type: "POST",
        url: "fetchnextnewsflash.php",
        data: "modus="+aktiv,
        success: function(retData)
		{
	var splitarray=retData.split("|||");
	for (i=0;i<splitarray.length-1;i++)
	{
	meinsplitzwei=splitarray[i].split('###');
			$('.mainright:eq('+i+')').css('background','url(images/c'+meinsplitzwei[0]+'.gif) no-repeat 97% 15px');
			$('.mainleft:eq('+i+') .mypic').attr('src',meinsplitzwei[1]);
			$('.mainright:eq('+i+') h6.datum').html(meinsplitzwei[2]);
			$('.mainright:eq('+i+') h3.mainheader span').text(meinsplitzwei[3]);
			$('.mainright:eq('+i+') h3.mainheader a[href]').attr('href','index.php?page=5&nfpara='+meinsplitzwei[5]);		
			$('.mainright:eq('+i+') p.intro').html(meinsplitzwei[4]);
			$('.mainright:eq('+i+') p.main').html(meinsplitzwei[6]);		
	}
	}
});
	// *** aktueller TAB *** //
	for (i=0;i<anzahl;i++)
	{
	$('.pages p a:eq('+i+')').removeClass('selected').addClass('n');
	}
	$(this).removeClass('n').addClass('selected');	
});

$('ul.taboben li a').click(function(){
	var aktiv=$('ul.taboben li a').index(this);
	$('ul.taboben li:eq(0)').removeClass('high').addClass('low');
	$('ul.taboben li:eq(1)').removeClass('high').addClass('low');
	$('ul.taboben li:eq('+aktiv+')').removeClass('low').addClass('high');

 	$.ajax({
        type: "POST",
        url: "fetchvsns.php",
        data: "modus="+aktiv,
        success: function(retData)
		{
		$('#vsns').empty();
		$('#vsns').html(retData);
		}
        });
});

// TOGGLE Ergebnisse ZGS + INT
$('.onoff').click(function(){
aktiv=$('.onoff').index(this);
anzahl=$('.onoff').length;

	if (savestatus >= 0)
	{
	$('.picpdf:eq('+savestatus+')').hide('slow');		
	$('.onoff:eq('+savestatus+')').hide();
	$('.onoff:eq('+savestatus+')').attr('src','images/plus.png');
	$('.onoff:eq('+savestatus+')').show();
	$('.showtable:eq('+savestatus+')').hide('slow');
	savestatus=-1;
	}

	if ($('.showtable:eq('+aktiv+')').is(':hidden'))
	{	
	$('.picpdf:eq('+aktiv+')').show('slow');
	$('.onoff:eq('+aktiv+')').hide();
	$('.onoff:eq('+aktiv+')').attr('src','images/minus.png');
	$('.onoff:eq('+aktiv+')').show();
	$('.showtable:eq('+aktiv+')').show('slow');
	savestatus=aktiv;
	}
});

$('#querycenter').click(function(){

	if ($('#racesearchdiv').is(':visible'))
	{
	$('#racesearchdiv').hide('slow');
	$('#racesearch').css("background-color","");
	}

	var div="#querydiv";

	if ($(div).is(':hidden'))
	{
	$('#querycenter').css("background-color","#000000");
	var offset=$('#querycenter').offset();
		var l=offset.left;
		var t=offset.top;
		var l=$('#querycenter').width() + offset.left + 10;
		var myscroll=$(window).scrollTop();
		var wh=$(window).height();	
		$(div).css("position","absolute");
		$(div).css("left",l);
		$(div).css("top",t);
		$(div).show('slow');
		$('#suchbegriff').focus();
		$('#suchbegriff').select();
		}
	else
	{
		$(div).hide('slow');
		$('#querycenter').css("background-color","");
	}
});
		
$('#racesearch').click(function(){

	if ($('#querydiv').is(':visible'))
	{
	$('#querydiv').hide('slow');
	$('#querycenter').css("background-color","");
	}

	var div="#racesearchdiv";

	if ($(div).is(':hidden'))
	{
	$('#racesearch').css("background-color","#000000");
	var offset=$('#racesearch').offset();
		var l=offset.left;
		var t=offset.top;

		var l=$('#racesearch').width() + offset.left +10;
		var myscroll=$(window).scrollTop();
		var wh=$(window).height();	
		$(div).css("position","absolute");
		$(div).css("left",l);
		$(div).css("top",t);
		$(div).show('slow');
		$('#bestsuchbegriff').focus();
		$('#bestsuchbegriff').select();
		}
	else
	{
		$(div).hide('slow');
		$('#racesearch').css("background-color","");
		}		
});

$('#suchpferd').focus(function(){
 if ($('#suchpferd').val() == "Pferdename")
 {
 $('#suchpferd').val('');
  $('#suchpferd').css('color','#000000');
 }
 }); 

$('#suchpferd').blur(function(){
 if ($('#suchpferd').val() == "")
 {
 $('#suchpferd').val('Pferdename');
 $('#suchpferd').css('color','#999999');
 }
 }); 

 
 $('#nfsearch').focus(function(){
	 if ($('#nfsearch').val() == "Suchbegriff")
	 {
	 $('#nfsearch').val('');
	 $('#nfsearch').css('color','#000000');
	 }
 }); 

$('#nfsearch').blur(function(){
	 if ($('#nfsearch').val() == "")
	 {
	 $('#nfsearch').val('Suchbegriff');
	 $('#nfsearch').css('color','#999999');
	 }
 }); 
 
 
$('#showmorenf').click(function(){

	var div="#morenewsflash";

	if ($(div).is(':hidden'))
	{
	var t=$('#showmorenf').attr('t');
	$.ajax({
    type: "POST",
    url: "nextnf.php",
    data: "t="+t,
    success: function(retData)
	{
	$('#morenewsflash').empty();
	$('#morenewsflash').html(retData);	
	}
});

		var offset=$('.morenewsflash').offset();
		var t=offset.top+25+"px";
		var l=offset.left+"px";
		$(div).css("position","absolute");
		$(div).css("left",l);
		$(div).css("top",t);
		$('.morenewsflash').removeClass("morenewsflash").addClass("lessnewsflash");
		$(div).slideDown(1000);
		}
		else
		{
		$(div).slideUp(1000);
		$('.lessnewsflash').removeClass("lessnewsflash").addClass("morenewsflash");
		}		
}); 

/*
if ($.cookie('res')!=1)
{
	var sc_w=screen.width;
	var sc_h=screen.height;
	
	$.ajax({
    type: "POST",
    url: "r.php",
    data: "sc_w="+sc_w+"&sc_h="+sc_h,
    success: function(retData)
	{
	$.cookie('res','1')
	}
});
}
*/

});
