//Portal jQuery to simulate existing flash element.

(function($) {
	$.is = {
		mobile: function() { 
			var sreturn = false;
			if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {	
				sreturn = true
			}
			return sreturn;
		}
	}
	
	$.portal = {   
		init: function(obj) {
			$portal = $(obj.containerClass);

			$portal.find('a').each(function( intCount ) {
				var leftPos = obj.positionLeft + (intCount * obj.imageWidth) + (obj.itemPadding * intCount);
				//alert(leftPos);
				$(this).css({ 'position' : 'absolute', 'z-index' : '0', 'display' : 'inline', 'top' : obj.positionTop+'px', 'left' : leftPos+'px' });

				if((!navigator.userAgent.match(/iPhone/i)) && (!navigator.userAgent.match(/iPod/i)) && (!navigator.userAgent.match(/iPad/i))) {
					$(this).bind('mouseenter', function() {
						var _this = $(this);
						window["tmp" + _this.children().attr('id')] = setTimeout(function() {	$.portal.enlargeItem(obj, _this, leftPos); }, obj.rollOverDelay);	
					});
					$(this).bind('mouseleave', function() {
						var _this = $(this);
						clearTimeout(window["tmp" + _this.children().attr('id')]);
						$.portal.shrinkItem(obj, $(this), leftPos);	
					});
				}
			});
		},
		switchFileName: function(filePath, toReplace, replaceWith) {
			var newImgPath = filePath.split('/');
			var filename = newImgPath[newImgPath.length-1];
			newImgPath[newImgPath.length-1] = filename.split(toReplace).join(replaceWith);
			
			return newImgPath.join('/');
		},
		activateHero: function($img) {
			var newSrc = $.portal.switchFileName($img.attr('src'), 'off', 'on');
			$img.attr({ 'src' : newSrc});
		},
		deactivateHero: function($img) {
			var newSrc = $.portal.switchFileName($img.attr('src'), 'on', 'off');
			$img.attr({ 'src' : newSrc});	
		},
		enlargeItem: function($settings, $obj, leftPos) {
			$img = $obj.find('img'); 
			$.portal.activateHero($img);
			$obj.css({ 'z-index' : 1 });
			$obj.animate({'left' : leftPos - Math.ceil($settings.enlargeSize/4)+'px'}, { duration: $settings.animationDuration, queue: $settings.animationQueue } );
			$img.animate({ 'width' : Number($settings.imageWidth) + Math.ceil($settings.enlargeSize/2) + 'px', 'height' : Number($settings.imageHeight) + Math.ceil($settings.enlargeSize/2) + 'px'}, { duration: $settings.animationDuration, queue: $settings.animationQueue });
		},
		shrinkItem: function($settings, $obj, leftPos) {
			$img = $obj.find('img');
			$.portal.deactivateHero($img);
			$obj.css({ 'z-index' : 1 });
			$obj.animate({'left' : leftPos+'px'}, { duration: $settings.animationDuration, queue: $settings.animationQueue });
			$img.animate({ 'width' : $settings.imageWidth + 'px', 'height' : $settings.imageHeight + 'px'}, { duration: $settings.animationDuration, queue: $settings.animationQueue });	
		}
	}
	
	$.fn.extend({
		portal: function(options) {
			this.settings = {
				eventTrigger	   		: "click",
				containerClass     		: "container",//etc, keep adding settings which you can set internally of externally
				$portal					: null,
				imageWidth				: 123,
				imageHeight				: 123,
				enlargeSize				: 30,
				animationDuration		: 150,
				itemPadding				: 5,
				positionTop				: 310,
				positionLeft			: 45,
				animationQueue			: true,
				rollOverDelay			: 50
			}	
			
			if(options){
				$.extend(this.settings, options);
			}	
			var settings = this.settings;
			
			$.portal.init(this.settings);
		}
	});	
})(jQuery);	
