$(document).ready(function() {
	font.setup(); // run setup when the DOM is ready
	if(!font.isInstalled('Myriad Pro'))
	{
		$("head").append("<link>");
		var css = $("head").children(":last");
		css.attr({
		      rel:  "stylesheet",
		      type: "text/css",
		      href: "/css_js/m_alternative.css"
		});
	}
	if(!font.isInstalled('Sabon LT Std'))
	{
		
	}
	
    if ( $.browser.mozilla == 'Firefox' && parseFloat($.browser.version) >1.9)
	{
			var link = $("<link>");
			link.attr({
			type: 'text/css',
			rel: 'stylesheet',
			href: 'firefox.css'
		});
		$("head").append( link ); 
    }


	// Work-around function voor .css('background-position') in IE
	(function($) {
		jQuery.fn.backgroundPosition = function() {
			var p = $(this).css('background-position');
			if(typeof(p) === 'undefined') return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
			else return p;
		};
	})(jQuery);
	
	var multiple_top=false; 
	var multiple_bottom=false;
	var multiple_leftbottom=false;
	
	// Slideshow/thumbs
	// Slideshow wordt gestart als er meer dan 1 grote foto is en het niet om een projectpagina gaat (waar je via de thumbnails de foto's kunt bekijken)
	
	
	$('ul#nav>li>a').bind('click', function(event) {
		if ( $(this).siblings('div.subnav_container').length == 1 ) {
			event.preventDefault();
			if ($(this).next('div.subnav_container').css('display') == 'none') {
				hide_subnav();
				$(this).next('div.subnav_container').css({'display':'block'}).find('div.subnav_inner').css({'opacity':0, 'top':'-30px'}).animate({'opacity':1, top:0}, 750);

				var bg_pos = '-400px ' + $(this).backgroundPosition().split(' ')[1];
				$(this).css({'background-position': bg_pos})
			}
		}
	});
});

var current_photo=0;

function hide_subnav() {
	$('ul#nav>li>div.subnav_container').each(function() {
		if ($(this).css('display') == 'block') {
			$(this).find('div.subnav_inner').animate({'opacity':0, 'top':'-30px'}, 250, function() {
				$(this).parent('div.subnav_container').css({'display':'none'});
			});
		}
	});

	$('ul#nav>li>a').each(function() {
//		alert( $(this).css('background-position-x') );
		var bg_pos = '0px ' + $(this).backgroundPosition().split(' ')[1];
		$(this).css({'background-position': bg_pos})
	});
}

function resizeMainBlock(firstmove)
{
	total=320;
	if(firstmove)
	{
		total=300;
		document.getElementById('right_bar').style.width="0px";
	}
	
	try
	{
		w=document.getElementById('wrapper').scrollWidth;
		if(w<500)
		{
			
		}
		else if(w<1000)
		{
			document.getElementById('main').style.width=(w-total)+"px";
		}
		else
		{
			document.getElementById('main').style.width=(w-total)+"px";
		}
	}
	catch(err)
	{
		
	}
}

function resizeRightBlock()
{
	try
	{
		h=document.getElementById('follow_me_id').clientHeight;
		
		//h=document.getElementById('right_bar').height;
		//alert(h);
		h=document.documentElement.clientHeight;
		h=(h-203);
		//alert(h);
		document.getElementById('follow_me_id').style.top=h+"px";
	}
	catch(err)
	{
		
	}
}

function resizeImageBlock()
{
	try
	{
		//h=document.getElementById('follow_me_id').clientHeight;
		
		//h=document.getElementById('right_bar').height;
		//alert(h);
		h=document.documentElement.clientHeight;
		
		//alert(h);
		document.getElementById('large_photo').style.height=h+"px";
	}
	catch(err)
	{
		
	}
}

function resizeContentBlock1(firstmove)
{
	try
	{
		h=document.documentElement.clientHeight;
		h3=h-70;
		h2=h-122;
		h1=h-175;
		
		if(h<660||!firstmove)
		{
			document.getElementById('titel_1').style.top=h1+"px";
			document.getElementById('titel_2').style.top=h2+"px";
			document.getElementById('content_1').style.top=h3+"px";
			
			// document.getElementById('large_photo').style.top=h+"px";
		}
	}
	catch(err)
	{
		
	}
}

