/*!!!!!!!!!!! jsRoger 2.0.0 !!!!!!!!!!!!!!
 * Copyright (c) 2002 - 2009
 * Author:		Roger
 * Site:		jsRoger.com
 * License:		GPL-LICENSE
 */
function jsRoger( obj, selector) {
	if ( typeof obj == STRING ) {
		if ( obj.substring(0,1)==":" ) {
			selector	=  obj;
			obj		= document.body;
		} else {
			obj		= document.getElementById(obj);
		}
	}
	if (!obj) {
		return null;
	}
	if ( obj == window ) {
		if	( jsRoger.Element.methods.addEvent)	{ window.addEvent	= jsRoger.Element.methods.addEvent;	}
		if	( jsRoger.Element.methods.removeEvent)	{ window.addEvent	= jsRoger.Element.methods.removeEvent;	}
		return obj;
	}
	if ( !obj.jsRogerReady && typeof obj == OBJECT ) {
		jsRoger.Object.merge( obj, jsRoger.Element.methods);
		obj.jsRogerReady	= true;
	}
	if ( selector ) {
		if ( !jsRoger.Element.GetElementsBySelector && jsRoger.Debug.showWarnings) {
			alert( 'A biblioteca "jsRoger.Element.GetElementsBySelector" é necessária para se executar a função "jsRoger( obj, selector)."');
		} else {
			return jsRoger.Element.GetElementsBySelector( obj, selector);
		}
	}
	return obj;
}
jCube	= jsRoger;
jsRoger.author	= "Roger Skywalker";
jsRoger.version	= "2.0.0";
jsRoger.Date			= {
	en:	{
		months:		["January",	"February",	"March",	"April",	"May",		"June",		"July",		"August",	"September",	"October",	"November",	"December"],
		weekdays:	["Sunday",	"Monday",	"Tuesday",	"Wednesday",	"Thursday",	"Friday",	"Saturday"],
		names:		["Day", "Days",	"Week", "Weeks", "Month", "Months", "Year", "Years"]
	},
	pt:	{
		months:		["Janeiro",	"Fevereiro",	"Mar&ccedil;o",	"Abril",	"Maio",		"junho",	"Julho",	"Agosto",	"Setembro",	"Outubro",	"Novembro",	"Dezembro"],
		weekdays:	["Domingo",	"Segunda-feira","Ter&ccedil;a-feira",	"Quarta-feira",	"Quinta-feira",	"Sexta-feira",	"S&aacute;bado"],
		names:		["Dia", "Dias",	"Semana", "Semanas", "M&ecirc;s", "Meses", "Ano", "Anos"]
	}
};
jsRoger.International	= {
	language:		'pt',
	dateLongFormat:		'%Y, %M %e - %W %T',
	dateMediumFormat:	'%Y, %b %e - %T',
	dateShortFormat:	'%Y/%b/%e - %T',
	thousandSeparator:	'.',
	decimalSeparator:	',',
	decimalWidth:		2,
	currencySimbol:		'R$',
	charset:		"UTF-8"
};
jsRoger.Debug		= {
	displayErrors:		false,
	showWarnings:		false,
	alertOnDuplicates:	false
};
jsRoger.Array		= {};
jsRoger.Color		= {};
jsRoger.Document	= {};
jsRoger.Element		= {
	SMP:			{},
	methods:		{},
	pMethods:		{}
};
jsRoger.Function	= {};
jsRoger.GUI			= {};
jsRoger.Math		= {};
jsRoger.Number		= {};
jsRoger.Object		= {};
jsRoger.Server		= {};
jsRoger.String		= {};
jsRoger.Time		= {};
jsRoger.Transition	= {};
jsRoger.Util		= {};
jsRoger.Window		= {
	DOMEvents:	[]
};
//útil para o Mozilla quando ele se recusa a atualizar o cache nos iframes
jsRoger.noCache		= false;
jsRoger.constants	= {
	DEFAULT_SCROLL_SPEED:		80,
	DEFAULT_FRAMES_PER_SECOND:	30,
	INPUT:			"INPUT",
	TABLE:			"TABLE",
	TBODY:			"TBODY",
	TR:			"TR",
	TD:			"TD",
	DIV:			"DIV",
	SPAN:			"SPAN",
	IMG:			"IMG",
	A:			"A",
	B:			"B",
	SELECT:			"SELECT",
	OPTION:			"OPTION",
	TEXTAREA:		"TEXTAREA",
	HORIZONTAL_ORIENTATION: "horizontal",
	VERTICAL_ORIENTATION:	"vertical",
	LEFT:			"left",
	TOP:			"top",
	RIGHT:			"right",
	BOTTOM:			"bottom",
	ABSOLUTE_POSITION:	"absolute",
	RELATIVE_POSITION:	"relative",
	IGNORE_CASE:		1,
	SIZE_REGULAR:		"regular",
	SIZE_SMALL:		"small",
	SIZE_MINI:		"mini",
	SIZE_LARGE:		"large",
	TEXT_NODE:		3,
	INTEGER:		"integer",
	FLOAT:			"float",
	ENUM:			"enum",
	CURRENCY:		"currency",
	TIMESTAMP:		"timestamp",
	UNICODE:		"unicode",
	TEXT:			"text",
	STRING:			"string",
	NUMBER:			"number",
	ARRAY:			"array",
	OBJECT:			"object",
	FUNCTION:		"function",
	BOOLEAN:		"boolean",
	SECOND:			1000,
	MINUTE:			1000 * 60,
	HOUR:			1000 * 60 * 60,
	DAY:			1000 * 60 * 60 * 24,
	WEEK:			1000 * 60 * 60 * 24 * 7,
	MONTH:			1000 * 60 * 60 * 24 * 30,
	YEAR:			1000 * 60 * 60 * 24 * 365,
	PRECISE_YEAR:		1000 * 60 * 60 * 24 * 365.2425
};
//inherits from its parent
if ( parent && parent.jsRoger) {
	jsRoger.Date		= parent.jsRoger.Date;
	jsRoger.International	= parent.jsRoger.International;
	jsRoger.Debug		= parent.jsRoger.Debug;
	jsRoger.noCache		= parent.jsRoger.noCache;
	jsRoger.constants	= parent.jsRoger.constants;
}
//Browser sniffer referencied by window and document objects
//we're starting to move to use user agent rather than object detection due to instability object detection problems and constant updates resulting in innacuracy
jsRoger.browser	= {};
if ( window.ActiveXObject ) {
	jsRoger.browser.msie	= true;
	jsRoger.browser.version	= window.XMLHttpRequest? 7: document.getBoundingClientRects?6:5.5;
	if ( document.documentMode ) {
		jsRoger.browser.version	= document.documentMode;
	} else if ( window.XMLHttpRequest ) {
		jsRoger.browser.msie7	= true;
	} else {
		jsRoger.browser.msie6AndBellow	= true;
	}
	//fixes image cache (css) for ie 6
	if ( !window.XMLHttpRequest ) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(e){};
	}
	jsRoger.browser.name	= "msie";
} else if ( /chrome/.test( navigator.userAgent.toLowerCase() ) ) {
	jsRoger.browser.version	= (navigator.userAgent.toLowerCase().match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1];
	jsRoger.browser.chrome	= true;
	jsRoger.browser.webkit	= true;
	jsRoger.browser.name	= "chrome";
} else if ( window.opera) {
	jsRoger.browser.opera	= true;
	jsRoger.browser.name	= "opera";
} else if (document.childNodes && !document.all && !navigator.taintEnabled ) {
	jsRoger.browser.safari	= true;
	jsRoger.browser.webkit	= true;
	jsRoger.browser.version	= !!(document.evaluate) ? "420" : "419";
	jsRoger.browser.name	= "safari";
} else if ( document.createElementNS != null) {
	jsRoger.browser.mozilla	= true;
	jsRoger.browser.version	= 1;
	jsRoger.browser.name	= "mozilla";
	if ( window.globalStorage && window.postMessage) {
		jsRoger.browser.version	= 3;
	} else if ( window.globalStorage) {
		jsRoger.browser.version	= 2;
	}
}
if ( /webkit/.test( navigator.userAgent.toLowerCase() )	 ) {
	jsRoger.browser.webkit	= true;
}
///////////////////////////////////////////// utilities //////////////////////////////////////////////////////
// dollar function
if ( !window.$ ) {
	window.$	= function ( obj) {
		if	( typeof obj == STRING ){
			return jsRoger(obj);
		}
		return obj;
	};
}
/* time */
window.$now	= function( yyyy, mm, dd, h, min, secs) {
	var t	= new Date();
	if ( yyyy )	{ t.setYear( yyyy);	}
	if ( mm )	{ t.setMonth( mm);	}
	if ( dd )	{ t.setDate( dd);	}
	if ( h )	{ t.setHours( h);	}
	if ( min )	{ t.setMinutes( min);	}
	if ( secs )	{ t.setSeconds( secs);	}
	
	return t.getTime();
};
Array.prototype.isArray		= true;
String.prototype.isString	= true;
Number.prototype.isNumber	= true;
Function.prototype.isFunction	= true;
// Array.remove e Object.merge agora são protótipos nativos do jsRoger
Array.prototype.remove		= function ( item) {
	for ( var i=0, len=this.length; i<len; i++) {
		if ( this[i] == item ) {
			this.splice( i, 1);
			len--;
			i--;
		}
	}
	return this;
};
Object.prototype.merge		= function ( obj, OBJ) {
	if ( !OBJ) {
		OBJ	= obj;
		obj	= this;
	}
	for ( var i in OBJ) {
		if ( !Object.prototype[i] ) {
			obj[i] = OBJ[i];
		}
	}
	return obj;
};
//SetMethods is intented for applying DOM methods to a collection of objs html
jsRoger.Element.SetMethods	= function( fxName) {
	jsRoger.Element.pMethods[fxName]	= function( a, b) {
		var objs	= [];
		for ( var i=0, crr; i<this.length; i++ ) {
			if ( (crr = this[i][fxName]( a, b))) {
				objs[objs.length]	= crr;
			}
		}
		return this;
	};
};
Object.prototype.merge( window, jsRoger.constants);
jsRoger.Object.merge	= Object.prototype.merge;
jsRoger.Array.remove	= Array.prototype.remove;
////////////////////////////////////////////////////// Debug ///////////////////////////////////////////////////////////
window.onerror	= function ( msg, url, line) {
	if ( jsRoger.Debug.displayErrors ) {
		alert( "Error message:\n\t"+ msg +"\nline:\t"+ line +"\n\nurl:\t"+ url );
	}
	return false;
};
jsRoger.Import	= function( url, charset) {
	charset	= charset	|| jsRoger.International.charset;
	
	if ( url.substring( url.length-4,url.length).toLowerCase() == ".css" ) {
		document.write('<link rel="stylesheet" charset="'+ charset +'" type="text/css" href="'+ url +'" />');
	} else {
		document.write('<scr' + 'ipt type="text/Javascript" src="'+ url +'" charset="'+ charset +'" ></scr' + 'ipt>');
	}
};
jsRoger.Include	= function( url, charset) {
	jsRoger.Import( jsRoger.root + url, charset);
};
jsRoger.root	= function() {
	for ( var i=0, crr, oScripts=document.getElementsByTagName("SCRIPT"); i<oScripts.length; i++) {
		crr	= oScripts[i].src.toLowerCase();
		
		if ( crr.substring(crr.length-10)=="jsroger.js" || crr.substring(crr.length-14)=="jsroger.min.js" || crr.substring(crr.length-17)=="jsroger.single.js" ){
			var filePos	= 0;
			if ( crr.substring(crr.length-10)=="jsroger.js") {
				filePos	= 10;
			} else if ( crr.substring(crr.length-14)=="jsroger.min.js") {
				filePos	= 14;
			} else if ( crr.substring(crr.length-17)=="jsroger.single.js") {
				filePos	= 17;
			}
				
			crr	= oScripts[i].src.substring(0,crr.length-filePos);
			if(document.location.protocol=="https:"){
				crr=crr.replace(/^http:/,"https:")
			}
			return crr
		}
	}
	
	return "";
}();
jsRoger.Include	= function( url, charset) {
	charset	= charset	|| jsRoger.International.charset;
	
	/*
		no caso de arquivos compilados, não é necessário prosseguir adiante
	*/
	if ( jsRoger.Include.compiled && url.substring( url.length-4).toLowerCase() != ".css") {
		jsRoger.Include.filesloaded[url]	= {type: "js"}
		return;
	}
	
	var parsedURL	= jsRoger.Include.ParseUrl( url),
		sURL	= parsedURL[0],
		jsURL	= parsedURL[1],
		cssURL	= parsedURL[2],
		nocache	= (jsURL && jsRoger.noCache? (jsURL.indexOf("?")>-1?"&":"?") + jsRoger.noCache: "")
	;
	
	if ( !jsRoger.Include.filesloaded[url] ) {
		var includeThis	= true;
		
		if ( url=="Util.CreateSingleFile" ) {
			includeThis	= false;
		}
		var OBJ	= {};
		
		if ( jsRoger.Server.Asset && jsRoger.Server.HttpRequest ) {
			new jsRoger.Server.Asset( url);
		} else if ( jsURL ) {
			var includedInParent	= false;
			try {
				if ( parent != window && parent.jsRoger && parent.jsRoger.Server.Asset && parent.jsRoger.Server.Asset[url] && parent.jsRoger.Server.Asset[url].content) {
					document.write("<scr" + "ipt charset=\""+ charset +"\" type=\"text/javascript\" id=\""+ url +"\" >"+ parent.jsRoger.Server.Asset[url].content +"</scr" + "ipt>");
					includedInParent	= true;
				}
			} catch(e) {
				if ( jsRoger.Debug.displayErrors) {
					throw new Error("Erro ao tentar acessar o objeto \"parent\"!");
				}
			}
			if ( !includedInParent) {
				if ( jsRoger.Server.HttpRequest && jsRoger.Server.Asset) {
					new jsRoger.Server.Asset(url);
				} else {
					document.write("<scr" + "ipt charset=\""+ charset +"\" type=\"text/javascript\" id=\""+ url +"\" src=\""+ jsURL + (nocache) +"\" ></scr" + "ipt>");
				}
			}
			
			OBJ.type= "js";
			OBJ.url	= jsURL;
			
			if ( includeThis) {
				jsRoger.Include.missing.push( jsURL);
			}
			
		} else if ( cssURL) {
			document.write('<link rel="stylesheet" charset="'+ charset +'" type="text/css" href="'+ cssURL +'" />');
			OBJ.type	= "css";
			OBJ.url	= cssURL;
			jsRoger.Include.files.push( cssURL);
		}
		
		if( includeThis ) {
			jsRoger.Include.filesloaded[url]	= OBJ;
			jsRoger.Include.count++;
		}
	} else if ( jsRoger.Debug.alertOnDuplicates ) {
		alert( "The following package \""+ url +"\" has already been loaded!" );
	}
};
jsRoger.Include.ParseUrl	= function ( url) {
	var	sURL	= null,
	 	cssURL	= null,
		jsURL	= null
	;
	
	if ( url.substring( url.length-4,url.length).toLowerCase() == ".css" ) {
		cssURL	= jsRoger.root + url;
		sURL	= cssURL.toLowerCase();
	} else {
		if ( url.substring( url.length-3,url.length).toLowerCase() == ".js" ) {
			jsURL	= jsRoger.root + url;
			sURL	= jsURL.toLowerCase();
		} else {
			if ( url.indexOf(".*") > -1 ) {
				var nome	= url.substring(0, url.indexOf("."));
				var files	= jsRoger.Include[nome];
				for	( var f=1; f<files.length; f++) {
					urls.push( nome +"."+ files[f]);
				}
				url	= nome +"."+ files[0];
			}
			if ( url.indexOf(".") == -1 ) {
				url		= url +"."+ url;
			} else {
				url		= url + url.substring( url.lastIndexOf("."));
			}
			jsURL	= jsRoger.root + url.replace(/\./g, "/") +".js";
			sURL	= jsURL.toLowerCase();
		}
	}
	sURL	= sURL.replace( /\//g, "_");
	sURL	= sURL.replace( /\./g, "D");
	
	return [ sURL, jsURL, cssURL, url];
};
jsRoger.Include.count		= 1;
jsRoger.Include.filesloaded	= [];
jsRoger.Include.files		= ["jsRoger.js"];
jsRoger.Include.missing		= [];
/*jsRoger.Include remove from here*/
//Se estiver faltando algum arquivo, mozilla falar-nos-á...
if ( window.addEventListener ) {
	window.addEventListener(
		"load",
		function() {
			window.loaded	= true;
			if ( jsRoger.Debug.showWarnings && jsRoger.browser.mozilla ) {
				if ( jsRoger.Include.missing.length && !jsRoger.browser.safari) {
					alert("The following file"+ (jsRoger.Include.missing.length>1?"s are":" is") +" missing:\n*\t"+ jsRoger.Include.missing.join("\n*\t"));
				}
				jsRoger.Include.files[0]	= "jsRoger.js";
			}
		},
		true
	);
}
