Cufon.replace('#global_menu');
Cufon.replace('.contact_title');
Cufon.replace('#tagline');

/*
$.fn.textWidth = function(){
	var html_org = $(this).html();
	var html_calc = '<span>' + html_org + '</span>'
	$('body').append(html_calc);
	var width = $('body').find('span:last').width();
	$('body').find('span:last').remove();
	return width;
};
*/

$.fn.textWidth = function(){

	// total width of the menu
	totalRowWidth = 930;
	textWidth = 0;

	cols = 0;
	$('#global_menu > li > a').each(function(e){
		//decrement the textWidth var
		textWidth += $(this).width();
		cols++;
	});

	totalRowWidth -= (cols*2);// allow for border widths between cols

	// find the amount to pad each cell with
	paddingBits = Math.floor( (totalRowWidth - textWidth) / (cols * 2 ) );
	// this is the amount left over after the padding has been
	// calculated for each cell and is the result of rounding down in
	// the division. It must be added back in at the start and end of the menu
	remainder = ( (totalRowWidth - textWidth)  - ( (paddingBits * 2) * cols ) );

	// cut up the remainder into 2 pieces
	if (remainder > 0){
		if (remainder > 1) {
			if (remainder % 2 != 0) {
				r1=Math.floor(remainder/2);
				r2=r1+1;
			} else {
				r1=remainder/2;
				r2=r1;
			}
		} else {
			r1=1;
			r2=0;
		}
	} else {
		r1=0;
		r2=0;
	}


	// now put the padding on the dom elements
	$('#global_menu > li > a').each(function(e){
		paddingBitsLeft=0;
		paddingBitsRight=0;
		if (e < 1) paddingBitsLeft += r1;//first col
		if (e == cols-1) paddingBitsRight += r2;//last col
		$(this).css('padding-left',paddingBits + paddingBitsLeft);
		$(this).css('padding-right',paddingBits + paddingBitsRight);
	});
};

$(document).ready(function() {
	// fix menu padding
	$.fn.textWidth();
	// add a bit of transparency to the text
	$('#global_menu li a span').addClass('transparency_class');
	// bring the menu back into the page
	$('#global_menu').css('left','0px');
	// in case current page is not on the main menu...
	if(typeof(reset_ucb_menu) != "undefined"){
		if (reset_ucb_menu) {
			// remove the 'active' id styling from current menu item
			$('#global_menu li.active').removeAttr('id');
		}
	}


	$('#splashFrame').cycle({
		fx: 'fade',
		pause: true,
		timeout: 7000,
		speed: 1500,
		random: true
	});

	/*$('.contact-popup').click(function() {
		$(this).FreezeBubblePopup();
	});
	$('body').click(function(event) {
		if (!$(event.target).closest('.contact-popup').length) {
			$('.contact-popup').UnfreezeBubblePopup();
			$('.contact-popup').HideBubblePopup();
		};
	});
	$('.contact-popup').CreateBubblePopup({ innerHtml: '<div id="getInTouch" class="round-corner-grad-squares"><dl> <dt>Radio &amp; TV Enquiries</dt> <dd>01782 642 000</dd> <dt>General Enquiries</dt> <dd>0845 6040401</dd> <dt>UCB UK Studio</dt> <dd>08456 300 400</dd> <dt>UCB Inspirational Studio</dt> <dd>01782 64 64 64</dd> <dt>SMS Text (standard charge)</dt> <dd>07797 800 710</dd> <dt>Email</dt> <dd><a href="mailto:info@ucbmedia.co.uk">info@ucbmedia.co.uk</a></dd> </dl></div> ', themePath: 'templates/ucbmedia_main/css/jquery-bubblepopup-theme' });
	*/
	
	
	$('.contact-popup-not a').hover(function(){
		$('#contact-popup').show();
	},function(){
		$('#contact-popup').hide();
	})
	
	$('#contact-popup').hover(function(){
		$(this).show();
	}, function(){
		$(this).hide();
	})
	
	
	
	$("#twitter").tweet({
		join_text: "auto",
		username: "UCBMedia",
		avatar_size: 30,
		count: 6,
		auto_join_text_default: "we said,",
		auto_join_text_ed: "we",
		auto_join_text_ing: "we were",
		auto_join_text_reply: "we replied",
		auto_join_text_url: "we were checking out",
		loading_text: "loading tweets...",
		query: "UCBMedia",
		template: "{avatar}{text}{time}"
	});

  $("#yousay-box ul").cycle({
		pause: true,
  		fx: 'scrollLeft',
  		timeout: 10000,
  		random: true
  	});

	
	$('.newsticker-jcarousellite').vTicker();
	
	$('#share-subscribe .friendrow').hide();
	$('#share-subscribe .friendrow').addClass('friendHidden');
	$('#share-subscribe .firstfriend').show();
	$('#share-subscribe .firstfriend').addClass('friendVisible');
	$('#share-subscribe .firstfriend').removeClass('friendHidden');
	$('#share-subscribe a.nextFriend').click(function(){
		$('#share-subscribe .friendHidden').first().slideDown();
		$('#share-subscribe .friendHidden').first().addClass('friendVisible')
		$('#share-subscribe .friendHidden').first().removeClass('friendHidden')
		return false;
	})
	
	

});
