$(document).ready(function(){
	
	$('#showBrowsers').click(function() {
      $(this).parent().animate({height: "110px"}, 500);
    });
	
	$('#lang_switch a').mouseover(function() {
		var lang = $(this).attr("label");
		
		$('#lang_txt').html(lang);

		
		if(lang == 'English') $('#lang_txt').css("paddingLeft","30px");
		else if(lang == 'Deutsch') $('#lang_txt').css("paddingLeft","56px");
		else if(lang == 'Español') $('#lang_txt').css("paddingLeft","74px");
		else $('#lang_txt').css("paddingLeft","4px");
	});
	
	$('#lang_switch a').mouseout(function() {
		$('#lang_txt').html('');
	});

	
	// Open/Close button for footer
	$('#open_close')
		.css({ backgroundPosition: "0px 18px" })
		.mouseover(function() {
			$(this).stop().animate({ backgroundPosition: "(0px 0px)" }, 400);
		})
		.mouseout(function() {
			$(this).stop().animate({ backgroundPosition: "(0px 18px)" }, 400);
		})
		.click(function() {
			
			getheights();
			
			$('#footer').stop().animate({ top: window_height-footer_height, height: "42px" }, 700, "swing");
			
			$('#content').stop().animate({ height: $('#content').height()-283+"px" }, 700, "swing");
			
			$('#blocks').stop().animate({ top: -331+"px"}, 700, "swing", function() { 
				$('#open_close').css('top', window_height-footer_height-40);
				$('#open_close_open').css('top', window_height-footer_height);
				$('#open_close_open').show();
				$('#open_close_open').animate({top: window_height-footer_height-40+"px"}, 400, "swing");
			});
			
			$(this).hide();
			$('#open_close').css('top', window_height-footer_height-40);
			
			
		});
	
	
	$('#open_close_open')
		.css({ backgroundPosition: "0px -40px" })
		.mouseover(function() {
			$(this).stop().animate({ backgroundPosition: "(0px -60px)" }, 400);
		})
		.mouseout(function() {
			$(this).stop().animate({ backgroundPosition: "(0px -40px)" }, 400);
		})
		.mouseover(function() {
			getheights();
			
			$('#content').stop().animate({ height: $('#content').height()+283+"px" }, 700, "swing", function() { $('#open_close').show(); $('#open_close').css('top', window_height-373-10); $('#open_close').animate({top: window_height-373-40}, 200, "swing") });
			
			var footer_height = $('#footer').height();
			
			$('#footer').stop().animate({ top: window_height-373, height: "373px"}, 700, "swing");
			
			$('#blocks').stop().animate({ top: "0px", height: window_height-373}, 700, "swing");
			
			
			$(this).hide();
			//$('#open_close').css('top', window_height-373-40);
			$('#open_close_open').css('top', window_height-373-40);
		});
	
	
	//$(".txt:first").css("font-size", "14px");
	
	$('.projecten').click(function() { window.scrollTo(0, 0); });
	
	$(".projecten").fancybox({
		'width'				: 960,
		'height'			: 580,
		'autoScale'			: false,
		'autoDimensions'    : false,
		'type'				: 'iframe',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.5,
		'padding'			: 0,
		'margin'			: 0,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'scrolling'			: 'no'
	});
	
	$('.forgot_pass').click(function() { window.scrollTo(0, 0); });
	$(".forgot_pass").fancybox({
		'width'				: 300,
		'height'			: 200,
		'autoScale'			: false,
		'autoDimensions'    : false,
		'type'				: 'iframe',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.5,
		'padding'			: 0,
		'margin'			: 0,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade'
	});
	
	$('#view_showreel').click(function() { window.scrollTo(0, 0); });
	$('#view_showreel').fancybox({
		'width'				: 768,
		'height'			: 462,
		'autoScale'			: false,
		'autoDimensions'    : false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'swf',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.5,
		'padding'			: 0,
		'margin'			: 0
	});
	
	getheights();
	var footer_height = $('#footer').height();
	$('#footer').css('top', window_height-footer_height);
	
	$('#content').css('height', $('#content').height()+110);
	$('#open_close').css('top', window_height-footer_height-40);
	$('#open_close_open').css('top', window_height-footer_height-40);
	
	$('#footer #footer_menu .left a:last').css('marginRight','0');
	$('#footer #footer_menu .right a:first').css('marginLeft','0');
	
	$('#lang_switch .lang_switch:last').css('marginRight','0');
	
	$('.showroom_item .showroom_title').click(function() {
		$('.showroom_item .sub_items').hide();
		$(this).next('.sub_items').show();
		
		if($('#content').height() < ($('#right_items').height()+$('#footer').height())) {
		  	var new_content_height = $('#right_items').height()+$('#footer').height();
		  	$('#content').height(new_content_height+60);
		}
		
	});
	
});

$(window).resize(function() {
	getheights();
	
	var footer_height = $('#footer').height();
	
	$('#footer').css('top', window_height-footer_height);
	$('#open_close').css('top', window_height-footer_height-40);
	$('#open_close_open').css('top', window_height-footer_height-40);
	
	if($('#right_items')) var left = ($(window).width() / 2)+200; $('#right_items').css("left",left+"px");
	
});

$('#content_holder').resize(function() {
	getheights();
	
	var footer_height = $('#footer').height();
	
	$('#footer').css('top', window_height-footer_height);
	$('#open_close').css('top', window_height-footer_height-40);
	$('#open_close_open').css('top', window_height-footer_height-40);
	
	if($('#right_items')) var left = ($(window).width() / 2)+200; $('#right_items').css("left",left+"px");
	
});

function getheights() {
	
	window.menu = 100;
	
	if($('#header').height() > 0) window.header = 384;
	  else  window.header = 0;
	
	if($('#bottom_items').height()) window.items = 28;
	  else window.items = 80;
	
	window.content = $('#content_holder').height()+menu+header+items;
	window.window_height = $(window).height();
	window.left_over = window_height-content;
	
	//alert('get heights!');
}

function slideSwitch() {
    var $active = $('#slider IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slider IMG:first');

    $active.addClass('last-active');

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

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

$(function() {
    
    if($('#right_items').height()) {
    
    var top = $('#right_items').offset().top - parseFloat($('#right_items').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      var benodigd = $('#right_items').height()+$('#footer').height()+42;
      
      // whether that's below the form
      if (y >= top) {
        
        if($(window).height() >= benodigd) {
        
          // if so, ad the fixed class
          $('#right_items').addClass('fixed');
        
          var left = ($(window).width() / 2)+200;
          $('#right_items').css("left",left+"px");
        }
        
      } else {
        // otherwise remove it
        $('#right_items').removeClass('fixed');
      }
      
    });
    
    }
});
