var $st=jQuery.noConflict();
var gblClient;

function flashMovie(elemID, vimeoID, flashW, flashH) {
	var flashLayer = $st('#' + elemID);	//ID of layer to load SWF
	var vimeoID = vimeoID;				//ID of vimeo clip
	var flashW = flashW;				//width of movie
	var flashH = flashH;				//height of movie
	var caseStudy = caseStudy;			//is it a case study? (1=yes, 0=no)

	var moogaloop = false;

	// Run the javascript when the page is ready
	var swf_id = 'moogaloop';	//do not change this

	var flashvars = {
		clip_id: vimeoID,
		show_portrait: 0,
		show_byline: 0,
		show_title: 0,
		color: '7D683C',
		server: 'vimeo.com',
		js_api: 1, // required in order to use the Javascript API
		js_onLoad: 'vimeo_player_loaded', // moogaloop will call this JS function when it's done loading (optional)
		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 = {
		wmode: 'transparent'
	};

	// For more SWFObject documentation visit: http://code.google.com/p/swfobject/wiki/documentation
	swfobject.embedSWF("http://vimeo.com/moogaloop.swf", swf_id, flashW, flashH, "9.0.0","expressInstall.swf", flashvars, params, attributes);

}

function vimeo_player_loaded(swf_id) {
//	alert(swf_id);
	moogaloop = document.getElementById(swf_id);
//	alert(moogaloop);
	moogaloop.api_addEventListener('onPlay', 'vimeo_on_play');
	moogaloop.api_addEventListener('onFinish', 'vimeo_on_finish');

}
var gblCycle = 0;

function vimeo_on_play(swf_id) {}
function vimeo_on_finish(swf_id) {}

function vimeoPlayerLoaded(swfId) {
	$st("#csCarousel").csCarousel('videoLoaded',swfId,"vimeo");
}

function vimeoOnPlay(swfId) {
	$st("#csCarousel").csCarousel('videoPlaying',swfId);
}

function vimeoOnFinish(swfId) {
	$st("#csCarousel").csCarousel('videoFinished',swfId);
}

function remLastMargin(elemID) {
	var elemID = elemID;
	$st("#" + elemID).find(".col:last").addClass("trim");
}

var curYTPlayer;

function onYouTubePlayerReady(swfId) {
	curYTPlayer = swfId;
	$st("#csCarousel").csCarousel('videoLoaded',swfId,"youtube");
}

function onytplayerStateChange(newState) {
	switch(newState)
	{
		case 0:
			$st("#csCarousel").csCarousel('videoFinished',curYTPlayer);
			break;
		case 1:
			$st("#csCarousel").csCarousel('videoPlaying',curYTPlayer);
			break;
		case 2:
			$st("#csCarousel").csCarousel('videoPaused',curYTPlayer);
			break;
		case 3:
			$st("#csCarousel").csCarousel('videoBuffering',curYTPlayer);
			break;
		case 5:	
			$st("#csCarousel").csCarousel('videoCued',curYTPlayer);
			break;
			
	}
}

function onytplayerError(error) {
	alert("YT Player's error: " + error);
}

var gblPath = "";
var gblPath = "assets/images/clients/" + gblClient + "/439x321";

function caseStudyCarousel(slideToStart) { }

function createCaseStudyCarousel(slideToStart) { }

function thumbRollover(img)
{
	var img2 = Pixastic.process(img, "desaturate");
	img2.onmouseout = function() {
		Pixastic.revert(this);
	}
}

function destaturateThumb(img)
{
	Pixastic.process(img, "desaturate");
}

function thumbnailContrast(){
		
	$st("#one-col.hero .cs-img").fadeOut(0);
	$st("#home-three-col .col a img.hl").fadeTo(0, 0.5);
		
	$st(".staffMember img.hl").fadeTo(0);
	$st(".staffMember .tagLine p").slideDown(0);
	$st(".staffMember .tagLine p").slideUp(0);
	
	$st("#one-col.hero .cs").mouseenter(function(){
		$st(this).find('.cs-img').fadeIn(300);
	}).mouseleave(function(){
		$st(this).find('.cs-img').fadeOut(300);
	});

	$st("#home-three-col .col a").mouseenter(function(){
		$st(this).find('img.hl').fadeTo(300, 1);
	}).mouseleave(function(){
		$st(this).find('img.hl').fadeTo(300, 0.5);
	});
	
	$st(".staffMember").mouseenter(function(){
		tlp = $st(this).find('.tagLine p');
		ihl = $st(this).find('img.hl');
		ihl.fadeTo(300, 1);
		tlp.slideToggle(500,'swing');
	}).mouseleave(function(){
		tlp = $st(this).find('.tagLine p');
		ihl = $st(this).find('img.hl');
		ihl.fadeTo(300, 0);
		tlp.slideToggle(300);
	});
}


function homeCarousel() {
	$st("#home-carousel").cycle({ 
	    fx: "fade", 
	    speed: "fast", 
	    timeout: 5000
	});
}

//activate news nav item
function activateNewsNav() {
	$st("UL#menu LI").eq(6).addClass("active");
}

function showThumbs(videos){
	var thumbs = $st('.vimeo-thumbs');
	
	for (var i = 0;i < 6;i++) {
		var thumbPath = videos[i].thumbnail_medium;
		var thumbURL = videos[i].id;
		thumbs.append('<a href="http://vimeo.com/channels/157073#'+thumbURL+'" target="_blank"><img class="hl" src="'+thumbPath+'" height="80" /></a>');
	}
}

//clearSearch onfocus
//removes default text from header search box
//usage: every page
function clearSearch() {
	$st("INPUT#search").focus(function() {
		$st(this).val("");
	});
}

$st(document).ready(function() {
	//common
	clearSearch();
	thumbnailContrast();
	//if($st('#two-col').hasClass('case-study')){ createCaseStudyCarousel(); };
	if(typeof(csdata) !== 'undefined') $st("#csCarousel").csCarousel({'jsonData':csdata});
});

