// ::::::::    FUNCYBOX    ::::::::

$(document).ready(function() {
	$(".impressum").fancybox();
});

// ::::::::    LOGO FADEIN   ::::::::

$(document).ready(function() {
	  $(".logo").fadeIn(3000).css("display","block");
});             

// ::::::::    START SLIDE MENÜ    ::::::::

$(document).ready(function(){

	var totWidth = 0;
	var positions = new Array();

	$('.slides li').each(function(i){

		positions[i] = totWidth;
		totWidth += $(this).width();

	});

	$('.slides').width(totWidth);

	$('.slides_menu li a').click(function(e,keepScroll){

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');

			var pos = $(this).parent().prevAll('.menuItem').length;

			$('.slides').stop().animate({marginLeft:-positions[pos]+'px'},450);

			e.preventDefault();

			if(!keepScroll) clearInterval(itvl);
	});

	$('.slides_menu li.menuItem:first').addClass('act').siblings().addClass('inact');

	var current=1;
	
	function autoAdvance(){
		
		if(current==-1) return false;

		$('.slides_menu li a').eq(current%$('.slides_menu li a').length).trigger('click',[true]);
		current++;
	}

	var changeEvery = 5;

	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

});

// ::::::::    REFERENZEN GALLERY    ::::::::

function mycarousel_initCallback(carousel){
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

$(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 5,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

$(document).ready(function() {
	$("#ref_slide_gallery").slideView()
});

// ::::::::   REFLECTION   ::::::::

$(document).ready(function() {
	  $("#mycarousel img").reflect();
});

// ::::::::  TABS  ::::::::

$(document).ready(function() {

	$(".tab_content").hide();
	$("ul.tabs li:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href"); 
		$(activeTab).fadeIn();
		return false;
	});

});

// ::::::::    FOOTER SLIDER    ::::::::

$(document).ready(function(){
	$(".btn-slide").click(function(){
		$(".contact_testimonials").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
});

// ::::::::    TESTIMONIALS   ::::::::

$(document).ready(function() {

	var x;
	var elementList;
	var rndm;

	x = loadXMLdoc();
	elementList = x.getElementsByTagName("id");	
	rndm = rndnumber();
	document.getElementById("testimonials_txt").innerHTML= x.getElementsByTagName("quote")[rndm].childNodes[0].nodeValue;
	document.getElementById("testimonials_name").innerHTML= x.getElementsByTagName("author")[rndm].childNodes[0].nodeValue;
	document.getElementById("testimonials_department").innerHTML= x.getElementsByTagName("department")[rndm].childNodes[0].nodeValue;

	setInterval(displayTestimonial, 10000);
	function displayTestimonial()  {
		$('#testimonials_container').fadeOut("slow");
		rndm = rndnumber();
		setTimeout(displayQuote, 500);
		function displayQuote() {
			document.getElementById("testimonials_txt").innerHTML= x.getElementsByTagName("quote")[rndm].childNodes[0].nodeValue;
			document.getElementById("testimonials_name").innerHTML= x.getElementsByTagName("author")[rndm].childNodes[0].nodeValue;
			document.getElementById("testimonials_department").innerHTML= x.getElementsByTagName("department")[rndm].childNodes[0].nodeValue;
		}
		$('#testimonials_container').fadeIn("slow");
	}

	function loadXMLdoc() {

	var xmlDoc;

	if (window.XMLHttpRequest)
	  {
	  xmlDoc=new window.XMLHttpRequest();
	  xmlDoc.open("GET","includes/testimonials.xml",false);
	  xmlDoc.send("");
	  return xmlDoc.responseXML;
	  }
	// IE 5 and IE 6
	else if (window.ActiveXObject)
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async=false;
	  xmlDoc.load("includes/testimonials.xml");
	  return xmlDoc;
	  }
	alert("Error loading document");
	return null;
	}

	function rndnumber(){
		var randscript = -1;
		while (randscript < 0 || randscript > elementList.length - 1) {
			randscript = parseInt(Math.random()*(elementList.length + 1))
		} return randscript
	}
});
