(function(){
	ua = navigator.userAgent.toLowerCase(),	  
	check = function(r){
		return r.test(ua);
	}
	isOpera = check(/opera/),			  
	isIE = check(/msie/),
	isIE7 = isIE && check(/msie 7/),
	isIE8 =	isIE && check(/msie 8/),
	isIE6 =	isIE && !isIE7 && !isIE8,
	isChrome = check(/chrome/),
	isWebKit =check(/webkit/),
	isSafari =!isChrome && check(/safari/),
	isSafari2 =	isSafari && check(/applewebkit\/4/),
	isSafari3 = isSafari && check(/version\/3/),
	isSafari4 = isSafari && check(/version\/4/),
	isGecko = !isWebKit && check(/gecko/),
	isGecko2 = isGecko && check(/rv:1\.8/),
	isGecko3 = isGecko && check(/rv:1\.9/),
	isWindows = check(/windows|win32/),	
	isMac = check(/macintosh|mac os x/),	
	isAir = check(/adobeair/),	
	isLinux = check(/linux/),
	
	
	jQuery.extend(jQuery.browser, {
		isOpera: isOpera,
		isIE:	isIE,
		isIE6: isIE6,
		isIE7: isIE7,
		isIE8: isIE8,
		isChrome: isChrome,
		isWebKit: isWebKit,
		isSafari: isSafari,
		isSafari2: isSafari2,
		isSafari3: isSafari3,
		isSafari4: isSafari4,
		isGecko: isGecko,
		isGecko2: isGecko2,
		isGecko3: isGecko3,
		isWindows: isWindows,
		isMac: isMac,
		isAir: isAir,
		isLinux: isLinux
	});
})();

(function($) {
	jQuery.fn.contactForm = function(settings){
		settings = jQuery.extend({								 
		}, settings);

		return this.each(function(){							  		
		var self = this;		
		$("form", this).validate({
		rules: {
		},								 
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}
		,submitHandler: function() {
			$("#contact-form", self).hide();
			$("#sending-msg", self).show();
			$('form', self).ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$("#sending-msg", self).hide();
					$("#contact-result", self).html("<p class=\"info\">Thanks "+result.name+", for contacting us, "+result.msg+".</p>" +
							             "<p align=\"center\">" +
              							 "<button id=\"btn-back\" class=\"x-btn\">Back</button>"+
            							 "</p>");	
					$("#contact-result", self).show();
					$("#btn-back", self).click(function(){
					    $("#contact-result", self).hide();
						$("#contact-form", self).show();												  
					});					
				}										  
			});
		}
		}
		);				
		});
	};
})(jQuery);

(function ($) {
    jQuery.fn.defaultText = function (settings) {
        var defaults = {
            text: ''
        };
        settings = $.extend(defaults, settings || {});

        return this.each(function () {
            $(this).val(settings.text);
            $(this).focus(function () {
                var text = $.trim($(this).val());
                if (text == settings.text) {
                    $(this).val('');
                }
            });
            $(this).blur(function () {
                var text = $.trim($(this).val());
                if ('' == text) {
                    $(this).val(settings.text);
                }
            });
        });
    };
})(jQuery);

(function($) {
	jQuery.fn.quickContactForm = function(settings){
		settings = jQuery.extend({								 
		}, settings);

		return this.each(function(){							  		
		$('.item-name', this).defaultText({text: 'Name:'});
		$('.item-email', this).defaultText({text: 'Email:'});
		$('.item-phone', this).defaultText({text: 'Phone:'});
		$('.item-service', this).defaultText({text: 'Service required:'});
		$('.item-desc', this).defaultText({text: 'Briefly describe event:'});
		var self = this;		
		$("form", this).validate({
		errorPlacement: function(error, element) {
			$(element).addClass('error');
		}
		,submitHandler: function() {
			$("#quick-contact-form", self).hide();
			$("#quick-sending-msg", self).show();
			$('form', self).ajaxSubmit({
				dataType: 'json',
				type: 'post',
				success : function(result){
					$("#quick-sending-msg", self).hide();
					$("#quick-contact-result", self).html("<p class=\"info\">Thanks "+result.name+", for contacting us, "+result.msg+".</p>" +
							             "<p align=\"center\">" +
              							 "<a href=\"javascript:;\" class=\"btn-back\"><img alt=\"back\" src=\"images/btn-back.png\"/></a>"+
            							 "</p>");	
					$("#quick-contact-result", self).show();
					$(".btn-back", self).click(function(){
					    $("#quick-contact-result", self).hide();
						$("#quick-contact-form", self).show();												  
					});					
				}										  
			});
		}
		}
		);				
		});
	};
})(jQuery);

(function($) {
	jQuery.fn.gallery = function(settings){
		settings = jQuery.extend({								 
		}, settings);

		return this.each(function(){							  		
			$('#gallery .thumb a').lightBox();			
		});
	};
})(jQuery);


$(document).ready(function(){		
	$('#quick-contact-wrap').quickContactForm();						   
	$('#contact-form-wrap').contactForm();
	//$('#gallery').gallery();
});
