(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({
		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.slideMenu = function(settings){
		
		return this.each(function(){									  							  
			var mHeight = $('ul', this).height();
			var mWidth = $('ul', this).width();


			if(mHeight){				
				 $('ul', this).wrap('<div class="submenu-wrap"></div>');
				 $('ul', this).wrap('<div class="submenu"></div>');
				  $('ul', this).wrap('<div class="submenu-inner"></div>');
				  $('.submenu-inner', this).after('<div class="submenu-bg"></div>');
				  
				  mHeight = $('ul', this).height();
				  
				  $('.submenu-inner', this).width(mWidth).height(mHeight);
				  $('.submenu-bg', this).width(mWidth).height(mHeight + 12);
				  $('.submenu', this).width(mWidth).height(mHeight);
				 
				 $('ul', this).show();

				 $('.submenu-wrap', this).width($('.sub-menu', this).width() + 2);
				 $('.submenu', this).css({'top': '-' + (mHeight) + 'px'});
				 
				 $('ul li', this).hover(function(){
					$(this).addClass('sub-over');												 
				 }, function(){
					 $(this).removeClass('sub-over');	
				 });
				 
				 
			}
		
			var show = function(obj){
				$(obj).addClass('over');
				$('.submenu-wrap', obj).height(mHeight + 12);
				$('.submenu', obj).stop().animate({top: 0}, 450, 'swing');
			}
		
			var hide = function(obj){
				if(mHeight){
					$('.submenu', obj).stop().animate({top: '-' + (mHeight) + 'px'}, 450, 'swing', function(){
						$('.submenu-wrap', obj).height(0);
						$(obj).removeClass('over');
					});
				}
				else{
					$(obj).removeClass('over');
				}
			}
		
			$(this).hover(function(){
				show(this);
			}, function(){
				hide(this);
			});								  
		});
	};
})(jQuery);	

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

		return this.each(function(){							  		
			$('#gallery a').lightBox({
            imageLoading:          theme_url + '/images/lightbox-ico-loading.gif',      // (string) Path and the name of the loading icon
            imageBtnPrev:          theme_url + '/images/lightbox-btn-prev.gif',         // (string) Path and the name of the prev button image
            imageBtnNext:          theme_url + '/images/lightbox-btn-next.gif',         // (string) Path and the name of the next button image
            imageBtnClose:         theme_url + '/images/lightbox-btn-close.gif',        // (string) Path and the name of the close btn
            imageBlank:            theme_url + '/images/lightbox-blank.gif'
            });			
		});
	};
})(jQuery);
$(document).ready(function(){		
	Cufon.replace('#nav ul li a', {hover: true});
	Cufon.replace('#content h2, #content h3, #contact-form ul li label');
	Cufon.replace('#content .post-detail h4.entry-title a', {hover: true});
	$('#nav > div > ul > li').slideMenu();
	$('#contact-form-wrap').contactForm();
	$('#content .aligncenter').parents('p').attr('align', 'center');
	$('#gallery').gallery();
});
