/* Author: Scott Borys

*/
/* 
$(function(){
	$("#twitter blockquote").tweet({
		username: "scottborys",
		count: 1,
		fetch: 1,
		template: "{text}",
		loading_text: "loading..."
	});
}); 
*/
$(document).ready( function(){
	// INPUT UX
	$("input:text").click( function() {
		valueIsDefault($(this)) ? $(this).caret(0,0) : $.noop();
		$(this).hasClass("focus") === false && $(this).val() == $(this).prop("defaultValue") ? $(this).addClass("focus") : $.noop();    
	}).keydown ( function(e) {
		var BACKSPACE_KEY_CODE = 8;
		var SHIFT_KEY_CODE     = 16;
		if ( e.which == SHIFT_KEY_CODE ) {
			// do nothing
		} else if ( e.which == BACKSPACE_KEY_CODE ) {
			if ( $(this).val().length == 1 ) {
				var temp = $(this).prop("defaultValue");
				$(this).val(temp).addClass("focus").caret(0,0);
			}
		} else {
			valueIsDefault($(this)) ? $(this).val("") : $.noop();
			var hasClass = $(this).hasClass("focus") ? true : false;
			var isBlank  = $(this).val() === "" ? true : false;
			if ( true === hasClass && true === isBlank ) {
				// do nothing
			} else if ( true === hasClass && false === isBlank ) {
				$(this).removeClass("focus");
			} else if ( false === hasClass && true === isBlank ) {
				$(this).addClass("focus");
			} else if ( false === hasClass && false === isBlank ) {
				// do nothing
			}
			if ( false === valueIsDefault($(this)) && $(this).hasClass("focus") ) {
				$(this).removeClass("focus");
			}            
		}
	}).blur ( function() {
		$(this).val() === "" ? $(this).val($(this).prop("defaultValue")) : $.noop();
		$(this).hasClass("focus") ? $(this).removeClass("focus") : $.noop();
	}); 
	
	//Smooth Scroll
	$("#main").localScroll({
		duration: 400
	});
	
	// YouTube Fancybox
	$("#play-video").click( function() {
		$.fancybox({
			'titleShow'     : true,
			'transitionIn'  : 'elastic',
			'transitionOut' : 'elastic',
			'width'         : '524',
			'height'        : '320',
			'title'         : this.title,
			'overlayOpacity': '0.8',
			'overlayColor'  : '#00192d',
			'titlePosition' : 'inside',           
			'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'          : 'swf',
			'swf'           : {'allowfullscreen':'true'}
		});
		return false;  	
	}); 
	
	// Form Validation for IE
	if ( true === $("html").hasClass("oldie") && true === $("html").hasClass("brochure-page") ) {
		$("#signup").validate({
			errorPlacement: function(error, element) {
				// do nothing
			},
			rules: {
				title: "required",
				fname: "required",
				lname: "required",
				organisation: "required",
				telephone: "required",
				email: {
					required: true,
					email: true
				}
			}
		});
	}
});






