Cufon.replace("body:not(.blog) h1, ul.menu li, body:not(.blog)>.content-parent h3", {hover: true, fontFamily: "Haptic"});
Cufon.replace("body:not(.blog)>.content-parent .three-columns h4, .projects h3, .partnership .superhero h3, .cols2 .r-content h3, .content h1", {fontFamily: "Haptic"});
Cufon.replace("p.tagline, .partnership h3, .realisations h3, .partnership ul p, .partnership ul p a, .header p.title, .content .section h2, .content .section h1, h1.offer-details, .cols2 h3, .two-columns h3", {fontFamily: "Haptic Light"});
Cufon.replace(".section.home h2", {fontFamily: "Haptic"});
Cufon.replace(".partnership h3 strong");
Cufon.replace(".partnership .superhero h3", {fontFamily: "Haptic"});
Cufon.replace(".partnership .superhero h3 strong", {fontFamily: "Haptic Black"});
//if(!$.browser.msie)
Cufon.replace(".section h3, .content h2", {fontFamily: "Haptic Light"});
Cufon.replace(".landing-page-banner h2", {fontFamily: "Haptic Light"});
Cufon.replace(".content.landing-page h2 span", {fontFamily: "Haptic Black"});

$("a.contrast").click(function() { $("body").toggleClass("hc"); createCookie("style", $("body").hasClass("hc") ? "hc" : "", 365); return false; });
if (readCookie("style") == "hc" && !$("body").hasClass("hc"))
	$("a.contrast").click();


String.prototype.startsWith = function(start) {
	var str = this.substr(0, Math.min(this.length, start.length));
	return str == start;
};


// plugin detection - displaying movie or intro
if($(".intro").length){
	if($.browser.flash){
		$(".player").not(".flash").remove();
		$(".player.flash").css("display", "block").html('<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="950" height="425"> <param name="movie" value="video/player.swf"> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="wmode" value="transparent"> <param name="flashvars" value="file=http://merixstudio.com/video/reel_small.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;vskin=video/skins/merix.xml&amp;autoplay=true&amp;plugins=hd&amp;hd.file=http://merixstudio.com/video/reel_big.mp4&amp;playerready=playerReadyCallback"> <embed type="application/x-shockwave-flash" id="player2" name="player2" src="video/player.swf" width="950" height="425" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" autoplay="true" flashvars="file=http://merixstudio.com/video/reel_small.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;skin=video/skins/merix.xml&amp;plugins=hd&amp;hd.file=http://merixstudio.com/video/reel_big.mp4&amp;playerready=playerReadyCallback"></object>');
		$(".intro").hide();
	} else if($.browser.qtime) {
		$(".player").not(".qtime").remove();
		$(".player.qtime").css("display", "block").html('<object class="quicktime" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" id="" height="950" width="425"><param name="src" value="http://merixstudio.com/video/showreel.m4v?width=950&amp;height=425"><param name="showlogo" value="false"><param name="scale" value="tofit"><param name="saveembedtags" value="true"><param name="postdomevents" value="true"><embed scale="tofit" showlogo="false" controller="true" postdomevents="true" type="video/quicktime" src="http://merixstudio.com/video/showreel.m4v?width=950&amp;height=425" height="425" width="950"><param name="controller" value="true"><param name="posterframe" value="video/preview.jpg"><param name="showlogo" value="false"><param name="autostart" value="true"><param name="cache" value="true"><param name="bgcolor" value="#333333"><param name="aggressivecleanup" value="false"><param name="controller" value="true"><param name="posterframe" value="video/preview.jpg"><param name="showlogo" value="false"><param name="autostart" value="true"><param name="cache" value="true"> <param name="bgcolor" value="#333333"> <param name="aggressivecleanup" value="false"> </object>');
		$(".intro").hide();
	} else if($.browser.wmp) {
		$(".player").not(".wmp").remove();
		$(".intro").hide();
	} else {
		$(".intro").show();
		$(".player").hide();
	}
}

if($(".landing-page").length){
	if($.browser.flash){
		$(".player").not(".flash").remove();
		$(".player.flash").css("display", "block").html('<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="598" height="278"> <param name="movie" value="video/player.swf"> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="wmode" value="transparent"> <param name="flashvars" value="file=http://merixstudio.com/video/reel_small.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;vskin=video/skins/merix.xml&amp;autoplay=true&amp;plugins=hd&amp;hd.file=http://merixstudio.com/video/reel_big.mp4&amp;playerready=playerReadyCallback"> <embed type="application/x-shockwave-flash" id="player2" name="player2" src="video/player.swf" width="598" height="276" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" autoplay="true" flashvars="file=http://merixstudio.com/video/reel_small.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;skin=video/skins/merix.xml&amp;plugins=hd&amp;hd.file=http://merixstudio.com/video/reel_big.mp4&amp;playerready=playerReadyCallback"></object>');
		$(".intro").hide();
	} else if($.browser.qtime) {
		$(".player").not(".qtime").remove();
		$(".player.qtime").css("display", "block").html('<object class="quicktime" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" id="" height="598" width="278"><param name="src" value="http://merixstudio.com/video/showreel.m4v?width=950&amp;height=425"><param name="showlogo" value="false"><param name="scale" value="tofit"><param name="saveembedtags" value="true"><param name="postdomevents" value="true"><embed scale="tofit" showlogo="false" controller="true" postdomevents="true" type="video/quicktime" src="http://merixstudio.com/video/showreel.m4v?width=598&amp;height=276" height="276" width="598"><param name="controller" value="true"><param name="posterframe" value="video/preview.jpg"><param name="showlogo" value="false"><param name="autostart" value="true"><param name="cache" value="true"><param name="bgcolor" value="#333333"><param name="aggressivecleanup" value="false"><param name="controller" value="true"><param name="posterframe" value="video/preview.jpg"><param name="showlogo" value="false"><param name="autostart" value="true"><param name="cache" value="true"> <param name="bgcolor" value="#333333"> <param name="aggressivecleanup" value="false"> </object>');
		$(".intro").hide();
	} else if($.browser.wmp) {
		$(".player").not(".wmp").remove();
		$(".intro").hide();
	} else {
		$(".intro").show();
		$(".player").hide();
	}
}

