/* Anything slider */

$(document).ready(function(){
	/* Fade page */
	//$('#wrapper').css({'display' : 'none'});
	//$('#wrapper').fadeIn(600);
	/* The sliders */
	$('#slider').add("#slider-detail").anythingSlider({
		// Appearance
		width               : 782,      // Override the default CSS width
		height              : 425,      // Override the default CSS height
		resizeContents      : true,      // If true, solitary images/objects in the panel will expand to fit the viewport
		tooltipClass        : 'tooltip', // Class added to navigation & start/stop button (text copied to title if it is hidden by a negative text indent)
		theme               : 'default', // Theme name
		themeDirectory      : null, // Theme directory & filename {themeName} is replaced by the theme value above
		// Navigation
		startPanel          : 1,         // This sets the initial panel
		hashTags            : false,      // Should links change the hashtag in the URL?
		enableKeyboard      : true,      // if false, keyboard arrow keys will not work for the current panel.
		buildArrows         : false,      // If true, builds the forwards and backwards buttons
		toggleArrows        : false,     // if true, side navigation arrows will slide out on hovering & hide @ other times
		buildNavigation     : true,      // If true, builds a list of anchor links to link to each panel
		enableNavigation    : true,      // if false, navigation links will still be visible, but not clickable.
		toggleControls      : false,     // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
		appendControlsTo    : "#navi",      // A HTML element (jQuery Object, selector or HTMLNode) to which the controls will be appended if not null
		navigationFormatter : function(index, panel){ return "<span>"+index+"</span>"; },      		// Details at the top of the file on this use (advanced use)
		forwardText         : "&raquo;", 	// Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
		backText            : "&laquo;", 	// Link text used to move the slider back (hidden by CSS, replace with arrow image)
		
		// Slideshow options
		enablePlay          : true,      // if false, the play/stop button will still be visible, but not clickable.
		autoPlay            : true,      // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
		autoPlayLocked      : true,     // If true, user changing slides will not stop the slideshow
		startStopped        : false,     // If autoPlay is on, this can force it to start stopped
		pauseOnHover        : true,      // If true & the slideshow is active, the slideshow will pause on hover
		resumeOnVideoEnd    : true,      // If true & the slideshow is active & a youtube video is playing, the autoplay will pause until the video completes
		stopAtEnd           : false,     // If true & the slideshow is active, the slideshow will stop on the last page
		playRtl             : false,     // If true, the slideshow will move right-to-left
		startText           : "",   			// Start button text
		stopText            : "",    			// Stop button text
		delay               : 8000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
		resumeDelay         : 15000,     // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
		animationTime       : 1200,       // How long the slideshow transition takes (in milliseconds)
		easing              : "easeInOutQuart",   // Anything other than "linear" or "swing" requires the easing plugin
		
		// Callbacks
		onBeforeInitialize  : null,      // Callback before the plugin initializes
		onInitialized       : function(slider){ Cufon.refresh(); },      // Callback when the plugin finished initializing
		onShowStart         : null,      // Callback on slideshow start
		onShowStop          : null,      // Callback after slideshow stops
		onShowPause         : null,      // Callback when slideshow pauses
		onShowUnpause       : null,      // Callback when slideshow unpauses - may not trigger properly if user clicks on any controls
		onSlideInit         : null,      // Callback when slide initiates, before control animation
		onSlideBegin        : null,      // Callback before slide animates
		onSlideComplete     : null,      // Callback when slide completes
		
		// Interactivity
		clickArrows         : "click",         // Event used to activate arrow functionality (e.g. "click" or "mouseenter")
		clickControls       : "click focusin", // Events used to activate navigation control functionality
		clickSlideshow      : "click",         // Event used to activate slideshow play/stop button
		
		// Misc options
		addWmodeToObject    : "opaque", // If there is an embedded object & swfobject.js is active, the script will automatically add this wmode parameter
		maxOverallWidth     : 32766     // Max width (in pixels) of combined sliders (side-to-side); set to 32766 to prevent problems with Opera
	});
	
	/* Bind events to Anythingslider callbacks */	
	$('#slider').bind('slide_begin', function(e, slider){
		$('#slider_caption h2').fadeOut(200);
	});
	$('#slider').bind('slide_complete', function(e, slider){
		var currentImg = slider.$currentPage.find("img");
		$('#slider_caption h2').html(currentImg.attr('title'));
		Cufon.refresh('h2', $("#slider_caption"));
		$('#slider_caption h2').fadeIn(200);
 	});
	/* Bind events to Anythingslider callbacks for the work detail slider */	
	$('#slider-detail').bind('slide_begin',function(e, slider){
		$('.fade_caption').stop(true,true).fadeOut(200);
	});
	/* Crossfade awards */
	$('#ribbons ul li').css({'display':'none', 'position':'absolute', 'top':'0', 'left':'0'});
		var all=$('#ribbons ul li').size();
		var n=0;
		$('#ribbons ul li:eq('+n+')').fadeIn('slow');
		(function crossFade() {
		  setTimeout(function() {
		      $('#ribbons ul li:eq('+n+')').fadeOut(400,function () {
		      	(n+1 == all)? n=0: n++;
		      	$('#ribbons ul li:eq('+n+')').fadeIn(400);
		      });
		      crossFade();
		  }, 8000);
	})();
	/* Animated boxes */
	/* Project boxes */
	$(".project_box").hover(function(){
		$(this).removeClass('project_box').addClass('project_box_over');
		$(this).find('li.client').stop(true,true).css({visibility:'visible',left:'-250px'});
		$(this).find('li.client').animate({left:'0'},200);		
	}, function(){
		$(this).removeClass('project_box_over').addClass('project_box');
		$(this).find('li.client').stop(true,true).animate({left:'251px'},200);
	});
	/* Services boxes */
	$(".services_box").mouseenter(function(){
		$(this).removeClass('services_box').addClass('services_box_over');
		Cufon.refresh('h5', $(this));
		$(this).find('p.copy').stop(true,true).delay(50).fadeIn('fast');
		$(this).find('div.slide').stop(true,true).animate({marginTop:'-110'}, 200, 'easeOutQuint');	
	});
	$(".services_box").mouseleave(function(){
		var slide = $(this).find('div.slide');
		$(this).removeClass('services_box_over').addClass('services_box');
		Cufon.refresh('h5', $(this));
		$(this).find('p.copy').stop(true,true).fadeOut('fast',function(){
			$(this).parent().stop(true,true).animate({marginTop:'0'}, 200, 'easeOutQuint');
		});	
	});
	/* Work finder */
	$("#work_finder").click(function(){
		$('#work_finder_panel').find('.inner').css({'display' : 'none'});
		$("#work_finder_panel").slideToggle("slow", function(){
			$('#work_finder_panel').load('test.php', function(){
				$('#work_finder_panel').find('.inner').stop(true,true).fadeIn('fast');
			});
		});
	});
	/* The video link */
	$("a.vimeo").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor' 		: '#111',
			'padding'		: 0,
			'title'			: 0,
			'width'			:	600,
			'height'		: 338,
			'type'			: 'iframe'
	});
	/* Flash attachment links */
	$("a.flash_attachment").fancybox({
			'overlayOpacity'	: 0.8,
			'overlayColor' 		: '#111',
			'padding'		: 0,
			'title'			: 0,
			'type'			: 'swf'
	});
	/* Contact pulldown link */
	$('a.contact_link').click(function(e){
		e.preventDefault();
		$('html, body').animate({scrollTop:0}, 'slow');
		if($("#contact_pulldown").hasClass("closed")) {
			$("#contact_pulldown").animate({marginTop:'0'});
			$("#contact_pulldown").removeClass("closed").addClass("open");
		} else {
			$("#contact_pulldown").animate({marginTop:'-560'});
			$("#contact_pulldown").removeClass("open").addClass("closed");		
		}
	});
	$("#map_close").click(function(){
		$("#contact_pulldown").animate({marginTop:'-560'});
		$("#contact_pulldown").removeClass("open").addClass("closed");
	});
	/* Work dropdown */
	$(".dropdown").mouseenter(function(){
		$(this).find('ul').fadeIn(0);
		$(this).addClass('dropdown_over');
		//$('#veil').css({'height' : $(document).height(), 'opacity' : 0.8});
		//$('#veil').stop(true, true).delay(100).fadeIn(200);
	});
	$(".dropdown").mouseleave(function(){
		$(this).find('ul').fadeOut(0);
		$(this).removeClass('dropdown_over');
		//$('#veil').stop(true, true).fadeOut(200)
	});
	$('#blog_list').masonry({
  	itemSelector: '.blog_box',
  	columnWidth: 261
	});
	/* BIGGer link */
	$('.min').biggerlink();
	$('.services_box').biggerlink();
});

/* Cufon replacements */

Cufon.replace('ul.main_nav li a', { fontFamily: 'Museo Slab 500', hover: true });
Cufon.replace('h2', { fontFamily: 'Museo Slab 300' }); // Lighter
Cufon.replace('h4', { fontFamily: 'Museo Slab 500' }); // Lighter
Cufon.replace('.fade_caption h3', { fontFamily: 'Museo Slab 500' }); // Lighter
Cufon.replace('h4 b', { fontFamily: 'Museo Slab 500' }); // Bold
Cufon.replace('.blog h5', { fontFamily: 'Museo Slab 500', color: '#0099CC' });
Cufon.replace('h5', { fontFamily: 'Museo Slab 500' });
