jQuery.noConflict();

/*window.addEvent('domready', function() {
	
	// Anpassung IE6
	if(window.ie6) var heightValue='100%';
	else var heightValue='';
	
	// Selektoren der Container fÃƒÂ¼r Schalter und Inhalt
	var togglerName='h3.toggler';
	var elementName='div.element';
	
		    
		var myAccordion = new Accordion($('accordion'), togglerName, elementName, {
			opacity: true,
			display: 0,
			alwaysHide: false,
           
			onActive: function(toggler, element){
                //toggler.setStyle('color', '#884b50');
                toggler.setStyle('background-position', 'bottom');
            },
            onBackground: function(toggler, element){
                //toggler.setStyle('color', '#fff');
                toggler.setStyle('background-position', 'top');	
            }
		});
		
		// Hover-Effekt umsetzen
        $$(togglerName).addEvent('mouseenter', function() { this.fireEvent('click'); });
		
    
});*/


jQuery(document).ready(function($) {
	
	var SERVER_DIR = $('link[rel=canonical]').attr('href');
	
	//initLytebox();
	//myLytebox.setSERVERDIR(SERVER_DIR);
	
	/* ---- scaleVideoToMax proportional HTML5  ---- */
	scaleVideoToMax = function (a){
		if($('#videoholder').length){
			var vdimwidth = 1280;
			var vdimheight = 720;						
			
			var hwidth = $('#videoholder').width();
			var hheight = $('#videoholder').height();							
			
			var factorX = hwidth / vdimwidth;
			var factorY = hheight / vdimheight;
			var scaleX = scaleY =  1;
		
			if(factorX < factorY){
				if(a == true){
					scaleY = scaleX = ($('#video_html5').height() / (vdimheight * factorX));				
				}else{
					scaleY = ($('#video_html5').height() / (vdimheight * factorX));	
				}
			}	
			if(factorX > factorY){
				if(a == true){
					scaleY = scaleX = ($('#video_html5').width() / (vdimwidth * factorY));				
				}else{
					scaleX = ($('#video_html5').width() / (vdimwidth * factorY));	
				}		
			}	
			var val = " scale(" + scaleX + ", " + scaleY + ")";
		
    	 	$('#video_html5').css({"-webkit-transform":val, "-moz-transform": val, "-o-transform": val, "-ms-transform": val, "transform": val});
			if(AC.Detector.isChrome()){
				//.hover();
				$('.intro_btn').stop().animate({"opacity": "1"}, "slow");
			}
			
		
		}
	}
	
	/* ---- scaleVideoToMin (a = true | proportional) HTML5  ---- */
	scaleVideoToMin = function (a){
		if($('#videoholder').length){
			var vdimwidth = 1280;
			var vdimheight = 720;
			
			if(AC.Detector.isChrome()){
				$(document).height($(document).height()+1);		
			}
			
			var hwidth = $('#videoholder').width();
			var hheight = $('#videoholder').height();
		
			var factorX = hwidth / vdimwidth;
			var factorY = hheight / vdimheight;
			var scaleX = scaleY =  1;
		
			if(factorX > factorY){
				if(a == true){
					scaleY = scaleX=  $('#video_html5').width() / (vdimwidth * factorY);					
				}else{
					scaleX =  $('#video_html5').width() / (vdimwidth * factorY);			
				}							
			}	

			if(factorX < factorY){
				if(a == true){
					scaleX = scaleY =  $('#bgVideo').height() / (vdimheight * factorX);						
				}else{
					scaleY =  $('#bgVideo').height() / (vdimheight * factorX);		
				}								
			}	
			var val = " scale(" + scaleX + ", " + scaleY + ")"
    	 	$('#video_html5').css({"-webkit-transform":val, "-moz-transform": val, "-webkit-transform": val, "-o-transform": val, "-ms-transform": val, "transform": val});
			
			
		}
	}


		/* show video in HMTL5 or Flash */
	if($('#videoholder').length){
		
		//no border for intro
		
		$('html').css( 'border', 'none' );
		
		if((AC.Detector.isWebKit() || AC.Detector.isChrome()) && !AC.Detector.isMobile()){					
			$('#video_html5').show();			
			$('#video_fla').hide();	
			$('#video_fallback_image').hide();				
		}else if(AC.Detector.isMobile()){
			$('#video_html5').hide();			
			$('#video_fla').hide();	
			$('#video_fallback_image').show();	
		}else{
			if($.flash.available){
				$('#videoContent').show();
				$('#video_fallback_image').hide();				
				flashMovieWithVars = $.flash.create(
					{
					// test_flashvars.swf is the flash document
					swf: SERVER_DIR + 'video/water-intro.swf',
					height: "100%",
					width: "100%",
					menu: "false",
					loop: "true",
					quality: "best",
					scale: "noborder",
					wmode: "opaque",
					bgcolor: "#000000",
					id: "flash_fla",
					name: "flash_fla"
					}
				);
				$('#videoContent').replaceWith(flashMovieWithVars);			
			}
		}

		if(AC.Detector.isIE()){
			scaleHolderIE = function(){
				$('#videoholder').height($(window).height());
				$('#videoholder').width($(window).width());					
			}
			scaleHolderIE();
			$(window).resize(function() { scaleHolderIE() });
		}
				
		scaleVideoToMax(true);
		$(window).resize(function() { scaleVideoToMax(true) });
	}
	
	
	/* ---- Accordion ---- */
	
	var section = parseInt($('#accordion').attr('class') -1);
	if(!section){
		section = 0;	
	}
    $("#accordion").accordion({ event: 'mouseover',	
								event: 'click',																								
								active: section, 					
   								header: '.head', 
							    navigation: true, 
								autoHeight: false,									
								animated: 'easeslide'		
							
							 });
							 
							 
	//$('[rel=overlay]').overlay({});
	$('[rel=overlay]').overlay({
								serverDir: SERVER_DIR,
								contentDir: "content/de/referenzen/referenzen/",
								url: SERVER_DIR + "de/referenzen/referenzen/"								
							});
	
	
	/* ---- home - set split element the same height ---- */
	if($('.split_copy').length){
		var lh = $('.split_copy.left').height();
		var rh = $('.split_copy.right').height();					
		$('.split_copy.right').height(lh >= rh ? lh : rh);
		$('.split_copy.left').height(lh >= rh ? lh : rh);		
	}
	
	
	/* slideShow for image*/
	 slideSwitch = function() {
   		var $active = $('#kSlideShow img.active');

    	if ( $active.length == 0 ) $active = $('#kSlideShow img:last');

	    var $next =  $active.next().length ? $active.next() : $('#kSlideShow img:first');

	    $active.addClass('last-active');
	
    	$next.css({opacity: 0.0})
        	.addClass('active')
	        .animate({opacity: 1.0}, 1000, function() {
    	        $active.removeClass('active last-active');
        	});
	}

	if($('#kSlideShow').length){
	    setInterval("slideSwitch()", 5000 );
	}	
});
  

	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
	//if debug log the value to the console, alt alert
	function _log(value){
			
		if (window.console != undefined) {
			console.log(value);	
		}else{
			alert(value);	
		}
			
	}
	function hasClass(ele,cls) {
			return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
	}
	
	function addClass(ele,cls) {	
		if (!this.hasClass(ele,cls)){ 
			ele.className += " "+cls;
		}
	}
	
	function removeClass(ele,cls) {
		if (hasClass(ele,cls)) {
			var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
			ele.className=ele.className.replace(reg,' ');
		}
	}
	
	
	function echo(s){
	    var elDebug = document.getElementById("debug");
    	elDebug.innerHTML = "<p>" + s + "</p>" + elDebug.innerHTML;
	
	}

	function trim(s) {
		return s.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"");
		//return s.replace(/^\s*([\S\s]*)\b\s*$/, '$1');	
	}
    
    function newWindow(url, name, width, height, toolbar, status, scrollbar, resizable, menubar, location) {

	var posX = parseInt((screen.availWidth/2) - (width/2));
	var posY = parseInt((screen.availHeight/2) - (height/2));
	
	
	 var windowFeatures = "width=" + width + ",height=" + height + ",toolbar=" + toolbar + ",status=" + status + ",scrollbars=" + scrollbar + ",resizable=" + resizable + ",menubar=" + menubar + ",location=" + location + "screenX=" + posX + ",screenY=" + posY + ",left=" + posX + ",top=" + posY + "";
	 
	 if(window.myWindow){
		window.myWindow.close(); 
	 }
	 
	 myWindow = window.open(url, name, windowFeatures);
	 if(window.myWindow){
		window.myWindow.focus();
	 }
	 return false;
}