function resizeContentBlock2()
{
	try
	{
		h=document.documentElement.clientHeight;
		h3=h-70;
		h2=h-122;
		h1=h-175;
		
		if(h<660)
		{
			document.getElementById('titel_1').style.top=h1+"px";
			document.getElementById('titel_2').style.top=h2+"px";
			document.getElementById('content_1').style.top=h3+"px";
		
		// document.getElementById('large_photo').style.top=h+"px";
		}
	}
	catch(err)
	{
		
	}
}

function resizeProjectenBlock()
{
	try
	{
		//h=document.documentElement.clientHeight;
		//h=h+150; 
		//document.getElementById('project_id');
		//document.getElementById('main').style.height=h+"px";
		
		//document.getElementById('main').style.height=h+"px";
		//h2=document.getElementById('project_id').scrollHeight;
		//h2=h2+220; 
		
		//document.getElementById('main').style.height=h2+"px";
		
		//w=document.getElementById('wrapper').scrollWidth;
		
		//if(w>1000)
		//{
			//document.getElementById('main').style.width=(w-420)+"px";
		//}
	}
	catch(err)
	{
		
	}
}

function resizeProjectdetailBlock()
{
	try
	{
		//h=document.documentElement.clientHeight;
		
		//document.getElementById('main').style.height=h+"px";
		//h2=document.getElementById('project2_id').scrollHeight;
		//h2=h2+200; 
		
		//document.getElementById('main').style.height=h2+"px";
	}
	catch(err)
	{
		
	}
}

function resizeBlocks(firstmove)
{
	resizeMainBlock(firstmove);
	resizeRightBlock();
	resizeImageBlock();
	resizeContentBlock1(firstmove);
	resizeContentBlock2();
	if(projectenpage==1&&projectdetail==0)
	{
		//resizeProjectenBlock();
	}
	if(projectenpage==1&&projectdetail==1)
	{
		//resizeProjectdetailBlock();
	}
}

function animateBlock1()
{
	
	w=document.documentElement.clientWidth;
	//$('#subnav').hide();
	$('#main').width((0));
	$('#topnav-mainbox').hide();
	
	document.getElementById('main').style.width=w+"px";
	
	$('#large_photo').show('fold', {   }, 1000, function() {
		//$('#topnav-mainbox').show('slide', {   }, 1000, function() {
		//$('#subnav').show('drop', { direction: 'up' }, 1000);
	
		
		
		$('#right_bar').show();
		 
		 total=320;
		
		$('#main').animate({width:(w-total)+"px"},1000);
		$('#right_bar').animate({width:"20px"},1000,function(){
			
			//document.getElementById('topnav-mainbox').innerHTML='&nbsp;';
			
			//$('#topnav-mainbox').show('slide', {   }, 1000);
			
			
			
			//document.getElementById('topnav-mainbox').style.width="300px";
			
			//$('#topnav-mainbox').animate({width:"300px"},1000);
			$('#main').animate({width:(w-total)+"px"},1000);
			$('#follow_me_id').show('drop', { direction: 'up' }, 1000,function(){
				$('#topnav-mainbox').show();
				$('#right_bar').animate({width:"20px"},1000,function(){
					if(titel1)
					{
						$('#titel_1').show('slide', {   }, 1000);
					}
					if(titel2)
					{
						$('#titel_2').show('slide', {   }, 1000,function(){
							$("#inner_title10_id").animate({"color": "#ffffff"},900);
							$("#inner_title20_id").animate({"color": "#ffffff"},900);
							$("#inner_content_id").animate({"color": "#000000"},900);
							$("#inner_content_id a").animate({"color": "#000000"},900);
						});
					}
					else
					{
						$("#inner_title10_id").animate({"color": "#ffffff"},900);
						$("#inner_title20_id").animate({"color": "#ffffff"},900);
						$("#inner_content_id").animate({"color": "#000000"},900);
						$("#inner_content_id a").animate({"color": "#000000"},900);
					}
					$('#content_1').show('slide', {   }, 1000);
				});
				
				
				if($('#content_1').length != 0)
	   			{
	   				w=document.documentElement.clientWidth;
	   				w=w-(320);
	   				w2=$("#large_photo>img").width();
	   				w3=w2-w;
	   				if(homewidth<=2000)
	   				{
	   					//$("#large_photo>img").animate({"left": "-=2000px"},30000);
	   				}
	   				else if(homewidth>2000&&homewidth<3000)
	   				{
	   					//$("#large_photo>img").animate({"left": "-="+w3+"px"},30000);
	   				}
	   				else
	   				{
	   					//$("#large_photo>img").animate({"left": "-="+w3+"px"},30000);
	   				}
	   			}

				$('#topnav-mainbox').animate({width:"300px"},1000);
			});
		}); 
		//$('#topnav-mainbox').show('slide', {   }, 1000);

	});
}

