$(document).ready(function() {
	
	
	$('#fblikes').hover(function() {
		$('#likebutton').stop(true).animate({opacity:1}, 100) ;
	}, function() {
		$('#likebutton').stop(true).animate({opacity:0}, 100) ;
	}) ;

	$('#prev').click(function() {
	alert('prev');
		$('#prevBtn').trigger('click') ;
	}) ;
	
	
	var ie = 'false' ;
	
	if($.browser.msie)
	{
		var ie = 'true' ;
	}
	
	$.ajax({
	url: 'blog.php', 
	data: {ie: ie},
	type: "GET",
	cache: false,
	success: function(data) {
		$('#blog').append(data) ;
		
		
		
		//$('#blogscroll_container').overscroll();
		
		$('.blogloader').animate({opacity:0});
		$('#blogscroll_container').animate({opacity: 1}) ;
		
		$("#blogscroll_container").easySlider({
			auto: false,
			continuous: true ,
			speed:400,
			prevText:'',
			nextText:''
		});
		
	}}) ;
	

	switch(window.location.hash) {
	case '#gowork' : $('#content_scroller').scrollTo('#showcase', '300', {easing: 'easeInOutExpo'});
					break;
	case '#goabout' : $('#content_scroller').scrollTo('#about', '300', {easing: 'easeInOutExpo'});
	break;
	
	case '#gocontact' : $('#content_scroller').scrollTo('#contact', '400', {easing: 'easeInOutExpo'});
	break;
	
	case '#goimpress' : $('#content_scroller').scrollTo('#impress', '200', {easing: 'easeInOutExpo'});
	break;
	
	case '#goblog' : $('#content_scroller').scrollTo('#blog', '500', {easing: 'easeInOutExpo'});
	break;
	
	}
	
	
	$('#work').click(function() {
		
		$('#close_detail').trigger('click') ;
		$('#content_scroller').scrollTo('#showcase', '300', {easing: 'easeInOutExpo'});
		//$('#showcase').delay(300).animate({opacity: 1 }, 500) ;
		
		window.location.hash = 'gowork' ;
		
		
		return false ;
	}) ;
	
	$('#logolink').click(function() {
		
		$('#content_scroller').scrollTo('0px', '300', {easing: 'easeInOutExpo'});
		
		window.location.hash = 'gotop' ;
		return false ;
	}) ;
	
	$('#aboutlink').click(function() {
		//alert($('#about').position().top+'px') ;
		$('#content_scroller').scrollTo('#about', '300', {easing: 'easeInOutExpo'});
		//$('#about').delay(300).animate({opacity: 1 }, 500) ;

		window.location.hash = 'goabout' ;
		
		
		return false ;
	}) ;
	

	$('#bloglink').click(function() {
		
		$('#content_scroller').scrollTo('#blog', '200', {easing: 'easeInOutExpo'});
		
		window.location.hash = 'goblog' ;
		
		return false ;
	}) ;
	
	
	$('#contactlink').click(function() {
		
		$('#content_scroller').scrollTo('#contact', '200', {easing: 'easeInOutExpo'});
		
		window.location.hash = 'gocontact' ;
		return false ;
	}) ;
	
	
	$('#impresslink').click(function() {
		
		$('#content_scroller').scrollTo('#impress', '200', {easing: 'easeInOutExpo'});
		
		window.location.hash = 'goimpress' ;
		
		return false ;
	}) ;
	
	
	//$('#blogscroller').jScrollPane();
	
	
	/*
	 * ABOUT STUFF
	 */
	

	
	$('.person_foto').hover(function() {
		
		//$(this).css('background-image', 'url(img/niklas2.jpg)') ;
		//$(this).children('.overlay').stop(true).animate({opacity: 1}, 'easeInOutExpo') ;
		
		//$(this).children('.overlay').stop(true).animate({height: 352}, 450, 'easeOutExpo') ;
		$(this).children('.overlay').stop(true).animate({width: 472}, 450, 'easeOutExpo') ;
		
	}, function() {
		
		$(this).children('.overlay').stop(true).animate({width: 0}, 600, 'easeOutExpo') ;	
		//$(this).children('.overlay').stop(true).animate({height: 0}, 600, 'easeInOutQuint') ;	
		//$(this).children('.overlay').stop(true).animate({opacity: 0}, 'easeInOutExpo') ;
		
	}) ;
	
	
	
	/*
	 * CONTACT FORM STUFF
	 */
	
	$('input[type="text"]').each(function() {
	
		$(this).val($(this).attr('title')) ;
		$(this).addClass('label_in')
		
		$(this).focus(function() {
			$(this).removeClass('label_in')
			
			if($(this).attr('title') == $(this).val())
			{
				$(this).val('') ;
			}
		}) ;
		
		$(this).blur(function() {
			if($(this).val() == '')
			{
				$(this).val($(this).attr('title')) ;
				$(this).addClass('label_in')
			}
		}) ;
		
	}) ;
	
	$('textarea').each(function() {
		
		$(this).val($(this).attr('title')) ;
		$(this).addClass('label_in')
		
		$(this).focus(function() {
			$(this).removeClass('label_in')
			
			if($(this).attr('title') == $(this).val())
			{
				$(this).val('') ;
			}
		}) ;
		
		$(this).blur(function() {
			if($(this).val() == '')
			{
				$(this).val($(this).attr('title')) ;
				$(this).addClass('label_in')
			}
		}) ;
		
	}) ;
	
	
	/*
	 * NAVI STUFF
	 */
	
	$('.navilink').mouseenter(function() {
		var pos = $(this).position() ;
		var width = $(this).width() ;
		
		$('#navi_and').stop(true).animate({left: pos.left+6+width/2}, 500, 'easeOutExpo') ;
		
	}) ;
	
	$('#navi').mouseleave(function() {
		$('#navi_and').stop(true).delay(300).animate({left: 580}, 500, 'easeOutExpo') ;
		//$('#navi_and').delay(1000).animate({left: 705}, 60000) ;
	}) ;
	
	
	
	var and_at_cursor = false ;
	
	$('#navi_and_container').mouseenter(function(e) {

		if((e.pageX - this.offsetLeft + 122) > 940)
		{
			var pos = 940-244 ;
		}
		else
		{
			if(e.pageX - this.offsetLeft < 244)
			{
				var pos = 0 ;
			}
			else
			{
				var pos = e.pageX - this.offsetLeft-244 ;
			}
		}
		
		
		$('#navi_and').stop(true).animate({left: pos}, 100).queue(function() {
			and_at_cursor = true ;
		}) ;
	}) ;	
	
	$('#navi_and_container').mouseleave(function(e) {
		$('#navi_and').stop(true).delay(300).animate({left: 580}, 500, 'easeOutExpo') ;
		and_at_cursor = false ;
	}) ;
		
	$('#navi_and_container').mousemove(function(e) {
		if(and_at_cursor == true)
		{
			
			if((e.pageX - this.offsetLeft + 0) > 940)
			{
				
				var pos = 940-244 ;
			}
			else
			{
				if(e.pageX - this.offsetLeft < 244)
				{
					var pos = 0 ;
				}
				else
				{
					var pos = e.pageX - this.offsetLeft-244 ;
				}
			}
			
			
			
			
			//alert(e.pageX - this.offsetLeft) ;
			$('#navi_and').css({left: pos}) ;
		}
	}) ;
	
	
	
	
	
	/*
	 * SHOWCASE STUFF 
	 */
	
	
	var open = 1 ;
	
	$('#showcase_img_1').click(function() {
		if(open != 1)
		{
			$('#showcase_img_'+open).trigger('shrink') ;
			$('#showcase_img_1').stop(true).animate({height: 580, width: 558, top: 25, left: 0}, 400, 'easeOutQuint') ;
			$('#showcase_img_1').css({cursor: 'default'}) ;
			open = 1 ;
		}
	}) ;
	
	$('#showcase_img_2').click(function() {
		if(open != 2)
		{
			$('#showcase_img_'+open).trigger('shrink') ;
			$('#showcase_img_2').stop(true).animate({height: 580, width: 558, top: 25, left: 0}, 400, 'easeOutQuint') ;
			$('#showcase_img_2').css({cursor: 'default'}) ;
			open = 2 ;
		}
	}) ;
	
	$('#showcase_img_3').click(function() {
		if(open != 3)
		{
			$('#showcase_img_'+open).trigger('shrink') ;
			$('#showcase_img_3').stop(true).animate({height: 580, width: 558, top: 25, left: 0}, 400, 'easeOutQuint') ;
			$('#showcase_img_3').css({cursor: 'default'}) ;
			open = 3 ;
		}
	}) ;
	
	
	$('#showcase_img_1').bind('shrink', function() {
		$('#showcase_img_1').stop(true).animate({height: 175, width: 175, top: 25, left: 580}, 300, 'easeOutQuint') ;
		$('#showcase_img_1').css({cursor: 'pointer'}) ;
	}) ;
	
	$('#showcase_img_2').bind('shrink', function() {
		$('#showcase_img_2').stop(true).animate({height: 175, width: 175, top: 227, left: 580}, 300, 'easeOutQuint') ;
		$('#showcase_img_2').css({cursor: 'pointer'}) ;
	}) ;
	
	$('#showcase_img_3').bind('shrink', function() {
		$('#showcase_img_3').stop(true).animate({height: 175, width: 175, top: 430, left: 580}, 300, 'easeOutQuint') ;
		$('#showcase_img_3').css({cursor: 'pointer'}) ;
	}) ;
	
	
	
	$('.showcase_trigger').click(function() {
		
		var id = $(this).attr('id') ;
		var title = $('#ref_'+id).attr('title') ;
		
		$('#ref_'+id).stop();
		$(this).trigger('mouseleave') ;
		
		$('#close_detail').css({opacity: 0}) ;
		$('#showcase_detail').css('display', 'block').animate({opacity: 1}, 500, 'easeOutQuint') ;
		
		$.ajax({url: 'get_details.php', data: {title: title}, type: 'POST', dataType: 'json', cache: false, success: function(data) {

			
			
			$('#showcase_detail_loader').stop(true).animate({opacity:0}).queue(function() {
				$('#showcase_detail_loader').css('display', 'none') ;
				$('#showcase_desc').html(data.desc).animate({opacity: 1}) ;
				
				$('#close_detail').animate({opacity: 1}) ;
				
				if(typeof data.images[1] != 'undefined')
				{
				
				$('#showcase_img_1')
				.css({'background-image': 'url('+data.images[1].img+')', 'background-position': data.images[1].pos, display: 'block'}).delay(200).animate({opacity: 1}) ; 
				}
				
				if(typeof data.images[2] != 'undefined')
				{
				$('#showcase_img_2')
				.css({'background-image': 'url('+data.images[2].img+')', 'background-position': data.images[2].pos, display: 'block'}).delay(400).animate({opacity: 1}) ;
				}
				
				if(typeof data.images[3] != 'undefined')
				{
				$('#showcase_img_3')
				.css({'background-image': 'url('+data.images[3].img+')', 'background-position': data.images[3].pos, display: 'block'}).delay(600).animate({opacity: 1}) ;
				}
				
			
			}) ;
		}}) ;
		
	});
	
	$('#close_detail').click(function() {
		$('#showcase_detail').animate({opacity: 0}, 500, 'easeOutQuint').queue(function() {
			$('#showcase_detail').css('display', 'none').stop(); ;
			$('#showcase_detail_loader').css({opacity: 1, display: 'block'}) ;
			$('#showcase_img_1').css({opacity: 0, display: 'none', top: 25, left: 0, width: 558, height: 580, cursor: 'default'}) ;
			$('#showcase_img_2').css({opacity: 0, display: 'none', top: 227, left: 580, width: 175, height: 175, cursor: 'pointer'}) ;
			$('#showcase_img_3').css({opacity: 0, display: 'none', top: 430, left: 580, width: 175, height: 175, cursor: 'pointer'}) ;
			$('#showcase_desc').css({opacity: 0}) ;
			open = 1 ;
		}) ;
	}) ;
	
	
	$('.showcase_trigger').mouseenter(function() {
		var id = $(this).attr('id') ;
		var position = $(this).position() ;
		
		//$('#ref_'+id).css({'box-shadow': '0px 0px 8px #000', '-webkit-box-shadow': '0px 0px 8px #000', '-moz-box-shadow': '0px 0px 8px #000'});

		//alert('enter') ;
		
		//$('#ref_'+id+'_bw').stop(true).animate({opacity:0}, 400, 'easeOutQuad') ;
		$('#ref_'+id).children('.showcase_fade').remove() ;
		
		var top = 175-$('#ref_'+id).children('.showcase_info').height()
		$('#ref_'+id).children('.showcase_info').stop(true).animate({top: top+'px'}, 200, 'easeOutQuad') ;

		
		$('#ref_'+id).append('<div class="showcase_fade"></div>') ;
		$('#ref_'+id).children('.showcase_fade').stop(true).animate({opacity:0.5}, 400, 'easeOutQuad') ;
		
	}) ;
	
	$('.showcase_trigger').mouseleave(function() {
		var id = $(this).attr('id') ;
		var position = $(this).position()
		
		$('#ref_'+id).children('.showcase_info').stop(true).animate({top: '175px'}, 300, 'easeOutQuad') ;
		
		//$('#ref_'+id+'_bw').stop(true).animate({opacity:1}, 400, 'easeOutQuad') ;
		
		$('#ref_'+id).children('.showcase_fade').stop(true).animate({opacity:0}, 400, 'easeOutQuad').queue(function() {
			$('#ref_'+id).children('.showcase_fade').remove() ;
		}) ;
		
		


	}) ;
		

	
}) ;
