jQuery(document).ready(function(){    
    $.fn.supersized.options = {  
					startwidth: 1200,  
					startheight: 800,
					minsize: .50
	};

	$().ready(function() {
		$('img.full_image').each(function(index) {
    		$(this).resizenow();
  		});
		
		$('#canvas').labels_pos();
		$('img.full_image').resizenow();
	});
	
	// In Bind een functie plaatsen die alle elementen meeschaalt, dit is niet de oplossing.
	// Dus een apart functie!
	
	$(window).bind("resize", function(){
    		$('img.full_image').each(function(index) {
    			$(this).resizenow();
    			$('div', this).resizenow();
  		});
  		$('#slide').resizenow();
  		//$('#categories').resizenow();
    		$('#canvas').labels_pos();
	});

	var rotate_state = 'open';

	$('.image_link').click(function(event) {
		event.preventDefault();
		$('<div class="label_image_popup"><img src="' + this.href + '"></div>')
		.appendTo($(this).parent().parent().parent().parent());
		
		if (parseInt($(this).parent().parent().parent().parent().css('top')) >= ($(window).height()/2)) {
			$('.label_image_popup').addClass('toolow');
		}
		
		rotate_state = 'close';
		$(this).parent().parent().parent().css({'display' : 'none'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(45) };
	   	return;
	});

	$('.video_link').click(function(event) {
		event.preventDefault();
		$('<div class="label_image_popup"><iframe src="' + this.href + '" width="' + $(this).attr("v_width") + '" height="' + $(this).attr("v_height") + '" frameborder="0"></iframe></div>')
		.appendTo($(this).parent().parent().parent().parent());

		if (parseInt($(this).parent().parent().parent().parent().css('top')) >= ($(window).height()/2)) {
			$('.label_image_popup').addClass('toolow');
		}
		
		rotate_state = 'close';
		$(this).parent().parent().parent().css({'display' : 'none'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(45) };
	   	return;
	});

	$('#slide').find(':first').find('a.open_onload:first').each(function() {
		
		if (parseInt($(this).css('top')) >= ($(window).height()/2)) {
	  		$(this).children('.label_menu_popup').addClass('toolow');
		}
		$(this).parent().parent().parent().css({'display' : 'block'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(-90) };
	});


	$('#slide').find(':first').find('a.video_link.open_onload:first').each(function() {
		//console.log('gevonden');
		//console.log(this.href);
		$('<div class="label_image_popup"><iframe src="' + this.href + '" width="' + $(this).attr("v_width") + '" height="' + $(this).attr("v_height") + '" frameborder="0"></iframe></div>')
		.appendTo($(this).parent().parent().parent().parent());

		if (parseInt($(this).parent().parent().parent().parent().css('top')) >= ($(window).height()/2)) {
			$('.label_image_popup').addClass('toolow');
		}
		
		rotate_state = 'close';
		$(this).parent().parent().parent().css({'display' : 'none'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(45) };
	   	return;
	});
		/*event.preventDefault();
		$('<div class="label_image_popup"><iframe src="' + this.href + '" width="' + $(this).attr("v_width") + '" height="' + $(this).attr("v_height") + '" frameborder="0"></iframe></div>')
		.appendTo($(this).parent().parent().parent().parent());

		if (parseInt($(this).parent().parent().parent().parent().css('top')) >= ($(window).height()/2)) {
			$('.label_image_popup').addClass('toolow');
		}
		
		rotate_state = 'close';
		$(this).parent().parent().parent().css({'display' : 'none'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(45) };
	   	return;*/
	


	$('.quote_link').click(function(event) {
		event.preventDefault();
		$('<div class="label_image_popup"><span class="quote">' + $(this).attr("quote") + '</span></div>')
		.appendTo($(this).parent().parent().parent().parent());

		if (parseInt($(this).parent().parent().parent().parent().css('top')) >= ($(window).height()/2)) {
			$('.label_image_popup').addClass('toolow');
		}
		
		rotate_state = 'close';
		$(this).parent().parent().parent().css({'display' : 'none'});
		if(!$.browser.msie){ $(this).parent().parent().parent().parent().children('.label_icon').rotateAnimation(45) };
	   	return;
	});

	
	$('.label').mouseenter(function(e) {
		if(rotate_state == 'close') {
			$('.label_icon, #left-nav, #right-nav, .full_image').click(function(e) {
				rotate_state = 'open';
				if(!$.browser.msie){ $('.label_icon').rotateAnimation(0) };
				$('.label_image_popup').remove();
			});
			return;
		}
		
		if (parseInt($(this).css('top')) >= ($(window).height()/2)) {
	  		$(this).children('.label_menu_popup').addClass('toolow');
		}
		$(this).children('.label_menu_popup').css({'display' : 'block'});
		if(!$.browser.msie){ $(this).children('.label_icon').rotateAnimation(-90) }
	});
	
	$('.label').mouseleave(function(e) {
		if(rotate_state == 'close') {
			if(!$.browser.msie){ $(this).children('.label_icon').rotateAnimation(45) };
			return;
		}
		
  		$(this).children('.label_menu_popup').removeClass('toolow');
		$(this).children('.label_menu_popup').css({'display' : 'none'});
		if(!$.browser.msie){ $(this).children('.label_icon').rotateAnimation(0) };
	});

	
	$('#right_menu, #hide_right_menu').click(function() {
    		var $menu = $("#menu");
    		var $navigatie = $("#navigatie");
    		$menu.animate({
      			width: parseInt($menu.css('width'),10) == 15 ? 175 : 15
    		});
   		$navigatie.animate({
   			right: parseInt($navigatie.css('right'),10) == 30 ? 190 : 30
   		});
   		$(".rightmenu-nav").toggleClass('active');
    		return false;
  	});
  	
  	$('#showall, #bringback').click(function(e) {
  		$('#slide, #left-nav, #right-nav, #page_info, #counter, #bringback, #categories').toggle(1);
  	});
  	
  	
  	$('#righter_menu, #hide_righter_menu').click(function(e) {
    	var $site = $("#menu");
    	var $navigatie = $("#navigatie");
    	$site.animate({
      		width: parseInt($site.css('width'),10) == 775 ? 175 : 775
    	});
   		$navigatie.animate({
   			right: parseInt($navigatie.css('right'),10) == 790 ? 190 : 790
   		});
    	return false;
  	});
  	
  	$('a.product_link').click(function(e) {
    	var $site = $("#menu");
    	var $site_content = $("#site_content");
    	var $navigatie = $("#navigatie");
    	//console.log(e);
    	$site_content.load("" + e.currentTarget + "");
    	$site.animate({
      		width: parseInt($site.css('width'),10) == 775 ? 175 : 775
    	});
   		$navigatie.animate({
   			right: parseInt($navigatie.css('right'),10) == 790 ? 190 : 790
   		});
   		$(".rightmenu-nav").addClass('active');
    	return false;
  	});
  	
  	$('a.menu_link').click(function(e) {
  		var $site = $("#menu");
    	var $site_content = $("#site_content");
    	var $navigatie = $("#navigatie");
    	$site_content.load("" + e.currentTarget + "");
    	$site.animate({
      		width: parseInt($site.css('width'),10) == 775 ? 775 : 775
    	});
   		$navigatie.animate({
   			right: parseInt($navigatie.css('right'),10) == 790 ? 790 : 790
   		});
    	return false;
  	});
  	
	$('a.page_link').click(function(e) {
  		var $site = $("#menu");
    	var $site_content = $("#site_content");
    	var $navigatie = $("#navigatie");
    	$site_content.load("" + e.currentTarget + "");
    	$site.animate({
      		width: parseInt($site.css('width'),10) == 775 ? 755 : 755
    	});
   		$navigatie.animate({
   			right: parseInt($navigatie.css('right'),10) == 790 ? 790 : 790
   		});
    	return false;
  	});
  	
  	$('#toggle_category, #toggle_image').click(function(e) {
  		$(this).toggleClass('active');
  		$(e.target.hash).slideToggle('fast', function() {
  			//animation complete
  		});
  		return false;
  	});
   
   	$('div.footer-nav').click(function() {
    	var $footer = $("#footer");
    	var $footernav = $("div.footer-nav");
    	$footer.animate({ height: parseInt($footer.css('height'),10) == 15 ? 150 : 15 });
    	$footernav.animate({ bottom: parseInt($footernav.css('bottom'),10) == 40 ? 175 : 40 });
    	$footernav.toggleClass('active_link');
  	});
  	
  	$('li.menu_footer_list_item').click(function(e) {
  		var index = $("li.menu_footer_list_item").index(this);
  		$('#slide').cycle(index);
  		return false;
  	});
   
   	/*$('#footer').mouseenter(function() {
    	var $footer = $("#footer");
    	var $footernav = $("div.footer-nav");
    	$footer.animate({ height: 115 });
    	$footernav.animate({ bottom: 140 });
    	$footernav.addClass('active_link');
  	}).mouseleave(function(){
      	var $footer = $("#footer");
    	var $footernav = $("div.footer-nav");
    	$footer.animate({ height: 15 });
    	$footernav.animate({ bottom: 40 });
    	$footernav.removeClass('active_link');
    });
   */
	$('#menu_footer_carousel').jcarousel();
})
