﻿$(function()
{
	$('.banner').css({height: '310px'});
	$('.footerFooter').show();
	$('.footer, .footerBackground').css({height: '145px'});
	$('.footerBackgroundBlue').css({bottom: '145px'});
	
	var ops	= 
	{
		'padding'				: 20,
		'overlayShow'			: true,
		'overlayOpacity'		: '0.5',
		'frameWidth'			: 873,
		'frameHeight'			: 480,
		'hideOnOverlayClick'	: true,
		'hideOnContentClick'	: false
	};
	
	$('.video').fancybox(ops).click(function(event)
	{
		setupVideo();
	});
});

function setupVideo()
{
	var vars =
	{
		file				: 'anvil_promo.flv',
		width				: '873',
		height				: '480',
		controlbar			: 'over',
		autostart			: 'true',
		repeat				: 'none',
		linktarget			: '_self',
		quality				: 'true',
		screencolor			: '000000',
		skin				: '/flash/modieus.swf',
		bufferlength		: '15',
		javascriptid		: 'video',
		abouttext			: 'Powered by Anvil Digital',
		aboutlink			: 'http://www.anvildigital.com/'
	};

	var params =
	{
		allowscriptaccess	: 'always',
		allowfullscreen		: 'true',
		wmode				: 'transparent'
	};
			
	$('#fancy_div #anvil_promo_video').flash(
	{
		swf					: '/flash/player_fullscreen.swf',
		width				: vars.width,
		height				: vars.height,
		flashvars			: vars,
		params				: params
	});
}

ServiceProxy	= function(serviceUrl)
{
	var _I = this;
	this.serviceUrl = serviceUrl;

	// *** Call a wrapped object
	this.invoke = function(method,data,callback,error,bare)
	{
		// *** Convert input data into JSON - REQUIRES Json2.js
		var json = JSON2.stringify(data); 

		// *** The service endpoint URL        
		var url = _I.serviceUrl + method;

		jQuery.ajax
		(
			{ 
				url: url,
				data: json,
				type: "POST",
				processData: false,
				contentType: "application/json",
				timeout: 10000,
				dataType: "text",  // not "json" we'll parse
				success: 
					function(res) 
					{                                    
						if (!callback) return;

						// *** Use json library so we can fix up MS AJAX dates
						var result = JSON2.parse(res);

						// *** Bare message IS result
						if (bare)
						{ callback(result); return; }

						// *** Wrapped message contains top level object node
						// *** strip it off
						for(var property in result)
						{
							callback( result[property] );
							break;
						}                    
					},
				error:  
					function(xhr)
					{
						if (!error) return;
						if (xhr.responseText)
						{
							var err = JSON2.parse(xhr.responseText);
							if (err)
								error(err); 
							else    
								error( { Message: "Unknown server error." })
						}
						return;
					}
			}
		);   
	}
}