$(".offer-movie.apps").html('<object id="player" wmode="transparent" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="430" height="305"> <param name="wmode" value="transparent"> <param name="movie" value="video/player.swf"> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="flashvars" value="file=loop_euroenergia.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;vskin=video/skins/merix.xml&amp;autoplay=true&amp;plugins=hd&amp;hd.file=loop_euroenergia.mp4&amp;playerready=playerReadyCallback&controlbar=none"> <embed type="application/x-shockwave-flash" id="player2" wmode="transparent" name="player2" src="video/player.swf" width="430" height="305" allowscriptaccess="always" allowfullscreen="true" autoplay="true" flashvars="file=loop_euroenergia.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;skin=video/skins/merix.xml&amp;plugins=hd&amp;hd.file=loop_euroenergia.mp4&amp;playerready=playerReadyCallback&amp;controlbar=none"></object>');
$(".offer-movie.design").html('<object id="player" wmode="transparent" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="430" height="305"> <param name="wmode" value="transparent"> <param name="movie" value="video/player.swf"> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="flashvars" value="file=loop_euroenergia.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;vskin=video/skins/merix.xml&amp;autoplay=true&amp;plugins=hd&amp;hd.file=loop_euroenergia.mp4&amp;playerready=autoPlay&controlbar=none"> <embed type="application/x-shockwave-flash" id="player2" wmode="transparent" name="player2" src="video/player.swf" width="430" height="305" allowscriptaccess="always" allowfullscreen="true" autoplay="true" flashvars="file=loop_euroenergia.mp4&amp;image=video/preview.jpg&amp;provider=http&amp;skin=video/skins/merix.xml&amp;plugins=hd&amp;hd.file=loop_euroenergia.mp4&amp;playerready=autoPlay&amp;controlbar=none"></object>');

var player;
function playerReadyCallback(obj){
	player = document.getElementById(obj['id']);
	player.sendEvent("PLAY","true");
	player.sendEvent("PLAY","false");
}
function autoPlay(obj){
	player = document.getElementById(obj['id']);
	player.sendEvent("PLAY","true");
}
var pl = $("body").hasClass("pl");


$(".intro").each(function(){
	var $intro = $(this);

	var $projects = $intro.find(".content");
	$projects.children("li").removeClass("hidden");
	$projects.children("li").not($projects.children("li").eq(0)).hide();


	var $introNav = $intro.find("> .navigation > ul");
	$introNav.find("> li:first").after("<li><a class=\"play\" href=\"#\">|| / [&gt;</a></li>");
	$introNav.find("> li:first").after("<li><a class=\"pause\" href=\"#\">|| / [&gt;</a></li>");
	introNavH = -$introNav.outerHeight() - $intro.find("> .navigation > p").outerHeight();
	$introNav.css("margin-top", introNavH + "px").hide();
	$intro.find("> .navigation")
		.bind("mouseenter", function() { $introNav.show().stop(true).animate({ marginTop: "0px" }, 350, "swing"); })
		.bind("mouseleave", function() { $introNav.stop(true).animate({ marginTop: introNavH + "px" }, 150, "swing", function() { $(this).hide(); }); });

	var
		$prev = $intro.find("a.previous"),
		$next = $intro.find("a.next"),
		$pause = $intro.find("a.pause"),
		$play = $intro.find("a.play"),
		currentSlide = 0,
		slideCount = $intro.find(".content li").length;
		freq = 3000,
		speed = 1000
	;

	$play.hide();
	function changeSlide(dir){
		if(!dir) dir = 1;
		$intro.find(".content li").eq(currentSlide).fadeOut(speed);
		if(dir > 0) {
			if(currentSlide == slideCount - 1) currentSlide = 0;
			else currentSlide++;
		} else {
			if(currentSlide == 0) currentSlide = slideCount - 1;
			else currentSlide--;
		}
		$intro.find(".content li").eq(currentSlide).fadeIn(speed);
	}

	var slideInt = setInterval(changeSlide, freq);

	$next.click(function(e){
		e.preventDefault();
		clearInterval(slideInt);
		$intro.find(".content li").eq(currentSlide).fadeOut(speed);
		if(currentSlide == slideCount - 1) currentSlide = 0;
		else currentSlide++;
		$intro.find(".content li").eq(currentSlide).fadeIn(speed);
		slideInt = setInterval(changeSlide, freq);
	});

	$prev.click(function(e){
		e.preventDefault();
		$intro.find(".content li").eq(currentSlide).fadeOut(speed);
		if(currentSlide == 0) currentSlide = slideCount - 1;
		else currentSlide--;
		$intro.find(".content li").eq(currentSlide).fadeIn(speed);
		slideInt = setInterval(changeSlide, freq);
	});

	$pause.click(function(e){
		e.preventDefault();
		clearInterval(slideInt);
		$(this).hide();
		$play.show();
	});

	$play.click(function(e){
		e.preventDefault();
		slideInt = setInterval(changeSlide, freq);
		$(this).hide();
		$pause.show();
	});

});

function introPause(dir){
	$intro = $(".intro");
	$intro.each(function(){
		$(this).find("a.pause").click();
	});
}



/*
** site map magix
*/

$("#site-map:first").clone().prependTo("body");
$(".site-map:last").remove();
var sitemap = $("#site-map");
var sitemapH = -sitemap.outerHeight();
sitemap.css("margin-top", sitemapH + "px").hide();

$("a[href=#site-map]").click(function()
{
	if (sitemap.is(":animated"))
		return false;
	if (sitemap.is(":visible"))
		sitemap.stop(true).animate({ marginTop: sitemapH + "px" }, 750, "swing", function() { $(this).hide(); });
	else
		sitemap.show().stop(true).animate({ marginTop: "0px" }, 750, "swing");
	return false;
});



var testimonials = $(".testimonials");
if (testimonials.length)
{
	testimonials.append("<ul class=\"numbers\"></ul>");
	var h = 0;
	testimonials.find("> ul:not(.numbers) > li").each(function(i)
	{
		h = Math.max(h, $(this).outerHeight());
		$(this).attr("id", "testimonial-" + i);
		testimonials.find(".numbers").append("<li><a href=\"#testimonial-" + i + "\">" + (i + 1) + "</a></li>");
	});
	testimonials.find("> ul:not(.numbers)").height(h);

	testimonials.find(".numbers a").click(function(event, fast)
	{
		if ($(this).hasClass("selected"))
			return false;

		$(this).parents(".numbers").find("a.selected").removeClass("selected");
		$(this).addClass("selected");

		if (fast)
		{
			$(this).parents(".testimonials").find("> ul:not(.numbers) > li:visible").hide();
			$($(this).hrefId()).show();
		}
		else
		{
			$(this).parents(".testimonials").find("> ul:not(.numbers) > li:visible").fadeOut(500);
			$($(this).hrefId()).animate({ opacity: "show" }, 500, "linear", function() { if ($.browser.msie && $.browser.version == 7) this.style.removeAttribute("filter"); });
		}

		return false;
	});

	testimonials.find(".numbers a:first").trigger("click", true);
}


