var rp;
var lastrp;
var intval=3000;
var mkqu=false;
var startrp=false;
var isie=false;
var bh;
jQuery.noConflict();
(function($){ 	
 	jQuery(document).ready(function($){  		
  		if($.browser.msie && parseInt($.browser.version)<8)
  			isie=true;
  			
  		/*var nas=document.getElementById('navi').getElementsByTagName('a');
  		for(i=0;i<nas.length;i++){
  		    nas[i].onmouseover=function(){
  		    	//showarrow(this);
  		    }
  		}*/
  		
  		$('#navi a').mouseout(
  			function(){
  				//$('#navi_pfeil').hide();
  				showarrowstart();
  			}
  		);
  		
  		rp=randompics;
  		bh=$('base')[0].href;
  		if(mkqu) 
  			qumaker();  		
  		
  		if(startrp) 
  			rpstart(); 	
  		
  		showarrowstart();	
  		
  		pbcrossfader("crossfader",3000);
  		
  		if($('*').is('.spacercon')){
  			$('.spacercon').height($('.spacercon').siblings('img').height());
  		}
		
  	}); 
  	
  	
  	$(window).resize(function() {
  		if(mkqu) qumaker();  
	});

	
})(jQuery);	

function qumaker(){
	jQuery.noConflict();
	(function($) { 
		var min=3;
		var minus=$('#navi').height()+$('#header').height()+$('#footer').height();
  	    var verf=Math.floor(($(document).height()-minus)/196);
  	    var verf2=Math.floor(($(window).height()-minus)/196);  	    
  	    if(verf>$('#col1 .qu').size() && verf<=rp.length){   	
  	    	times=verf-$('#col1 .qu').size();
  	    	for(i=0;i<times;i++){
  	    		$('#col1').append('<div class="qu qumb qumr quart qupc"></div>');
  	    		randompic($('#col1 .quart').last());
  	    	}
  	    }else if(verf2<$('#col1 .qu').size() && verf2>=min && $(document).height()-minus-$("#col2").height()>3){
  	    	$('#col1 .quart').last().remove();
  	    }
	})(jQuery);	
}

function showarrow(el){
	jQuery.noConflict();
	(function($) { 
 		var goleft=Math.round($(el).position().left-$('#navi').position().left+$(el).width()/2);
 		if(isie)
 			goleft-=77;
 		$('#navi_pfeil').show(); 
 		$('#navi_pfeil').css('margin-left',goleft+"px");
	})(jQuery);	
}

function showarrowstart(){
	jQuery.noConflict();
	(function($) { 
 		if($('#navi .active').size()>0){
 			var goleft=Math.round($('#navi .active').first().position().left-$('#navi').position().left+$('#navi .active').first().width()/2);
 			if(isie)
 				goleft-=77;
 			$('#navi_pfeil').show(); 
 			$('#navi_pfeil').css('margin-left',goleft+"px");
 		}
	})(jQuery);	
}

function rpstart(){
	jQuery.noConflict();
	(function($) { 
		var qurp=$('.qupc');
    	for(i=0;i<qurp.length;i++){
    		if($(qurp[i]).css('background-image')=="none"){
    			randompic(qurp[i]);
    		}
    	}	
   		var rpsetter=window.setInterval("setrp()", intval);
    })(jQuery);	
}

function setrp(){
	jQuery.noConflict();
	(function($) { 
		var qurp=$('.qupc');
		var rand=Math.floor(Math.random()*qurp.length);
		if(qurp.length>1)
			while(rand==lastrp)
				rand=Math.floor(Math.random()*qurp.length);
		lastrp=rand;
		qp=qurp[rand];
		bg=str_replace(')','',str_replace('url(','',str_replace('"','',$(qp).css('background-image'))));
		$(qp).append('<img id="qupic'+rand+'" src="'+bg+'" />');
		randompic(qp);
		$("#qupic"+rand).fadeOut(300,function(){$("#qupic"+rand).remove()});	
	})(jQuery);	
}

function randompic(qp){
	jQuery.noConflict();
	(function($) { 
		var qurp=$('.qupc');
		var set=false;
		while(!set){
			yet=false;
		    rpn=rp[Math.floor(Math.random()*rp.length)];
		    for(ji=0;ji<qurp.length;ji++){		    	
		    	bg=str_replace(')','',str_replace('url(','',str_replace('"','',$(qurp[ji]).css('background-image'))))
		    	if(bg=='url('+bh+rpn+')'){
		    		yet=true;
		    		break;
		    	} 
		    }
		    if(!yet){ 
		    	set=true;
		    	picloader(rpn);	
		    }
		}
		$(qp).css('background-image','url("'+bh+rpn+'")');
	})(jQuery);	
}

function picloader(img){
	var clearImage = new Image(); 
	clearImage.src = img; 
}

function str_replace(search,replace,subject) {
	return subject.split(search).join(replace);
}


var zeit, message="Rechtsklick ist deaktiviert! Sorry!";
  function click0() {
    if (event.button != 1) {
      popup();
      return false;
    }
  }
  function nsc(e) {
    if (e.which != 1) keinkontext();
  }
  function popup() {
    return false;
  }
  function nichts(e) {
    if (e.which != 1) return false;
  }
  function keinkontext() {
    clearTimeout(zeit);
    zeit = setTimeout("kontext()",1);
  }
  function kontext() {
    clearTimeout(zeit);
    popup();
  }
  if (document.all)
    if (document.getElementById) document.oncontextmenu=popup;
    else document.onmousedown=click0;
  if (!(document.all) && document.getElementById)
    document.oncontextmenu=popup;
  if (document.layers) {
    document.captureEvents(Event.MOUSEUP | Event.MOUSEDOWN);
    document.onmousedown=nichts;
    document.onmouseup=nsc;
  }
