// JavaScript Document
$(function() {
	$('#c1, #c2, #c3, #c4').mouseover(function(){
		$(this).css('border-left-color','#FFF');
		$(this).find('li:first > a').css('color','#0EBFF2');
	});
	$('#c1, #c2, #c3, #c4').mouseout(function(){
		$(this).css('border-left-color','#252525');
		$(this).find('li:first > a').css('color','#087392');
	});
});

$(document).ready(function() {
	$("a#fancylink").fancybox({
		'overlayShow':false, 'transitionIn':'elastic', 'transitionOut':'elastic', 'autoScale':false
	});
	$("a#fancybox").fancybox({
		'overlayShow':false, 'transitionIn':'elastic', 'transitionOut':'elastic'
	});
	$("a[rel=example_group], a[rel=group1], a[rel=group2], a[rel=group3], a[rel=group4], a[rel=group5], a[rel=group6], a[rel=group7], a[rel=group8], a[rel=group9], a[rel=group10], a[rel=group11]").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'cyclic'			: true,
				'overlayShow'		: false,
				'titlePosition' 	: 'inside',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
	});
	
	var $content = $('#content'),
	$thumb_list = $content.find('.thumb > ul');
	
	$thumb_list.each(function(){
		var $this_list = $(this),
		total_w = 0,
		loaded = 0,
		//prelaod all the images first
		$images = $this_list.find('img'),
		total_images = $images.length;
		$images.each(function(){
			var $img = $(this);
			$('<img alt="">').load(function(){
				++loaded;
				if (loaded == total_images){
					$this_list.data('current',0).children().each(function(){
						total_w += $(this).width();
					});
					$this_list.css('width', total_w + 'px');
					//next / prev events
					$this_list.parent()
					.siblings('.next')
					.bind('click',function(e){
						var current = $this_list.data('current');
						if (current == $this_list.children().length -1) return false;
						var next = ++current,
						ml = -next * $this_list.children(':first').width();
						$this_list.data('current',next).stop().animate({'marginLeft': ml + 'px'},400);
						e.preventDefault();
					})
					.end()
					.siblings('.prev')
					.bind('click',function(e){
						var current = $this_list.data('current');
						if (current == 0) return false;
						var prev = --current,
						ml = -prev * $this_list.children(':first').width();
						$this_list.data('current',prev).stop().animate({'marginLeft': ml + 'px'},400);
						e.preventDefault();
					});
				}
			}).attr('src',$img.attr('src'));
		});
	});
});