function setMenuWinder(main_item,sub_item)
{
	$('#subnav>li').removeClass("menu_active");
	$('#subnav>li').addClass("menu");
	$('#'+main_item).removeClass("menu");
	$('#'+main_item).addClass("menu_active");
}

var busy=false;
var currentdirection='';
var currenturl='';
var lasturl='';
var datax={ external: "1" };

function sendContactAjax(form)
{
	datax={ external: "1",naam:form.naam.value,email:form.email.value,onderwerp:form.onderwerp.value,bericht:form.bericht.value };
	
	loadWinder("/send-contact","","");
}

function loadWinder(url,main_item,sub_item)
{	
	//if(main_item!='')
	//{
		//setMenuWinder(main_item,sub_item);
	//}
	//return false;
	if(busy==false&&currenturl!=url||url=='/send-contact'&&busy==false)
	{
		lasturl=currenturl;
		
		busy=true;
		resetMenu();
		if(main_item!='')
		{
			setMenuWinder(main_item,sub_item);
		}
		currenturl=url;
		$('#loading_animation_id').attr("src", "/images/loading_0.jpg");
		$('#titel_loading').show('clip', {   }, 1000,function(){
			$('#loading_animation_id').attr("src", "/images/loading_1.jpg");
			resetMenu();
		});
			
		$.post(url, datax,function(data){
			
			datax={ external: "1" };
	   		$('#titel_loading').hide('clip', {    }, 500, function(){
	   			if($('#content_1').length == 0)
	   			{
	   				if($('#content_2').length != 0)
	   				{
		   				$('#titel_3').hide('fold', {   });
						$('#titel_4').hide('fold', {   });
						$('#content_2').hide('fold', {   }, 1000, function(){
							$('#content_2').remove();
							$('#titel_4').remove();
							$('#titel_3').remove();
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
						});
					}
					if($('#news_id').length != 0)
	   				{
		   				$('#news_id').hide('fold', {   }, 1000);
						$('#tweets_id').hide('fold', {   }, 1000, function(){
							$('#tweets_id').remove();
							$('#news_id').remove();
							$('#project_wrapper').remove();
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
						});
					}
					if($('#project_id').length != 0)
	   				{
		   				$('#titel_5').hide('fold', {   }, 1000);
						$('#titel_6').hide('fold', {   }, 1000);
						$('#project_id').hide('fold', {   }, 1000, function(){
							$('.project_img>img').remove();
							$('.project_img').remove();
							$('#project_id').remove();
							$('#titel_5').remove();
							$('#titel_6').remove();
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
						});
					}
					if($('#project_detail_id').length != 0)
	   				{
	   					if(lasturl.indexOf("/project/")!=-1&&currenturl.indexOf("/project/")!=-1)
						{
							$('#titel_5').hide();
							$('#titel_6').hide();
							$('#project_gallery_id').hide();
							$('#project_gallery_horizontal').hide();
							$('#project_wrapper').hide();
							
							$('#mycarousel').hide();
							$('#project_detail_id').hide();
							$('#project_description').hide();
							
							doneScrolling=true;
							
							$('#mycarousel>img').remove();
							$('.project_gallery_img>img').remove();
							$('#project_detail_id>img').remove();
							$('#project_gallery_id>img').remove();
							$('.project_gallery').remove();
							
							$('#project_description').remove();
							$('#mycarousel').remove();
							$('#project_gallery_horizontal').remove();
							$('#project_detail_id').remove();
							$('#project_gallery_id').remove();
							$('#titel_5').remove();
							$('#titel_6').remove();
							$('#project_wrapper').remove();
							
							
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
							current_photo=0;
						}
						else
						{
							$('#titel_5').hide('fold', {   }, 1000);
							$('#titel_6').hide('fold', {   }, 1000);
							$('#project_gallery_id').hide();
							$('#project_detail_id').hide('fold', {   }, 1000, function(){
								$('#project_detail_id').remove();
								$('#project_description').remove();
								$('#project_gallery_id').remove();
								$('#mycarousel').remove();
								doneScrolling=true;
								$('#project_gallery_horizontal').remove();
								$('#titel_5').remove();
								$('#titel_6').remove();
								$('#project_wrapper').remove();
								$('#main').html($('#main').html()+data);
								loadMainImage(url);
							});
						}
					}
					if($('#people_id').length != 0)
	   				{
	   					$('#people_id').hide('fold', {   }, 1000, function(){
							$('#people_id').remove();
							$('#project_wrapper').remove();
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
						});
					}
					if($('#content_3').length != 0)
	   				{
	   					$('#content_4').hide('fold', {   }, 1000, function(){
	   						$('#content_4').remove();
	   					});
	   					$('#content_3').hide('fold', {   }, 1000, function(){
							$('#content_3').remove();
							$('#main').html($('#main').html()+data);
							loadMainImage(url);
						});
					}
	   			}
	   			else
	   			{
	   				animateHomepage(data,url);
		   		}
	   		});
	   });
   	}
}

