// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['easeOutQuad'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	}
});


// ============================================== //

		// EMBED HEADER FLASH //

// ============================================== //

			
$.fn.initFlash = function(runAnimVar) {
	//
	var flashvars = {
		runAnim: runAnimVar,
		homelink: 'index.html'
	};
	//
	var params = {};
	//
	var attributes = {
		id: 'headerFlash',
		name: 'headerFlash'
	};
	//
	swfobject.embedSWF('http://www.pacific7.com/includes/flash/p7_header.swf', 'header_inner', '960', '98', '9.0.0','', flashvars, params, attributes);
};

// ============================================== //

		// HOME VIDEO //

// ============================================== //

initHomePlayer = function(){
	var target = $('#player');
	var imagePath = target.find('img').attr('src');
	var moviePath = target.attr('href');
	target.html('');
	setPlayer('player', imagePath, moviePath, false)
};

// ============================================== //

		// EMBED FLOWPLAYER //

// ============================================== //


setPlayer = function(playerId, imagePath, moviePath, thisBuffer){
	$f(playerId, {src: 'http://www.pacific7.com/includes/flash/flowplayer-3.2.5.swf', wmode: 'opaque'}, {	
	
		clip: {
			bufferLength: 5
		},
		
		plugins: {
			/*
			viral: {
				// load the viral videos plugin
				url: 'http://www.gloss-media.com/includes/flash/flowplayer.viralvideos-3.2.2.swf',
				email: false,
				share: {
					description: 'Gloss Media Video by '+dirName
				}
			},*/
		},

		playlist: [
			// this first PNG clip works as a splash image
			{
				url: imagePath, 
				scaling: true
			},
			// second clip is a video. when autoPlay is set to false the splash screen will be shown
			{
				url: moviePath, 
				autoPlay: false, 
				// video will be buffered when splash screen is visible
				autoBuffering: thisBuffer 
			}
		]
	});
	//.ipad({simulateiDevice: false, controls: true});
};

// ============================================== //

		// WORK PAGE //

// ============================================== //

//embed video

initWorkPlayer = function(){
	var target = $('#player');
	var imagePath = target.find('img').attr('src');
	var moviePath = target.attr('href');
	target.html('');
	setPlayer('player', imagePath, moviePath, false);
};

//roll overs

initWorkRoll = function(target, playMov){
	var homebool = false;
	
	if ($('#page_home').length) {
		homebool = true;
		$('#home_movie ul li').animate({ opacity: 0}, 0.001);
	};

	$(target).each(function(i){
		/*$(this).find('a').animate({'opacity':0},0.001, function(){
			$(this).css({
				'text-indent' : 0
			});
		});*/
		var scrollNum = parseInt($(this).find('a.work_desc').css('top'), 10);
		var tempLink = $(this).find('a.work_desc').attr('href');
		var tempHtml =	'<a href="'+tempLink+'" class="work_overlay"><\/a>';
		$(this).append(tempHtml);
		$(this).find('a.work_overlay').data('this_eq', i).hover(function() {
			$(this).parent().find('a.work_desc').stop().animate({'top':0}, 300);
			$('#home_movie ul').show();
			$('#home_movie ul li').eq($(this).data('this_eq')).stop().animate({ opacity: 1}, 200);
		}, function() {
			$(this).parent().find('a.work_desc').stop().animate({'top':scrollNum},400);	
			$('#home_movie ul li').stop().animate({ opacity: 0}, 0.001);
			$('#home_movie ul').hide();
			//$('#home_movie ul li').stop().animate({ opacity: 0}, 0.001);
		});
		if(playMov){
			$(this).find('a.work_overlay').click(function(){
				//var thisTarget = $(this);
				$('#home_movie ul').hide();
				$f().play($(this).attr('href'));
				if('#page_home'){
					$('#content_b h3:first').html($(this).parent().find('a.work_desc span').html());
				}else{
					$('#content h2:first').html($(this).parent().find('a.work_desc span').html());
				}
				return false;
			});
		}
		/*
		.click(function(){
			//var thisTarget = $(this);
			$f().play($(this).attr('href'));
			return false;
		});	*/								  
		
	});
};



// ============================================== //

		// CUSTOM SELECT BOXES //