$(".welcome p:first-child").append("<a class=\"close\">X</a>");
$(".welcome a.close").click(function() { $(this).parent().height($(this).parent().height()).animate({ opacity: "hide" }, 1000, "linear", function() { $(this).css({ display: "block", visibility: "hidden" }); $(this).parent().animate({ height: 0, paddingTop: 0, paddingBottom: 0 }, 1000, "swing", function() { $(this).remove(); }); }); return false; });


/*
** Google map
*/
var googleMap = $(".google-map");
var map;
if (googleMap.length)
{
	map = new GMap2(googleMap.empty()[0]);
	var center = new GLatLng(52.396567, 16.923923);
	map.setCenter(center, 15);
	map.addOverlay(new GMarker(center));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
    map.addControl(new GOverviewMapControl());
	$(window).unload(GUnload);
}


var $twitter = $("ul.three-columns p.twitter");
if ($twitter.length)
{
	$.getJSON("http://www.twitter.com/statuses/user_timeline/merix_studio.json?count=1&callback=?", function(data)
	{
		if (data[0] && data[0].text && data[0].text.length)
		{
			data[0].text = data[0].text.replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '<a href="$&">$&</a>');
			$twitter.html(data[0].text);
		}
		else
			$twitter.text("Error loading content.");
	});
}


if ($.isFunction($("input.date").DatePicker))
	$("input.date").DatePicker({
		date: ""
	,	onBeforeShow: function() { $("input.date").DatePickerSetDate($("input.date").val(), true); }
	,	onChange: function(formated, dates) { $("input.date").val(formated); }
	});


$("div.more").each(function() { $(this).prev().append(" <a class=\"show-more\">rozwiń</a>").find("a.show-more").click(function() { $(this).parent().next(".more").show(); $(this).fadeOut(2000, function() { $(this).remove(); }); return false; }); });


if ($.browser.msie)
	$("a:not([href])").attr("href", "#");


/*
 * Merix projects gallery
 */
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

var gallery = null;
var $overlay = $('<div class="overlay overlay-loading overlay-hidden"></div>').appendTo("body");


function openGallery(prj) {
	var sizes = ___getPageSize();
	$overlay.css("height", sizes[1]);


	if (gallery) {
		$overlay.removeClass('overlay-loading');
		_openGallery(prj);
	} else {
		if ($.browser.msie && $.browser.version <= 6)
			$overlay.height($("body").height());
		$overlay.css("opacity", "0").show().animate({opacity: 1}, 2000);

		$.getJSON("data/work" + (pl ? "_pl" : "") + ".js", function(data)
		{
			for (var g in data)
				for (var p = 0; p < data[g]['projects'].length; p++)
					if (data[g]['projects'][p]['visible'] == 1) {
						data[g]['projects'].splice(p, 1);
						p--;
					}

			$overlay.removeClass('overlay-loading');
			gallery = data;
			_openGallery(prj, true);
		});
	}
}


$('a[href$="' + (pl ? 'portfolio' : 'work') + '"]').each(function() {
	$(this).attr('href', $(this).attr('href') + (pl ? '#portfolio' : '#work'));
});