function loadMainImage(url)
{
	$.post(url, { external: "1",load_img: "1" },function(data2){
		if($('#project_id').length == 0&&$('#project_detail_id').length == 0)
		{
			//h=document.documentElement.clientHeight;
			//w=document.documentElement.clientWidth;
		
			//$('#main').css( "width",(w-320)+"px" ); 
			//$('#main').css( "height",h+"px" ); 
		}
	
		if($('#project_id').length != 0)
		{
			$('#main').css( "background-color", "#ffffff" );
			projectenpage=1;
			projectdetail=0;
		}
		else if($('#project_detail_id').length != 0)
		{
			projectdetail=1;
			projectenpage=1;
			$('#main').css( "background-color", "#ffffff" );
		}
		else
		{
			projectenpage=0;
			projectdetail=0;
			$('#main').css( "background-color", "#000000" );
		}
		
		if($('#large_photo>img').length == 0)
	   	{
	   		animateAndLoad(data2);
	   	}
		else
		{
			if(currenturl=='/send-contact')
			{
				animateAndLoad(data2);
			}
			else
			{
				$('#large_photo>img').hide('drop', {  direction: 'right' }, 1000,function(){
					animateAndLoad(data2);
				});
			}
		}
	});
}

function animateAndLoad(data2)
{
	$('#large_photo>img').remove();
	$('#large_photo').html(data2);
	$('#large_photo>img').hide();
		
	var tn_array = Array();

	$('#large_photo img').each(function() {
	    tn_array.push($(this).attr('src'));
	});

	
	if(currenturl=='/send-contact')
	{
		$('#large_photo>img').show();
		animateBlocks();
	}
	else if($.browser.msie)
	{
		if($('#large_photo>img').length == 0)
	   	{
	   		animateBlocks();
	   	}
		else
		{
			$('#large_photo>img').show('drop', { direction: 'right'  }, 1000,function(){
				animateBlocks();
			});
		}
	}
	else
	{
		$.preload(
			 tn_array 
			, {
			init: function(loaded, total) {
				if(total==0)
				{
					animateBlocks();
				}
				if(loaded==1)
				{
					animateBlock1();
				}
			},
			loaded: function(img, loaded, total) {
				
			},
			loaded_all: function(loaded, total) {
				$('#large_photo>img').show('drop', { direction: 'right'  }, 1000,function(){
					animateBlocks();
				});
			}
		});
	}
}

