/*Define three t namespace*/
site = { };

/**********************************
* Begin Cufon
**********************************/
//Font
//Cufon.set('fontFamily', '');
Cufon.replace('.sidebox h3, #home-footer h3, #home-footer cite, #page-left h1, #page-left h2, #page-right h1, #page-contact h1, .snippet h2, .box h2, #sidebox-services ul li a, div.slide-text', 
{
	//letterSpacing : '-0.5em'
});
/**********************************
* End Cufon
**********************************/


/**********************************
* Begin Cornerz
**********************************/
site.rounded_corners =
{
	init : function()
	{
		// Return if it doesn't look like cornerz has been loaded into jquery
		if (!$.fn.cornerz)
			return;

		var activate = false;

		// TODO: This will require expanding for other browsers that need cornerz
		if (navigator.appName=="Microsoft Internet Explorer")
			activate = parseInt(navigator.appVersion) <= 8;

		if (activate)
			site.rounded_corners.apply_styles();
	},

	// NB styles will not be applied to anything with a .no-cornerz class assigned.
	apply_styles : function()
	{
		$('.rounded-button').not('.no-cornerz').cornerz({radius:6, background:'#3D768C'});
		$('.rounded-box').not('.no-cornerz').cornerz({radius:10, background:'#3D768C'});
	}
};


/**********************************
* Toggle Gibblets (singleton)
**********************************/
site.toggler =
{
	control_class : false,
	subject_class : false,
	active_suffix : '-active',
	hidden_class : 'hide',
	
	init : function(control_class, subject_class)
	{
		this.control_class = control_class;
		this.subject_class = subject_class;
		this.bind();
	},
	
	bind : function()
	{
		t = site.toggler;
		
		$(t.control_class).bind("change", function()
		{
			target_id = $(this).attr("name") + "-" + $(this).val();
			
			$(t.subject_class).each(function()
			{
				if ($(this).attr('id') == target_id)
					$(this).removeClass(t.hidden_class);
				else
					$(this).addClass(t.hidden_class);
			});
		});
	}
	
};

/**********************************
* AG: Form Submit Proxy JQ Plugin
* Allow another element to submit a form held in the same parent el
* or should the subject specify a target via the rel attribute then the
* submission of this given form where subject rel = target id
**********************************/
(function($)
{
	$.fn.form_submit_proxy = function()
	{  
		return this.each(function()
		{
			$this = $(this);
			$this.bind("click", function()
			{
				rel = $(this).attr("rel");
				
				if ((rel != "") && ($("#" + rel).length > 0))
					target = $("#" + rel)
				else
					target = $(this).parents().eq(0).find("form").eq(0);
				
				target.submit();
				
				return false;
			});
		});
	};
})(jQuery);	
/**********************************
* End FSP
**********************************/

/**********************************
* Dom Ready
**********************************/
$(function()
{
	site.rounded_corners.init();
	
	site.toggler.init('.toggle-id-control', '.toggle-id-subject');
	
	
	
	/**************************************************************************
	- Start Hero Slider
	**************************************************************************/
	
	if ($('#home-hero').length)
	{
		$('#home-hero').cycle(
		{ 
			fx:      'fade', 
			speed:    700, 
			timeout:  5000
			//before: onBefore,
			//after: onAfter
		});	
	}
	/*
	function onAfter() {
		// get this eq
		var eq = parseInt(this.alt.substr(-1))-1;
				
		
		// The active text
		$('#home-hero-text div:eq('+eq+')').css({
			'display' : 'inline'
		});
	}
	
	function onBefore() {
		$('#home-hero-text').children('cufon').remove();
		
		$('#home-hero-text div').each(function() {
			$(this).css({
				"display" : "none",
				"z-index" : "4",
			});
		});
	}
	*/
	/**************************************************************************
	- End Hero Slider
	**************************************************************************/
	
	
	
	//FSP
	$(".fsp").form_submit_proxy();
	
	//Open in new window
	$('a[href$=".zip"],a[href$=".pdf"],a[href$=".doc"],a[href$=".docx"],a[href$=".xls"],.open_external').live("click", function()
	{
		window.open( $(this).attr("href") );
		return false;
	});	
});
