jQuery(document).ready(function()
{
	// IF SMALLER THEN 1200 ACTIVE AUTO HIDE
	if(jQuery(window).width() <= 1200)
	{
		if(jQuery('#floatmenu').hasClass('hide') == false)
		{
			jQuery('#floatmenu').animate({"left": "-152px"},"slow","linear");	
		}
		if(jQuery('#floatmenu').attr("onmouseout") == null)
		{
			jQuery('#floatmenu').attr("onmouseout","fixOnMouseOut(this, event, 'floatout()');");
		}
	}
	 var thumbsHeight = jQuery('#workthumbs').innerHeight();
	/* ------------------------------------------------------------------ 
	*
	* SET PROPS
	*
	 ------------------------------------------------------------------*/
	 jQuery("#sidebar").css("height", (jQuery(document).height()-57));
	 jQuery(".person").css("opacity","0.5");
	 jQuery(".linkedin").css("opacity","0.5");
	 jQuery("#uparrow").css("opacity","0");
	 jQuery('#workthumbs').css("height","768px");
	/* ------------------------------------------------------------------ 
	*
	* HANDLE VARS
	*
	 ------------------------------------------------------------------*/
	 var imageInterval;
	/* ------------------------------------------------------------------ 
	*
	* HANDLE LINKED IN BALLOONS AND HOME
	*
	 ------------------------------------------------------------------*/
	function movepersonout()
	{
		clearTimeout(imageInterval);
		/*jQuery("#Dries").fadeTo("fast",0.5);
		jQuery("#Bert").fadeTo("fast",0.5);
		jQuery("#Pieter").fadeTo("fast",0.5);*/
		jQuery(".person").fadeTo("fast",0.5);
		jQuery('.balloon').fadeTo("fast",0);
	}
	
	jQuery(".person").mouseout(function()
	{
		imageInterval=setTimeout(function () {movepersonout();},2000);
	});
	
	jQuery("#clientzone").mouseover(function()
	{
		jQuery(".clientlink").addClass('trigger');
	})
	
	jQuery("#clientzone").mouseout(function()
	{
		jQuery(".clientlink").removeClass('trigger');
	})
	
	jQuery(".person").mouseover(function()
	{
		clearTimeout(imageInterval);
		jQuery(this).fadeTo("fast",1);
		jQuery('.balloon p').text(jQuery(this).attr('id'));
		jQuery('.balloon').fadeTo("fast",1);
		switch(jQuery(this).attr('id'))
		{
			case 'Pieter':
				jQuery("#Dries").fadeTo("fast",0.5);
				jQuery("#Bram").fadeTo("fast",0.5);
				jQuery("#Bert").fadeTo("fast",0.5);
				jQuery(".balloon").css( "margin-left", "755px");
			break;
			case 'Dries':
				jQuery("#Pieter").fadeTo("fast",0.5);
				jQuery("#Bert").fadeTo("fast",0.5);
				jQuery("#Bram").fadeTo("fast",0.5);
				jQuery(".balloon").css( "margin-left", "795px");
			break;
			case 'Bert':
				jQuery("#Dries").fadeTo("fast",0.5);
				jQuery("#Pieter").fadeTo("fast",0.5);
				jQuery("#Bram").fadeTo("fast",0.5);
				jQuery(".balloon").css( "margin-left", "835px");
			break;
			case 'Bram':
				jQuery("#Dries").fadeTo("fast",0.5);
				jQuery("#Bert").fadeTo("fast",0.5);
				jQuery("#Pieter").fadeTo("fast",0.5);
				jQuery(".balloon").css( "margin-left", "875px");
			break;
		}
	});
	// IN THE PICTURE
	jQuery('#inthepicture').click(function()
	{
		document.location = jQuery('#inthepicture #description .title').attr('href');
	});
	
	jQuery(".linkedin").mouseover(function()
	{
		jQuery(this).fadeTo("fast",1);
	});
	
	jQuery(".linkedin").mouseout(function()
	{
		jQuery(this).fadeTo("fast",0.5);
	});
	/* ------------------------------------------------------------------ 
	*
	* HANDLE LAVAGOODIE
	*
	 ------------------------------------------------------------------*/
	 if (window.location.toString().indexOf("/lavagoodie/") >0)
	{
		slidePage('goodie');
    }
	/* ------------------------------------------------------------------ 
	*
	* HANDLE WORK
	*
	 ------------------------------------------------------------------*/ 			 
	if (window.location.toString().indexOf("/work") >=0 || window.location.toString().indexOf("/projecten") >=0)
	{
		slidePage('work');
		jQuery("#workthumbs .thumb a").each(function()
		{
			jQuery(this).attr("href",jQuery(this).attr("href")+"/reload");
		});
    }
    
	jQuery(".slide").click(function()
	{
		slidePage('work');	
	});
	
	if(window.location.toString().indexOf("/reload/all") >0)
	{
		jQuery('#loadmore').hide();
		jQuery('#workthumbs').css("height","auto");
		jQuery("#workthumbs .thumb a").each(function()
		{
			jQuery(this).attr("href",jQuery(this).attr("href")+"/all");
		});
	}
	
	 //alert(thumbsHeight);
	jQuery("#loadmore").click(function()
	{
		jQuery("#workthumbs .thumb a").each(function()
		{
			jQuery(this).attr("href",jQuery(this).attr("href")+"/all");
		});
		
		jQuery(this).hide();
		jQuery('#workthumbs').animate({"height":thumbsHeight+"px"},"slow","linear");
	});
	/* ------------------------------------------------------------------ 
	*
	* HANDLE PLAYGROUND
	*
	 ------------------------------------------------------------------*/
	if (window.location.toString().indexOf("/playground") >0)
	{
		if (window.location.hash) 
		{
			jQuery.scrollTo('#'+window.location.hash.substr(1), 1000);
		}
		
		jQuery('.playground #footer #top').click(function()
		{
		
			jQuery('html, body').animate({scrollTop:0}, 'slow');
		});
	
		if(jQuery('#floatmenu').length != 0)
		{
		 // MADE A GLOBAL
		}
	}
	
	/* ------------------------------------------------------------------ 
	*
	* HANDLE FLOAT MENU
	*
	 ------------------------------------------------------------------*/	 
	 var name = "#floatmenu";
	 var menuYloc = null;
	 menuYloc = parseInt(jQuery(name).css("top").substring(0,jQuery(name).css("top").indexOf("px")))
	 jQuery(window).scroll(function ()
	  { 
	   	var offset = menuYloc+jQuery(document).scrollTop()+"px";
	  	jQuery(name).animate({top:offset},{duration:500,queue:false});
	 });

	 
	 jQuery('#floatmenu').hover(function()
	 {
	 		if(jQuery('#floatmenu').offset().left == -152)
	 		{
	 			jQuery('#floatmenu').animate({"left": "0px"},"slow","linear");
	 		}
	 });	 	
});

