var basic = {
  FxEvents: {
    setImageHoverFade: function(str) {
      $(str).hover(function(){
         $(this).fadeTo('fast', 0.5);
      }, function(){
        $(this).fadeTo('fast', 1);
      });
      return this;
    }
  },
	Startpage: {
		init: function() {
		  $("a.lightbox").fancybox();
		  
		  $("#footer .cooperation img").hover(function(){
        this.src = this.src.replace('-0','-1');
      },function(){
        this.src = this.src.replace('-1','-0');
      });
		  
			$('.imageItem').fadeTo(1100,1);
      $(".slideshow")
        .after('<div id="slidePager"><ul id="nav">')
        .cycle({
          fx: 'fade',
          pager: '#nav',
          speed: '800',
          timeout: '10000',
          pause: true,
          before: onBefore, 
          after: onAfter,  
          pagerAnchorBuilder: function(idx, slide) { 
            return '<li><a href="#">' + jQuery(slide).children("h3").eq(0).text() + '</a></li>';
          }
        });
        function onBefore() { 
          $(this).children('.imageItem').children('.imageOverlay').stop().fadeTo(400, 0);
          $('.imageInfo').stop().animate({marginTop: "0px", opacity:0}, 300);
          $('.imageSymbol').stop().animate({marginTop: "0px", opacity:0}, 300);
        } 
        function onAfter() {
            $(this).children('.imageItem').children('.imageOverlay').delay(800).fadeTo(800, 0.7);
            $('.imageInfo').delay(1600).animate({
                marginTop: "10px",
                opacity: 1
            }, 800);
            if($(this).children('.imageSymbol').hasClass('heatSymbol')) { 
              $('.imageSymbol').delay(2800).animate({
                  marginLeft: "30px",
                  opacity: 1
              }, 900);
            } else {
              $('.imageSymbol').delay(2800).animate({
                  marginTop: "30px",
                  opacity: 1
              }, 900);
            }
        }
  	}
	},
	Faq: function() {
  	  $(".ce_projectheadline").click(function() {
  	    $this = $(this);
  	    $content = $this.next(".ce_projecttext");
  	    $(".ce_projectheadline").removeClass('expanded');
  	    if (!$content.is(":visible")) {
  	      $this.addClass('expanded').removeClass('collapsed');
          $(".ce_projecttext:visible").slideToggle(400);
        }
        $content.slideToggle(500);
      });
	}
}

$(document).ready(function(){
	basic.Startpage.init();
	basic.FxEvents.setImageHoverFade(".ce_text a img");
	basic.FxEvents.setImageHoverFade(".ce_gallery a img");
	basic.FxEvents.setImageHoverFade("#footer .facebook");
	
	basic.Faq();
});
