﻿		
/**
 * Flash Tag Object v2.1b - by Lucas Ferreira
 * @author Lucas Ferreira - http://lucasferreira.com/
 * @version 2.1b
 * @date April 6, 2008
 * @copyright (c) 2008 Lucas Ferreira (lucasferreira.com)
 * @example Visit http://www.lucasferreira.com/flashtag/ for more informations about this
 */

var FlashTag = function()
{
	var FP_VERSION = null;
	return {
		YOUTUBE_URL_PLAYER: "http://www.youtube.com/v/%s",
		init: function()
		{
			FP_VERSION = this.getPlayerVersion();
			
			var s = document.getElementsByTagName("SCRIPT");
			for(var i=0; i<s.length; i++)
			{
				if(s[i].getAttribute("src") && s[i].getAttribute("src").indexOf("?correct-all") > -1)
				{
					FlashTag.automatic();
				}
			}
			
			//FlashTag embed functions...
			return (
				function(movie, id, width, height, initParams)
				{
					//variables...
					this.onNotDetect = function(){};
					this.variables = new Array();
					this.flashversion = (initParams && initParams.flashversion != undefined) ? initParams.flashversion : "6,0,21";
					this.protocol = (window.location.protocol.indexOf("https") < 0) ? "http" : "https";
					this.attributes = {
						"classid": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
						"codebase": this.protocol + "://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=" + this.flashversion,
						"type": "application/x-shockwave-flash",
						"rel": "flashtag"
					};

					this.params = { "pluginurl": this.protocol + "://www.macromedia.com/go/getflashplayer" };
					
					//methods...				
					this.addAttribute = function(prop, val){ this.attributes[prop] = val; };
					this.addParameter = function(prop, val){ this.params[prop] = val; };
					this.addVariable = function(prop, val){ this.variables.push([prop, val]); };
					this.getFlashVars = function()
					{
						for(var i=0, tempString = new Array(); i<this.variables.length; i++) tempString.push(this.variables[i].join("="));
						return tempString.join("&");
					};
					
					this.getObject = function()
					{
						return FlashTag.getObject(this);
					};					
					
					this.toString = function()
					{
						this.html = "";
						this.params.flashVars = this.getFlashVars();
						
						if(FlashTag.isIE())
						{
							//IE
							this.html = "<ob" + "ject";
							var attr = FlashTag.getObjectByExceptions(this.attributes, ["type", "data", "variables"]);
							for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
							this.html += "> ";
							var params = FlashTag.getObjectByExceptions(this.params, ["pluginurl", "extend", "version", "variables"]);
							for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
							this.html += " </obj" + "ect>";
						}
						else
						{
							//non-IE
							this.html = "<!--[if !IE]> <--> <obj" + "ect";
							var attr = FlashTag.getObjectByExceptions(this.attributes, ["classid", "codebase", "variables"]);
							for(var i in attr) if(i.toString() != "extend") this.html += " " + i.toString() + " = \"" + attr[i] + "\"";
							this.html += "> ";
							var params = FlashTag.getObjectByExceptions(this.params, ["extend", "version", "variables"]);
							for(var i in params) if(i.toString() != "extend") this.html += "<param name=\"" + i.toString() + "\" value=\"" + params[i] + "\" /> ";
							this.html += " </obj" + "ect> <!--> <![endif]-->";
						}
						return this.html;
					};
					
					this.redirectToUrl = function(url)
					{
						window.location.href = url;
					};
					
					this.write = function(o)										
					{
						if(typeof o != "undefined")
						{
							return this.writeIn(o);
						}						
						
						document.write( this.toString() );
						
						var f = FlashTag.getPlayerVersion();
						if(!f || (typeof this.params["version"] != "undefined" && !FlashTag.isMajor(f, this.params["version"])))
						{
							this.onNotDetect(f);
							
							if(typeof this.params["redirectUrl"] != "undefined")
							{
								this.redirectToUrl(this.params["redirectUrl"]);
							}
						}
						
						return true;
					};
					
					this.writeIn = function(o)
					{
						if(typeof o == "undefined")
						{
							return this.write();
						}
						else if(typeof o == "string")
						{
							o = document.getElementById(o) || null;
						}
						
						if(o == undefined || o == null) return false;
						
						var f = FlashTag.getPlayerVersion();
						if(!f || (typeof this.params["version"] != "undefined" && !FlashTag.isMajor(f, this.params["version"])))
						{
							this.onNotDetect(f);
							
							if(typeof this.params["redirectUrl"] != "undefined")
							{
								this.redirectToUrl(this.params["redirectUrl"]);
							}
						}
						else
						{
							o.innerHTML = this.toString();
						}
						
						return true;
					};
					
					//initial methods...
					if(movie)
					{
						this.addAttribute("data", movie);
						this.addParameter("movie", movie);
					}

					if(id && id != null && (this.id = id)) 
					{
						this.addAttribute("id", this.id);
						this.addAttribute("name", this.id);
					}
					else
					{
						this.id = null;
					}

					if(width) this.addAttribute("width", width);
					if(height) this.addAttribute("height", height);

					if(initParams != undefined)
					{
						for(var i in initParams)
						{
							if(i.toLowerCase() != "variables" && i.toLowerCase() != "flashvars")
							{
								this.addParameter(i.toString(), initParams[i]);
							}
							else
							{
								for(var j in initParams[i]) this.addVariable(j.toString(), initParams[i][j]);
							}
						}
					}					
				}
			);
		},
		
		isIE: function()
		{
			return (window.ActiveXObject && document.all && navigator.userAgent.toLowerCase().indexOf("msie") > -1  && navigator.userAgent.toLowerCase().indexOf("opera") == -1) ? true : false;
		},
		
		getObjectByExceptions: function(obj, excep)
		{
			var tempObj = {};
			for(var i in obj)
			{
				for(var j=0, EOF=false; j<excep.length; j++)
					if(excep[j] == i.toString()) { EOF = true; break; };
					
				if(!EOF) tempObj[i] = obj[i];
			}
			return tempObj;
		},	
		
		getObject: function(fo)
		{
			if(fo.id == null) return null;
			try
			{
				if(window.document[fo.id])
				{
					return window.document[fo.id];
				}
				else
				{
					return document.getElementById(fo.id);
				}
			}
			catch(e) { return null; }
		},
		
		createInstanceFromObject: function(o)
		{
			var attrs = {}, params = {}, src, on;

			for(var i=0; i<o.attributes.length; i++)
			{
				var attrn = (o.attributes[i].nodeName || i.toString()).toLowerCase(), attrv = o.getAttribute(attrn);
				if(attrn != "contenteditable" && attrn != "style" && attrv != "" && attrv != null && attrv != "null") 
				{
					try { attrs[attrn] = attrv; } catch(ex) { null; }
				}
				if(attrn == "style" && attrv != "" && attrv != null && attrv != "null" && o.outerHTML)
				{
					try
					{
						attrv = o.outerHTML.replace(/\s=/g, "=").replace(/=\s/g, "=").match(/style=[\"\'](.+)[\"\']/);
						if(attrv.length > 1) attrs[attrn.toString()] = attrv[1];
					}
					catch(ex) { null; }
				}
			}
			
			for(var i=0; i<o.childNodes.length; i++)
			{
				if((on=o.childNodes[i]).nodeType && on.nodeType == 1 && on.nodeName && on.nodeName.toLowerCase() == "param")
				{
					try { params[on.getAttribute("name")] = on.getAttribute("value"); } catch(ex) { null; }
				}
			}
			
			if((src = (attrs["src"] || attrs["data"] || attrs["movie"] || params["movie"] || null)) != null)
			{
				var tempInstance = new Flash(src, (attrs["id"] || null), (attrs["width"] || "100%"), (attrs["height"] || "100%"));
				for(var i in attrs) tempInstance.addAttribute(i.toString(), attrs[i]);
				for(var i in params) tempInstance.addParameter(i.toString(), params[i]);
				
				return tempInstance;
			}
			
			return false; 
		},
		
		correctAll: function()
		{
			var o = document.getElementsByTagName("OBJECT"), e = document.getElementsByTagName("EMBED"), objects = [];
			
			for(var i=0; i<e.length; i++)
			{
				if(!e[i].getAttribute("rel") || e[i].getAttribute("rel") != "flashtag") objects.push(e[i]);
			}		
			
			for(var i=0; i<o.length; i++)
			{
				if(!o[i].getAttribute("rel") || o[i].getAttribute("rel") != "flashtag") objects.push(o[i]);
			}
			
			for(var i=0; i<objects.length; i++)
			{
				if(objects[i].outerHTML)
				{
					try
					{
						
						var to = FlashTag.createInstanceFromObject(objects[i]);
						if(!to) continue;
						
						objects[i].style.visibility = "hidden";
						objects[i].outerHTML = to.toString();
						objects[i].style.visibility = "visible";
						
					} catch(ex){ null; }
				}
			}
		},
		
		automatic: function()
		{
			if(!FlashTag.isIE() || !document.getElementsByTagName) return false;

			//Correct all SWF's in a page...
			if(window.attachEvent)
			{
				window.attachEvent("onload", FlashTag.correctAll);
			}
		},
		
		isMajor: function(f1, f2)
		{
			for(var i=0, f1 = f1.replace(/[,]/g, ".").split("."); i<f1.length; (f1[i]=parseInt(f1[i])), i++);
			for(var i=0, f2 = f2.replace(/[,]/g, ".").split("."); i<f2.length; (f2[i]=parseInt(f2[i])), i++);			

			if(f1.length > 0 && f2.length > 0)
			{
				for(var i = -1, l = Math.min(f1.length, f2.length); ++i < l && f2[i] == f1[i];);
				return +(i != l && f2[i] - f1[i]) > 0 ? false : true;
			}
			
			return false;			
		},
		
		getPlayerVersion: function()
		{
			if(FP_VERSION == null)
			{
				if(!this.isIE() && navigator.plugins && navigator.mimeTypes.length
					&& (f=navigator.plugins["Shockwave Flash"]) && f.description)
				{
					return (f.description.replace(/[^0-9r.]/g, "").replace(/[r]/g, "."));
				}
				else
				{
					var acx = null;
					try
					{
						acx = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
					}
					catch(e)
					{
						var v = 8;
						do
						{
							try
							{
								acx = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + v);
								try { acx.AllowScriptAccess = "always"; } catch(eex){}
								
							} catch(ee) { acx = null; }
						}
						while(v-- && v > 2 && acx==null);
					}
					return (acx != null && acx) ? acx.GetVariable("$version").replace(/[^0-9,]/g, "").replace(/[,]/g, ".") : false;
				}
			}
			else
			{
				return FP_VERSION;
			}
		}
		
	};
	
}();

var Flash = FlashTag.init();

//new youtube method...
Flash.YouTube = function(youtube_url, id, width, height, initParams)
{
	if(!youtube_url) return false;
	
	movie = youtube_url.match(/\?([v=]?[^\&?]+)/);
	if(movie.length > 1)
	{
		movie = movie[1].replace(/v=/gi, "");
		movie = FlashTag.YOUTUBE_URL_PLAYER.split("%s").join(movie);
		
		return (new Flash(movie, id, width, height, initParams));
	}
	
	return false;
};

/****************************************************************************
* Fim do Flash Tag Write Object v2.1 - by Lucas Fererira - www.lucasferreira.com            *
****************************************************************************/




/* =========================================================

// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com

// based on the work of Matt Oakes http://portfolio.gizone.co.uk/applications/slideshow/
// and Ralf S. Engelschall http://trainofthoughts.org/

 *
 *  <ul id="news"> 
 *      <li>content 1</li>
 *      <li>content 2</li>
 *      <li>content 3</li>
 *  </ul>
 *  
 *  $('#news').innerfade({ 
 *	  animationtype: Type of animation 'fade' or 'slide' (Default: 'fade'), 
 *	  speed: Fading-/Sliding-Speed in milliseconds or keywords (slow, normal or fast) (Default: 'normal'), 
 *	  timeout: Time between the fades in milliseconds (Default: '2000'), 
 *	  type: Type of slideshow: 'sequence', 'random' or 'random_start' (Default: 'sequence'), 
 * 		containerheight: Height of the containing element in any css-height-value (Default: 'auto'),
 *	  runningclass: CSS-Class which the container getâ€™s applied (Default: 'innerfade'),
 *	  children: optional children selector (Default: null)
 *  }); 
 *

// ========================================================= */


(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        		'animationtype':    'fade',
            'speed':            'normal',
            'type':             'sequence',
            'timeout':          2000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
												current = Math.floor ( Math.random ( ) * ( elements.length ) );
										} while (last == current );             
										$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };

    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}
/***************************
* Fim do jQuery InnerFade  *
****************************/