// ============================================== //
/*
$.fn.selectDrop = function(){
	var target = $(this);
	// open menu
	target.find('dt a').click(function() {
		//
		if(target.hasClass('filter_open')){
			target.removeClass('filter_open').find('dd ul').slideUp(300);
		}else{
			$('#work_filter dl.filter_open').removeClass('filter_open').find('dd ul').slideUp(300);
			target.addClass('filter_open');
			target.find('dd ul').slideDown(300);
		}
		return false;
	});	
	// hide if clicked outside
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass('filter_drop')) {
			$('#work_filter dl.filter_open').removeClass('filter_open').find('dd ul').slideUp(300);
		}
	});
	// item selected
	target.find('dd ul li a').click(function() {
		var text = $(this).html();
		target.find('dt a').html(text);	
		target.removeClass('filter_open').find('dd ul').slideUp(300);
		orderWork(target.attr('id'), $(this).attr('name'));
	});
};

orderWork = function(orderGroup, orderBy){
	//alert(orderGroup+'  '+orderBy);
	var target = $('#content_c');
	if(orderGroup=='filter_drop_clients'){
		target.find('#work_filter dl#filter_drop_type dt a').html('Job Type');	
	}else{
		target.find('#work_filter dl#filter_drop_clients dt a').html('Clients');	
	}
	//$('.'+style+' dd ul').toggle();
	target.find('div.work_item').each(function(){
		if($(this).hasClass(orderBy))	{
			$(this).animate({'opacity':1},200);
		}else{
			$(this).animate({'opacity':.5},200);
		}
	});
};*/

// ============================================== //

		// WORK PAGE //

// ============================================== //

var newsPlayerInc = 0;
var classNameAr = new Array;
var imagePathAr = new Array;
var moviePathAr = new Array;
//
initNewsPlayer = function(target,mov_width,mov_height){
	$(target).each(function(){
		newsPlayerInc++;
		var thisTarget = $(this);
		imagePathAr[newsPlayerInc] = thisTarget.find('img').attr('src');
		moviePathAr[newsPlayerInc] = thisTarget.attr('href');
		thisTarget.css({'width' : mov_width, 'height' : mov_height});
		classNameAr[newsPlayerInc] = 'news_inc_'+newsPlayerInc;
		thisTarget.addClass(classNameAr[newsPlayerInc]);
		thisTarget.html('');
		setPlayer('a.'+classNameAr[newsPlayerInc], imagePathAr[newsPlayerInc], moviePathAr[newsPlayerInc], false);
	});
	/*
	for(var i=1; i<=newsPlayerInc; i++){
		setPlayer('a.'+classNameAr[i], imagePathAr[i], moviePathAr[i]);
	}*/
	
};

/*
$.fn.initNewsPlayer = function() {
	newsPlayerInc++;
	alert(newsPlayerInc);
	
	var target = this;
	var imagePath = target.find('img').attr('src');
	var moviePath = target.attr('href');
	target.css({'width' : 400, 'height' : 225});
	target.addClass('news_inc_'+newsPlayerInc);
	target.html('');
	setPlayer('a.news_inc_'+newsPlayerInc, imagePath, moviePath);
	
	//$("a.news_player").flowembed("http://www.pacific7.com/includes/flash/flowplayer-3.2.5.swf",  {initialScale:'scale'});
};*/

// ============================================== //

		// INITIALISE //

// ============================================== //

$(document).ready(function(){
	/*
	if ($('#page_home').length) {
		$('#header_inner').initFlash('0');
	}else{
		$('#header_inner').initFlash('1');
	}
	*/
	// Home movie
	if ($('#page_home #player').length) {
		initHomePlayer();
	};
	// Work movie
	if ($('#page_work_item #player').length) {
		initWorkPlayer();
	};
	// Work rollovers
	if ($('#page_work').length) {
		initWorkRoll('div.work_item');
	};
	if ($('#page_work_item').length) {
		initWorkRoll('div.work_item', false);
		/*
		$('#work_filter dl.filter_drop').each(function(){
			$(this).selectDrop()										   
		});*/
	};
	// work carousel rollovers
	if ($('#movie_carousel').length) {
		initWorkRoll('#movie_carousel li', true);
	};
	// News page video embeds
	if ($('#page_news').length) {
		//initNewsPlayer();
		initNewsPlayer('a.news_player',400,225);
	};
	// The Beach page video embeds
	if ($('#page_beach').length) {
		//initNewsPlayer();
		initNewsPlayer('a.news_player',480,270);
	};
});