function _openGallery(project, overlayVisible)
{
	if (typeof pageTracker != 'undefined')
		pageTracker._trackPageview('/js-' + (pl ? 'portfolio' : 'work'));

	introPause();
	$(".player").hide();
	window.scroll(0, 0);

	var $gallery = $('<div id="gallery">\
		<div class="navigation">\
			<div class="tabs"><ul></ul><p class="right"><a href="contact">Contact Us</a></p></div>\
			<div class="slider"><div class="slider-child"><p class="left"><a href="#">&lt;</a></p><p class="right"><a href="#">&gt;</a></p><div class="clip"><div class="fade-left"></div><div class="fade-right"></div></div></div></div></div>\
		<div class="thumbnails"><p class="close"><a href="#">Close Showcase</a></p><h1>Merix Studio <em>Showcase</em></h1></div>\
		<div class="preview"><div style="overflow: hidden; zoom: 1;"><ul class="tabs"></ul><p class="visit"><a href="#">Visit site</a></p><p class="back"><a href="#">Back to index</a></p></div><div class="description"></div>\
		<p class="loading"><img src="images/gallery/loading_alt.gif" alt="" /></p><img src="" alt=""></div>\
		<div class="project"><p class="prev"><a title="Previous project" href="#">&lt;</a></p><p class="next"><a title="Next project" href="#">&gt;</a></p></div></div>').hide().appendTo("body");

	if ($.browser.msie && $.browser.version <= 6)
	{
		$overlay.height($(window).height());
		$gallery.height($(window).height());
	}

	var tooltip2AltShow = function(element, text)
	{
		var i = text.indexOf(":");
		tooltip2Alt.find("span").empty().append("<strong>" + text.substring(0, i + 1) + "</strong> " + text.substring(i + 1));

		var IEOffset = { left: 0 };
		if ($.browser.msie)
			IEOffset = $("body").offset();
		var offset = element.offset();

		tooltip2Alt.css({ left: (offset.left + element.width() - IEOffset.left) + "px", top: (offset.top + (element.outerHeight() - tooltip2Alt.outerHeight()) / 2) + "px" }).show();
	};
	$("body").append("<p id=\"tooltip2-alt\"><span></span></p>");
	var tooltip2Alt = $("#tooltip2-alt").hide();

	var $tabs = $gallery.find(".navigation .tabs ul");
	var $clip = $gallery.find(".navigation .slider .clip");
	var $thumbs = $gallery.children('.thumbnails');
	var $preview = $gallery.children('.preview');
	var $project = $gallery.children('.project');
	var modes = {thumbs: 1, preview: 2};
	var mode = modes.thumbs;
	var gPos = 0, pPos = 0;

	if (pl)
	{
		$thumbs.find("p.close>a").text('Zamknij Portfolio');
		$thumbs.children("h1").html('<em>Portfolio</em> Merix Studio');
		$gallery.find(">.navigation .tabs p.right a").attr("href", "kontakt").text("Skontaktuj się z nami");
		$preview.find("p.visit>a").text("Odwiedź stronę");
		$preview.find("p.back>a").text("Wróć do listy projektów");
		$project.find(">p.prev>a").attr("title", "Poprzedni projekt");
		$project.find(">p.next>a").attr("title", "Następny projekt");
	}

	$tabs.append('<li><a gindex="-1" class="active" href="#gallery-slider-all">' + (pl ? 'Wszystkie' : 'Index') + '</a></li>');
	var showProjectGallery = -1, showProjectIndex = -1;
	for (var g in gallery)
	{
		$thumbs.append('<h2 gindex="' + g + '">' + gallery[g]['name'] + '</h2>');
		var $list = $('<ul gindex="' + g + '"></ul>').appendTo($thumbs);

		$tabs.append('<li><a gindex="' + g + '" href="#gallery-slider-' + g + '">' + gallery[g]['name'] + '</a></li>');
		var $list2 = $('<ul id="gallery-slider-' + g + '"></ul>').prependTo($clip);
		for (var p in gallery[g]['projects']) {
			$list.add($list2).append('<li><a gindex="' + g + '" iindex="' + p + '" href="#gallery-slider-' + g + '"><img src="data/gallery/thumbnails/' + gallery[g]['projects'][p]['file'] + '.jpg" alt=""><span></span></a></li>');
			if (project && project == gallery[g]['projects'][p]['file'])
			{
				showProjectGallery = g;
				showProjectIndex = p;
			}
		}
	}

	Cufon.replace('#gallery .thumbnails h1, #gallery .thumbnails p.close a,#gallery .thumbnails h2');
	Cufon.replace('#gallery .navigation .tabs a', { hover: true });

	var $curThumbs = $gallery.find(".slider ul").eq(0), thumbsPos = 0, thumbsMax = Math.max($curThumbs.children().length - 5, 0);

	// Close preview and display thumbnails.
	$preview.find(".back a").click(function()
	{
		$tabs.find('a[gindex="-1"]').click();
		return false;
	});

	var showProject = function(gindex, iindex, tabClick)
	{
		iindex = parseInt(iindex, 10);
		if (typeof pageTracker != 'undefined')
			pageTracker._trackPageview('/js-' + (pl ? 'portfolio/' : 'work/') + gallery[gPos]["projects"][iindex]['file']);

		var oldmode = mode;
		mode = modes.preview;
		$preview.find('p.loading').show();
		$tabs.find('a[gindex="' + gindex + '"]').trigger("click", true);

		gPos = gindex;
		pPos = iindex;

		var $desc = $preview.children(".description").empty().hide();
		var project = gallery[gPos]["projects"][iindex];
		if (project["description"])
		{
			var desc = project["description"];
			$desc.append('<h3>' + desc.title + '</h3><p class="date">' + desc.date + '</p>');
			for (var t in desc.text)
				$desc.append('<p>' + desc.text[t] + '</p>');
			if (desc.design || desc.templates || desc.programming)
			{
				var p = '<p class="tooltip-alt">', label = pl ? 'Zakres prac: ' : 'The scope of work: ';
				if (desc.design)
					p += '<img src="images/gallery/icon_04.png" alt="' + label + (pl ? 'projekt graficzny' : 'Graphic Design') + '" title="' + label + (pl ? 'projekt graficzny' : 'Graphic Design') + '">'
				if (desc.templates)
					p += '<img src="images/gallery/icon_11.png" alt="' + label + (pl ? 'szablony (X)HTML/CSS/JS' : '(X)HTML/CSS/JS templates') + '" title="' + label + (pl ? 'szablony (X)HTML/CSS/JS' : '(X)HTML/CSS/JS templates') + '">'
				if (desc.programming)
				{
					var prog_text = pl ? ["serwis internetowy", "zarządzanie treścią", "sklep internetowy"] : ["Website (PHP)", "Content Management System (CMS)", "Online Store"];
					p += '<img src="images/gallery/icon_14.png" alt="' + label + prog_text[desc.programming - 1] + '" title="' + label + prog_text[desc.programming - 1] + '">'
				}
				$desc.append(p + '</p>');
				$desc.find("p.tooltip-alt img").hover(function() { tooltip2AltShow($(this), $(this).attr("alt")); }, function() { tooltip2Alt.hide(); });
			}

			Cufon.replace("#gallery>.preview>.description h3");
		}

		var $ptabs = $preview.find('ul.tabs').empty().hide();
		for (var i = 0; i < project.count; i++)
			$ptabs.append('<li><a pos="' + (i + 1) + '" href="#">' + (i + 1) + '</a></li>');
		$ptabs.children(":first").children().addClass("active");
		if (project["description"])
			$ptabs.prepend('<li class="description"><a href="#">' + (pl ? 'Szczegóły' : 'About') + '</a></li>');

		if (project.visit)
			$preview.find("p.visit").css("visibility", "visible").children("a").attr("href", project.visit);
		else
			$preview.find("p.visit").css("visibility", "hidden");

		if (!project["hideTabs"] && $ptabs.children().length > 1)
		{
			$ptabs.show().find("a").click(function()
			{
				if ($(this).parent().hasClass("description"))
				{
					$(this).toggleClass("active");
					$preview.children("div.description").animate({height: "toggle"}, 500);
				}
				else
				{
					if ($(this).hasClass("active"))
						return false;


					$(this).addClass("active").parent().siblings().not(".description").children().removeClass("active");
					$preview.find('p.loading').show();
					var pos = parseInt($(this).attr("pos"), 10);

					$preview.children("img").each(function() {
						$(this).unbind('load').removeClass('new').css('margin-bottom', (-$(this).outerHeight()) + 'px');
					});
					$('<img alt="" class="new">').css('opacity', '0').appendTo($preview).load(function() {
						if (!$(this).hasClass('new')) {
							$(this).css('margin-bottom', (-$(this).outerHeight()) + 'px');
							return;
						}
						$preview.find('p.loading').hide();
						$preview.children("img").not(this).fadeOut(500, function() { $(this).remove(); });
						$(this).animate({opacity: "1"}, 500, function() { $(this).removeClass('new'); });
					}).attr("src", "data/gallery/" + project.file + "_" + (pos < 10 ? "0" : "") + pos + ".jpg");
				}

				return false;
			});
		}

		if (oldmode == modes.preview && mode == modes.preview)
		{
			$preview.children("img").each(function() {
				$(this).unbind('load').removeClass('new').css('margin-bottom', (-$(this).outerHeight()) + 'px');
			});
			$('<img alt="" class="new">').css('opacity', '0').appendTo($preview).load(function() {
				if (!$(this).hasClass('new')) {
					$(this).css('margin-bottom', (-$(this).outerHeight()) + 'px');
					return;
				}
				$preview.find('p.loading').hide();
				$preview.children("img").not(this).fadeOut(500, function() { $(this).remove(); });
				$(this).animate({opacity: "1"}, 500, function() { $(this).removeClass('new'); });
			}).attr("src", "data/gallery/" + project.file + "_01.jpg");
		}
		else {
			$preview.children("img").css({opacity: "0"}).removeAttr("src").load(function()
			{
				$preview.find('p.loading').hide();
				$(this).animate({opacity: "1"}, 250).unbind("load");
			}).attr("src", "data/gallery/" + project.file + "_01.jpg");
		}

		if (oldmode == modes.thumbs && mode == modes.preview)
			$thumbs.fadeOut(500, function()
			{
				window.scroll(0, 0);
				$preview.fadeIn(750, function() { if ($.browser.msie && $.browser.version <= 8 && $.browser.version > 6) this.style.removeAttribute("filter"); });
				$project.fadeIn(500);
			});

		thumbsMax = Math.max($curThumbs.children().length - 5, 0);

		thumbsPos = pPos - 2;
		thumbsPos = Math.min(Math.max(thumbsPos, 0), thumbsMax);

		$curThumbs.stop(true).animate({left: (thumbsPos * -160) + "px"}, 500);

		window.location.hash = (pl ? '#portfolio' : '#work') + (':' + project.file);
	};


	$thumbs.find("ul a").click(function()
	{
		showProject(parseInt($(this).attr("gindex"), 10), parseInt($(this).attr("iindex"), 10));
		return false;
	});


	$tabs.find("a").click(function(e, dontResetPos)
	{
		var g = parseInt($(this).attr("gindex"), 10);
		if (g == -1)
		{
			$(this).addClass("active").parent().siblings().find("a").removeClass("active");
			$thumbs.children('h2,ul').show();
			$gallery.find(".navigation").trigger("mouseleave");
			mode = modes.thumbs;
			$project.stop(true).fadeOut(500);
			$preview.stop(true).fadeOut(500, function() { $thumbs.stop(true).fadeIn(500); });
			window.location.hash = (pl ? '#portfolio' : '#work');
			return false;
		}

		if (mode == modes.thumbs)
		{
			$(this).addClass("active").parent().siblings().find("a").removeClass("active");
			$thumbs.children('h2,ul').hide().filter('[gindex="' + g + '"]').show();
		}
		else
		{
			$(this).addClass("active").parent().siblings().find("a").removeClass("active");

			if (!dontResetPos/* && !($.browser.msie && $.version != 6)*/)
			{
				var $a = $(this);
				$gallery.find(">.navigation .slider-child").stop(true).animate({marginTop: "-162px"}, 250, function()
				{
					$gallery.find(">.navigation .slider-child").animate({marginTop: "0px"}, 250);

					$curThumbs = $clip.find("ul" + $a.hrefId()).addClass("active");
					if (!dontResetPos)
					{
						$curThumbs.css("left", "0");
						thumbsMax = Math.max($curThumbs.children().length - 5, 0);
						thumbsPos = 0;
					}
					$curThumbs.siblings("ul").removeClass("active");
					$curThumbs.find('a').eq(0).click();
				});
			}
			else
			{
				$curThumbs = $clip.find("ul" + $(this).hrefId()).addClass("active");
				if (!dontResetPos)
				{
					$curThumbs.css("left", "0");
					thumbsMax = Math.max($curThumbs.children().length - 5, 0);
					thumbsPos = 0;
				}
				$curThumbs.siblings("ul").removeClass("active");
				//$curThumbs.find('a').eq(0).trigger('click');
			}

			gPos = Math.max(g, 0);
			pPos = 0;
		}
		return false;
	});

	$gallery.find(".navigation")
		.bind("mouseenter", function()
		{
			if (mode != modes.preview)
				return;

			$(this).find(".slider-child").stop(true).animate({marginTop: "0px"}, 500);
			$gallery.children(".preview").stop(true).animate({opacity: "1", paddingTop: "244px"}, 500, function() { if ($.browser.msie && $.browser.version <= 8 && $.browser.version > 6) this.style.removeAttribute("filter"); });

			// Firefox fix - force parent redraw
			if ($.browser.mozilla)
				$gallery.find(".slider").css("outline", "0px solid rgba(0, 0, 0, 0)").animate({outlineWidth: "10px"}, 500);
		}).bind("mouseleave", function()
		{
			if (mode != modes.preview) {
				$gallery.children(".preview").animate({paddingTop: "82px"}, 500);
				return;
			}
			$(this).find(".slider-child").stop(true).animate({marginTop: "-162px"}, 500);
			$gallery.children(".preview").stop(true).animate({opacity: "1", paddingTop: "82px"}, 500, function() { if ($.browser.msie && $.browser.version <= 8 && $.browser.version > 6) this.style.removeAttribute("filter"); });
		});

	$gallery.find(".slider p.right a").click(function()
	{
		if (thumbsPos < thumbsMax)
			$curThumbs.stop(true).animate({left: (++thumbsPos * -160) + "px"}, 500);
		return false;
	});
	$gallery.find(".slider p.left a").click(function()
	{
		if (thumbsPos > 0)
			$curThumbs.stop(true).animate({left: (--thumbsPos * -160) + "px"}, 500);
		return false;
	});

	$clip.find("ul a").click(function()
	{
		showProject(parseInt($(this).attr("gindex"), 10), parseInt($(this).attr("iindex"), 10));
		return false;
	});

	// Close whole gallery.
	$thumbs.find("p.close>a").click(function()
	{
		$overlay.fadeOut(500, function() { $(this).addClass('overlay-loading'); });
		$gallery.fadeOut(500, function() { $(this).remove(); });
		tooltip2Alt.remove();
		$(".player").show();
		introPause();
		window.location.hash = '';
		return false;
	});

	$project.find("p.prev a").click(function()
	{
		if ($tabs.find('a[gindex="-1"]').hasClass("active"))
		{
			if (pPos <= 0)
			{
				if (gPos > 0)
					gPos--;
				else
					gPos = gallery.length - 1;
				pPos = gallery[gPos]["projects"].length;
			}
		}
		else
			pPos = (pPos <= 0) ? gallery[gPos]["projects"].length : pPos;
		if ($preview.children("div.description").is(':visible'))
			$preview.children("div.description").animate({height: "hide"}, 500, function() {
				showProject(gPos, pPos - 1, true);
			});
		else
			showProject(gPos, pPos - 1, true);
		return false;
	});

	$project.find("p.next a").click(function()
	{
		if ($tabs.find('a[gindex="-1"]').hasClass("active"))
		{
			if (pPos >= gallery[gPos]["projects"].length - 1)
			{
				if (gPos < gallery.length - 1)
					gPos++;
				else
					gPos = 0;
				pPos = 0;
			}
			else
				pPos++;
		}
		else
			pPos = (pPos >= gallery[gPos]["projects"].length - 1) ? 0 : pPos + 1;
		if ($preview.children("div.description").is(':visible'))
			$preview.children("div.description").animate({height: "hide"}, 500, function() {
				showProject(gPos, pPos, true);
			});
		else
			showProject(gPos, pPos, true);
		return false;
	});


	window.location.hash = (pl ? '#portfolio' : '#work');

	if (!overlayVisible)
		$overlay.css("opacity", "0").show().animate({opacity: 1}, 2000);
	$gallery.fadeIn(1000);
	if (project)
		showProject(showProjectGallery, showProjectIndex);
}


