/*!
 * jQuery JavaScript Library v1.4.1
 * http://jquery.com/
 *
 * Copyright 2010, John Resig
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://jquery.org/license
 *
 * Includes Sizzle.js
 * http://sizzlejs.com/
 * Copyright 2010, The Dojo Foundation
 * Released under the MIT, BSD, and GPL Licenses.
 *
 * Date: Mon Jan 25 19:43:33 2010 -0500
 */
;(function($) {
	
var overlay = $('<div class="Dialog-overlay"></div>');
var dialog = $('<div class="Dialog-frame"><div class="Dialog-frame2"><div class="Dialog-closePanel"><a class="Dialog-close" href="#"></a></div><div class="Dialog-content"></div></div></div>');	
var progress = '<div class="Dialog-progress"></div>';
var timeout;

function showProgress() {
	if (!dialog.is(":visible")) {
		dialog.find('.Dialog-close').hide();
		dialog.find('.Dialog-content').html(progress);
	
		dialog
//		.css('margin-left', -(dialog.width() / 2))
		dialog.css('top', ($(window).height() - dialog.height()) / 2);
//		.css('margin-top', -(dialog.height() / 2))
		;
		
		dialog.fadeIn('fast');
	}
}

$.dialog = {};

$.dialog.options = {};

$.dialog.events  = {};
$.dialog.events.load = function() {};

$.dialog.close = function() {
	dialog.fadeOut('fast', function() {
		overlay.hide();
	});
}

$.dialog.show = function(data) {
	$(overlay).show();

	dialog.find('.Dialog-content').html(data);

	dialog
	.css('margin-left', '0px')
	dialog.css('top', ($(window).height() - dialog.height()) / 2);
//	.css('margin-top', -(dialog.height() / 2))
	;
	
	dialog.fadeIn('fast'); 
	dialog.css('top', ($(window).height() - dialog.height()) / 2);
//	dialog.css('margin-top', -(dialog.height() / 2))
}

$.dialog.open = function(link) {
	$(overlay).show();
	clearTimeout(timeout);
	timeout = setTimeout(showProgress, 500);
	
	$.get(link, function(data) {
		dialog.hide();
		dialog.find('.Dialog-content').html(data);
		dialog.find('.Dialog-close').show();

		$.dialog.events.load();
		
		dialog
		.css('margin-left', '0px');

		dialog.fadeIn('fast', function() {
			dialog.css('top', ($(window).height() - dialog.height()) / 2);
		});
	});
}


$.fn.dialog = function() {
	$(this).live('click', function() {
		var link = $(this).attr('href');
		
		$.dialog.open(link);
		
		return false;
	})
}

$(document).ready(function() {
	$(overlay).appendTo($('body')).hide()
	.css('z-index', '1000')
	.css('position', 'fixed')
	.css('width', '100%')
	.css('height', '100%')
	.css('left', '0px')
	.css('top', '0px')
	;
	
	$(dialog).appendTo($('body')).hide()
	.css('position', 'fixed')
	.css('z-index', '1001')
	.css('left', '0px')
//	.css('top', '50%')
	;
	
	$(dialog).find('.Dialog-close').click(function() {
		$.dialog.close();
		return false;
	});
	
	$(document).bind('keydown', function(event) {
		if (event.keyCode == 27 && dialog.is(':visible')) {
			$.dialog.close();
		}
	});
	
	$(window).resize(function() {
		dialog.css('top', ($(window).height() - dialog.height()) / 2);
	});
});

})(jQuery);
;(function($) {
	var largeItems;
	var totalItems;
	var position = 0;
	var widget;
	var content;

	function move() {
		var start = position;
		if (position > 0) {
			start = position - 1;
		}
		
		var amount = position * 700;
		content.animate({left: '-' + amount + 'px'}, 300);
		
		if (position > 0) {
			widget.find('.LinkSlide-leftButton').addClass('LinkSlide-leftButton-active');
		} else {
			widget.find('.LinkSlide-leftButton').removeClass('LinkSlide-leftButton-active');
		}

		if (position < totalItems - 1) {
			widget.find('.LinkSlide-rightButton').addClass('LinkSlide-rightButton-active');
		} else {
			widget.find('.LinkSlide-rightButton').removeClass('LinkSlide-rightButton-active');
		}
	};


	$.gallerySwitchPosition = function(pos) {
		position = pos;
		move();
	};

	$.gallerySwitch = function() {
		widget = $('.LargeLinkSlide');
		content = widget.find('.LargeLinkSlide-content');
		largeItems = widget.find('.LargeLinkSlide-smallLink');
		totalItems = largeItems.length;
		
		$('.LinkSlide-leftButton').live('click', function() {
			if (position > 0) {
				position--;
			}
			
			move();
			return false;
		});

		$('.LinkSlide-rightButton').live('click', function() {
			if (position < totalItems - 1) {
				position++;
			}
			move();
			
			return false;
		});
		
		position = 0;
		move();
	};
})(jQuery);




