(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
	});
	
	jQuery.extend({
	  addStyle: function(path){
		var style = document.createElement('link');
		style.setAttribute('rel','stylesheet');
		style.setAttribute('type','text/css');
		style.setAttribute('href',path);
		document.getElementsByTagName('head')[0].appendChild(style)	;	  
	  }, 	  
	  
	  parseQuery: function(url) {
		   var query = url.replace(/^[^\?]+\??/,'');
		   var Params = {};
		   if ( ! query ) {return Params;}// return empty object
		   var Pairs = query.split(/[;&]/);
		   for ( var i = 0; i < Pairs.length; i++ ) {
		      var KeyVal = Pairs[i].split('=');	
		      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
		      var key = unescape( KeyVal[0] );
		      var val = unescape( KeyVal[1] );
		      val = val.replace(/\+/g, ' ');
		      Params[key] = val;
		   }
		   return Params;		  
	  }	  
	});

})();

if ($.browser.isIE) {
	//addStyle('css/stylefix.css');
}
function addStyle(patch){
	var style = document.createElement('link');
	style.setAttribute('rel','stylesheet');
	style.setAttribute('type','text/css');
	style.setAttribute('href',patch);
	document.getElementsByTagName('head')[0].appendChild(style)	;	
}


(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.slideBanner = function (settings) {
        var defaults = {
            text: ''
        };
        settings = $.extend(defaults, settings || {});

        return this.each(function () {
			$(this).append('<div class="nav-list"></div>');
			var items = $('.panel', this);
			var width  = $(this).width();
			var count = items.length;
			var self = this;
			$('.items', this).width(900 * count);
			$(items).each(function(index){$('.nav-list', self).append('<a href="javascript:;">'+index+'</a>');});
			
			$(this).serialScroll({
				axis: 'x',
				target: $('#banner-ct', this),
				navigation: $('.nav-list a', this),
				easing: 'swing',
				interval: 7 * 1000,
				duration: 500,
				items: items,
				onBefore: function(p1, p2, p3, p4, pos){
					$('.nav-list a', self).removeClass('active').eq(pos).addClass('active');
				}
			});
			$('.nav-list > a:first-child', self).click();
        });
    };
})(jQuery);

(function ($) {
    jQuery.fn.portfolioGallery = function (settings) {
		var defaults = {
			itemWidth: 722
		};
        settings = $.extend(defaults, settings || {});
        return this.each(function () {							   
			var count = $('.s-g-photo', this).length;
			$('.s-g-photos', this).width(count * settings.itemWidth);
			$('.s-gallery-wrap', this).serialScroll({
				axis: 'x',
				target: $('.s-gallery', this),
				prev: '.btn-left',
				next: '.btn-right',
				easing: 'swing',
				interval: 7 * 1000,
				duration: 500,
				items: $('.s-g-photo', this)
			});	
			var self = this;
			setTimeout(function(){$('.btn-right', self).click()}, 7 * 1000);
        });
    };
})(jQuery);

$(document).ready(function(){		
	$('#nav ul li').hover(function(){$(this).addClass('over');}, function(){$(this).removeClass('over');});	
	$('#banner').slideBanner();
 	$(window).scroll(function(){
	var pos = $('#btn-contact-us').css('top');
	pos = pos.replace('px', '');
	pos = $(window).scrollTop() + ($(window).height()/3);
    if (is_home || $('body').hasClass('sub-page')) {
        pos = $(window).scrollTop() - $('.container-wrap').scrollTop() - 107;
    }
	if (pos < 10) pos = 20;
  	$('#btn-contact-us').stop().animate({top: pos},750,'swing');});	
    
    $('.portfolio-items img').captify({
        speedOut: 100,
        speedOver: 100,
        itemWrapClass: 'portfolio-item-inner',
        className: 'portfolio-item-mask'
    });    
	$('#gallery').portfolioGallery();
	
 	if ($.browser.isIE6) {
		$('#banner .panel-pic').pngFix();
		//DD_belatedPNG.fix(".ie6fix");
	}	
});