if (window.location.hash.startsWith(pl ? '#portfolio' : '#work')) {
	var i = window.location.hash.indexOf(':'), project = null;
	if (i >= 0)
		project = window.location.hash.substr(i + 1);
	openGallery(project);
}

$.fn.extend({attachGallery: function() {
	return this.each(function() {
		var id = $(this).hrefId();
		if (id.startsWith(pl ? '#portfolio' : '#work'))
			$(this).attr('href', pl ? '#portfolio' : '#work').click(function() {
				var i = id.indexOf(':'), project = null;
				if (i >= 0)
					project = id.substr(i + 1);
				openGallery(project);
				return false;
			});
	});
}});

$('a[href]').attachGallery();


$.easing['easeOutQuint'] = function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; };


$.fn.cardOpen = function() {
	return this.each(function() {
		$(this).siblings('img').stop(true);
		$(this).stop(true).animate({width: 0, marginLeft: 0}, 500, 'easeOutQuint', function() {
			var $img = $(this).siblings('img.card');
			var ie6 = ($.browser.msie && $.browser.version <= 6) ? '_ie6' : '';
			$img.attr('src', 'images/card_' + Math.floor(Math.random() * 12) + ie6 + '.png');
			$img.animate({width: '236px', marginLeft: '-118px'}, 500, 'easeOutQuint', function() {
				$(this).parent().parent().removeClass('opening');
			});
		});

		var $content = $(this).parent().parent().addClass('opening').find('div.content').stop(true);
		$content.children('div').stop(true);
		var h = $content.data('h');
		$content.css({opacity: 0});
		$content.removeClass('content-hidden');
		$content.animate({opacity: 1}, 333, function() {
			$content.animate({marginTop: '-230px', paddingTop: '240px', height: h + 'px'}, 500, function() { $(this).removeClass('content-opening').parent().addClass('active'); });
			$content.children('div').css({height: 'auto'}).animate({opacity: 1, paddingBottom: '30px'}, 250, function() { if ($.browser.msie && $.browser.version <= 8) this.style.removeAttribute("filter"); });
		});
	});
};


