jQuery(document).ready(function() {	
	// Flash-Text Replacement: H1
	$('.default h1 span, .toplevel h1 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #0D0D0D; }',
					'a { color: #0D0D0D; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	
	// Flash-Text Replacement: Content + Sidepanel H2's
	$('.page h2 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #0D0D0D; }',
					'a { color: #0D0D0D; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	
	// Flash-Text Replacement: Footer H2's
	$('.footer h2 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #939391; }',
					'a { color: #939391; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);	
	
	// Flash-Text Replacement: Homepage Feature Cycle Headings
	$('#featured .cycle h2').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #ffffff; }',
					'a { color: #ffffff; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	
	// Flash-Text Replacement: Homepage content strip headings
	$('.homepage .content-strips h2 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #0D0D0D; }',
					'a { color: #0D0D0D; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	
	// Flash-Text Replacement: Homepage content strip headings
	$('.homepage .container h2 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #0D0D0D; }',
					'a { color: #0D0D0D; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	$('.homepage .inverted-tabs h3 span').flash(
		{ 
			src: basePath+'interface/flash/helvetica-neue_67-medium-condensed.swf',  
			flashvars: { 
				css: [
					'* { color: #0D0D0D; }',
					'a { color: #0D0D0D; text-decoration: none; }',
					'a:hover { text-decoration: underline; }'
				].join(' ')
			},
			wmode: "transparent"
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<span>'+this.innerHTML+'</span>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));						
		}
	);
	
	// Menu
	$("#header li").hoverIntent({
		sensitivity: 1, 
		interval: 1, 
		over: function() {
			$(this).addClass("selected");
			$(".sub", this).removeClass("hide").animate({opacity: .95}, 100);
		}, 
		timeout: 50, 
		out: function() {
			$(this).removeClass("selected");
			$(".sub", this).addClass("hide").animate({opacity: .0}, 100);
		}
	});
	$("#header .sub").addClass("hide");
	
	// Carousel : Pimped version used on case studies / testimonials
	if(document.getElementById('pimpedCarousel')) {
		$(".carousel").prepend('<div class="controls"><a href="#" id="ctrPrev"><span class="offleft">Previous</span></a><a href="#" id="ctrNext"><span class="offleft">Next</span></a></div>');
		$(".carousel").append('<div class="quicknav"></div>');
		$("#pimpedCarousel").cycle({ 
			fx:     'fade', 
			speed:   400, 
			timeout: 20000,
			delay: 60000,
			pause:   1,
			startingSlide: carouselStartAt,
			next: '#ctrNext',
			prev: '#ctrPrev',
			pager: '.quicknav'
		});
		$("#ddlCSFilter").change(
			function() {
				//$.log("testimonials-"+$(this).val()+".php");
				ddlEle = $(this);
				$("#pimpedCarousel").animate({opacity: 0}, 400, function() {
					$("#carouselContainer").empty().append('<div class="loading"></div>');
					
					$(".quicknav").empty();
					$("#carouselContainer").load(ddlEle.attr("class")+"-"+ddlEle.val()+".php", {}, function() { 
						$("#pimpedCarousel").cycle({ 
							fx:     'fade', 
							speed:   400,  
							timeout: 20000,
							delay: 60000,
							pause:   1,
							startingSlide: carouselStartAt,
							next: '#ctrNext',
							prev: '#ctrPrev',
							pager: '.quicknav'
						});
						
						$("#pimpedCarousel a.fancybox").fancybox({
							overlayOpacity: 0.8,
							zoomSpeedIn: 500,
							hideOnContentClick: false,
							frameWidth: 680,
							frameHeight: 510
						});
					});
					
				});
			}
		);
	}
	
	// Tabs : Homepage
	$(".inverted-tabs .controls a").click(
		function() {
			if($(this).attr("href") != $("#invertedTabs .controls li.selected a").attr("href")) {
				newEle = $($(this).attr("href"));
				$("#invertedTabs .active").animate(
					{opacity: 0},
					300,
					function() {
						$("#invertedTabs .container").removeClass("active");
						newEle.addClass("active").animate({opacity: 1}, 300);						
					}
				);
				
				$("#invertedTabs .controls li").removeClass("selected");
				$(this).parents("li:first").addClass("selected");
			}
			
			return false;
		}
	);
	
	// Cycle : Homepage
	$(".feature-flashes").prepend('<div id="featureControls" class="cycle-controls"></div>');
	$(".feature-flashes .cycle").cycle({ 
		fx:     'fade', 
	    speed:   400, 
	    timeout: 8000, 
	    pause:   1, 
		pager:	'.cycle-controls',
		before: function() {
			eleRef = $("div", this).attr("class");
			$("#featuredImage").animate(
				{opacity:0},
				800,
				function() {
					$("#featuredImage")[0].className = "featured-"+eleRef;
					$("#featuredImage").animate(
						{opacity: 1},
						1800
					);
				}
			);
		}
	});
	$(".cycle li").addClass("active");
	$(".cycle li div").each(
		function() {
			$(this).flash({
				src: basePath+'interface/flash/'+$(this).attr("class")+'.swf',
				width: 310,
				height: 107,
				wmode: "transparent"
			},
			{
				expressInstall: true,
				version: '9'
			});	
		}
	);
	
	// Generic Fancybox
	$("a.fancybox").fancybox({
		overlayOpacity: 0.8,
		zoomSpeedIn: 500,
		hideOnContentClick: false,
		frameWidth: 680,
		frameHeight: 510
	});
});

var ga_source = '';
var ga_campaign = '';
var ga_medium = '';
var ga_term = '';
var ga_content = '';
var gc = '';
var c_name = "__utmz";
$(window).bind('load', function() {
	// Make GA Cookie Source Info available
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			gc = unescape(document.cookie.substring(c_start,c_end));
		}
	}
	if(gc != ""){
		var z = gc.split('.'); 
		if(z.length >= 4){
		var y = z[4].split('|');
			for(i=0; i<y.length; i++){
					if(y[i].indexOf('utmcsr=') >= 0) ga_source = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmccn=') >= 0) ga_campaign = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmcmd=') >= 0) ga_medium = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmctr=') >= 0) ga_term = y[i].substring(y[i].indexOf('=')+1);
					if(y[i].indexOf('utmcct=') >= 0) ga_content = y[i].substring(y[i].indexOf('=')+1);
			}
		}
	}
	$("#AnalyticsTracking").val(ga_source + "/" + ga_medium + (ga_term != "" ? " ("+ga_term+")" : ""));
});

function printPage() {
	if (window.print) {
		window.print() ;
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = "";
	}
}

// Debugging
jQuery.fn.debug = function() {
  return this.each(function(){
    alert(this);
  });
};
jQuery.log = function(message) {
  if(window.console) {
     console.debug(message);
  } else {
     alert(message);
  }
};

function manageCS(cItem) {
	if(document.getElementById('caseStudies')) {
		if(cItem=="all") {
			$("#caseStudies li").addClass("active");
		} else {
			$("#caseStudies li").removeClass("active");
			$("#caseStudies li."+cItem).addClass("active");
		}
		$("#caseStudies")[0].className = "show-"+cItem;
	}
}