$(function() {
	// Options for SuperBGImage
	$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: 0, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: 1, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 90, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 1, // 0-none, 1-show title
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 6000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 'slow', // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: superbgimage_show, // function-callback show image
		//onClick: superbgimage_click, // function-callback click image
		onHide: superbgimage_hide, // function-callback hide image
		onMouseenter: superbgimage_mouseenter, // function-callback mouseenter
		onMouseleave: superbgimage_mouseleave, // function-callback mouseleave
		onMousemove: superbgimage_mousemove // function-callback mousemove
	};

	// initialize SuperBGImage
	$('#thumbs1').superbgimage();

});


// Function to toggle left right bound to arrow keys on keyboard
$(document).keydown(function(e){
    if (e.keyCode == 39) { 
	$('#thumbs').nextSlide();
       return false;
    }
});

$(document).keydown(function(e){
    if (e.keyCode == 37) { 
	$('#thumbs').prevSlide();
       return false;
    }
});

$(document).keydown(function(e){
    if (e.keyCode == 40) { 
	
       return false;
    }
});

// function callback on hiding image
function superbgimage_hide(img) {
	$('#showtitle').hide();
}

// function callback on showing image
// get title and display it
function superbgimage_show(img) {
	$('#superbgimage').css('background', 'none');
	//$('#superbgimage').append($('#showtitle'));
	$('#showtitle p.imagecount').html( + img + ' of ' + $.superbg_imgIndex);

	  $('.loadset').each(function(){
       	var myval = $(this).attr('value');
       	var myvals = $('#thumbs' + myval).css('display');
		
		if(myvals == 'block'){
		$('#showtitle span').html($('#thumbs' + myval + ' a' + "[rel='" + img + "']").html());
		$('#showtitle p.title').html($('#thumbs' + myval + ' a' + "[rel='" + img + "']").attr('title'));
			
			return false}
      });
	  
	$('#showtitle').fadeIn('fast');
	Cufon.replace('#showtitle', {fontFamily: 'Vista Sans OT Book',hover: true });
}

// function callback on clicking image, show next slide
function superbgimage_click(img) {
	$('#thumbs').nextSlide();
}

my_slideshowActive = false;

// function callback onmouseenter, stop slideshow, show pause-indicator
function superbgimage_mouseenter(img) {
	if ($.superbg_slideshowActive) {
		my_slideshowActive = true;
		if ($('#pause').length == 0) { 
			$('body').prepend('');
		}
		$('#pause').css('position', 'absolute').css('z-index', 3).show();
		return $('#thumbs').stopSlideShow();
	}
}

// function callback onmouseleave, start slideshow, hide pause-indicator
function superbgimage_mouseleave(img) {
	if (my_slideshowActive && ($('#pause').length > 0) && ($('#pause').css('display') == 'block'))  { 
		$('#pause').hide();
		return $('#thumbs').startSlideShow();
	}	
}

// function callback onmousemove, show and move pause-indicator
function superbgimage_mousemove(img, e) {
	if (my_slideshowActive && ($('#pause').length > 0)) { 
		$("#pause").css("top",(e.pageY + 20) + "px").css("left",(e.pageX + 20) + "px").show();
	}
}

 $(document).ready(function(){
	$("#content-container").css("display","none"); 
    $('.fadein').click(function(){
      //$('#candy').slideDown('slow');
	  $('#content-container').fadeIn("fast");
      return false;
    });
				$('#ourstorylink').click(function(){
			event.preventDefault();
			});
  });


 
  $(document).ready(function(){
    $('.fadeout').click(function(){
	  //$("#candy").css("display","none");
	  //$('#candy').hide("slide", {direction: 'down'}, 500);
	  $('#content-container').fadeOut("fast");

								 
    });
  });
$(document).ready(function(){
	$('#previous-container,#next-container').height(document.documentElement.clientHeight);
	$(window).resize(function(){$('#previous-container,#next-container').height(document.documentElement.clientHeight)});
    $('#previous-container').hover(function(){
 	$(this).find('a').toggleClass('prev-prehover');
	 
    },function(){
	$(this).find('a').toggleClass('prev-prehover');
	});

    $('#next-container').hover(function(){
 	$(this).find('a').toggleClass('next-prehover');
	 
    },function(){
	$(this).find('a').toggleClass('next-prehover');
	});

});


// service fade in script 
	
		$(function(){
			
			$("#advertising-button").css({
				opacity: 0.5
			});
			
			$("#marketing-button").css({
				opacity: 0.5
			});
			
			$("#design-button").css({
				opacity: 0.5
			});
			
			$("#web-button").css({
				opacity: 0.5
			});
			
			$("#strategy-button").css({
				opacity: 0.5
			});
			
			$("#print-button").css({
				opacity: 0.5
			});
			
			$("#interactive-button").css({
				opacity: 0.5
			});
			
			$("#environment-button").css({
				opacity: 0.5
			});
			
		
			$("#page-wrap div.button").click(function(){
				
				$clicked = $(this);
				
				// if the button is not already "transformed" AND is not animated
				if ($clicked.css("opacity") != "1" && $clicked.is(":not(animated)")) {
					
					$clicked.animate({
						opacity: 1,
						borderWidth: 5
					}, 600 );
					
					// each button div MUST have a "xx-button" and the target div must have an id "xx" 
					var idToLoad = $clicked.attr("id").split('-');
					
					//we search trough the content for the visible div and we fade it out
					$("#content").find("div:visible").fadeOut("fast", function(){
						//once the fade out is completed, we start to fade in the right div
						$(this).parent().find("#"+idToLoad[0]).fadeIn();
					})
				}
				
				//we reset the other buttons to default style
				$clicked.siblings(".button").animate({
					opacity: 0.5,
					borderWidth: 1
				}, 600 );
				
			});
			
		});
$(document).ready(function(){
	function loadCandy(){
	 $('#content-container').fadeIn("fast");
	}
	if(document.location.hash){
	var hash = document.location.hash;
	window.setTimeout(loadCandy,1000);
	$("a[href="+hash+"]").trigger('click');
	}
	function changeUrl(){
	$('.tabs-nav li a').bind('click',changeUrl);
	document.location.href = document.location.href.split('#')[0] + "#" + $(this).attr('href').split('#')[1];
	$(this).unbind('click',changeUrl);
	}
	$('.tabs-nav li a').bind('click',changeUrl);
});