$.fn.cardClose = function() {
	return this.each(function() {
		$(this).siblings('img').stop(true);
		$(this).animate({width: 0, marginLeft: 0}, 500, 'easeOutQuint', function() {
			var $img = $(this).siblings('img.deck');
			$img.animate({width: '236px', marginLeft: '-118px'}, 500, 'easeOutQuint');
		});

		var $content = $(this).parent().parent().find('div.content').css({height: 'auto'});
		$content.children('div').animate({height: 0, paddingBottom: '10px'}, 250);
		$content.animate({marginTop: '-20px', paddingTop: '10px'}, 500, function() {
			$content.animate({opacity: 0}, 250, function() {
				$(this).parent().removeClass('opening');
				$(this).addClass('content-hidden').removeAttr('style').children('div').removeAttr('style');
				$(this).parent().removeClass('active');
			});
		});
		$content.children('div').animate({paddingBottom: '10px'}, 250);
	});
};


$('div.cards div.item').each(function() {

	var $item = $(this);
	var $close = $('<p class="close"><a href="#">X</a></p>').appendTo($item.find('div.content>div'));

	$close.click(function() {
		$item.find('div.card img.card').cardClose();
		return false;
	});

	var $content = $item.find('div.content').addClass('content-hidden');
	$(function() {
		$content.data('h', $content.height() - 1);
	});

	$content.find('h2').clone().appendTo($item.find('div.card'));

	$item.find('>div.card h2').each(function() {
		$(this).css({marginTop: ($(this).height() / -2 - 12) + 'px'});
		$(this).after('<div class="question"></div>');
	});

	$item.find('>div.card>img.card').click(function() {
		$(this).cardClose();
	});
	$item.find('>div.card>h2,>div.card>div.question').click(function() {
		$(this).siblings('img.deck').click();
	});

	if ($.browser.msie && $.browser.version <= 6)
		$item.find('>div.card>img.deck').attr('src', 'images/card_deck_ie6.png');
	$item.find('>div.card>img.deck').click(function() {
		$(this).cardOpen();
		var $dad = $(this).parent().parent();
		$(this).parent().parent().parent().parent().find('div.item').not($dad).find('img.card').cardClose();
	});

});


