function contentTransform()
{
	var content;
	var videoCount = 0;
	var flagPost = 0;
	//var divLastExpanded = new Array();
	var divsHitClicked = new Array();
	
	// Player size
	var youtubeVW = 640;
	var youtubeVH = 385;
	var vimeoVW = 400;
	var vimeoVH = 225;
	
	//--------------------------------------
	// INIT
	//--------------------------------------
	
	this.init = function()
	{
		
	}
	
	this.update = function()
	{	
		// Videos
		this.setVideos();
	}
	
	
	//--------------------------------------
	// IMAGES BROSWER (__WEBKIT E FIREFOX__)
	//--------------------------------------
	
	this.setImagesNO_IE7 = function( obj )
	{
		// Handler for .load() called.
		var $this = $( obj );
		var aspect = $this.attr("height") / $this.attr("width");

		
		//
		if( $this.attr("width") > postWidth )
		{
			$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
		}
		
		// 	Set Image IE	
		if( $.browser.msie ) 
		{
			var $this = $(this);
			
			var img = new Image();
			img.src = $this.attr( 'src' );
			
			var _height = img.height;
			var _width = img.width;
			var aspect = _height / _width;
			
			if( _width > postWidth )
			$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
			$this.css( 'display', "inline" );
		}			
	}
	
	
	
	
	
	//--------------------------------------
	// IMAGES BROSWER (__IE7__)
	//--------------------------------------
	
	this.setImages_IE7 = function( post_name )
	{
		if( post_name == "post_1" )
		{
			$(document).onImagesLoad
			(
			{
				selectorCallback: function() 
				{
				  $( '#' + post_name + ' #post_content img' ).each(function()
				  {
						var $this = $(this);
						$this.remove();
			
						var img = new Image();
						img.src = $this.attr( 'src' );
						
						var _height = img.height;
						var _width = img.width;
						var aspect = _height / _width;
					
						
						if( _width > postWidth )
						{
							$( '#' + post_name + ' #post_content' ).append("<div><img style='margin:10px 0px 10px 0px' width='"+postWidth+"' height='"+parseInt( postWidth * aspect )+"' src='"+$this.attr( 'src' )+"'></div>");
							$( '#' + post_name + ' #post_content img' ).css( 'display', "inline" );
						}
						else
						{
							$( '#' + post_name + ' #post_content' ).append("<div><img style='margin:10px 0px 10px 0px;' width='"+img.width+"' height='"+img.height+"' src='"+$this.attr( 'src' )+"'></div>");
							$( '#' + post_name + ' #post_content img' ).css( 'display', "inline" );
						}	
						
				  });
				}
			}
			);
		}
		else
		{
			$( '#' + post_name + ' #post_content img' ).each
			(
			function()
			{
				// 	Set Image IE	
				if( $.browser.msie ) 
				{
					var $this = $(this);
					
					var img = new Image();
					img.src = $this.attr( 'src' );
					
					var _height = img.height;
					var _width = img.width;
					var aspect = _height / _width;
					
					if( _width > postWidth )
					$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
					$this.css( 'display', "inline" );
				}
			});
		}

	}
	
	
	//--------------------------------------
	// GALLERY ONE BROSWER (__WEBKIT E FIREFOX E IE8__)
	//--------------------------------------
	
	this.setGallerOne = function()
	{
		if( postName == "post_1" )
		{
			$( '#post_1 #post_content img' ).css( 'display', 'inline' );
		}
			
		// IMG LOAD	
		$( '#' + postName + ' #post_content img' ).load( function() 
		{
			// Handler for .load() called.
			var $this = $(this);
			var aspect = $this.attr("height") / $this.attr("width");
			
			
			if( $this.attr("width") > postWidth )
			{
				$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
				$this.css( 'display', "inline" );
				console.log('display')
			}
			else if( $this.attr("width") == postWidth )
			{
				$this.css( 'display', "inline" );
			}
			
			
			// 	Set Image IE	
			if( $.browser.msie ) 
			{
				var $this = $(this);
				
				var img = new Image();
				img.src = $this.attr( 'src' );
				
				var _height = img.height;
				var _width = img.width;
				var aspect = _height / _width;
				
				if( _width > postWidth )
				$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
				$this.css( 'display', "inline" );
			}
			
		});

	}
	
	//--------------------------------------
	// GALLERY SEVERAL BROSWER (__WEBKIT E FIREFOX E IE8__)
	//--------------------------------------
	
	this.setGallerSeveral = function()
	{
		// IMG LOAD	
		$( '#' + postName + ' #post_content img' ).load(function() 
		{	
			// Handler for .load() called.
			var $this = $(this);
			var aspect = $this.attr("height") / $this.attr("width");
	
			
			//
			if( $this.attr("width") > postWidth )
			{
				$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
				$this.css( 'display', "inline" );
			}
			
			
			// 	Set Image IE	
			if( $.browser.msie ) 
			{
				var $this = $(this);
				
				var img = new Image();
				img.src = $this.attr( 'src' );
				
				var _height = img.height;
				var _width = img.width;
				var aspect = _height / _width;
				
				if( _width > postWidth )
				$this.width( postWidth ).height( parseInt( postWidth * aspect ) );
			}
			
		});

	}
	
	
	
	//--------------------------------------
	// VIDEOS
	//--------------------------------------
	
	this.setVideos = function()
	{	
		$(".post_txt").each
		(
			function()
			{
				// CONTETN
				content = $(this).text();
				
				
				// Transform
				while( content )
				{
					// POST ID
					var postID = $(this).parent().parent().attr("id");
					postID = postID.substring( postID.indexOf( "_" ) + 1 );
						
					content = videosTransform( content, postID );
				}
			}
		);
	}
	
	function videosTransform( content, postID )
	{
		var playerWidth = postWidth;
		var playerHeight;
		var videoTag = false;
		var videoType;
		var startTag, endTag;
		
		//var youtubeVW = 640;
		//var youtubeVH = 385;
		var youtubeUrl = "http://www.youtube.com/watch?v=";
		//var youtubeEmbed = "http://www.youtube.com/v/";
		var youtubeEmbed = "http://www.youtube.com/embed/";
		var youtubeInfo = "?ap=%2526fmt%3D18&autoplay=0&rel=0&fs=1&border=0&loop=0&wmode=transparent";
		
		//var vimeoVW = 400;
		//var vimeoVH = 225;
		var vimeoUrl1 = "http://vimeo.com/";
		var vimeoUrl2 = "http://www.vimeo.com/";
		var vimeoEmbed = "http://player.vimeo.com/video/";
		var vimeoEmbed2 = "http://vimeo.com/moogaloop.swf?clip_id=";
		var vimeoInfo = "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff";
		var vimeoInfo2 = '&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=00ADEF&amp;fullscreen=1&amp;autoplay=0&amp;loop=0" type="application/x-shockwave-flash';
		
		
		// TAG
		if( videoTag = contentTransformGetTagValue( content, "[youtube=", "]" ) )
		{
			startTag = "[youtube=";
			endTag = "]";
			videoType = "youtube";
		}
		else if( videoTag = contentTransformGetTagValue( content, "[youtube=", "]" ) )
		{
			startTag = "[vimeo=";
			endTag = "]";
			videoType = "vimeo";
		}
		else if( videoTag = contentTransformGetTagValue( content, "[youtube]", "[/youtube]" ) )
		{
			startTag = "[youtube]";
			endTag = "[/youtube]";
			videoType = "youtube";
		}
		else if( videoTag = contentTransformGetTagValue( content, "[vimeo]", "[/vimeo]" ) )
		{
			startTag = "[vimeo]";
			endTag = "[/vimeo]";
			videoType = "vimeo";
		}
		else
		{
			videoTag = false;
		}
		
		
		if( videoTag )
		{
			videoCount++;
						
			if( videoType == "youtube" )
			{
				// SIZE
				playerHeight = parseInt( postWidth * ( youtubeVH / youtubeVW ) );
				
				
				// URL
				var videoUrl = contentTransformGetUrlValue( videoTag, startTag, endTag );
				var urlThumb;
				var string_v_url = "v=";
				
	
				if( videoUrl.indexOf(  string_v_url  ) >= 0 )
				{
					if( videoUrl.indexOf(  '&'  ) != -1 )
					{
						var videoIDLegth = videoUrl.indexOf(  'v='  ) - videoUrl.length + string_v_url.length;
						urlThumb = videoUrl.slice(  videoIDLegth, videoUrl.indexOf(  '&'  )  );
					}
					else
					{
						var videoIDLegth = videoUrl.indexOf(  'v='  ) - videoUrl.length + string_v_url.length;
						urlThumb = videoUrl.slice(  videoIDLegth );
					}
				}
			
				var videoIdentification =  contentTransformGetVideoID( youtubeUrl, videoUrl );
				videoUrl = youtubeEmbed + videoIdentification + youtubeInfo;
				
				
				// IDs
				var videoID = videoCount;
				var hitDivID = "hitDiv_" + videoID;
				
				
				var iframeID = "iframeObj_" + videoID;
				var expandParams = "'youtube','" + postID + "','" + videoID + "'";
				

				// YOUTUBE EMBED
				if( !_iphone && !_ipad )
				{
				
					// IE7
					if( msie7 )
					{
						var videoEmbed = '<iframe title="YouTube video player" src="' + videoUrl + '" width="' + playerWidth + '" height="' + playerHeight + '" frameborder="0" allowfullscreen></iframe>';
					}
					
					// ALL OTHER BROWSERS
					else
					{
						var videoEmbed = '<div style="position:relative;"><div id="' + hitDivID + '" onclick="contentTransformExpand(' + expandParams + ')" style="position:absolute; width:' + playerWidth + 'px; height:' + playerHeight + 'px; filter:alpha(opacity=0); background:red; -khtml-opacity: 0; opacity: 0;"></div>';
						videoEmbed += '<iframe title="YouTube video player" id="' + iframeID + '" src="' + videoUrl + '" width="' + playerWidth + '" height="' + playerHeight + '" frameborder="0" allowfullscreen></iframe></div>';
					}
					
				}
				
				
				// IPHONE IPAD
				else
				{	
					var playerPosX = playerWidth/2 - 65/2;
					var playerPosY = playerHeight/2 - 65/2;
					
					var videoEmbed ='<a href="' + videoUrl + '"><div style="position:absolute; width: 65px; height: 65px; margin-left: ' + playerPosX + 'px; margin-top:' + playerPosY + 'px; opacity:0.8";><img src="'+ globalURL + '/wp-content/themes/talkability/images/buttonPlayerYouTube.png" width="65px" height=" 65px" /></div><div style="width: ' + playerWidth + 'px; height: ' + playerHeight + 'px;"><img src="http://img.youtube.com/vi/' + urlThumb + '/0.jpg" width="' + playerWidth + 'px" height="' + playerHeight + 'px" /></div></a>';
					
				}
			}
			
			
			
			else if( videoType == "vimeo" )
			{
				// SIZE
				playerHeight = parseInt( postWidth * ( vimeoVH / vimeoVW ) );
				
				
				// URL
				var videoUrl = contentTransformGetUrlValue( videoTag, startTag, endTag );
				var vimeoUrl;
				if( videoUrl.search( vimeoUrl1 ) >= 0 ){ vimeoUrl = vimeoUrl1; } else { vimeoUrl = vimeoUrl2; };
				var videoIdentification = videoUrl.replace( vimeoUrl, "" );
				
				
								
				// IDs
				var videoID = videoCount;
				var hitDivID = "hitDiv_" + videoID;
				var expandParams = "'vimeo','" + postID + "','" + videoID + "'";
				
			

						
				// IE8
				if( msie8 )
				{
					
					videoUrl = videoUrl.replace( vimeoUrl, vimeoEmbed2 );
					videoUrl = videoUrl + vimeoInfo2;
					
					// IDs
					var objectID = "objectTag_" + videoID;
					var embedID = "embedTag_" + videoID;
					
					
					
					var videoEmbed = '<div id="' + hitDivID + '" onclick="contentTransformExpand(' + expandParams + ')" style="position: absolute; width:' + playerWidth + 'px; height:' + playerHeight + 'px; background: red; filter:alpha(opacity=0); -khtml-opacity: 0; opacity: 0; "></div><object id="' + objectID + '"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="' + videoUrl + '" /><embed wmode="opaque" id="' + embedID + '" src="' + videoUrl + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + playerWidth + '" height="' + playerHeight + '"></embed></object>';
				}
				
				
				
				
				// IE7
				else if( msie7 )
				{
					
					videoUrl = videoUrl.replace( vimeoUrl, vimeoEmbed2 );
					videoUrl = videoUrl + vimeoInfo2;
					
								
					var videoEmbed = '<object><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="' + videoUrl + '" /><embed wmode="opaque" id="' + embedID + '" src="' + videoUrl + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' + playerWidth + '" height="' + playerHeight + '"></embed></object>';
				}
				
				
				
				// CHROME, FIREFOX, OPERA
				else
				{
					
					videoUrl = videoUrl.replace( vimeoUrl, vimeoEmbed );
					videoUrl = videoUrl + vimeoInfo;
					
					// IDs
					var iframeID = "iframeObj_" + videoID;
										
					
					var videoEmbed = '<div style="position:relative; z-index: 0;"><div id="' + hitDivID + '" onclick="contentTransformExpand(' + expandParams + ')" style="position:absolute; width:' + playerWidth + 'px; height:' + playerHeight + 'px; filter:alpha(opacity=0); background:red; -khtml-opacity: 0; opacity: 0;"></div>';
					//videoEmbed += '<iframe  style="background: blue;" id="' + iframeID + '" src="' + videoUrl + '" width="' + playerWidth + '" height="' + playerHeight + '" frameborder="0"></iframe></div>';
					videoEmbed += '<iframe  style=" width:' + playerWidth + 'px; height:' + playerHeight + 'px;" id="' + iframeID + '"  src="' + videoUrl + '" width="' + playerWidth + '" height="' + playerHeight + '" frameborder="0"></iframe></div>';
				}
				
					
				/*
				// IDs
				var videoID = videoCount;
				var hitDivID = "hitDiv_" + videoID;
				var iframeID = "iframeObj_" + videoID;
				var expandParams = "'vimeo','" + postID + "','" + videoID + "'";
				
				
				// VIMEO EMBED
				
				var videoEmbed = '<div style="position:relative; z-index: 0;"><div id="' + hitDivID + '" onclick="contentTransformExpand(' + expandParams + ')" style="position:absolute; width:' + playerWidth + 'px; height:' + playerHeight + 'px; filter:alpha(opacity=0); background:red; -khtml-opacity: 0; opacity: 0;"></div>';
				videoEmbed += '<iframe id="' + iframeID + '" src="' + videoUrl + '" width="' + playerWidth + '" height="' + playerHeight + '" frameborder="0"></iframe></div>';
				*/
				
			}
			
			
			// REPLACE
			$("body #post_content .post_txt *").replaceText( videoTag, videoEmbed );
			content = content.replace( videoTag, videoEmbed );
			
			
			// Return
			return content;
		}
		else
		{
			// Return
			return false;
		}
	}
	
	
		
	
	//--------------------------------------
	// GET VALUE
	//--------------------------------------
	
	// TAG
	function contentTransformGetTagValue( content, startTag, endTag )
	{
		if( content.indexOf( startTag ) >= 0 )
		{
			var tagValue = content.substr( content.indexOf( startTag ), content.length );
			tagValue = tagValue.substr( 0, tagValue.indexOf( endTag ) + endTag.length );
			
			return tagValue;
		}
		else
		{
			return false;
		}
	}
	
	// URL
	function contentTransformGetUrlValue( content, startTag, endTag )
	{
		if( content.indexOf( startTag ) >= 0 )
		{
			var urlValue = content.replace( startTag, "" );
			urlValue = urlValue.replace( endTag, "" );
			
			return urlValue;
		}
		else
		{
			return false;
		}
	}
	
	
	
function contentTransformGetVideoID( videoHostUrl, videoUrl  )
{
	
	if( videoUrl.indexOf(  '&'  ) >= 0 )
	{
		var videoIDLegth = videoUrl.indexOf(  '&'  ) - videoHostUrl.length;
		var videoID = videoUrl.substr(  videoHostUrl.length, videoIDLegth );
	}
	else
	{
		var videoID = videoUrl.substr(  videoHostUrl.length );
	}
	
	return videoID;
	
}
	
	
	//--------------------------------------
	// EXPAND CONTENT
	//--------------------------------------
	
	
	// CONTRACT
	this.contract = function()
	{
		contractContent();
	}
	
	
	
	// EXPAND
	this.expand = function( _videoType, _postID, _videoID )
	{
		expandContent( _videoType, _postID, _videoID );		
	}
	
	
	
	expandContent = function( _videoType, _postID, _videoID )
	{
		// IDs
		var divName = "#post_" + _postID;
		
				
		// Contract the last expaded Div
		if( divLastExpanded['divName']!= divName )
		{
			contractContent();
		}
 				
						
		// YOUTUBE
		if( _videoType == "youtube" )
		{
			
			var hitDivID = "#hitDiv_" + _videoID;
			
			var iframeTagID = "#iframeObj_" + _videoID;
			
			// SIZE
			var expandWidth = postWidth + postDistance;
			var proportion = expandWidth / $( iframeTagID ).attr("width");
			var playerHeight = parseInt( $( iframeTagID ).attr("height") );
						
			
			// ANIMATE
			if( $( iframeTagID ).attr("width") <  expandWidth )
			{
				
				//$( divName ).animate({ 'width': expandWidth }, 250 );
				//$( iframeTagID ).animate({ width: expandWidth, height: playerHeight * proportion }, 250 );
				
				$( divName ).css( 'width', expandWidth );
				$( iframeTagID ).css( 'width', expandWidth );
				$( iframeTagID ).css( 'height', playerHeight * proportion );
				
				
				$( hitDivID ).css( "display", "none" );
				
				divLastExpanded['youtube'] = true;
				divLastExpanded['divName'] = divName;
				divsHitClicked.push( hitDivID );
			}
		}
		// VIMEO
		else if( _videoType == "vimeo" )
		{
			
			
			var hitDivID = "#hitDiv_" + _videoID;
			
			
			if( msie8 )
			{
				
				// IDs
				var objectID = "#objectTag_" + _videoID;
				var embedID = "#embedTag_" + _videoID;
				
				
				// SIZE
				var expandWidth = postWidth + postDistance;
				var proportion = expandWidth / $( embedID ).attr("width");
				var playerHeight = parseInt( $( embedID ).attr("height") );
				
				
				
				// ANIMATE
				if( $( embedID ).attr("width") <  expandWidth )
				{
					
									
					$( hitDivID ).css( "display", "none" );
					
					//$( divName ).animate({ 'width': expandWidth }, 250 );
					//$( iframeTagID ).animate({ width: expandWidth, height: playerHeight * proportion }, 250 );
			
								
					$( divName ).css( 'width', expandWidth );
					$( objectID ).attr( 'width', expandWidth );
					$( objectID ).attr( 'height', playerHeight * proportion );
					$( embedID ).attr( 'width', expandWidth );
					$( embedID ).attr( 'height', playerHeight * proportion );
					
					divLastExpanded['vimeo'] = true;
					divLastExpanded['divName'] = divName;
					divsHitClicked.push( hitDivID );
					
				}
				
			}
			else
			{
				
				
				var iframeTagID = "#iframeObj_" + _videoID;
								
				// SIZE
				var expandWidth = postWidth + postDistance;
				var proportion = expandWidth / $( iframeTagID ).attr("width");
				var playerHeight = parseInt( $( iframeTagID ).attr("height") );
				
				
				
				// ANIMATE
				if( $( iframeTagID ).attr("width") <  expandWidth )
				{				
					$( hitDivID ).css( "display", "none" );
					
					//$( divName ).animate({ 'width': expandWidth }, 250 );
					//$( iframeTagID ).animate({ width: expandWidth, height: playerHeight * proportion }, 250 );
				
					//		
					$( divName ).css( 'width', expandWidth );
					$( iframeTagID ).css( 'width', expandWidth );
					$( iframeTagID ).css( 'height', playerHeight * proportion );
			
				/*	$( divName ).css( 'width', 800 );
					$( iframeTagID ).css( 'width', 800 );
					$( iframeTagID ).css( 'height', 800 );*/
					
					divLastExpanded['vimeo'] = true;
					divLastExpanded['divName'] = divName;
					divsHitClicked.push( hitDivID );
					
				}
				
			}
						
		}
		
	}
	
	
	contractContent = function()
	{

		// HEIGHT
		var playerHeight = parseInt( postWidth * ( youtubeVH / youtubeVW ) );
				
			
		// YOUTUBE
		if( divLastExpanded['youtube'] )
		{
			
			// ANIMATE
			//$( divLastExpanded['divName']  ).animate({ 'width': postWidth }, 150 );
			//$( divLastExpanded['divName'] + " iframe" ).animate({ width: postWidth, 'height': playerHeight }, 150 );
			
			//$( divLastExpanded['divName']  ).css( 'width': postWidth );
			//$( divLastExpanded['divName'] + " iframe"  ).css( 'width': postWidth, 'height': playerHeight );
			
			$( divLastExpanded['divName'] ).css( 'width', postWidth );
			$( divLastExpanded['divName'] + " iframe"   ).css( 'width', postWidth );
			$( divLastExpanded['divName'] + " iframe"   ).css( 'height', playerHeight );
			
		}
		
		// VIMEO
		if( divLastExpanded['vimeo'] )
		{
			
			
			playerHeight = parseInt( postWidth * ( vimeoVH / vimeoVW ) );
			
			
			// ANIMATE
			//$( divLastExpanded['divName']  ).animate({ 'width': postWidth }, 150 );
			//$( divLastExpanded['divName'] + " iframe" ).animate({ width: postWidth, height: playerHeight }, 150 );
			
			if( msie8 )
			{
				$( divLastExpanded['divName'] ).css( 'width', postWidth );
				$( divLastExpanded['divName'] + " object"   ).attr( 'width', postWidth );
				$( divLastExpanded['divName'] + " object"   ).attr( 'height', playerHeight );
				$( divLastExpanded['divName'] + " embed"   ).attr( 'width', postWidth );
				$( divLastExpanded['divName'] + " embed"   ).attr( 'height', playerHeight );
			}
			else
			{	
				$( divLastExpanded['divName'] ).css( 'width', postWidth );
				$( divLastExpanded['divName'] + " iframe"   ).css( 'width', postWidth );
				$( divLastExpanded['divName'] + " iframe"   ).css( 'height', playerHeight );
			}
			
			
		}

				
		for( var i = 0; i < divsHitClicked.length; i++ )
		{
			$( divsHitClicked[i] ).css( "display", "block" );
		}
		
				
		divLastExpanded = new Array();
		divsHitClicked = new Array();
	}
			
}
