/*
 * SWFObject (http://jquery.thewikies.com/swfobject/)
 *
 */

(function(F,C){var D=function(H){var G,I=[];for(G in H){if(/string|number/.test(typeof H[G])&&H[G]!==""){I.push(G+'="'+H[G]+'"')}}return I[A]("")},E=function(I){var G,K,J=[],H;if(typeof I=="object"){for(G in I){if(typeof I[G]=="object"){H=[];for(K in I[G]){H.push([K,"=",encodeURIComponent(I[G][K])][A](""))}I[G]=H[A]("&amp;")}if(I[G]){J.push(['<param name="',G,'" value="',I[G],'" />'][A](""))}}I=J[A]("")}return I},B=false,A="join";F[C]=(function(){try{var G="0,0,0",H=navigator.plugins["Shockwave Flash"]||ActiveXObject;G=H.description||(function(){try{return(new H("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(J){}}())}catch(I){}G=G.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+[d|r]|,)(\d+)/);return{available:G[1]>0,activeX:H&&!H.name,version:{major:G[1]*1,minor:G[2]*1,release:G[3]*1},hasVersion:function(K){var N=this.version,L="major",M="minor",J="release";K=(/string|number/.test(typeof K))?K.toString().split("."):K||[0,0,0];K=[K[L]||K[0]||N[L],K[M]||K[1]||N[M],K[J]||K[2]||N[J]];return(K[0]<N[L])||(K[0]==N[L]&&K[1]<N[M])||(K[0]==N[L]&&K[1]==N[M]&&K[2]<=N[J])},expressInstall:"expressInstall.swf",create:function(J){if(!F[C].available||B||!typeof J=="object"||!J.swf){return false}if(J.hasVersion&&!F[C].hasVersion(J.hasVersion)){J={swf:J.expressInstall||F[C].expressInstall,attrs:{id:J.id||"SWFObjectExprInst",name:J.name,height:Math.max(J.height||137),width:Math.max(J.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(F[C].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};B=true}else{J=F.extend(true,{attrs:{id:J.id,name:J.name,height:J.height||180,width:J.width||320},params:{wmode:J.wmode||"opaque",flashvars:J.flashvars}},J)}if(F[C].activeX){J.attrs.classid=J.attrs.classid||"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";J.params.movie=J.params.movie||J.swf}else{J.attrs.type=J.attrs.classid||"application/x-shockwave-flash";J.attrs.data=J.attrs.data||J.swf}return["<object ",D(J.attrs),">",E(J.params),"</object>"][A]("")}}}());F.fn[C]=function(G){if(typeof G=="object"){this.each(function(){var I=document.createElement(C);var H=F[C].create(G);if(H){I.innerHTML=H;if(I.childNodes[0]){this.appendChild(I.childNodes[0])}}})}else{if(typeof G=="function"){this.find("object").andSelf().filter("object").each(function(){var I=this,H="jsInteractionTimeoutMs";I[H]=I[H]||0;if(I[H]<660){if(I.clientWidth||I.clientHeight){G.call(this)}else{setTimeout(function(){F(I)[C](G)},I[H]+66)}}})}}return this}}(jQuery,"flash"));


/*
 * Initiate Jquery Functions
 *
 */

//Kick-off / Page Load Functions
$(document).ready(function(){
		
	//NEW TAB POPUP
	$('a[rel="external"]').attr("target", "_blank");
	$('a[rel="external nofollow"]').attr("target", "_blank");
	
	if ( ($('#content h1.name').length < 1) && ($("#content h2.main").length < 1) ) {
		$("#content h1").append(".");
	} else {
		$("#content h2.main").append(".");
	}
	
	//FANCYBOX
	$('a.fancybox').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300 });
	$('a.popup_learn_more').fancybox({
		'autoDimensions':false,
		'width': 420,
		'height': 180,
		'overlayColor':'#000',
		'overlayOpacity': .5,
		'titleShow': false,
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300
	});
	$('a.play_reel').fancybox({
		'overlayColor':'#000',
		'overlayOpacity': .5,
		'width': 640,
		'height': 360,
		'titleShow': false,
		'type': 'iframe',
		'scrolling': 'no'
	});	
	$('ul.video_grid li a, ul.video_list li a').fancybox({
		'overlayColor':'#000',
		'overlayOpacity': .5,
		'width': 640,
		'height': 360,
		'titlePosition': 'inside',
		'type': 'iframe',
		'scrolling': 'no'
	});	
	$('.popup_form').fancybox({
		'overlayColor':'#000',
		'overlayOpacity': .5,
		'width': 545,
		'height': 430,
		'titleShow': false,
		'type': 'iframe'
	});
	
	
	//AUTOPOPULATE
	$(".populate").each( function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	$(".populate").focus(function(){
		if ( $(this).val() == $(this).attr("title") ) {
			$(this).val("");
		}
	});
	$(".populate").blur(function(){
		if ( $(this).val() == "" ) {
			$(this).val( $(this).attr("title") );
		}
	});
	
	//EMAIL MASK/ENCRYPT
	$(".mask").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});
	
	//TABS
	$('#section_tabs').tabs({ fx: { opacity: 'toggle', duration: 'fast' } });

	//Refreshes the cufon when a new tab is selected
	$('#section_tabs').bind('tabsshow', function(event, ui) {
		Cufon.refresh();
	});
	
	//CUFON
	Cufon.replace('h1, ul.video_list li .description h3, ul.audio_list li .description h3, ul.services_grid li a .overlay h3, #aside h4, #interview h3');
	Cufon.replace('h2, #section_tabs ul.nav li', { hover: true });

	
	//ROTATING BANNERS
	$('#banner_home .slides img:first').fadeIn(1000, function() {
        $('#banner_home .slides').cycle();
	});
	$('#group_slideshow .slides img:first').fadeIn(1500, function() {
        $('#group_slideshow .slides').cycle({
            prev:    '.prev',
            next:    '.next',
			pause:   1
        });
	});
	
	$('#group_slideshow .slides').hover(
		function () {
			$(this).parent().find('.pause').fadeOut();
		},
		function () {
			$(this).parent().find('.pause').fadeIn();
		});

		
	//SLIDES
    $('ul.video_grid li a, ul.video_list li a').hover(function() {
		$(this).find('.overlay').slideDown();
    },
	function () {
        $('.overlay').stop(false, true);
		$(this).find('.overlay').slideUp();
	});
	
    $('ul.services_grid li a').hover(function() {
		$(this).find('.overlay .inner').slideDown();
    },
	function () {
        $('.overlay .inner').stop(false, true);
		$(this).find('.overlay .inner').slideUp();
	});


});