var onHomepage;
/* ------------------------------------------------------------------ 
* HANDLE WORK FUNCTIONS
------------------------------------------------------------------*/	 	
function slidePage(page)
{		
	var fade_arr = ['#header', '#slideshow', '#workthumbs'];
		
	for(var i=0; i<fade_arr.length; i++)
	{
		jQuery('#work '+fade_arr[i]).fadeTo(0,1);
	}
	
	if(window.location.toString().indexOf("/reload") >0 && jQuery('#floatmenu ul li:first').hasClass('selected') !='')
	{	
		// HANDLE THE ABOVE REQUEST IN THE HEADER
		jQuery("#uparrow").fadeTo(0,1);
		jQuery.scrollTo('#work', 1000);
		initPage();
	}
	else{
		jQuery("#paper").animate({"top": "-1290px"},"slow","linear",initPage());
		jQuery("#uparrow").fadeTo("fast",1);
		if(jQuery(window).width() >1200)
		{
			setTimeout('showFloat()', 1000);
			if(onHomepage == true)
			{
				jQuery('#floatmenu').removeAttr('onmouseout');
			}
		}
	}			
	if(page=='projecten')
	{
		jQuery('#floatmenu ul li a.selected').removeClass('selected');
		jQuery('#floatmenu ul li a#projecten').addClass('selected');
		
		if(jQuery(window).width() >1200)
 		{
 			//jQuery('#floatmenu').removeAttr('onmouseout');
			//jQuery('#floatmenu').animate({"left": "0px"},"slow","linear");
		}
		
		document.title = prev_title;
		// CHECK IF LOAD ALL
		if(jQuery("#workthumbs.thumbs .thumb:first a").attr('href').indexOf("/reload/all") > 0) // SHOW EXTRA ITEMS
		{
			jQuery("#loadmore").trigger('click');
		}
	}
	else if(window.location.toString().indexOf("/lavagoodie/") >0)
	{
		jQuery('#floatmenu ul li:first a').attr('href','javascript:bringmeHome();');
		setTimeout('saySome()', 1500);
	} 	
	onHomepage = false;		
}
	
function initPage()
{	
	jQuery("#paper-bottom").css("cursor", "pointer");
	showControllers();
	jQuery("#paper-bottom").click(function()
	{
		bringmeHome();
	});
}
	
var prev_title = document.title;
	
function exitPage()
{
	document.title = "Lavagraphics - Grafisch Ontwerp en Webdesign";
}
	
function hideControllers()
{
	jQuery('.scrollButtons').css("display","none");
}
	
function showControllers()
{
	jQuery('.scrollButtons').css("display","block");
}
	
	
function saySome()
{
	jQuery("#floatmenu").addClass('goodie');
	if(jQuery(window).width() >1200)
	{
		setTimeout('showFloat()', 1000);
	}
	
}
	
function showFloat()
{
	jQuery('#floatmenu').animate({"left": "0px"},"slow","linear");
}
	
function bringmeHome()
{	
	// CLOSE MORE ITEMS
	onHomepage = true;
	jQuery('#workthumbs').animate({"height":"768px"},"slow","linear");		 
	jQuery("#paper").animate({"top": "15px"},"slow","linear",exitPage());
	jQuery(this).unbind('click');
	jQuery(this).css("cursor", "default");
	jQuery("#uparrow").fadeTo("fast",0);
	// ADD FLOATMENU SCRIPTS
	jQuery('#floatmenu').animate({"left": "-152px"},"slow","linear");
	jQuery('#floatmenu ul li a.selected').removeClass('selected');
	jQuery('#floatmenu ul li:first a').addClass('selected');
	if(window.location.toString().indexOf("/lavagoodie/") <=0)
	{
		jQuery('a#projecten').attr('href', "javascript:slidePage('projecten');");
		jQuery('#part3 h3 a').attr('href', jQuery('a#projecten').attr('href'));
	}else
	{
		jQuery("#floatmenu").removeClass('goodie');
		exitPage();
	}
	
	if(jQuery('#floatmenu').attr("onmouseout") == null)
	{
		jQuery('#floatmenu').attr("onmouseout","fixOnMouseOut(this, event, 'floatout()');");
	}
}