;(function($) {
	
var overlay;
var dialog = $('<div class="Dialog-frame Dialog-frameSlide"><div class="Dialog-frame2"><div class="Dialog-closePanel"><a class="Dialog-close" href="#"></a></div><div class="Dialog-content"></div></div></div>');	
var timeout;

$.gallery = {};

$.gallery.close = function() {
	dialog.fadeOut('fast', function() {
		if ($('.Dialog-frame:visible').length == 0) {
			overlay.hide();
		}
	});
}

$.gallery.open = function(link, action) {
	$(overlay).show();
	
	$.get(link, function(data) {
		dialog.hide();
		dialog.find('.Dialog-content').html(data);
		dialog.find('.Dialog-close').show();
		
		dialog
		.css('margin-left', '0px')
		;

		action();
		dialog.show();
/*		dialog.fadeIn('fast', function() {
			dialog.css('top', ($(window).height() - dialog.height()) / 2);
		});*/
	});
}

$(document).ready(function() {
	$(dialog).appendTo($('body')).hide()
	.css('position', 'fixed')
	.css('z-index', '2001')
	.css('left', '0px')
	.css('top', '50%')
	.css('margin-top', '-290px')
	;
	
	$(dialog).find('.Dialog-close').click(function() {
		//$.gallery.close();
		$('.Dialog-frame').fadeOut('fast', function() {
			$('.Dialog-overlay').hide();
		});
		
		return false;
	});
	
	$(document).bind('keydown', function(event) {
		if (event.keyCode == 27 && dialog.is(':visible')) {
			$.dialog.close();
		}
	});
	
	overlay = $('.Dialog-overlay');

	
	$('.GalleryAction').live('click', function() {
		$.gallery.open($(this).next('.CurrentGallery').text(), function() {
			$.gallerySwitch();
		});
		return false;
	});
	
	$('.GalleryClose').live('click', function() {
		$.gallery.close();
		return false;
	});
});

})(jQuery);
;(function($) {

function trackPage(link) {
	var _gaq = _gaq || [];
	_gaq.push(['_trackPageview', link]);
}
	
function gallerySwitch() {
	$('.CaseSwitch').live('click', function() {
		var link = $(this).attr('href');
		trackPage(link)
		
		$('.CaseSwitch-selected').removeClass('CaseSwitch-selected');
		$(this).addClass('CaseSwitch-selected');
		
		if (link.lastIndexOf(".flv") > link.length - 5) {
			$('.CasePicture').hide();
			$('.ArticleOriginalMediaPlayer').text('');

			var result = '<div class="ArticleMediaPlayer"> <object type="application/x-shockwave-flash" data="/flash/player.swf" width="350" height="280"><param name="movie" value="/flash/player.swf" /><param name="allowFullScreen" value="true" /><param name="FlashVars" value="flv=' 
				 + encodeURI(link) 
				 + '&amp;width=350&amp;height=280&amp;autoplay=1&amp;margin=0&amp;slidercolor2=eeeeee" /></object></div>'; 
	
			$('.CasePlayer').text('').html(result);			
		} else {
			$('.ArticleOriginalMediaPlayer').text('');
			$('.CasePlayer').html('');
			$('.CasePicture').show().attr('src', link);
		}
		return false;
	});
}
	
function articlePopup() {
	$('.ArticleLink').live('click', function() {
		trackPage($(this).attr('href'));
		$.dialog.open($(this).attr('href'));
		return false;
	});
}

function articleClick() {
	$('.Article').live('click', function() {
		trackPage($(this).find('a').attr('href'));
		$.dialog.open($(this).find('a').attr('href'));
		return false;
	});
}


function folioSlide() {
	var active = false;
	$('.LeftFolio').hide()
	.mouseenter(function() {
		if (active) {
			return;
		}
		active = true;
		$('#FolioContent').stop(true);
		$('.RightFolio').show();
		$('#FolioContent').animate({
			marginLeft: '0px'
		}, 500, function() {
			$('.LeftFolio').fadeOut('fast', function() {active = false;});
		});
	});

	$('.RightFolio')
	.mouseenter(function() {
		if (active) {
			return;
		}
		active = true;
		$('#FolioContent').stop(true);
		$('.LeftFolio').show();
		$('#FolioContent').animate({
			marginLeft: '-189px'
		}, 500, function() {
			$('.RightFolio').fadeOut('fast', function() {active = false;});
		});
	});
}
	
function personHover() {
	$('.PersonActual')
	.live('mouseenter', function() {
		$('.PersonSummary-' + $(this).attr('href').substring(8)).fadeIn('fast');
		$(this).find('.Person-hover').fadeIn('fast');
	})
	.live('mouseleave', function() {
		$('.PersonSummary-' + $(this).attr('href').substring(8)).fadeOut('fast');
		$(this).find('.Person-hover').fadeOut('fast');
	})
	.live('click', function() {
		trackPage($(this).attr('href'));
		$.dialog.open($(this).attr('href'));
		return false;
	});
}
	
function caseHover() {
	$('.Case')
/*	.live('mouseenter', function() {
		$(this).find('.CaseHover').fadeIn('medium');
	})
	.live('mouseleave', function() {
		$(this).find('.CaseHover').fadeOut('fast');
	}) */
	.live('click', function() {
		trackPage($(this).attr('href'));
		$.dialog.open($(this).attr('href'));
		return false;
	});
}

function mailReveal() {
	$('.Lobster').each(function() {
		var link = $(this).attr('href');
		$(this).removeClass('Lobster');
		$(this).text(link + '@appiosmetaxas.com');
		$(this).attr('href', 'mailto:' + link + '@appiosmetaxas.com');
	});
}

function togglePanel2() {
	$('.PanelHeader a').live('click', function() {
		var section = $(this).parent().parent();
		var panel = section.find('.PanelContent');
		
		var old = $('.PanelLoaded');
		old.find('.PanelContent').slideUp('fast');
		old.removeClass('PanelLoaded');

		if (old.attr('id') != null && old.find('.PanelContent').attr('id') == panel.attr('id')) {
			return false;
		}
		
		link = $(this).attr('href');
		$.get(link, function(data) {
			panel.hide().html('<div class="PanelContent-inside">' + data + '</div>').slideDown('slow');
			panel.parent().addClass('PanelLoaded');
			mailReveal();
		});
		
		return false;
	});
}

var mapFirst = true;
function togglePanel() {
	$('.PanelHeader a').live('click', function() {
		var section = $(this).parent().parent();
		var panel = section.find('.PanelContent');
		
		var old = $('.PanelLoaded');
		old.find('.PanelContent').slideUp('fast');
		old.removeClass('PanelLoaded');

		if (old.attr('id') != null && old.find('.PanelContent').attr('id') == panel.attr('id')) {
			return false;
		}
		
		if (panel.attr('id') == 'PanelContent-Clientele') {
			$.showClients();
		} else if (panel.attr('id') == 'PanelContent-Find' && mapFirst) {
			mapFirst = false;
			$.showMap();
		}

		link = $(this).attr('href');
		trackPage(link);
		panel.hide().slideDown('slow');
		panel.parent().addClass('PanelLoaded');
		
		return false;
	});
}
	
$(document).ready(function() {
	togglePanel();
	personHover();
	caseHover();
	articlePopup();
	gallerySwitch();
	folioSlide();
	articleClick();
	
	//$.forms();
	
	$.dialog.events.load = function() {
		mailReveal();
	};
	
	mailReveal();
	
	if ($('#PanelContent-Clientele').is(':visible')) {
		$.showClients();
	} else if ($('#PanelContent-Find').is(':visible')) {
		mapFirst = false;
		$.showMap();
	}
});
})(jQuery);
