$(document).ready(function(){ 
	
	//open first accordion element
//	$('div.accordion:first').find('.text_wrapper').show().removeClass('open');
//	$('div.accordion:first').find('.csc-textpic').show().removeClass('open');
//	$('div.accordion:first').find('.wrapper_inner').show().removeClass('open');
	
	//accordion effect 
	$('div.accordion .csc-header').toggle(
		function(){
			$(this).addClass('open');
			$(this).next().slideToggle();
		},
		function(){
			$(this).removeClass('open');
			$(this).next().slideToggle();
		}
	);
	
	//cufon
	Cufon.replace('h1');
	Cufon.replace('#headline h2');
	Cufon.replace('ul.portfolio h2');
	Cufon.replace('ul.portfolio h4');
	Cufon.replace('#filter a');
	Cufon.replace('.press .header');
	Cufon.replace('.meta h4');
	Cufon.replace('.meta .overview a');
	Cufon.replace('.detail h2');
	Cufon.replace('#formhandler_contact_form h1');
	Cufon.replace('#languages a');
	
	//portfolio
	$('ul.portfolio a')
		.mouseover(function(){
			
			var pos = $(this).position();
			
			if( pos.left == 0 ){
				left = 236; 
			}else{
				left = pos.left-236;
			}
			
			$(this).next().css({
				left:left+'px',
				top:pos.top+'px'
			});
			$(this).next().show();
			
		})
		.mouseleave(function(){
			$(this).next().hide();
		});
	
	
	//portfolio navigation with cursor
	$(document).keydown(function(e){
		
		switch(e.keyCode){
			case 39: 
			case 40:
				if($('a.next').length > 0){
					link = $('a.next').attr('href');
					link = '/'+link;
					window.location = link;
				}
				break;
			case 37: 
			case 38:
				if( $('a.prev').length > 0 ){
					link = $('a.prev').attr('href');
					link = '/'+link;
					window.location = link;
				}
				break;				
		}

	});
	
	//gallery portfolio
	$('.thumbs a').click(function(e){

		var src = $(this).children('img').attr('src');
		$('.big img').attr('src', src);
		
		return false;
	});
	
	//coworker
	$('.worker a.image').click(function(e){
		
		//hide all
		$('.detail').hide();
		
		//add all workers toggle class
		//fading is binded to class="toggle"
		$('.worker a').addClass('toggle');
		$(this).removeClass('toggle');
		
		$('.toggle img').fadeTo('normal',.3);
		$(this).children('img').fadeTo('normal',1);
		
		//get position of textbox
		var pos 	= $(this).position();
		var detail 	= $(this).next();
		var left 	= pos.left + $(this).width();
		
		if( pos.left > 470 ){
			left = pos.left - ($(this).width()*2);
		}
		
		detail.css({left:left});

		$(this).next().show();
		
		return false;
	});
	
	$('.worker .close').click(function(){
		$(this).parent().hide();
		$(this).parent().prev().addClass('toggle');
		$('.toggle img').fadeTo('normal',1);
		return false;
	});
	
	//show ie6 notice
	if( $.browser.msie && $.browser.version < 7 ){
		$('#ie6').show();
	}
	
});

function debug(v){
	console.log(v);
}