function animateBlocks()
{
	if(titel1)
	{
		$('#titel_1').show('slide', {   }, 1000);
	}
	if(titel2)
	{
		$('#titel_2').show('slide', {   }, 1000);
	}
	$('#content_1').show('slide', {   }, 1000,function(){
		$("#inner_title10_id").animate({"color": "#ffffff"},900);
		$("#inner_title20_id").animate({"color": "#ffffff"},900);
		$("#inner_content_id").animate({"color": "#000000"},900);
		$("#inner_content_id a").animate({"color": "#000000"},900);
	});
	
	if($('#content_1').length != 0)
	{
		w=document.documentElement.clientWidth;
		w=w-(320);
		w2=$("#large_photo>img").width();
		w3=w2-w;
		if(homewidth<=2000)
		{
			//$("#large_photo>img").animate({"left": "-=2000px"},30000);
		}
		else if(homewidth>2000&&homewidth<3000)
		{
			//$("#large_photo>img").animate({"left": "-="+w3+"px"},30000);
		}
		else
		{
			//$("#large_photo>img").animate({"left": "-="+w3+"px"},30000); 
		}
	}
	
	$('#titel_3').show('fold', {   }, 500);
	$('#titel_4').show('fold', {   }, 500);
	$('#content_2').show('fold', {   }, 500,function(){
		$("#inner1_id").animate({"color": "#ffffff"},2000);
		$("#inner2_id").animate({"color": "#ffffff"},2000);
		$("#inner3_id").animate({"color": "#ffffff"},2000);
	});
	
	if(lasturl.indexOf("/project/")!=-1&&currenturl.indexOf("/project/")!=-1)
	{
		$('#project_detail_id').show();
		//$('#project_gallery_id').show();
		$('#mycarousel').show();
		$('#titel_5').show();
		$('#titel_6').show();
	
		h=document.getElementById('project_description').clientHeight;
		w=document.documentElement.clientWidth;
			
		//$('#main').css( "width",(w-340)+"px" ); 
		//$('#main').css( "height",(h+670)+"px" ); 
		
		prepareProjectDetail();
	}
	else
	{
		$('#titel_5').show('fold', {   }, 500);
		$('#titel_6').show('fold', {   }, 500);
	
		$('#mycarousel').show('fold', {   }, 500, function (){  });
		$('#project_detail_id').show('fold', {   }, 500, function (){
			prepareProjectDetail();
		});
	}
	
	$('#project_id').show('fold', {   }, 500,function(){
		h=document.documentElement.clientHeight;
		w=document.documentElement.clientWidth;
		if(h<800)
		{
			//$('#main').css( "width",(w-440)+"px" ); 
			//$('#main').css( "height","800px" ); 
		}
	});
	
	$('#content_3').show('fold', {   }, 1500,function(){
		$('.inner_content2').show('fade', {   }, 1500,function(){
		
		});
	});
	$('#content_4').show('fold', {   }, 1500,function(){
		$('.inner_content6').show('fade', {   }, 1500,function(){
		
		});
	});
	$('#people_id').show('fold', {   }, 1000);
	
	$('#news_id').show('fold', {   }, 1000,function(){
		
		w=document.documentElement.clientWidth;
		h=document.getElementById('news_id').clientHeight;
		h2=document.getElementById('wrapper').clientHeight;
		
		$(".news_bigcontent").animate({"color": "#ffffff"},2000);
		$(".news_descr>h1").animate({"color": "#ffffff"},2000);
		
		$(".inner_tweets").animate({"color": "#000000"},2000);
		
		if(h>520)
		{
			$('#main').css( "width",(w-340)+"px" ); 
			//$('#main').css( "height",(h2)+"px" ); 
		}	
	});
	$('#tweets_id').show('fold', {   }, 1000);
	
	busy=false;
}

function animateHomepage(data,url)
{
	if(titel1)
	{
		$('#titel_1').hide('slide', {   }, 1000);
	}
	if(titel2)
	{
		$('#titel_2').hide('slide', {   }, 1000);
	}
	$('#content_1').hide('slide', {   }, 1000, function(){
		$('#titel_1').remove();
		$('#titel_2').remove();
		$('#content_1').remove();
			
		$('#main').html($('#main').html()+data);
		
		loadMainImage(url);
	});
}

function showDescription()
{
	$('#project_detail_img_id').fadeOut('slow', function() {
		$('#project_detail_text').fadeIn('slow');
		
    	// Animation complete.
    	$('#project_link_id').removeClass('volgende');
    	$('#project_link_id').addClass('volgende2');
 	 });
}

function closeDescription()
{
	$('#project_detail_img_id').fadeIn('slow', function() {
		$('#project_detail_text').hide();
    	$('#project_link_id').removeClass('volgende2');
    	$('#project_link_id').addClass('volgende');
 	 });
}

