
/************************ Image Zooming **************************/
function Zoomer(){};

Zoomer.prototype = 
{
	init: function()
	{
		this.useTransitions = this.getTransitionsSupported();
		this.imageSet = Math.ceil(Math.random()*5);
		var self = this;
		$('.zoom_image').each(function(i)
		{
			// choose image
			var imagePath = self.getDirectory()+'/image0'+(i+1)+'_thumb.jpg';
			this.setAttribute('src', imagePath);
			// cache
			self.cacheImage(self.getZoomedImagePath(imagePath));
		});
		$('.zoom_image').bind('mouseup',  function(e) {return self.zoom(e)}, false);
	},
	
	cacheImage: function(imagePath)
	{
		  document.createElement('img').src =imagePath;
	},
	
	getTransitionsSupported: function()
	{
		var result = false;
		var div = document.createElement('div');
		div.innerHTML = '<div style="-webkit-transition:color 1s linear;"></div>';
		result = (div.firstChild.style.webkitTransition !== undefined);
		delete div;
		return result;
	},
	
	getDirectory: function()
	{
		return 'flash_images/Intro_'+this.imageSet;
	},
	
	zoom: function(e)
	{
		e.stopPropagation();
		if ($('.zoomed_image').length>0)
		{
			this.unzoom(e);
			return;
		}
		var self = this;
		$('.zoomed_image').remove();
		var target = $(e.currentTarget);
		//var imgSrc = target.attr('src').split('_thumb.').join('.');
		var imgSrc = this.getZoomedImagePath(target.attr('src'));
		var zoomedTarget =  $('<img src="'+imgSrc+'"/>');
		$('#body_content').append(zoomedTarget);
		zoomedTarget.addClass('zoom_image zoomed_image');
		
		zoomedTarget.css(this.getZoomedCss());
		 if (this.useTransitions)
		 {
			setTimeout( function () {zoomedTarget.css('opacity', 1);}, 1);
		 }
		 else
		 {
			setTimeout( function () {zoomedTarget.fadeTo('300ms', 1);}, 1);
			;
		 }
		$('#body_content').bind('mouseup',  function(e) {return self.unzoom(e)}, false);
		//zoomedTarget.bind('mouseup',  function(e) {return self.unzoom(e)}, false);
	},
	getZoomedImagePath: function(thumbPath)
	{
		return thumbPath.split('_thumb.').join('.');
	},
	unzoom: function(e)
	{ 
		var self = this;
		e.stopPropagation();
		$('.zoomed_image').remove();
	},
	
	isiPhad: function()
	{
		var ua = navigator.userAgent;
		var ipad = /iPad/i.test(navigator.userAgent);
		var iphone = /iPhone/i.test(navigator.userAgent);
		var result = (ipad || iphone);
		return result;
	},
	
	getZoomedCss: function()
	{
		var result = {};
		var body_content = $('#body_content');
		result.position = "absolute";
		result.width = 505;
		result.height = 379;
		result.opacity = 0;
		result.left = (body_content.width()- result.width) * 0.5;
		result.top = (body_content.height()- result.height) * 0.5;
		result['-webkit-transition-duration'] = '300ms';
		result['-webkit-transition-timing-function'] =  'ease-in';
		return result;
	}
}

  $(document).ready(
	function()
	{		
	  new Zoomer().init();
	});

