function toggle_chatbox () {
	if ($('.chatboxcontent iframe').height() == 0) 
	{  
		$('.chatboxcontent iframe').height(250);
	} 
	else 
	{
		$('.chatboxcontent iframe').height(0);		
	}
}

function close_chatbox(chatboxtitle) 
{
	$('.chatboxcontent iframe').remove();
	$('.chatbox').remove();
}

function init_chatbox()
{
	var chat_url = $('.chatboxtitle').attr('title');
	$("<iframe/>").attr('id','chat_frame').src(chat_url).appendTo("div.chatboxcontent");
	$("div.chatbox").show();
}

function chat_manager ()
{
	$('.gtalk-link').click(function () 
	{
		var chat_url = $(this).attr('href');
		$("<iframe/>").src(chat_url).appendTo("div.chatboxcontent");
		$("div.chatbox").show();
		return false;
	});	
	$('.chatboxoptions a.minimise_chat').click(function () 
	{
		if ($("div.chatboxcontent iframe").length)
		{
			toggle_chatbox();
		}
		else
		{
			init_chatbox();			
		}
		return false;
	});
	$('.chatboxoptions a.close_chat').click(function () 
	{
		close_chatbox();
		return false;
	});
}

$(document).ready(function () 
{		
	Cufon.replace('#header .left_col ul li a, a.more, .pagination a, #breadcrumbs a', {
		hover: true		
	});
	Cufon.replace('#header .right_col p, #content .module h2, #content .listing h3, #content .listing span.date, #content h1, #address h2, .article h2, .pagination span, .form_success, .form_error, #breadcrumbs span');	
	
	if (typeof document.body.style.maxHeight != "undefined")
	{
		chat_manager();
	}
	$('a[rel="external"]').attr('target','_blank');
	
	if ($('#banner').length)
	{
		var initWindowWidth = $(window).width();
				
		var carousel = $("#banner").CloudCarousel(		
		{			
			xPos: parseInt($('#banner').width() / 2),
			yPos: 27,
			minScale: 0.25,
			xRadius: 1000,
			yRadius: 98,	
			autoRotate: 'right',	
			autoRotateDelay: 4000,
			speed: 0.2
			/*
			buttonLeft: $("#left-but"),
			buttonRight: $("#right-but"),			
			*/
		});
		
		$(window).resize(function() 
		{
			currentWindowWidth = $(window).width();
			position = (currentWindowWidth - initWindowWidth) / 2;
			$('#banner div').css('left', position + 'px');
		});
		
	}
	
	if ($('.infield').length)
	{
		$(".infield label").inFieldLabels();
	}	
	
	if ($('#contact_form').length)
	{
		$('#contact_form').validate(
		{
			messages: 
			{
				full_name: {
					required: $('p.required_error').text()					
				},
				email: {
					required: $('p.required_error').text(),
					email: $('p.email_error').text()	
				},
				message: {
					required: $('p.required_error').text()						
				}, 
				delivery_address: {
					required: $('p.required_error').text()
				}
				
			}
		});
		$('#reset_button').click(function() 
		{
			$(':input','#contact_form').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
			return false;
		});
	}
});