var pbusy=false;

function showProjectImage(index)
{
	if(!pbusy&&index!=current_photo)
	{
		pbusy=true;
		var photo = $('#project_detail_img_id>img');
		
		prev_image=current_photo;
		
		current_photo=index;
		if(photo.length==(current_photo+1))
		{
			$('#projectdetail_next_id').hide();
		}
		else if(photo.length<(current_photo+1))
		{
			current_photo=(photo.length-1);
		}
		else
		{
			$('#projectdetail_next_id').show();
		}
		
		if(current_photo>0)
		{
			$('#projectdetail_prev_id').show();
		}
		
		$(photo[current_photo]).show();
		$(photo[(current_photo)]).css("z-index","10");
		
		$(photo[(prev_image)]).css("z-index","20");
		$(photo[(current_photo)]).css('opacity','1');
		$(photo[prev_image]).animate({'opacity':0}, 500,function(){
			pbusy=false;
		});
	}
}

function nextProjectImage()
{
	if(!pbusy)
	{
		pbusy=true;
		var photo = $('#project_detail_img_id>img');
		
		current_photo=current_photo+1;
		if(photo.length==(current_photo+1))
		{
			$('#projectdetail_next_id').hide();
		}
		else if(photo.length<(current_photo+1))
		{
			current_photo=(photo.length-1);
		}
		else
		{
			$('#projectdetail_next_id').show();
		}
		
		if(current_photo>0)
		{
			$('#projectdetail_prev_id').show();
		}
		
		$(photo[current_photo]).show();
		$(photo[(current_photo)]).css("z-index","10");
		$(photo[(current_photo-1)]).css("z-index","20");
		$(photo[(current_photo)]).css('opacity','1');
		$(photo[current_photo-1]).animate({'opacity':0}, 500,function(){
			pbusy=false;
		});
	}
}

function prevProjectImage()
{
	if(!pbusy)
	{
		pbusy=true;
		var photo = $('#project_detail_img_id>img');
	
		if(photo.length<(current_photo+1))
		{
			current_photo=(photo.length-1);
		}
		
		if(current_photo!=0)
		{
			current_photo=current_photo-1;
		}
		if(photo.length!=(current_photo+1))
		{
			$('#projectdetail_next_id').show();
		}
		
		if(current_photo==0)
		{
			$('#projectdetail_prev_id').hide();
		}
		else
		{
			$('#projectdetail_prev_id').show();
		}
		
		$(photo[current_photo]).show();
		$(photo[(current_photo)]).css("z-index","10");
		$(photo[(current_photo+1)]).css("z-index","20");
		$(photo[(current_photo)]).css('opacity','1');
		$(photo[current_photo+1]).animate({'opacity':0}, 500,function(){
			pbusy=false;
		});
	}
}

var doneScrolling=false;

function startCarousel(carousel)
{
	$("#project_gallery_horizontal").show();
	$("#mycarousel>li").bind('click', function() {
        carousel.scroll($(this).index());
		$("#mycarousel>li img").animate({'opacity':0.5}, 500);
		carousel_images=$("#mycarousel>li img"); 
				
		$(carousel_images[$(this).index()]).animate({'opacity':1}, 500);
		showProjectImage($(this).index());
				
		doneScrolling=true;
		
        return false;
    });
    
    setTimeout(function(){scrollCarousel(carousel)},3000);

}

function scrollCarousel(carousel)
{
	if(!doneScrolling)
	{
	
		carousel_images=$("#mycarousel>li img");
		
		$(carousel_images[current_photo]).animate({'opacity':0.5}, 500);
		
		n=$("#mycarousel>li").length;
		if(n==(current_photo+1))
		{
			tcurrent_photo=0;
		}
		else
		{
			tcurrent_photo=current_photo+1;
		}
		$(carousel_images[tcurrent_photo]).animate({'opacity':1}, 500);
		
		carousel.scroll(tcurrent_photo);
		showProjectImage(tcurrent_photo);
	
		setTimeout(function(){scrollCarousel(carousel)},3000);
	}
}

