var img_resize_timer = false;
var gallery_resize_timer = false;
$(document).ready(function()
{
	// http://davecardwell.co.uk/javascript/jquery/plugins/jquery-browserdetect/
	if ($.browser.mac())
	{
		$('#latest .lft').css('padding-top','11px');
		$('#latest .mdl').css('padding-top','11px');
		$('#latest .rgt').css('padding-top','11px');
	}
	if ($.browser.safari() && $.browser.win())
	{
		$('#nav .inner').css('padding','6px 0 4px 0');
		$('#menu-primary-1 a').css('padding','8px 10px 10px 10px');
	}
	if (($.browser.safari() || $.browser.mozilla()) && $.browser.mac())
	{
		$('#nav .inner').css('padding','8px 0 3px 0');
		$('#menu-primary-1 a').css('padding','8px 10px 10px 10px');
	}
	if ($.browser.firefox() && $.browser.mac())
	{
		$('#nav .inner').css('padding','6px 0 3px 0');
		$('#menu-primary-1 a').css('padding','8px 10px 10px 10px');
	}

	if (typeof $.browser.SafariMobile != 'undefined' && $.browser.SafariMobile != null)
	{
	}

	// disable right click on images
	$('img').live('contextmenu',function(e){return false;});

	$('.new-window').click(function(){return !window.open($(this).attr('href'));});

	if ($('.txt-scroll').length > 0)
	{
		$('.txt-scroll').anythingSlider({
			easing:'easeInOutExpo',
			autoPlay:true,
			buildArrows:false,
			buildStartStop:false,
			stopAtEnd:true,
			hashTags:false,
			infiniteSlides:false,
			autoPlay:true,
			delay:10000,
			animationTime:1000
		});

		if ($('#clients-content .lft p').length > 0)
		{
			var w = $('div.anythingSlider .activePage').width() - ($('div.anythingSlider .anythingControls ul').width() + 5);
			$('#clients-content .lft p').css({
				'width':w
			});
		}
	}

	if ($('.img-scroll').length > 0)
	{
		$('.img-scroll').bind('initialized',function(base){
			$('div.anythingSlider .back').hide();
		}).anythingSlider({
			easing:'easeInOutExpo',
			autoPlay:false,
			buildStartStop:false,
			stopAtEnd:true,
			hashTags:false,
			infiniteSlides:false,
			animationTime:1000,
			onSlideComplete:function(base){
				if (base.currentPage == 1) base.$back.hide(); else base.$back.show();
				if (base.currentPage == base.pages) base.$forward.hide(); else base.$forward.show();
			}
		});
	}

	if ($('#contactform').length > 0)
	{
		$('#contactform').validate();
	}

	if ($('#img').length > 0 || $('#gallery').length > 0)
	{
		$('#loading').show();
	}

	// http://fancybox.net/api
	if ($('a[rel = "fancybox"]').length > 0)
	{
		$('a[rel = "fancybox"]').fancybox({
			'titleShow':false,
			'autoScale':false,
			'hideOnOverlayClick':true,
			'showCloseButton':true,
			'overlayOpacity':'0.84',
			'overlayColor':'#000',
			'padding':1
		});
	}

	if ($('#nav .menu li:last').length > 0)
	{
		$('a[href = "#inspired-by"]').addClass('inspired-by').attr('href','javascript:;');
		$('#logo,#wc,#nav .menu a').hover(function(){$('#inspired-by').hide();});
		$('a.inspired-by').hover(function()
		{
			var t = $(this).offset().top + $(this).outerHeight();
			var l = $(this).offset().left;
			$('#inspired-by').css({'top':t,'left':l}).show();
		});
		$('#inspired-by ul:last').addClass('last');
		$('#nav .menu li:last').addClass('last');
	}
});

$(window).load(function()
{
	position_img();
	$(window).bind('resize.img',function(){
		if (img_resize_timer != false) window.clearTimeout(img_resize_timer);
		img_resize_timer = window.setTimeout('position_img();',200);
	});

	position_gallery();
	$(window).bind('resize.gallery',function(){
		if (gallery_resize_timer != false) window.clearTimeout(gallery_resize_timer);
		gallery_resize_timer = window.setTimeout('position_gallery();',200);
	});

	$('#loading').hide();
});


function position_img()
{
	if ($('#img').length > 0)
	{
		var h = $(window).height();
		h = h - $('#latest').outerHeight();
		h = h - $('#home-logo').outerHeight();
		h = h - $('#nav').outerHeight();
		h = h - $('#home-content').outerHeight();
		h = h - $('#footer').outerHeight();
		h = h + 20;
		if (h < 200)
			h = 200;
		$('#img').height(h);
		if (h > $('#img img').height())
			$('#img').height($('#img img').height());
	}
}

function position_gallery()
{
	if ($('#gallery').length > 0)
	{
		var w = $('#gallery').css('width','100%').width();
		w = Math.floor(w / 8);
		if (typeof $.browser.SafariMobile != 'undefined' && $.browser.SafariMobile != null)
		{
		}
		if ($.browser.msie())
			w = w - 3;
		if ($.browser.safari())
			w = w - 3;
		if ($.browser.firefox())
			w = w - 3;
		$('#gallery .img').css('width',w).fadeTo(0,0.35).hover(function(){$(this).fadeTo(0,1);},function(){$(this).fadeTo(0,0.35);});

		var g_w = w * 8;
		$('#gallery').css('width',g_w);

		/*if (g_w < $('#gallery').width())
		{
			var first_img_w = w + ($('#gallery').width() - g_w);
			$('#gallery .img-first').css('width',first_img_w);
		}*/
	}
}

