function isEmpty(inner_html){
	var inner_html_trimmed = inner_html.replace(/^\s+|\s+$/g, '');
	if (inner_html_trimmed == ''){
		return true;
	}
	return false;
}

function clearEmpty() {
	jQuery('.huge, .hide_empty').each(function(i){
		if (isEmpty($(this).html())){
			$(this).hide();
		}
	});
}

jQuery(document).ready(function()
{
    // make the sub nav links load the content
    // into the area on the right
	jQuery('#nav_sub ul li a').click(function(i){

	    jQuery("#content .inner_right").html('');
	    jQuery('#nav_sub ul li a').removeClass('selected');

        var doc_id = jQuery(this).attr('id').replace(/^sub/g, '');
        jQuery("#content .inner_right").load("/index.php #content .inner_right .inner_right_inner", {doc: doc_id}, function(){});
        clearEmpty();

        jQuery(this).addClass('selected');

		return false;
	});

	// hide boxes with no content - user populated
	clearEmpty();

	jQuery.browser.msie6 = jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 && !window["XMLHttpRequest"];

	FLIR.init( { path: '/media/text/javascript/facelift/' } );
	jQuery('.alpha h1:not(.main_nav h1)').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('.alpha h2:not(.main_nav h2)').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'})); } );
	jQuery('.alpha h3:not(.main_nav h3)').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('#news_recent h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('.news_article h2').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('.news_article h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'})); } );
	jQuery('.news_article_content').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy',mode:'wrap', cColor:'808285'})); } );
	jQuery('.alpha h4:not(.main_nav h4)').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'})); } );
	jQuery('#news_recent h4').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'})); } );
	jQuery('.theme_0 .huge h2').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'00aeef'})); } );
	jQuery('.theme_1 .huge h2').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'eb008b'})); } );
	jQuery('.theme_2 .huge h2').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffca07'})); } );
	jQuery('.theme_3 .huge h2').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'e3e415'})); } );
	jQuery('.theme_0 .huge h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', mode:'wrap', cColor:'00aeef'})); } );
	jQuery('.theme_1 .huge h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', mode:'wrap', cColor:'eb008b'})); } );
	jQuery('.theme_2 .huge h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', mode:'wrap', cColor:'ffca07'})); } );
	jQuery('.theme_3 .huge h3').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', mode:'wrap', cColor:'e3e415'})); } );
	jQuery('.beta h1').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('#biline').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'}, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'}))); } );
	jQuery('#nav_util li').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'}, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'808285'}))); } );
	jQuery('#staff_list h4 a.link_main').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdHeavy', cColor:'ffffff'})); } );
	jQuery('#staff_list h5').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdLight', cColor:'ffffff'})); } );
	jQuery('#staff_list a.link_sub').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdLight', cColor:'808285'})); } );

	jQuery('blockquote').each( function() {
			FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStdLight',mode:'wrap', cColor:'808285'}));
	});

	if (jQuery.browser.msie6) {
		//jQuery('blockquote').each().css('width','695px');
	} else {
		//jQuery('blockquote span').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'rockwell', mode:'wrap', cColor:'yellow'})); } );

		//jQuery('blockquote:not(#news_recent blockquote)').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStd_Light', mode:'wrap', cColor:'808285'})); } );
		//jQuery('#news_recent blockquote').each( function() { FLIR.replace(this, new FLIRStyle({cFont:'CaeciliaLTStd_Light', mode:'wrap', cColor:'ffffff'})); } );

		//jQuery('blockquote').each( function() { FLIR.replace(FLIR.getChildren(FLIR.getParentNode(this))[1]); } );
		//jQuery('blockquote').each( function() { FLIR.replace(FLIR.getChildren(FLIR.getParentNode(this))); } );
	}

	jQuery('div.client_list ul li.featured div.image a').hover(
	function(i){
		var src_a = jQuery(this).children('img.on').attr('src');
		var src_b = jQuery(this).children('img.off').attr('src');
		jQuery(this).children('img.off').attr('src',src_a);
		jQuery(this).children('img.on').attr('src',src_b);
	},
	function(i){
		var src_a = jQuery(this).children('img.on').attr('src');
		var src_b = jQuery(this).children('img.off').attr('src');
		jQuery(this).children('img.off').attr('src',src_a);
		jQuery(this).children('img.on').attr('src',src_b);
	}
	);

	jQuery('a.iframe').fancybox({
		hideOnContentClick:	true,
		imageScale:         false,
		zoomOpacity:        true,
		zoomSpeedIn:		500,
		zoomSpeedOut:		500,
		frameWidth:			700,
		frameHeight:		500,
		overlayShow:		true,
		overlayOpacity:		0.6,
		padding: 0
	});


	/* jcarousel */


	// Example of fancy content loading function to keep it simple since the animation is not the point, you're free to let your divs fly around as you want
	/*switchTeamContent = function(i) {
	$('.fancy_content_item').slideUp('fast');
	$('.fancy_content-'+i).slideDown('normal');
	};

	var mycarousel_itemList = [];
	var mycarousel_itemHTML = [];
	$('.jcarousel-skin-custom li').each(function(i){
	var thisimg = $(this).find('img');
	mycarousel_itemList[i] = {
	url: thisimg.attr('src'),
	title: thisimg.attr('title')
	};
	mycarousel_itemHTML.push($(this).html());
	});
	mycarousel_itemVisibleInCallback = function (carousel, item, i, state, evt) {
	var idx = carousel.index(i, mycarousel_itemList.length);
	carousel.add(i, mycarousel_itemHTML[idx - 1]);
	};
	mycarousel_itemVisibleOutCallback = function (carousel, item, i, state, evt) {
	carousel.remove(i);
	};
	var outOpacity = 0.7;
	switchOffCarouselItem = function(li,animate) {
	if (animate) {
	$(li).fadeTo('normal',outOpacity).removeClass('active');
	} else {
	$(li).css('opacity',outOpacity).removeClass('active');
	}
	};
	onSwitchCarousel = function(carousel,li,i,state,name,last) {
	switch(state) {
	case 'init':
	switchOffCarouselItem(li);
	break;
	case 'next':
	if (last) {
	switchOffCarouselItem(li);
	} else {
	switchOffCarouselItem(li,true);
	}
	break;
	case 'prev':
	if (last) {
	switchOffCarouselItem(li,true);
	} else {
	switchOffCarouselItem(li);
	}
	break;
	}
	if (last) {
	$(li).prev().fadeTo('normal',1).addClass('active');
	var idx = carousel.index(i, mycarousel_itemList.length);
	if (idx == 1) {
	switchTeamContent(mycarousel_itemList.length);
	} else {
	switchTeamContent(idx - 1);
	}
	}
	};
	onSwitchToLast = function(carousel,li,i,state,name) {
	onSwitchCarousel(carousel,li,i,state,name,true);
	};*/

	/*$('#staff_list ul').jcarousel({
	scroll: 1,
	wrap: 'circular',
	auto: 1,
	animation: 1000,
	itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
	itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback},
	itemFirstInCallback: {onBeforeAnimation: onSwitchCarousel},
	itemLastInCallback: {onBeforeAnimation: onSwitchToLast},
	btnPrev: null,			// previous button customization
	btnNext: null			// next button customization
	});*/

	// initialize scrollable
	$(".scrollable").scrollable({

		// items are auto-scrolled in 2 secnod interval
		interval: 1500,

		// when last item is encountered go back to first item
		loop: true,

		// make animation a little slower than the default
		speed: 1200,

		// when seek starts make items little transparent
		onBeforeSeek: function() {

			//alert(this.getIndex());

		},

		// when seek ends resume items to full transparency
		onSeek: function() {

			var kids = this.getItemWrap().children(":nth-child(" + this.getIndex() + ")");
			this.getItemWrap().append('<div>' + kids.html() + '</div>');
			this.reload();


			jQuery('#staff_list a.reveal_bio').click(function(i){
				var bio_id = jQuery(this).attr('rel');
				var bio_html = jQuery('#' + bio_id).html();
				if (jQuery.browser.msie6) {
					jQuery('#bio').html(bio_html);
				} else {
					jQuery('#bio').html(bio_html);
				}
				return false;
			});

		}
	});


	jQuery('#staff_list a.reveal_bio').click(function(i){
		var bio_id = jQuery(this).attr('rel');
		var bio_html = jQuery('#' + bio_id).html();
		if (jQuery.browser.msie6) {
			jQuery('#bio').html(bio_html);
		} else {
			jQuery('#bio').html(bio_html);
		}
		return false;
	});

});

function openUrl(url)
{
	window.open(url, '_self');
}
function openUrlFromSelect(select)
{
	var url = select.options[select.options.selectedIndex].value;
	openUrl(url);
}
function submitOnChange(idForm)
{
	jQuery('#' + idForm).submit();
}

function ccTypeSelectShowHide(selectOrValue)
{
	if (typeof(selectOrValue) == 'string') {
		var val = selectOrValue;
	} else if (selectOrValue != undefined) {
		var val = selectOrValue.options[selectOrValue.options.selectedIndex].value;
	} else {
		var val = 'rubbish';
	}

	if (
	val == 'Solo'
	|| val == 'Switch'
	|| val == 'American Express'
	) {
		jQuery('#ecom_cc_extra').show();
		if (val != 'American Express') {
			$('#ecom_cc_extra_issue').show();
		} else {
			$('#ecom_cc_extra_issue').hide();
		}
	} else {
		jQuery('#ecom_cc_extra_issue').hide();
		jQuery('#ecom_cc_extra').hide();
	}
}