$('p.flickr>a').each(function() {
	$(this).click(function() {
		var $overlay = $('<div class="overlay overlay-loading"></div>').css({opacity: 0}).appendTo('body');

		if ($overlay.height() < $(window).height())
			$overlay.height($(window).height());

		$overlay.click(function() {
			$(this).animate({opacity: 0}, 500, function() { $(this).remove(); });
			$('.modal-flickr').remove();
		});

		$overlay.animate({opacity: .75}, 500, function() {
			$overlay.removeClass('overlay-loading');
			var $modal = $('<div class="modal-flickr">\
				<object width="500" height="375"> <param name="flashvars" value="offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fworldofmerix%2Fsets%2F72157623953033521%2Fshow%2F&page_show_back_url=%2Fphotos%2Fworldofmerix%2Fsets%2F72157623953033521%2F&set_id=72157623953033521&jump_to="></param> <param name="movie" value="http://www.flickr.com/apps/slideshow/show.swf?v=71649"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/slideshow/show.swf?v=71649" allowFullScreen="true" flashvars="offsite=true&lang=en-us&page_show_url=%2Fphotos%2Fworldofmerix%2Fsets%2F72157623953033521%2Fshow%2F&page_show_back_url=%2Fphotos%2Fworldofmerix%2Fsets%2F72157623953033521%2F&set_id=72157623953033521&jump_to=" width="500" height="375"></embed></object>\
			</div>').appendTo('body');

			if (pageTracker)
				pageTracker._trackPageview(pl ? '/firma/galeria-biuro' : '/company/office-gallery');
		});
		return false;
	});
});

//slider item click

$("ul.slided li").click(function(){
	var url = $(this).children("h3").children("a").attr("href");
	if(!url) url = $(this).children("h2").children("a").attr("href");
	window.location = url;
});


// the offer slider
var $sections = $('.section');
$sections.each(function(i) {
	var slideSpeed = 500;
	var slideStep = 310;

	var $section = $(this);
	var $prev = $section.find('.slider-controls a.prev');
	var $next = $section.find('.slider-controls a.next');
	var $slider = $section.find('ul.slided');
	$slider.children("li").show();
	var count = $slider.children().length, clickCount = 0;
	var autoTimer = null, autoInitTimer = null;

	$slider.wrap('<div class="slider-box" />').width('999em');

	if($slider.children("li").length <= 3) {
		$section.find(".slider-controls").hide();
		$section.find(".head").css("width", "auto").css("border", "none");
	}
	if(!$.browser.msie)  Cufon.replace(".section h3, .section li h2");


	function sliderMove(dir, count) {
		var prevClickCount = clickCount;
		if (typeof count != 'undefined')
			clickCount += count;
		else
			clickCount++

		if($.browser.msie){
			$slider.stop(true, true);
			var maxLeft =  0 - ($slider.children("li").length - 3) * slideStep;
			var xPos = parseInt($slider.css("left"), 10);
			//alert("xPos: " + xPos + ", slideStep:" + slideStep + ", count:" + count + ":::" + $slider.css("left"));
			if(dir > 0) {
				if(xPos == maxLeft) xPos = 0;
				else {
					xPos = xPos - slideStep * count;
					while(xPos < maxLeft) xPos += slideStep;
				}
			} else {
				if(xPos == 0) xPos = maxLeft;
				else {
					xPos = xPos + slideStep * count;
					while(xPos > 0) xPos -= slideStep;
				}
			}
			$slider.animate({left: xPos}, slideSpeed);
		} else {
			for (var i = 0; i < clickCount - prevClickCount; i++)
				if (dir < 0) {
					var $last = $slider.children().not('.delete');
					$last = $last.eq($last.length - 1);
					$last.addClass('delete');
					$last.clone(true).prependTo($slider).removeClass('delete');
					var left = parseInt($slider.css('left'), 10);
					$slider.css("left", (left - slideStep) + "px");
				} else {
					var $first = $slider.children().not('.delete').eq(0);
					$first.addClass('delete');
					$first.clone(true).appendTo($slider).removeClass('delete');
				}
			if(!$.browser.msie) Cufon.replace(".section h3, .section li h2");

			var dstLeft = dir < 0 ? 0 : -1 * slideStep;

			$slider.stop(true).animate({left: (clickCount * dstLeft) + 'px'}, slideSpeed, function() {
				var $toDelete = $slider.children('.delete');
				var toDeleteLength = $toDelete.length;
				$toDelete.remove();
				if (dir > 0) {
					var left = parseInt($slider.css('left'), 10) + dir * toDeleteLength * slideStep;
					$slider.css("left", left + "px");
				}
				clickCount = 0;
			});
		}
	}

	if($section.hasClass("home")) var step = 3;
	else step = 1;

	$prev.click(function(e) {
		e.preventDefault();

		if (autoInitTimer || autoTimer) {
			clearTimeout(autoInitTimer);
			clearInterval(autoTimer);
			autoInitTimer = autoTimer = null
		}

		sliderMove(-1, step);
	});

	$next.click(function(e) {
		e.preventDefault();

		if (autoInitTimer || autoTimer) {
			clearTimeout(autoInitTimer);
			clearInterval(autoTimer);
			autoInitTimer = autoTimer = null
		}

		sliderMove(1, step);
	});


	if(count > 3){
		autoInitTimer = setTimeout(function() {
			sliderMove(1, 1);
			autoTimer = setInterval(function() {
				sliderMove(1, 1);
			}, 5000 * $sections.length);

			autoInitTimer = null;
		}, 5000 * (i + 1));
	}
});


// tabs switching
var lastSection = $(".section").length - 1;
var chosenTab = $(".tabs a.selected").attr("rel");
$(".tabs.no-reload a").click(function(){
	var selected = $(this).attr("rel");

	if(chosenTab != selected){
		if(chosenTab == "all"){
			$(".section").not($(".section."+selected)).slideUp();
			$(".section."+selected).addClass("last");
		} else {
			if(selected == "all"){
				$(".section").not($(".section."+chosenTab)).slideDown();
				$(".section").removeClass("last");
				$(".section").eq(lastSection).addClass("last");
			} else {
				$(".section."+chosenTab).slideUp().removeClass("last");
				$(".section."+selected).slideDown().addClass("last");
			}
		}
		chosenTab = selected;
		$(".tabs.no-reload a").removeClass("selected");
		$(this).addClass("selected");
	}
	return false;
});


//tabs in offer details