jQuery.extend(jQuery.browser,{SafariMobile:navigator.userAgent.toLowerCase().match(/iP(hone|ad)/i)});


// jQBrowser v0.2: http://davecardwell.co.uk/javascript/jquery/plugins/jquery-browserdetect/
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(c/a))+String.fromCharCode(c%a+161)};while(c--){if(k[c]){p=p.replace(new RegExp(e(c),'g'),k[c])}}return p}('Ö ¡(){® Ø={\'¥\':¡(){¢ £.¥},\'©\':{\'±\':¡(){¢ £.©.±},\'¯\':¡(){¢ £.©.¯}},\'¬\':¡(){¢ £.¬},\'¶\':¡(){¢ £.¶},\'º\':¡(){¢ £.º},\'Á\':¡(){¢ £.Á},\'À\':¡(){¢ £.À},\'½\':¡(){¢ £.½},\'¾\':¡(){¢ £.¾},\'¼\':¡(){¢ £.¼},\'·\':¡(){¢ £.·},\'Â\':¡(){¢ £.Â},\'³\':¡(){¢ £.³},\'Ä\':¡(){¢ £.Ä},\'Ã\':¡(){¢ £.Ã},\'Å\':¡(){¢ £.Å},\'¸\':¡(){¢ £.¸}};$.¥=Ø;® £={\'¥\':\'¿\',\'©\':{\'±\':²,\'¯\':\'¿\'},\'¬\':\'¿\',\'¶\':§,\'º\':§,\'Á\':§,\'À\':§,\'½\':§,\'¾\':§,\'¼\':§,\'·\':§,\'Â\':§,\'³\':§,\'Ä\':§,\'Ã\':§,\'Å\':§,\'¸\':§};Î(® i=0,«=».ì,°=».í,¦=[{\'¤\':\'Ý\',\'¥\':¡(){¢/Ù/.¨(°)}},{\'¤\':\'Ú\',\'¥\':¡(){¢ Û.³!=²}},{\'¤\':\'È\',\'¥\':¡(){¢/È/.¨(°)}},{\'¤\':\'Ü\',\'¥\':¡(){¢/Þ/.¨(°)}},{\'ª\':\'¶\',\'¤\':\'ß Ñ\',\'¥\':¡(){¢/` á â/.¨(«)},\'©\':¡(){¢ «.¹(/ã(\\d+(?:\\.\\d+)+)/)}},{\'¤\':\'Ì\',\'¥\':¡(){¢/Ì/.¨(«)}},{\'¤\':\'Í\',\'¥\':¡(){¢/Í/.¨(°)}},{\'¤\':\'Ï\',\'¥\':¡(){¢/Ï/.¨(«)}},{\'¤\':\'Ð\',\'¥\':¡(){¢/Ð/.¨(«)}},{\'ª\':\'·\',\'¤\':\'å Ñ\',\'¥\':¡(){¢/Ò/.¨(«)},\'©\':¡(){¢ «.¹(/Ò (\\d+(?:\\.\\d+)+(?:b\\d*)?)/)}},{\'¤\':\'Ó\',\'¥\':¡(){¢/æ|Ó/.¨(«)},\'©\':¡(){¢ «.¹(/è:(\\d+(?:\\.\\d+)+)/)}}];i<¦.Ë;i++){µ(¦[i].¥()){® ª=¦[i].ª?¦[i].ª:¦[i].¤.Õ();£[ª]=É;£.¥=¦[i].¤;® ­;µ(¦[i].©!=²&&(­=¦[i].©())){£.©.¯=­[1];£.©.±=Ê(­[1])}ê{® Ç=Ö ë(¦[i].¤+\'(?:\\\\s|\\\\/)(\\\\d+(?:\\\\.\\\\d+)+(?:(?:a|b)\\\\d*)?)\');­=«.¹(Ç);µ(­!=²){£.©.¯=­[1];£.©.±=Ê(­[1])}}×}};Î(® i=0,´=».ä,¦=[{\'ª\':\'¸\',\'¤\':\'ç\',\'¬\':¡(){¢/é/.¨(´)}},{\'¤\':\'Ô\',\'¬\':¡(){¢/Ô/.¨(´)}},{\'¤\':\'Æ\',\'¬\':¡(){¢/Æ/.¨(´)}}];i<¦.Ë;i++){µ(¦[i].¬()){® ª=¦[i].ª?¦[i].ª:¦[i].¤.Õ();£[ª]=É;£.¬=¦[i].¤;×}}}();',77,77,'function|return|Private|name|browser|data|false|test|version|identifier|ua|OS|result|var|string|ve|number|undefined|opera|pl|if|aol|msie|win|match|camino|navigator|mozilla|icab|konqueror|Unknown|flock|firefox|netscape|linux|safari|mac|Linux|re|iCab|true|parseFloat|length|Flock|Camino|for|Firefox|Netscape|Explorer|MSIE|Mozilla|Mac|toLowerCase|new|break|Public|Apple|Opera|window|Konqueror|Safari|KDE|AOL|America|Online|Browser|rev|platform|Internet|Gecko|Windows|rv|Win|else|RegExp|userAgent|vendor'.split('|')));

