$(function () {
			var tab_offerings = $('div#offerings > div'); var opened_offer = (window.location.hash);
			if (opened_offer == "")
			{
				tab_offerings.hide().filter(':first').show(); $('div#offerings ul.tabNavigation a:first').addClass('selected');
			}
			else
			{
				tab_offerings.hide().filter(opened_offer).show(); $('div#offerings ul.tabNavigation a[href='+opened_offer+']').addClass('selected');
			}			
			$('div#offerings ul.tabNavigation a').click(function () {
				tab_offerings.hide();
				tab_offerings.filter(this.hash).show();
				$('div#offerings ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			});
		});
		
		$(function () {
			var tab_expertise = $('div#expertise > div'); var opened_expertise = (window.location.hash);
			if (opened_expertise == "")
			{
				tab_expertise.hide().filter(':first').show(); $('div#expertise ul.tabNavigation a:first').addClass('selected');
			}
			else
			{
				tab_expertise.hide().filter(opened_expertise).show(); $('div#expertise ul.tabNavigation a[href='+opened_expertise+']').addClass('selected');
			}			
			$('div#expertise ul.tabNavigation a').click(function () {
				tab_expertise.hide();
				tab_expertise.filter(this.hash).show();
				$('div#expertise ul.tabNavigation a').removeClass('selected');
				$(this).addClass('selected');
				return false;
			});
		});
		
		
		
		$(document).ready(function () {
    $(".toggle_container").hide();
        $("div h3.trigger").click(function () {
            $(this).toggleClass("active").next().slideToggle("slow");
        });
    });
	
	
	$('.sitemap ul ul li:nth-child(3n)').after('<li class="clear" style="width:95%;"></li>');
	
	$(".brief_proj").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
	$(document).ready(function(){
	$("a[rel=gallery]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			
			
	$('.project_thumb a').hover(function(){
		$(this).find('span').fadeIn(400);
	},function(){
		$(this).find('span').fadeOut(300);
	});
})


$(window).load(function(){
	$('#iphone #main_image').append('<div class="preloader"></div>');
	var strip_width = $('#iphone .filmstrip').outerWidth();
	$('#iphone .filmstrip').css({'margin-left': -strip_width/2,'visibility':'visible'});
	$('#iphone .filmstrip li:first-child img').addClass('current');
	$('#iphone .filmstrip img').click(function(){
		$('#iphone .filmstrip img').removeClass('current');
		
		if($('#iphone #main_image .projet_main_image').attr('src') == $(this).attr('class'))
		{
		}
		else
		{
			$('#iphone .preloader').css('display','block');
			//$('#iphone #main_image img').attr('src',$(this).attr('rel'));		
			$('#iphone #main_image .projet_main_image').load( function() {			
			$('#iphone .preloader').css('display','none');			
			}).attr('src', $(this).attr('class'));		
		}
		
		$('#iphone #main_image a').hide();
		var my_id = $(this).attr("id");
		//alert (my_id);
		$('#main_'+my_id).show();
		
		$(this).addClass('current');
	})
	
	var thumbs = $('#iphone .filmstrip ul');
	var init_margin = parseInt($('#iphone .filmstrip ul').css('margin-left'));
	
	thumbs.wrap('<div id="thumbs_scroller"></div>');
	$('#thumbs_scroller').css({'width': thumbs.width(), 'height': thumbs.find('img').outerHeight(), 'overflow':'hidden'});
	thumbs.css({'width': ($('#iphone .filmstrip li').length*74)-5});
	
	if(thumbs.width() <= 291)
	{
		$('#iphone .prev_image').hide();
		$('#iphone .next_image').hide();
	}
	
	$('#iphone .prev_image').click(function(){		
		var current_margin = (parseInt($('#iphone .filmstrip ul').css('margin-left')));
		if(current_margin<=-73)
		{
			$('#iphone .filmstrip ul').animate({'margin-left':current_margin+74}, 200);
		}
	})
	
	$('#iphone .next_image').click(function(){		
		var current_margin = -(parseInt($('#iphone .filmstrip ul').css('margin-left')));
		var max_width = -(parseInt($('#iphone .filmstrip ul').outerWidth())-(parseInt($('#iphone #thumbs_scroller').outerWidth())+73));
		if(-current_margin>= max_width)
		{
			$('#iphone .filmstrip ul').animate({'margin-left':-(current_margin+74)}, 200);
		}
	})
})
