$(window).bind('load', function() {
	/**
	 * people hover effect
	 *
	 */
	var $people = $('#people-list');
	if ( $people.size() < 1 ) return;
	// set in center
	var $peopleList = $people.find('ul');
	var listWidth = $peopleList.outerWidth();
	if ( listWidth > 0 ) {
		$peopleList.css({left:'50%', marginLeft:'-' + (parseInt(listWidth) / 2) + 'px'});
	}
	
	$people.find('span').css({opacity:'0', display:'block'});
	$people.find('a').hover(function() {
		$(this).find('span').stop().fadeTo(500, 1);
	}, function() {
		$(this).find('span').stop().fadeTo(500, 0);
	});
});

$(window).bind('load', function() {
	/**
	 * gallery
	 *
	 */
	var $gallery = $('#gallery-list');
	if ( $gallery.size() < 1 ) return;
	$gallery.find('a').each(function() {
		var _this = $(this);
		var $img = _this.find('img');
		_this.append('<span style="width:' + $img.width() + 'px;height:' + $img.height() + 'px;"></span>');
	}).hover(function() {
		$(this).addClass('hovered');
	}, function() {
		$(this).removeClass('hovered');
	}).fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'fade',
		'transitionOut'	: 'fade'
	});
});

$(function() {
	/**
	 * home flash
	 */
	var $flash = $('#slider-flash');
	if ( $flash.size() < 1 ) return;
	var $slider = $('#slider-content');
	
	var goSlider = function() {
		if ( !$slider.size() ) return false;
		
		// rebuild the image
		$slider.parent().show();
		$slider.find('div').each(function() {
			var _this = $(this);
			_this.html('<img src="' + $.trim(_this.html()) + '" alt="" />');
		});
		
		$slider.cycle({
			'pager':    '#slider-nav',
			'fx':       'fade',
			'timeout':  4000,           // milliseconds between slide transitions (0 to disable auto advance)
			'speed':    1000,           // speed of the transition (any valid fx speed value)
			'delay':    2000            // additional delay (in ms) for first transition (hint: can be negative)
		});
		$('#slider-nav a').each(function() {
			var _this = $(this);
			_this.html('<span>' + _this.text() + '</span>');
		});
	};
	
	swfobject.embedSWF("gridslider.swf", "slider-flash", "901", "396", "9.0.0", null, null, null, null, function() {
		if ( !arguments[0].success ) {
			goSlider();
		} else {
			$slider.parent().remove();
		}
	});
});
