$(document).ready(function() {
	
	if(document.getElementById('splash')) {
		$('div.image img').fadeTo(0, 1);
		
		$('div.item').hover(function() {
			$(this).children('div').fadeTo(300, 0.5);
		}, function() {
			$(this).children('div').fadeTo(150, 1);
		});	
	}
	
});

var application = new Object();

application.comingsoon = function() {
	$('div.comingsoon').click(function() {
		return false;
	});
}

application.writeemail = function() {
	$('.writeemail').text('leslie' + '@' + 'shepherd-photography.com');
}

application.writephone = function() {
	$('.writephone').text('405' + '-' + '234' + '-' + '7735');
}

application.notifyemail = function() {
	$('div#notifyemail form').submit(function() {
		var url = $(this).attr('action');
		var email = $(this).children('div').children('input:first-child').val();
		var regex = new RegExp('(".+"\s)?<?[a-z\._0-9]+[^\._]@([a-z0-9]+\.)+[a-z0-9]{2,6}>?;?', 'i');
		if(email.match(regex) == null) {
			$('div#notifyemail div#output').text('email invalid');
			$(this).children('div').children('input:first-child').focus();
			return false;
		}
		$('div#notifyemail div#output').text('working...');
		$.post(url, { 'email' : email, 'ajax' : 1 }, function() {
			$('div#notifyemail div#output').text('Thank you!');
		});
	
		return false;
	});
	
	$('div#notifyemail form div input:first-child').focus(function() {
		if($(this).val() == this.defaultValue) {
			$(this).val('');
		}
	});
	
}

 /* Silvertlight */

/*  
function onSourceDownloadProgressChanged(sender, eventArgs) {
	var myHost = document.getElementById('silverlightObject');
	var rectBar = myHost.content.findName('rectBar');
	var rectBorder = myHost.content.findName('rectBorder')
	var loadText = myHost.content.findName('loadText')
	if(eventArgs.progress) {
		rectBar.Width = eventArgs.progress * rectBorder.Width;
		loadText.Text = "Loading... " + Math.round(eventArgs.progress * 100).toString() + "%";
	} else {
		rectBar.Width = eventArgs.get_progress() * rectBorder.Width;
		loadText.Text = "Loading... " + Math.round(eventArgs.get_progress() * 100).toString() + "%";
	}
} 
*/

function new_window(url, target, options){
	window.open(url, target, options);
}

// Error
function onSilverlightError(sender, args) {
	var appSource = "";
	if (sender != null && sender != 0) {
	  appSource = sender.getHost().Source;
	}
	
	var errorType = args.ErrorType;
	var iErrorCode = args.ErrorCode;

	if (errorType == "ImageError" || errorType == "MediaError") {
	  return;
	}

	var errMsg = "Unhandled Error in Silverlight Application " +  appSource + "\n" ;

	errMsg += "Code: "+ iErrorCode + "    \n";
	errMsg += "Category: " + errorType + "       \n";
	errMsg += "Message: " + args.ErrorMessage + "     \n";

	if (errorType == "ParserError") {
		errMsg += "File: " + args.xamlFile + "     \n";
		errMsg += "Line: " + args.lineNumber + "     \n";
		errMsg += "Position: " + args.charPosition + "     \n";
	}
	else if (errorType == "RuntimeError") {           
		if (args.lineNumber != 0) {
			errMsg += "Line: " + args.lineNumber + "     \n";
			errMsg += "Position: " +  args.charPosition + "     \n";
		}
		errMsg += "MethodName: " + args.methodName + "     \n";
	}

	throw new Error(errMsg);
}
