$(document).ready(function()
{

    $("#referencetext").css('color','#FFFFFF');
    var standardueberschrift=document.getElementById("referencetext").innerHTML;
    function pulsate() {
      if (document.getElementById("referencetext").innerHTML==standardueberschrift)
      {
        $("#referencetext").
        animate({opacity: 0.4}, 1000, 'linear').
        animate({opacity: 1}, 1000, 'linear', pulsate);
      }
    }
    pulsate();
  
  
    
    
    setInterval(function() {
       	if (get_url_param('effect')==1)
      	{
      	  animateReferences1();
      	}
      	if (get_url_param('effect')==2)
      	{
      	  animateReferences2();
      	}
      	
      	t=setTimeout("animatereferenceglobal()",1000);
    },3000);







        var activepic=0;
        var standardueberschrift=document.getElementById("referencetext").innerHTML;
        var standardcontent1=document.getElementById("content1").innerHTML;
        var standardcontent2=document.getElementById("content2").innerHTML;
        
	for(var currentpic=1; currentpic<=piccount; currentpic++)
	{
		var einzelbilder=bilder[currentpic].split(",");
		$("#ref"+currentpic).css('background', 'url(uploads/pics/'+einzelbilder[1]+')');
		$("#ref"+currentpic).css('cursor', 'pointer');		

		$("#ref"+currentpic).hover( function(){
			var currentId=$(this).attr('id').substring(3);
			$(this).css('background', 'url(uploads/pics/'+bilder[currentId].split(",")[0]+')');
			$('#referencetext').html(unterschriften[currentId]);
			$('#referencetext').stop().animate({opacity: 1}, 0, 'linear');
		});

		$("#ref"+currentpic).mouseout( function(){
			var currentId=$(this).attr('id').substring(3);
			if (currentId!=activepic) {
				$(this).css('background', 'url(uploads/pics/'+bilder[currentId].split(",")[1]+')');
			}
			$('#referencetext').html(standardueberschrift);
			pulsate();			
		});

		$("#ref"+currentpic).click( function(){

			var currentId=$(this).attr('id').substring(3);
			activepic=currentId;
			changeReference(currentId, unterschriften[currentId], bilder[currentId].split(",")[2],bilder[currentId].split(",")[3],bilder[currentId].split(",")[4]);
			resetPictures();
		});
		
		if (currentpic==1)
		{
		    $('#picturetext').html("N&auml;here Informationen finden Sie in den nachfolgenden Bilderleisten.");
		}
	}



	    function GetRandom( min, max ) {
				if( min > max ) {
					return( -1 );
				}
				if( min == max ) {
					return( min );
				}
           return( min + parseInt( Math.random() * ( max-min+1 ) ) );
			}

	
	function animateReferences1() {
	    var move=new Array();
	    var time=new Array();
	    for (i=1;i<=7;i++)
	    {
		move[i]=GetRandom(20,50);
  		move[i+7]=move[i];
  		time[i]=GetRandom(120,200);
  		time[i+7]=time[i];
	    };
		
	 
  	    for (i=1;i<=14;i++)
	    {
	        $("#ref"+i).animate({
		    top: '-='+move[i]
		}, time[i] ).animate({
		    top: '+='+move[i]
		}, time[i] );
  	    };
        }

	function animateReferences2() {
	    var move=new Array();
	    var time=new Array();
	    for (i=1;i<=7;i++)
	    {
		move[i]=25;
  		move[i+7]=-move[i];
  		time[i]=150;
  		time[i+7]=time[i];
	    };
		
	 
  	    for (i=1;i<=7;i++)
	    {
	        $("#ref"+i).delay(i*150).animate({
		    top: '-='+move[i]
		}, time[i] ).animate({
		    top: '+='+move[i]
		}, time[i] );
		
	        $("#ref"+(i+7)).delay(i*150).animate({
		    top: '+='+move[i]
		}, time[i] ).animate({
		    top: '-='+move[i]
		}, time[i] );

  	    };
        }
	
	function resetPictures() {
		for(var currentpic=1; currentpic<=piccount; currentpic++)
		{
			var einzelbilder=bilder[currentpic].split(",");
			if (currentpic!=activepic) {
				$("#ref"+currentpic).css('background', 'url(uploads/pics/'+einzelbilder[1]+')');
			}
		}
	}


function get_url_param( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );

	if ( results == null )
		return "";
	else
		return results[1];
}

	function checkBrowserName(name){  
		var agent = navigator.userAgent.toLowerCase();  
		if (agent.indexOf(name.toLowerCase())>-1) {  
			return true;  
		}  
		
		return false;  
	}  


	function changeReference(id, text, contentbig, content1, content2)
	{
		var contentpath = "/uploads/pics/";
		var flvplayerpath="fileadmin/flvplayer/";  
		var ref = document.getElementById("reference");
		var img = null;
		var innerhtml = null;
		var object = null;


		var splitfile = contentbig.split(".");
		var type = "";
		for(var j=0; j<splitfile.length; ++j)
		{
			type = splitfile[j];
		}

		switch(type)
		{
			case "flv":
				object=document.createElement("div");
				object.setAttribute("style","height:400px; width:400px;");

				newhtml='<object type="application/x-shockwave-flash" align="right" data='+flvplayerpath+'flvplayer.swf?contentpath='+contentpath+'&amp;preview=&amp;video=' + content + '&amp;captions=&amp;preroll=&amp;autoplay=true&amp;loop=&amp;islive=&amp;volume=&amp;smoothing=true&amp;autoscale=false&amp;videowidth=400&amp;videoheight=400&amp;skincolor=&amp;skinscalemaximum=&amp;skin=&amp;preloader=&amp;buttonoverlay=&amp;ending=&amp;debug=" width="400" height="400" id="grafik" style="visibility: visible; "><param name="scale" value="noscale"><param name="allowfullscreen" value="false"><param name="salign" value="tl"><param name="bgcolor" value="#C5C5C5"><param name="base" value="."></object>';
				if (checkBrowserName("MSIE")) {
					newhtml='<object width="400" height="400" align="right" id="grafik" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" style="visibility: visible;"><param name="scale" value="noscale"/><param name="allowfullscreen" value="false"/><param name="salign" value="tl"/><param name="bgcolor" value="#C5C5C5"/><param name="base" value="."/><param name="movie" value="'+flvplayerpath+'flvplayer.swf?contentpath='+contentpath+'/&preview=&video=' + content + '&captions=&preroll=&autoplay=true&loop=&islive=&volume=&smoothing=true&autoscale=false&videowidth=400&videoheight=400&skincolor=&skinscalemaximum=&skin=&preloader=&buttonoverlay=&ending=&debug="/>';
				}

				object.innerHTML=newhtml;
				break;
				
			case "swf":
				object=document.createElement("div");
				object.setAttribute("style","height:400; width:400;");
				newhtml='<object type="application/x-shockwave-flash" width="400" height="400" data="'+contentpath+contentbig+'"><param name="movie" value="'+contentpath+content+'"></object>';
				object.innerHTML=newhtml;
				break;
				

			case "pdf":
				window.open(contentpath+contentbig);
				break;
				
			case "htm":
			case "html":
				object=document.createElement("iframe");
				object.setAttribute("src",contentpath+contentbig);
				object.setAttribute("height","400px");
				object.setAttribute("width","400px");
				object.setAttribute("frameborder","0");
				object.setAttribute("style","height:400; width:400;");
				break;
				
			default:
				object = document.createElement("img");
				object.src =  contentpath + contentbig;
				break;
		}

		$('#reference').html(object);
		$('#picturetext').html(text);
		

		var newcontent2=document.getElementById("referencetext"+id).innerHTML;
		var changed=false;
		
		if (newcontent2!="")
		{
		  newcontent2="<div class=\"content\">"+newcontent2+"</div>";
  		  $('#content2').html(newcontent2);
  		  changed=true;
  		}

  		if (content2!=undefined)
  		{
		  newcontent2="<img src='"+contentpath+content2+"' height='240' width='240'/>";
  		  $('#content2').html(newcontent2);
  		  changed=true;
  		}

  		if (changed==false)
  		{
  		  $('#content2').html(standardcontent2);
  		}
  		
  		
  		if (content1!=undefined)
  		{
  		  newcontent1="<img src='"+contentpath+content1+"' height='240' width='240'/>";
  		  $('#content1').html(newcontent1);
  		}
  		else
  		{
  		  $('#content1').html(standardcontent1);
  		}
  		
  		
  		
  		$('.content').jScrollPane({showArrows:true, scrollbarWidth:13, scrollbarMargin:0, dragMinHeight:32, dragMaxHeight:32, arrowSize:22});

	}

});
