$(document).ready(function(){
	
	//scrollto
	$('.prev-next, .menu, .wall-item, .logo').localScroll(800);
	//RepositionNav();
	$(window).resize(function(){
		RepositionNav();
	});	
	//.moveRelative() options:
	//x position
	//adjuster (y position to start from)
	//inertia (speed to move relative to vertical scroll)
	//outerHeight (true/false)
	$('#top').moveRelative("0%", 0, 0.1, true);
	//$('#nokia-ramadan').moveRelative("50%", 0, 0.1, true);
	$('#intro').moveRelative("0%", 1050, 0.1, true);
	
	$('#cointreau').moveRelative("0%", 2100, 0.1, true);
	$('#asl').moveRelative("0%", 3050, 0.1, true);
	
	$('#fwad').moveRelative("0%", 4100, 0.1, true);
	$('#style-pass').moveRelative("0%", 5250, 0.1, true);
	$('#ampm').moveRelative("0%", 6100, 0.1, true);
	$('#tearfund').moveRelative("0%", 7300, 0.1, true);
	$('#geron').moveRelative("0%", 8400, 0.1, true);
	
	$('#headspace').moveRelative("0%", 9300, 0.1, true);
	$('#jeego').moveRelative("0%", 10500, 0.1, true);
	$('#ellesse').moveRelative("0%", 11300, 0.1, true);
	$('#ellie').moveRelative("0%", 12600, 0.1, true);
	$('#faldo').moveRelative("0%", 13600, 0.1, true);
	
	$('#bbc').moveRelative("0%", 14650, 0.1, true);
	$('#cwm').moveRelative("0%", 15600, 0.1, true);
	$('#mos').moveRelative("0%", 16500, 0.1, true);
	$('#mtv').moveRelative("0%", 17600, 0.1, true);
	$('#roadtov').moveRelative("0%", 18500, 0.1, true);
	
	$('#xl-records').moveRelative("0%", 19100, 0.1, true);
	$('#jwt').moveRelative("0%", 21000, 0.1, true);
	$('#amnesty').moveRelative("0%", 22000, 0.1, true);
	$('#chiva').moveRelative("0%", 23100, 0.1, true);
	$('#retreat').moveRelative("0%", 23800, 0.1, true);
	
	$('#living').moveRelative("0%", 24900, 0.1, true);
	$('#airspaces').moveRelative("0%", 26000, 0.1, true);
	$('#aandr').moveRelative("0%", 27000, 0.1, true);
	$('#frank').moveRelative("0%", 28300, 0.1, true);
	$('#gq').moveRelative("0%", 29300, 0.1, true);

//clients
$(".clients").click(function(){
	//$("#clients").hide();
	$("#clients").fadeIn('slow');
	return false;
});

//showreel
	$("#showreel").hide();
	$(".showreel").click(function(){
	$("#overlay").fadeIn('slow');
	$("#showreel").fadeIn('slow');
	return false;
	});
	
	$(".close-reel").click(function(){
	$("#showreel").fadeOut('slow');
	$("#overlay").fadeOut('slow');
	return false;
});

//work
$("#wall-container").hide();
$("#wall").hide();
$('.work').click(function(e){
	$("#wall-container").fadeIn('slow');
	$("#wall").fadeIn('slow');
	$('#overlay').fadeIn('slow');
	$('#wall').jmFullWall({
		itemsForRow : 5,
		itemTransition : 'fadeIn',
		itemTransitionSpeed : 150,
		detailTransitionIn : 'slideDown',
		detailTransitionOut : 'slideUp'
	});
	e.preventDefault();	
});

$(".work-close").click(function(e){
	//window.location = '#fourth';
	$("#wall-container").fadeOut('slow');
	$("#overlay").fadeOut('slow');
	e.preventDefault();
	});	
});

//modal
var time_fade = '500';
var mask_opacity = '0.95';

	$(document).ready(function(){
		//get the height and width of the page
		var window_width = $(window).width();
		var window_height = $(window).height();
		//vertical and horizontal centering of modal window(s)
		/*we will use each function so if we have more then 1
		modal window we center them all*/
		$('.modal_window').each(function(){
			//get the height and width of the modal
			var modal_height = $(this).outerHeight();
			var modal_width = $(this).outerWidth();

			//calculate top and left offset needed for centering
			var top = (window_height-modal_height)/2;
			var left = (window_width-modal_width)/2;

			//apply new top and left css values
			$(this).css({'top' : top , 'left' : left});
		});
		
		$('.activate_modal').click(function(e){
			//get the id of the modal window stored in the name of the activating element
			var modal_id = $(this).attr('name');
			//use the function to show it
			show_modal(modal_id);
			
			$( '#' + $( this ).attr( 'name' ) + ' #paginate' ).empty();
			$( '#' + $( this ).attr( 'name' ) + ' #detailsImageWrap #detailsImage').before('').cycle( {
            fx:     'scrollLeft',
            speed:  '900',
            timeout:  5000,
            pager:  '#' + $( this ).attr( 'name' ) + ' #paginate',
            pause: 0
        	});
			e.preventDefault();
		});

		$('.close_modal').click(function(e){
			//use the function to close it
			close_modal();
			e.preventDefault();
		});
		
		$('.close').click(function(e){
			//use the function to close it
			close_modal();
			e.preventDefault();
		});

	});

	//open close functions
	function close_modal(){
		//hide the mask
		$('#mask').fadeOut(time_fade);
		//hide modal window(s)
		$('.modal_window').fadeOut(time_fade);
	}

	function show_modal(modal_id){
		//set display to block and opacity to 0 so we can use fadeTo
		//event.preventDefault();
		$('#mask').css({ 'display' : 'block', opacity : 0});
		$('#mask').fadeTo(time_fade,mask_opacity);
		$('#'+modal_id).fadeIn(time_fade);
		 
	}
	
//vimeo
	var video_id = 14738873;
	var moogaloop = false;
	var swf_id = 'moogaloop';
	var flashvars = {
	    clip_id: video_id,
	    show_portrait: 0,
	    show_byline: 0,
	    show_title: 0,
		js_api: 1, // required in order to use the Javascript API
		js_onLoad: 'vimeo_player_loaded',
		js_swf_id: 'moogaloop' // this will be passed into all event methods so you can keep track of multiple moogaloops (optional)
	    };
		var params = {
			allowscriptaccess: 'always',
			allowfullscreen: 'true'
		};
		var attributes = {};
		swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, "500", "400", "9.0.0","expressInstall.swf", flashvars, params, attributes);
