 (function($) {
  
  // Arguments are image paths relative to the current page.
  $.preloadImages = function() {
  	var cache = [];
    var teh_args = arguments;
    var args_len = arguments.length-1;
    for (var i = 0; i < args_len; i++) {
      var cacheImage = document.createElement('img');
      cacheImage.onload = function() {
      	--args_len;
      	if(args_len == 0) {
      		teh_args[teh_args.length-1](cache);
      	}
      }
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);



$("a[rel=blog_group]").fancybox({
	'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
});


var img_index = 1;
var images = $('.images:first');
var first_img_height = images.children(':first').height();
var text_height = $('.content-body').height();
if(images.children().length > 1) {
	while (first_img_height < text_height) {
		first_img_height += images.children(0).height();
		++img_index;
	}
	$('#images_footer').append(images.children().slice(img_index,images.children().length));
}


 
 $(document).ready(function() {
 
	$.preloadImages('/media/images/splash_plans.gif', function(img) {
	    $('#flash-movie .loader').fadeOut(500, function() {
	
		    var the_image = $(img[0]);
		    the_image.css('opacity', 0);
		    //the_image.css('position', 'relative').css('left', 'auto').css('top', 'auto');
		    $('#flash-movie').append(the_image);
		    the_image.animate({
		    	opacity:1
		    }, 2000, function() {
		    	$.preloadImages('/media/images/splash_image_large.jpg', function(img2) {
		    		setTimeout(function() {
		    		
				    	the_image.parent().css('position', 'relative');
				    	the_image.css('position', 'absolute').css('left', '50px').css('top', 0);
		    	
			    		var the_image2 = $(img2[0]);
					    the_image2.css('opacity', 0);
					    the_image2.css('position', 'absolute').css('left', '50px').css('top', 0);
					    $('#flash-movie').append(the_image2);
					    the_image2.animate({
					    	opacity:1
					    }, 2000, function() {
					    	the_image2.css('position', '').css('left', 'auto').css('top', 'auto');
					    	the_image.parent().css('position', '');
					    });
					    the_image.animate({
					    	opacity:0
					    }, 2000, function() {
					    	the_image.css('position', '').css('left', 'auto').css('top', 'auto').hide();
					    });
				    }, 2000);
		    	})
		    })
	    });
	    //var i = $('<img src=')
	    
	})
 });