$('div.pt').each(function() {
	var h = 0;
	var $pt = $(this);

	$pt.find("ul.tab-content").each(function(){
		if(parseInt($(this).height(), 10) > h)
			h = parseInt($(this).height(), 10);
	});

	$pt.height(h + 60);
	var activeTab = $pt.find(".tabs a.selected").attr("rel");
	$pt.find("ul.tab-content").not($pt.find("ul.tab-content." + activeTab)).hide();
	$pt.find(".tabs a").click(function(e){
		e.preventDefault();

		if(activeTab != $(this).attr("rel")){
			$pt.find("ul.tab-content." + activeTab).fadeOut();
			activeTab = $(this).attr("rel");
			$pt.find("ul.tab-content." + activeTab).fadeIn();
		}

		$pt.find(".tabs a").removeClass("selected");
		$(this).addClass("selected");
	});
});


// logos slider
$(window).load(function(){
	$(".realisations, .awards").each(function(){
		$box = $(this);
		$logoList = $box.find("ul.logos");
		$logoList.wrap('<div class="slider" />');
		$slider = $box.find(".slider");
		$forward = $box.find("a.next-logo");
		$back = $box.find("a.prev-logo");

		var logosW = $logoList.width();
		var pos = 0;
		var dir = -1;
		var initTime = $slider.find("li").length * 4000;
		var initDst = logosW;
		var currentPos = 0;
		var distance = 0;
		var animTime = 500;

		$slider.find("li").each(function(){
			var img = new Image();
			img.src = $(this).find("img").attr("src");
			$(this).css("width", img.width + "px");
		});

		function logosMove(dir, change){
			$slider.find(".delete").remove();
			if(dir < 0) {
				$logoList = $slider.find("ul.logos").eq(0);
				$logoList.addClass("delete");
				$logoList.clone(true).appendTo($slider).removeClass("delete");
				$slider.width(2*logosW);
				currentPos = parseInt($slider.css("left"), 10);
				pos = -logosW;
				distance = (pos - currentPos) * -1;
			} else {
				if(change) $slider.css("left", (parseInt($slider.css("left"), 10) + logosW) + "px");
				$logoList = $slider.find("ul.logos").eq($slider.find("ul.logos").length - 1);
				$logoList.addClass("delete");
				$logoList.clone(true).prependTo($slider).removeClass("delete");
				$slider.width(2*logosW);
				$slider.css("left", (parseInt($slider.css("left"), 10) - logosW) + "px");

				currentPos = parseInt($slider.css("left"), 10);
				pos = 0;
				distance = currentPos * -1;
			}
			animTime = Math.round((distance * initTime) / initDst);

			$slider.animate({left: pos}, animTime, "linear", function(){
				if(dir < 0) $slider.css("left", 0);
				logosMove(dir, false);
			});
		}

		function changeDir(){
			dir *= -1;
			$slider.stop(true);
			logosMove(dir, true);
		}

		if(logosW > $box.width()) logosMove(dir);
		else $box.find("ul.slider-controls").hide();

		$back.click(function(e){
			e.preventDefault();
			if (dir < 0)
				changeDir();
		});
		$forward.click(function(e){
			e.preventDefault();
			if (dir > 0)
				changeDir();
		});
	});

});

//uri based tab selection
$("ul.tabs.no-reload li a").each(function(){
	if ($(this).attr("rel") == window.location.hash.substring(1))
		$(this).click();
});

$("a.off").click(function() { return false; });


//moving the secondary menu if browsing on iJunk so the mBlocks link doesn't cover the menu
//if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
if ($("body").width() < 1100) {
	$(".header ul.tools").css("right", "100px");
	$(".welcome").css("width", "850px");
}
//}


// Adwords splash window
Cufon.replace('.splash p.close a,.splash ul a,.splash .contact a', {fontFamily: 'Haptic', hover: true});
Cufon.replace('.splash h2,.splash h3', {fontFamily: 'Haptic Black'});
// Adwords webdesign splash window
Cufon.replace('.splash.webdesign h2', {fontFamily: 'Haptic Light'});
Cufon.replace('.splash.webdesign h2 b, .splash.webdesign h2 i', {fontFamily: 'Haptic'});
Cufon.replace('.splash.webdesign p.reasons, .splash.webdesign ul.reasons', {fontFamily: 'Haptic'});
Cufon.replace('.splash.webdesign p.reasons b', {fontFamily: 'Haptic Black'});

$('body>.splash').each(function() {
	var $overlay = $('.splash-overlay').css({opacity: .9});
	var $splash = $(this);

	var closeSplash = function() {
		$overlay.animate({opacity: 0}, 500, function() { $overlay.remove(); });
		$splash.animate({opacity: 0}, 500, function() { $splash.remove(); });
	};

	$splash.find('.close a,a.c2a').click(function(e) {
		e.preventDefault();
		closeSplash();
	});
	$splash.find('a.work').click(function(e) {
		e.preventDefault();
		closeSplash();
		openGallery();
	});
});


// Awards slider
//$('.awards').each(function() {
//    var $ul = $(this).find('ul');
//    var animating = false;
//
//    $ul.find('li').clone().appendTo($ul);
//
//    var $prev = $(this).find('a.prev-logo').click(function(e) {
//        e.preventDefault();
//
//        if (animating)
//            return;
//
//        animating = true;
//
//        var $last = $ul.find('li:last');
//        var w = $last.outerWidth(true);
//
//        $last.prependTo($ul);
//        $ul.css('marginLeft', -w + 'px');
//        $ul.stop(true).animate({'marginLeft': '0px'}, 500, function() {
//            animating = false;
//        });
//    });
//
//    var $next = $(this).find('a.next-logo').click(function(e) {
//        e.preventDefault();
//
//        if (animating)
//            return;
//
//        animating = true;
//
//        var $first = $ul.find('li:first');
//        var w = $first.outerWidth(true);
//
//        $ul.stop(true).animate({'marginLeft': -w + 'px'}, 500, function() {
//            $first.appendTo($ul);
//            $ul.css('marginLeft', '0px');
//            animating = false;
//        });
//    });
//
//    var interval;
//
//    var startAnimation = function() {
//        interval = setInterval(function() {
//            $next.click();
//        }, 5000);
//    };
//
//    $(this).hover(function() {
//        clearInterval(interval);
//    }, function() {
//        startAnimation();
//    });
//
//    startAnimation();
//});