function prepareProjectDetail()
{
	doneScrolling=false;
	current_photo=0;
	try
	{
	    jQuery('#mycarousel').jcarousel({
	    	initCallback:startCarousel,
	        itemFallbackDimension:580
	    });
	
	    var carouselitems=$("#mycarousel>li img").animate({ opacity: 0.5 }, 500);

	    $("#project_gallery_horizontal").show();
	    
	    $(carouselitems[0]).animate({'opacity':1}, 500);
	    
		var photo = $('#project_detail_img_id>img').css({'opacity':0});
		
		if( $('#project_detail_img_id>img').length > 0 ) 
		{
			$(photo[0]).show();
			$(photo[0]).animate({'opacity':1}, 500);
			$('#project_gallery_id li:first-child').addClass('project_gallery_active');
		}
		
		if(photo.length<2)
		{
			$('#projectdetail_next_id').hide();
		}
		else
		{
			$('#projectdetail_next_id').show();
		}
		
		if(current_photo>0)
		{
			$('#projectdetail_prev_id').show();
		}
		else
		{
			$('#projectdetail_prev_id').hide();
		}
		
	}
	catch(err)
	{
		
	}
}

function start()
{
	var tn_array = Array();

	if(startfromhome==1)
	{
		if($.browser.msie)
		{
			animateBlock1();
		}
		else
		{
			$('#large_photo img').each(function() {
			    tn_array.push($(this).attr('src'));
			});
	
			$.preload(
			 tn_array 
			, {
			init: function(loaded, total) {
				if(total==0)
				{
					animateBlock1();
				}
				if(loaded==1)
				{
					animateBlock1();
				}
			},
			loaded: function(img, loaded, total) {
				
			},
			loaded_all: function(loaded, total) {
				animateBlock1();
				}
			});
		}
	}
	else
	{
		w=document.documentElement.clientWidth;
		//$('#subnav').hide();
		$('#main').width((0));
		$('#topnav-mainbox').hide();
	
		document.getElementById('main').style.width=w+"px";
	
		$('#large_photo').show('fold', {   }, 1000, function() {
			$('#titel_1').show('slide', {   }, 1000);
			$('#titel_2').show('slide', {   }, 1000);
			$('#content_1').show('slide', {   }, 1000);
			
			$('#right_bar').show();
			 
			 total=320;
			
			$('#main').animate({width:(w-total)+"px"},1000);
			$('#right_bar').animate({width:"20px"},1000,function(){
				$('#main').animate({width:(w-total)+"px"},1000);
				$('#follow_me_id').show('drop', { direction: 'up' }, 1000,function(){
					$('#topnav-mainbox').show();
					$('#right_bar').animate({width:"20px"},1000);
					$('#topnav-mainbox').animate({width:"300px"},1000);
					animateBlocks();
				});
			});
		});
	}
}

$(document).ready(function(){  
	if(startfromhome==0)
	{
		setMenuWinder('main_item_6','');
	}
	resizeBlocks(true);
	setTimeout("start()",500);
	

       // $('#main').hide();
        //$('#main').show('clip', { direction: 'horizontal' }, 500);


      //  $('#main').hide('explode', { pieces: 30 }, 500);
   		//$('#main').hide('explode', { pieces: 30 }, 500);

	//resizeBlocks(false);
	
	try
	{
		var photo = $('#project_detail_img_id>img').css({'opacity':0});
		
		$('#project_gallery_id>li>a').bind('click', function(event) {
			event.preventDefault();
			if ( $(this).parent('li').hasClass('project_gallery_active') == false ) {
				$('#project_gallery_id>li').removeClass('project_gallery_active');
				$(photo).each(function() {
					if ( $(this).css('opacity') > 0 ) {
						$(this).animate({'opacity':0}, 500);
					}
				}); 
				current_photo = $(this).parent('li').addClass('project_gallery_active').index();
				$(photo[current_photo]).animate({'opacity':1}, 500);
			}
		});
		
		if( $('#project_detail_img_id>img').length > 0 ) 
		{
			$(photo[0]).animate({'opacity':1}, 500);
			$('#project_gallery_id li:first-child').addClass('project_gallery_active');
		}
	}
	catch(err)
	{
		
	}
});

try
{
	$(window).resize($.debounce(1000, function() {
	   resizeBlocks(false);
	}));
	$(window).resize(function() {
	  resizeBlocks(false);
	});

}
catch(err)
{
	
}
