// JavaScript Document
//window.onerror = function(){location.reload(true); return false;}

	/////////// PROCURA EM ARRAYS, KEYS INCOMPATIVEIS
	function searchInArray(array, value){
		for(var i=0; i<array.length; i++){
			if (array[i] == value) return true;
		}
		return false;
	}
	function t_maxLength(field, e, limit){
		noKey = [8, 38, 40, 37, 46, 39];
		var keyCode=e.charCode? e.charCode : e.keyCode;
		if (keyCode!=8 && keyCode!=9 && keyCode!=13){
			if (!searchInArray(noKey, keyCode)){ 
				if(field.value.length >= limit) return false //disable key press
			}
		}
		return true;
	}
	


//ADICIONA VALOR DEFAULT NO CAMPO
function defaultMsnValue(field, value, compare){
	fieldName = field.attributes.getNamedItem("name").value;
	
	if (compare){
		if (!field.value){field.value = value;this["value_" + fieldName] = false;} 
		else this["value_" + fieldName] = field.value;
	}else{
		if (!field.value || field.value == value){
			field.value = "";
			field.onblur = function(){defaultMsnValue(field, value, true);};
		}
	}
}

//ADICIONA VALOR DEFAULT NO CAMPO
function returnValue(form, field, value){
	if (field.value == value || !field.value) return false;
	else {sendForm(form);}
}

//SHOW HIDDEN ELEMENT
function showHide(field, modeIni){
	var target = document.getElementById(field);
	if (target){
		if (!target.style.display) target.style.display = modeIni;
		else if (target.style.display == "none") target.style.display = "block";
		else									 target.style.display = "none";
	}
}
function getScrollHeight(){
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}
//POPUP MSN
function popupMsn(msn, func){
	
	str = "<div id=\"popupMsn\">";
	str += "<div class=\"popupShadow\">";
	str += "<div class=\"popupBox\" style=\"margin-top:"+ (getScrollHeight()-130) +"px;\">";
	str += "<div class=\"popMsn\">" + msn + "</div>";
	str += "<div class=\"popBts\">";
	str += "<input type=\"button\" name=\"sim\" value=\"Sim\" class=\"btForm\"  onClick=\"removeObj('lightmask'); " + func + "\"> ";
	str += "<input type=\"button\" name=\"nao\" value=\"Não\" class=\"btForm\" onClick=\"removeObj('lightmask')\">";
	str += "</div>";
	str += "</div>";
	str += "</div>";
	str += "</div>";
			
	height 		= $(document).height();
	width  		= $(document).width();
		
	$("body").prepend("<div id=\"lightmask\"></div>");
	$("#lightmask").after(str);
	
	$("#lightmask").css('height',height+'px');
	$("#lightmask").css('width',width+'px');
}

function removeObj(obj){
	str = obj;
	obj = document.getElementById(obj);
	if (obj){
		document.body.removeChild(obj);
		if(str == 'lightmask')
			$("#popupMsn").remove();
	}
	
}

/* -- OPTIONS CONTENT -- */

	//MAXIMIZE CONTENT
	function maximizeContent(fieldMenu, fieldContent, widthMAX, widthMIN){
		var fieldMenu = document.getElementById(fieldMenu);
		var fieldContent = document.getElementById(fieldContent);
		
		if (fieldMenu && fieldContent){
			if (fieldMenu.style.display == "none"){
				fieldMenu.style.display = "block";
				fieldContent.style.width = widthMIN + "px";
				
				document.getElementById('iconMax').style.display = "";
				document.getElementById('iconMin').style.display = "none";
			}else{
				fieldMenu.style.display = "none";
				fieldContent.style.width = widthMAX + "px";
				
				document.getElementById('iconMax').style.display = "none";
				document.getElementById('iconMin').style.display = "";
			}
		}
	}
	
	//PRINT VERSION
	function printContent(pagePrint, id){
		var width 	= 500;
		var height 	= 500;
		var top 	= screen.height/2 - height/2;
		var left 	= screen.width/2 - width/2;
		window.open(pagePrint + "?" + id, 'SPR', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',scrollbars=yes,fullscreen=no');
	}
	
	//REMOVE CHCKED
	function clearCheck(field){
		if (!field.length){
			field.checked = false;
		}else{
			for(var i=0; i<field.length; i++){
				field[i].checked = false;
			}
		}
	}
	
	//ABRE POPUP
	function popup(page, name, width, height){
		var posX = screen.width/2 - width/2;
		var posY = screen.height/2 - height/2;
		window.open(page, name, "height=" + height + ",width=" + width + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes, left=" + posX + ", top=" + posY);
	}
	
	//CRIA POPUP NA PAGINA
	function popupCreate(content, width, height){
		
		if(width == 950){width2 = "width:"+width+"px;";}else{width2="";}
		if(height == 500){height2 = "height:"+height+"px;";}else{height2="";}
		
		var obj = document.getElementById('boxPOPUP');
		if (!obj){
			
			target = document.getElementById("BASE");
			var newElement = document.createElement('div');
			newElement.setAttribute('id',		'boxPOPUP');
			newElement.setAttribute('name',		'boxPOPUP');
			document.body.appendChild(newElement);
			obj = newElement;
		}
		
		obj.innerHTML = "";
		obj.style.display = "block";

		var posTop = -( (height+18)/2 - document.documentElement.scrollTop);
		var strHTML = "<div onclick=\"popupRemove('boxPOPUP')\" id=\"lightMASK\" style=\"position:fixed;top:0;left:0;width:100%;height:"+$(document).height()+"px;z-index:1500;background-color:#000000;opacity:0.8;filter:alpha(opacity=80);\" ></div>";
			strHTML += "<div id=\"popupPDF\"  style=\" "+width2+height2+"position:fixed; z-index:2000; top:50%; left:50%; margin:" + posTop + "px 0px 0px -" + width/2 + "px; background:none; \">";
			strHTML += "<div class=\"popupTitle\" style=\"text-align:right\"><a href=\"javascript:popupRemove('boxPOPUP');\" title=\"Fechar\"><img src=\"http://www.spr.org.br/pags/view/img/fechar.gif\" alt=\"Fechar\" /></a></div>";
			strHTML += "<div style=\" border:1px solid #FFFFFF;\">";
			strHTML += content;
			strHTML += "</div>";
			strHTML += "</div>";
			strHTML += "";
		
		obj.innerHTML = strHTML;
	}
	
	function popupRemove(obj){
		obj = document.getElementById(obj);
		if (obj){
			obj.style.display = "none";
			obj.innerHTML = "";
		}
	}
	
	function popupImg(url, width, height){
		var strHTML = "<div><img src=\"" + url + "\" border=\"0\" /></div>";
		popupCreate(strHTML, width, height);
	}
	
	//====
	function apresentacao(url){
        if(url.indexOf('http://www.spr.org.br/') == -1){
            url = 'http://www.spr.org.br/'+url;
        }
        
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"705\" height=\"564\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/apresentacao.swf?url=" + url + "\" />";
			strHTML += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
			strHTML += "<param name=\"quality\" value=\"high\" />";
			strHTML += "<param name=\"allowFullScreen\" value=\"true\" />";
			strHTML += "<param name=\"bgcolor\" value=\"#000000\" />";
			strHTML += "<embed src=\"http://www.spr.org.br/swf/apresentacao.swf?url=" + url + "\" quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"720\" height=\"564\"></embed>";
			strHTML += "</object>";
		popupCreate(strHTML, 705, 564);
	}
	
	function apresentacaob(url){
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"705\" height=\"564\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/apresentacaob.swf?url_=" + url + "\" />";
			strHTML += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
			strHTML += "<param name=\"quality\" value=\"high\" />";
			strHTML += "<param name=\"allowFullScreen\" value=\"true\" />";
			strHTML += "<param name=\"bgcolor\" value=\"#000000\" />";
			strHTML += "<embed src=\"http://www.spr.org.br/swf/apresentacaob.swf?url_=" + url + "\" quality=\"high\" allowScriptAccess=\"sameDomain\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"720\" height=\"564\"></embed>";
			strHTML += "</object>";
		popupCreate(strHTML, 705, 564);
	}
	function videoFLV(url, Width, Height){
		if(navigator.userAgent.indexOf("MSIE")!= -1){
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\""+Width+"\" height=\""+(Height+40)+"\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/video.swf?videoID=http://www.spr.org.br/" + url + "\">";
			strHTML += "<param name=\"allowfullscreen\" value=\"true\" />";
			strHTML += "<param name=\"allowscriptaccess\" value=\"always\" />";
			strHTML += "<param name=\"flashvars\" value=\"file=http://www.spr.org.br/" + url + "\" />";
			strHTML += "<param name=\"quality\" value=\"high\">";
			strHTML += "</object>";	
		}else{
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\""+Width+"\" height=\""+(Height+40)+"\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/video.swf?videoID=http://www.spr.org.br/" + url + "\">";
			strHTML += "<param name=\"allowfullscreen\" value=\"true\" />";
			strHTML += "<param name=\"allowscriptaccess\" value=\"always\" />";
			strHTML += "<param name=\"flashvars\" value=\"file=http://www.spr.org.br/" + url + "\" />";
			strHTML += "<object type=\"application/x-shockwave-flash\" data=\"http://www.spr.org.br/swf/video.swf\" width=\""+Width+"\" height=\""+(Height+40)+"\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/video.swf?videoID=http://www.spr.org.br/" + url + "\">";
			strHTML += "<param name=\"allowfullscreen\" value=\"true\" />";
			strHTML += "<param name=\"allowscriptaccess\" value=\"always\" />";
			strHTML += "<param name=\"flashvars\" value=\"file=http://www.spr.org.br/" + url + "\" />";
			strHTML += "</object>";
			strHTML += "</object>";
		}		
		popupCreate(strHTML, Width, (Height+12));
	}
	function videoFLVa(url, Width, Height){
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\""+Width+"\" height=\""+(Height+40)+"\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/video.swf?videoID=http://www.spr.org.br/" + url + "\">";
			strHTML += "<param name=\"quality\" value=\"high\">";
			strHTML += "<embed src=\"http://www.spr.org.br/swf/video.swf?videoID=http://www.spr.org.br/" + url + "\" width=\""+Width+"\" height=\""+(Height+10)+"\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"></embed>";
			strHTML += "</object>";
		popupCreate(strHTML, Width, (Height+12));
	}
	function videoFLVb(url, Width, Height){
		var strHTML  = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\""+Width+"\" height=\""+(Height+40)+"\">";
			strHTML += "<param name=\"movie\" value=\"http://www.spr.org.br/swf/video.swf?videoID=" + url + "\">";
			strHTML += "<param name=\"quality\" value=\"high\">";
			strHTML += "<embed src=\"http://www.spr.org.br/swf/video.swf?videoID=" + url + "\" width=\""+Width+"\" height=\""+(Height+40)+"\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\"></embed>";
			strHTML += "</object>";
			document.write(strHTML);
	}
	//------------------------------------------------------------
	function loadAjaxQ($pag, $box, $dados){
		if($pag && $box){
			$.ajax({
				type: "GET",
				url: $pag,      
				global: false,
				data: $dados,
				dataType: "html",
				success: function(content){
					//alert( ">>>>>>>>>>>>>>>>>>: " + content );
					$($box).html(content);
			  }
			});
			if($("#middle").length)
				$("#middle").find(".lista").css("margin-top","0px");
		}
	}
	
		function selectCategoria(value){
			if(value)loadAjaxQ(value, '.lista', '');
		}
	/* */
	function galeria(){
				if($("#GALERIA a")){
					/**/
					$('#GALERIA a').lightBox({
						overlayBgColor: '#222',
						overlayOpacity: 0.7,
						imageLoading: 	'img/light_loader.gif',
						imageBtnClose: 	'img/light_close.gif',
						imageBtnPrev: 	'img/light_prev.gif',
						imageBtnNext: 	'img/light_next.gif',
						fixedNavigation:true,
						containerResizeSpeed: 390,
						txtImage: '',
						txtOf: 'de'
				   });
					
			}
				
	}
	
	function galeria_interna(){
				if($("#GALERIA_INTERNA a")){
					/**/
					$('#GALERIA_INTERNA a').lightBox({
						overlayBgColor: '#222',
						overlayOpacity: 0.7,
						imageLoading: 	'img/light_loader.gif',
						imageBtnClose: 	'img/light_close.gif',
						imageBtnPrev: 	'img/light_prev.gif',
						imageBtnNext: 	'img/light_next.gif',
						fixedNavigation:true,
						containerResizeSpeed: 390,
						txtImage: '',
						txtOf: 'de'
				   });
					
			}
	}
	
	
t = 1;
resultPos = 0;
i = 0;
_i = 4;
intervalo = 0;
cal_dia = 1;
var dia;
var mes;
var ano;
document.cal_dia = 1;
document.cal_mes = 2;
document.cal_ano = 2006;
document.cal_ano_ant = 2005;
document.cal_mes_ant = 1;
document.cal_ano_pro = 2007;
document.cal_mes_pro = 3;
//---------------------------------------------------------------------------------------------------
jQuery(document).ready(function($){
		//	prepara_calendario();
			if($("#CALENDARIO").length){
				destaqueDia();
				if(document.home == 'sim') prepara_calendario(document.dia,document.mes,document.ano);
				else{
					prepara_calendario_tabela(0,document.mes,document._ano);
					prepara_calendario_int(document.dia,document.mes,document.ano);
				}
			}
			
			if($("#header_login").length){
				$("#login").bind("focus", 
						function(e){$(this).val("");}
				);
				$("#login").bind("blur",
						function(e){if($(this).val() == "")$(this).val("E-mail");}
				);
				$("#password").bind("focus", function(e){
							$(this).val("");
				});
				$("#password").bind("blur",
							function(e){if($(this).val() == "")$(this).val("*****");}
				);
			}
			
						
			if($("#VIDEOS").length){
				
				videoSliding = false;
				
				$("#VIDEOS").find(".up img").bind("mouseup",function(ev){
                    if(videoSliding) { return; }

                    var pad = parseInt($("#VIDEOS").find(".lista").css("margin-top").replace("px",""));
                    var h = $("#VIDEOS").find(".lista .boxContent").height() + 5;

                    if(pad < 0){
                        videoSliding = true;
                        $("#VIDEOS").find(".lista").animate({
                                marginTop:(pad + h)+"px"
                            },
                            { duration: 150, complete:function(){ videoSliding = false; }
                        });
                    }
				});	
				
				$("#VIDEOS").find(".down img").bind("mouseup",function(ev){
                    if(videoSliding) { return; }

                    var pad = $("#VIDEOS").find(".lista").css("margin-top").replace("px","");
                    var h = $("#VIDEOS").find(".lista .boxContent").height() + 5;
                    var height = (($("#VIDEOS").find(".lista .boxContent").length - 1) * h) ;

                    if(pad > (height * (-1))){
                        videoSliding = true;
                        $("#VIDEOS").find(".lista").animate(
                            { marginTop:(pad - h)+"px"},
                            { duration: 150, complete:function(){ videoSliding = false; }
                        });
                    }
				});	
			}
			
			if($("#middle").length){
				
				
				$("#middle").find(".up>img").bind("mouseup",function(ev){
						var pad = parseInt($("#middle").find(".lista").css("margin-top").replace("px",""));
						var h = $("#middle").find(".lista>.boxContent").height() + 8;
						if(pad < 0){
							$("#middle").find(".lista").stop().animate({ 
									marginTop:(pad + h)+"px" 
								},
								{
									duration: 150, complete:function(p){}
							});
						}
				});	
				
				$("#middle").find(".down>img").bind("mouseup",function(ev){
						var pad = $("#middle").find(".lista").css("margin-top").replace("px","");
						var h = $("#middle").find(".lista>.boxContent").height() + 8;
						var height = (($("#middle").find(".lista>.boxContent").length - 2) * h) ;
												
						if(pad > (height * (-1))){
							$("#middle").find(".lista").stop().animate({ 
									marginTop:(pad - h)+"px"  
								},
								{
									duration: 150, complete:function(p){}
							});
						}
				});	
			}
			
			if($("#boxVideosHome").length > 0){
					$("#boxVideosHome").find("a").each(function(ev){
						$(this).bind("mouseup",function(even){
								videoFLV($(this).attr("href"), 510, 400);
						});																
					});	
			}
			if($("#boxVideo").length > 0){
				$("#boxVideo").find("a").each(function(ev){
						$(this).bind("mouseup",function(even){
								videoFLV($(this).attr("href"), 510, 400);
						});																
					});	
			}
			if($(".conteudo_filtros").length > 0){
					$(".conteudo_filtros").find("input:eq(0)").bind("mouseup",function(ev){
						categoria = $("#conteudo_categoria").val();
						tipo = $("#conteudo_tipo").val();
						selectCategoria('conteudo_cientifico/'+categoria+'_'+tipo+'.htm');
					});
			}
		
		if($(".uploads").length > 0){
			
				$(".uploads").find(".option").each(function(e){
					$(this).bind("mouseup",function(ev){
						
						
						id = $(this).find("img").attr("class").replace("upload_","");
						idresumo = $(this).parent().parent().attr("id");
						nome = $(this).parent().find(".fileName").html();
						
						popupMsn('Deseja realmente remover o arquivo '+nome+'?', "window.location.href = 'jpr2011_upload_control.php?action=delete&id="+id+"&idresumo="+idresumo+"'")
						
					});
				});
				
		}
});

//----------------------------------------------------------------------------------------------------
function destaqueDia(){
	$lista =  $("#CALENDARIO_MASK").find('ul:eq(0)').find('li');
	$("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq(0)').css({opacity:.5});
	$lista.each(function(l){
		op = ((l-3)==i )? 1:.5;
		$(this).stop().animate(
			{opacity:op},
			{duration: 350, easing:"easeOutSine", complete:function(p){ 	
		}});
	});
}
//----------------------------------------------------------------------------------------------------
function destaqueMes(){
	$lista =  $("#CALENDARIO_MASK").find('ul:eq(0)').find('li');
	if(i >= 11) i =11;
	if(i <= -1) i = document.mes;
	//alert(i);
	$lista.each(function(l){
		op = ( (l)==i )? 1:.5;
		$(this).stop().animate(
			{opacity:op},
			{duration: 250, easing:"easeOutSine", complete:function(p){ 	
		}});
	});
}
//----------------------------------------------------------------------------------------------------
function prepara_calendario_tabela(_dia,_mes,_ano){
    
		if(_dia <=0) _dia = 1;
		if(_dia >=31) _dia = 31;
		if(_mes <=0) _mes = 1;
		if(_mes >=12) _mes = 12;

		document.dia		= _dia;
		document.mes		= _mes;
		document.ano		= _ano;
        
		$.ajax({
            type: "GET",
            url: PATH+"agenda/",
            global: false,
            data: "dia="+_dia+"&mes="+_mes+"&ano="+_ano,
            dataType: "html",
            success: function(content){
                $("#CALENDARIO_TABELA").html(content);
            }
        });
}

function prepara_calendario_int(_dia,_mes,_ano){

				t = $("#CALENDARIO_MASK").find('ul:eq(0)').find('li').size();
				array = new Array();
				for(z=0;z<=t;z++){
                    if($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(z)+')').offset()){
                        array.push(-($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(z)+')').offset().left - $("#CALENDARIO_DIAS").offset().left - ($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq(5)').outerWidth()/2)));
                    }
				}
				i = document.mes-1;
			//	if(i >= (9))  = 9;
				
				p = i;
				if(p >= (9)) p = 9;
				destaqueMes();
				$("#CALENDARIO_MASK").stop().animate(
					{opacity:1},
					{duration: 320, easing:"easeOutSine", complete:function(p){
				}});
				/**/
				px = (array[p-2] != undefined) ? array[p-2]:0;

				$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
					{marginLeft: px+"px"},
					{duration: 900, easing:"easeOutSine", complete:function(p){
				}});
				// ------------------------------------------------------------------------------------------------------
			
				$('#AVANCA_MES').bind("mouseup", function(e){
					document._ano++;
					document.ano++;
					prepara_calendario_tabela(document.dia,document.mes,document.ano);
					$("#CALENDARIO_MES").find('h3:eq(0)').html(document._ano);
					//if(document.cal_mes_pro == 1) document.cal_ano++;
					//prepara_calendario_int(document.cal_dia,document.cal_mes_pro,document.cal_ano);
				});
				// ------------------------------------------------------------------------------------------------------
				$('#VOLTA_MES').bind("mouseup", function(e){
					document._ano--;
					document.ano--;
					prepara_calendario_tabela(document.dia,document.mes,document.ano);	
					$("#CALENDARIO_MES").find('h3:eq(0)').html(document._ano);				
				//	if(document.cal_mes_ant ==12) document.cal_ano--;
				//	prepara_calendario(document.cal_dia,document.cal_mes_ant,document.cal_ano);
				});
				
				$lista =  $("#CALENDARIO_MASK").find('ul:eq(0)').find('li');
				$lista.each(function(g){
					this.f = g;
					//alert('?'+ g);
					this.saida = 'dentro'; 
					$(this).bind("mouseup keyup", function(e){
					
						prepara_calendario_tabela(0,this.f+1,document._ano);
						document.cal_dia = this.f+1;
					//	alert('::'+ this.f);
						i = this.f;
						destaqueMes()
						if(this.f >= (t-3)) i = t-3;
						try{
							$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
								{marginLeft: (array[i-2])+"px"},
								{duration: 450, easing:"easeOutSine", complete:function(p){
							}});
						}
						catch(e){}
						if(this.f >= (t-2)) i = t+5;
						$(this).find('dl:eq(0)').stop().animate({ 
											opacity: 1
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }} );		
						if(_i == i){
						}
						_i = i;
					});
					
					$(this).find('dl:eq(0)').css({'display':'none', 'opacity':0});
					$(this).find('b:eq(0)').bind("mouseover", function(e){
						$(this).next().css({'display':'block','opacity':0});
						$(this).next().stop().animate(
							{opacity: 1},
							{duration: 450, easing:"easeOutSine", complete:function(p){
						}});
					});
					$(this).find('dl:eq(0)').css({'display':'none', 'opacity':0});
					$(this).hover(
						function(p){
								$(this).find('dl:eq(0)').stop().animate({ 
											opacity: 1
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }} );							
						},
						function(){							
							$(this).find('dl:eq(0)').animate(
									{opacity: 0},
									{duration: 450, easing:"easeOutSine", complete:function(p){
										$(this).css({'display':'none','opacity':0});
							}});
						}						
					);
				});
				// ------------------------------------------------------------
				$("#AVANCA_DIA").bind("mousedown keydown", function(e){
					if(i < t) i++;
					intervalo = window.setInterval(function(){ 
						if(i < 11) i++;
						if(i >=2 && i <= (4)){
							var pnx = (array[i+1] != undefined)? array[i+1] : array[array.length-1];
							$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
								{marginLeft: (pnx)+"px"},
								{duration: 1650, easing:"easeOutSine", complete:function(p){
							}});
						}
					}, 135);
					if(i >= (4) && i <= (t-3)){
						var pnx = (array[i+2] != undefined)? array[i+2] : array[array.length-1];
						$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
							{marginLeft: (pnx)+"px"},
							{duration: 1650, easing:"easeOutSine", complete:function(p){
						}});
					}
					else{destaqueMes();}
				});				
				$("#AVANCA_DIA").bind("mouseup keyup", function(e){	
					clearInterval(intervalo);
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop();
					t = $("#CALENDARIO_MASK").find('ul:eq(0)').find('li').size();
					f = ((i/2) >= t) ? (t-1):(i-1);
					_posI = -($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(f)+')').offset().left - $("#CALENDARIO").offset().left);
					//	alert();
					//alert(i+' / '+_posI);
					p = (i >= (t-3)) ? t-3:i;
					ff = (i >= 12) ? 2:i;
					g = (i >=10)? 9 : i;
					var pnx = (array[g-2] != undefined)? array[g-2] : 0;
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
						{marginLeft: (pnx)+"px"},
						{duration: 450, easing:"easeOutSine", complete:function(p){
							prepara_calendario_tabela(document.dia,i+1,document.ano);
					}});
					destaqueMes();
				});
				// ------------------------------------------------------------
				$("#VOLTA_DIA").bind("mousedown keydown", function(e){
					
					if(i > 0) i--;
					//resultPos = _posX-(_posW*i)-8;
					intervalo = window.setInterval(function(){ 
						if(i > 0) i--;
						//resultPos = _posX-(_posW*i)-8;
					}, 135);
					if(i <= 0) i = 0;
					if(i > 0 && i <= (t-3)){
						var pnx = (array[i-2] != undefined)? array[i-2] : 0;
						$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
							{marginLeft: (pnx)+"px"},
							{duration: 1650, easing:"easeOutSine", complete:function(p){
						}});
					}
				});				
				$("#VOLTA_DIA").bind("mouseup keyup", function(e){	
					clearInterval(intervalo);
					p = (i >= (t-3)) ? t-3:i;
					ff = (p <= 0) ? 0:p;
					var ffx = (array[ff-2] != undefined)? array[ff-2] : 0;
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
						{marginLeft: (ffx)+"px"},
						{duration: 450, easing:"easeOutSine", complete:function(p){ 
						prepara_calendario_tabela(document.dia,ff+1,document.ano);
						destaqueMes();
					}});
				});
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
function prepara_calendario(_dia,_mes,_ano){

			if($("#CALENDARIO_MASK")){

				$("#CALENDARIO_MASK").stop().animate({opacity: 0},{duration: 180, easing:"easeOutSine", complete:function(p){ 
					 $.ajax({
						type: "GET",
						url: "calendario_home.php",      
						global: false,
						data: "dia="+_dia+"&mes="+_mes+"&ano="+_ano,
						dataType: "html",
						success: function(content){
							//alert( ">>>>>>>>>>>>>>>>>>: " + content );
						
							$("#CALENDARIO_MASK").html(content);
							$("#CALENDARIO_MASK").css({opacity: 0});
							$('#AVANCA_ANO').unbind("mouseup");
							$('#VOLTA_ANO').unbind("mouseup");
							$('#AVANCA_MES').unbind("mouseup");
							
							$('#VOLTA_MES').unbind("mouseup");
							$('#AVANCA_DIA').unbind("mouseup mousedown keyup keydown");
							$('#VOLTA_DIA').unbind("mouseup mousedown keyup keydown");
							$("#CALENDARIO_MASK").css({opacity: 0}).stop().animate({opacity: 0},{duration: 180, easing:"easeOutSine", complete:function(p){ativa_calendario()}});
						
						}
					});																										 
				}});
				
			}
}
//----------------------------------------------------------------------------------------------------
function ativa_calendario(){	
				t = $("#CALENDARIO_MASK").find('ul:eq(0)').find('li').size();
				array = new Array();
				for(z=0;z<=t;z++){
                    if($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(z)+')').offset()){
                        array.push(-($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(z)+')').offset().left - $("#CALENDARIO").offset().left - ($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq(0)').outerWidth()/2)));
                    }
				}		
				i = document.cal_dia-4;
				p = i;
				if(p >= (t-7)) p = t-7;
				
				destaqueDia();
				$("#CALENDARIO_MASK").stop().animate(
					{opacity:1},
					{duration: 320, easing:"easeOutSine", complete:function(p){
				}});
				var px1 = (array[p] == undefined)? 1:array[p] ;
				//alert(px1);
				$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
					{marginLeft: (px1)+"px"},
					{duration: 900, easing:"easeOutSine", complete:function(p){
				}});
				// ------------------------------------------------------------------------------------------------------
				$('#AVANCA_ANO').bind("mouseup", function(e){
					prepara_calendario(document.cal_dia,document.cal_mes,document.cal_ano_pro);
				});
				// ------------------------------------------------------------------------------------------------------
				$('#VOLTA_ANO').bind("mouseup", function(e){
					prepara_calendario(document.cal_dia,document.cal_mes,document.cal_ano_ant);
				});
				// ------------------------------------------------------------------------------------------------------
				$('#AVANCA_MES').bind("mouseup", function(e){
					if(document.cal_mes_pro == 1) document.cal_ano++;
					prepara_calendario(document.cal_dia,document.cal_mes_pro,document.cal_ano);
				});
				// ------------------------------------------------------------------------------------------------------
				$('#VOLTA_MES').bind("mouseup", function(e){
					if(document.cal_mes_ant ==12) document.cal_ano--;
					prepara_calendario(document.cal_dia,document.cal_mes_ant,document.cal_ano);
				});

				$lista =  $("#CALENDARIO_MASK").find('ul:eq(0)').find('li');
				$lista.each(function(g){
					this.f = g;				
					this.saida = 'dentro'; 
					$(this).bind("mouseup keyup", function(e){
						document.cal_dia = this.f+1;
						i = this.f-3;
						destaqueDia()
						if(this.f >= (t-3)) i = t-7;
						try{
							$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
								{marginLeft: (array[i])+"px"},
								{duration: 450, easing:"easeOutSine", complete:function(p){
							}});
						}
						catch(e){}
						if(this.f >= (t-3)) i = t+7;
						$(this).find('dl:eq(0)').stop().animate({ 
											opacity: 1
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }} );		
						if(_i == i){
						}
						_i = i;
					});
					
					$(this).find('dl:eq(0)').css({'display':'none', 'opacity':0});
					$(this).find('b:eq(0)').bind("mouseover", function(e){
						$(this).next().css({'display':'block','opacity':0});
						$(this).next().stop().animate(
							{opacity: 1},
							{duration: 450, easing:"easeOutSine", complete:function(p){
						}});
					});
					$(this).find('dl:eq(0)').css({'display':'none', 'opacity':0});
					$(this).hover(
						function(p){
								$(this).find('dl:eq(0)').stop().animate({ 
											opacity: 1
								}, {duration: 350, easing:"easeOutSine", complete:function(p){ }} );							
						},
						function(){							
							$(this).find('dl:eq(0)').animate(
									{opacity: 0},
									{duration: 450, easing:"easeOutSine", complete:function(p){
										$(this).css({'display':'none','opacity':0});
							}});
						}						
					);
				});
				// ------------------------------------------------------------
				$("#AVANCA_DIA").bind("mousedown keydown", function(e){
					if(i < t) i++;
					intervalo = window.setInterval(function(){ 
						if(i < t) i++;
					}, 135);
					if(i <= (t-7)){
						$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
							{marginLeft: (array[i+2])+"px"},
							{duration: 1650, easing:"easeOutSine", complete:function(p){
						}});
					}
				});				
				$("#AVANCA_DIA").bind("mouseup keyup", function(e){	
					clearInterval(intervalo);
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop();
					t = $("#CALENDARIO_MASK").find('ul:eq(0)').find('li').size();
					f = ((i/2) >= t) ? (t-1):(i-1);
					_posI = -($("#CALENDARIO_MASK").find('ul:eq(0)').find('li:eq('+(f)+')').offset().left - $("#CALENDARIO").offset().left);
					//	alert();
					//alert(i+' / '+_posI);
					i = (i >= (t-7)) ? t-7:i;
					
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
						{marginLeft: (array[i])+"px"},
						{duration: 450, easing:"easeOutSine", complete:function(p){
					}});
					destaqueDia();
				});
				// ------------------------------------------------------------
				$("#VOLTA_DIA").bind("mousedown keydown", function(e){
					
					if(i > 0) i--;
					//resultPos = _posX-(_posW*i)-8;
					intervalo = window.setInterval(function(){ 
						if(i > 0) i--;
						//resultPos = _posX-(_posW*i)-8;
					}, 135);
					if(i > 0){
						$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
							{marginLeft: (array[i-2])+"px"},
							{duration: 1650, easing:"easeOutSine", complete:function(p){
						}});
					}
				});				
				$("#VOLTA_DIA").bind("mouseup keyup", function(e){	
					clearInterval(intervalo);
					i = (i >= (t-7)) ? t-7:i;
					ff = (i <= 0) ? 0:i;
					$("#CALENDARIO_MASK").find('ul:eq(0)').stop().animate(
						{marginLeft: (array[ff])+"px"},
						{duration: 450, easing:"easeOutSine", complete:function(p){ 	
						destaqueDia();
					}});
				});
}


////////////////////////////////////////////////////////////////////
/////////////// GALERIA CLUBE MANOEL DE ABREU //////////////////////
////////////////////////////////////////////////////////////////////

function trocaImg(src){
	div = document.getElementById("IMG_GRANDE");
	$div = $("#IMG_GRANDE");
	$div.stop().animate({opacity: 0},{duration:100, easing:"easeOutSine", complete:function(p){ 
									div.innerHTML = "<div class=\"imgGrandeBg\"><img src=\""+ src +"\" height=\"400\" /></div>"; 					
	}});
	$div.animate({opacity: 1},{duration: 200, easing:"easeInSine", complete:function(p){  }});
}
function iniciarGaleria(){	
	criaTroca(); 
	$("#GALERIA_CLUBE").find('a:eq('+indice+')').mouseup();
	$("#GALERIA_CLUBE").find('a:eq(0)').css({'opacity':'1'});
	if($('#galeriaG_right')){
		$('#galeriaG_right').unbind("mouseup");
		$('#galeriaG_right').bind('mouseup', function(e){_gal_avancar();});
	}	
	if($('#galeriaG_left')){
		$('#galeriaG_left').unbind("mouseup");
		$('#galeriaG_left').bind('mouseup', function(e){_gal_voltar();});
	}	
}
function _gal_avancar(){
	flag=true;
	total = $("#GALERIA_CLUBE").find('a').size();
	if(indice <= total) indice++;
	if(indice <= total) $("#GALERIA_CLUBE").find('a:eq('+indice+')').mouseup();
	if(indice >= total){indice = 0;$("#GALERIA_CLUBE").css("margin-left","-5px");$("#GALERIA_CLUBE").find('a:eq(0)').mouseup();flag=false;}
	
	var margin = $("#GALERIA_CLUBE").css("margin-left");
	var width  = ($("#GALERIA_CLUBE > ul > li").size() - 8) * (-85);
	margin = parseInt(margin);
	total_m = margin - 85;
	diferencial = width - margin;//alert("Margin: "+margin+" Width: "+width+" Dif: "+diferencial+" Ind: "+indice);
	if(diferencial < -5 && (flag == true)){
	//alert(total_m +'/'+width +'/'+diferencial);
		$("#GALERIA_CLUBE").stop().animate({ 
				marginLeft:total_m
				}, {duration: 50, easing:"easeInOutSine", complete:function(p){  }} );
	}
	
	//$('#galeriaG_right').
}
function _gal_voltar(){
	flag=true;
	total = $("#GALERIA_CLUBE").find('a').size();
	if(indice>0)indice--;
	var margin = $("#GALERIA_CLUBE").css("margin-left");
	var width  = ($("#GALERIA_CLUBE > ul > li").size() - 8) * (-85);
	if(indice == 0) {indice = total;$("#GALERIA_CLUBE").css("margin-left",(width-5)+"px");indice--;flag=false;}
	
	$("#GALERIA_CLUBE").find('a:eq('+indice+')').mouseup();
	margin = parseInt(margin);
	total_m = margin + 85;
	
	diferencial = width - margin;
	//alert(margin +'/'+total_m +'/'+ width +'/'+diferencial);
	//if($("#GALERIA_CLUBE").offset().left >= 440) //total_m = (-85 * indice)+(85*7);
	//alert($("#GALERIA_CLUBE").offset().left);
	if((flag) && (indice > 0) && indice > 7 && margin < -5){
		$("#GALERIA_CLUBE").stop().animate({ 
				marginLeft:total_m
				}, {duration: 200, easing:"easeInOutSine", complete:function(p){  }} );
	}
}
function loadAjax($pag, $box, $dados, hash){
	var sub_li = $('.menu_principal').find('li').css('background-image','none');
	sub_li.each(function(eve){this.flag = false;});
	if($pag && $box){
		$.ajax({
			type: "GET",
			url: $pag,      
			global: false,
			data: $dados,
			dataType: "html",
		  success: function(content){
			//alert( ">>>>>>>>>>>>>>>>>>: " + content );
            if(content.indexOf('galeria/') != -1){
                content = content.replace(/src="/gi, 'src="http://www.spr.org.br/');
                content = content.replace(/href="/gi, 'href="http://www.spr.org.br/');
            }
			$($box).html(content);
			nome = $pag.split(".htm");
			nome = nome[0];
			if(hash == null){
				window.location.hash = "/"+nome;
				// $("#box_Right").html(content);
			}
	 	  }
		});
	}
}

function criaTroca(){
		var i=0;
		var size = $("#GALERIA_CLUBE").find('a').size();
		$alink = $("#GALERIA_CLUBE").find('a').css({'opacity':'0.4'}).unbind("mouseup").each(function(ev){
										this.i = i;
										$(this).bind("mouseup", function(e){ 
										indice = this.i;
										trocaImg($(this).attr('href'));  
										obj_atual.stop().animate({opacity: 0.4},{duration: 200, easing:"easeOutSine", complete:function(p){  }});
										$(this).stop().animate({opacity: 1},{duration: 280, easing:"easeOutSine", complete:function(p){  }});
										obj_atual = $(this); 
										$('#legenda').html(obj_atual.attr('title')+" - Foto "+(indice+1)+" de "+size+ "" );
										
			});i++;
		});
		
		$alink.bind("click",function(e){return false;});

	var $currentlink = $("#GALERIA_CLUBE").find('a:eq(0)');
	trocaImg($currentlink.attr('href'));
	
	var width = ($("#GALERIA_CLUBE > ul > li").size() * 95) + "px";
	$("#GALERIA_CLUBE").css({'width':width,'margin-left':'-5px'});
}

function bg_li(){
		
		var li = $('.menu_principal').find('li');
		li.each(function(i){
			$(this).bind('mouseover',function(e) { 
											  $(this).css({'background-image':'url(img/select_li.jpg)','background-repeat':'repeat-x'});
											  
											  //alert(this.flag);
											  if(this.flag != true){
											  		$(this).bind('mouseout' ,function(ev){$(this).css('background-image','none');});
													this.flag = false;
											  }
			});
			
			$(this).bind('click'  ,function(ee){ 
											  $(this).unbind('mouseout');
											  var sub_li = $('.menu_principal').find('li').css('background-image','none');
											  sub_li.each(function(evv){this.flag = false;});
											  $(this).css({'background-image':'url(img/select_li.jpg)','background-repeat':'repeat-x'});
											  this.flag = true;
											  			});
		});
	}
	
function moveGallery(goTO){
	var margin = $("#GALERIA_CLUBE").css("margin-left");
	var width  = ($("#GALERIA_CLUBE > ul > li").size() - 8) * (-85);
	margin = parseInt(margin);
	flag = false;
	
	if(goTO == '+1' && (margin > width)){
		sumMargin = -85;
		flag = true;
	}
	
	if(goTO == '-1' && (margin < -5)){
		sumMargin = 85;
		flag = true;
	}
	
	total = margin + sumMargin;
	//alert(total);
	if(flag){
	$("#GALERIA_CLUBE").stop().animate({ 
				marginLeft:total
				}, {duration: 10, easing:"easeOutSine", complete:function(p){  }} );
	}
}

function openNewsletter(file){
    popupCreate('<iframe border="0" src="http://www.spr.org.br/pags/view/files/newsletters/'+file+'.pdf" width="100%" height="500">', 950, 500);
}

function galeria(){
	
	jQuery(function($) {
		
		$('.gallery_demo_unstyled').addClass('gallery_demo'); // adds new class name to maintain degradability
		
		$('ul.gallery_demo').galleria({
			history   : true, // ativa a legenda da foto ampliada
			clickNext : true, // ativa o link sobre a imagem ampliada para a próxima
			insert    : '#main_image', // nome do div onde aparecerá a imagem ampliada
			onImage   : function(image,caption,thumb) { 
				
				// efeito na imagem e na legenda
				if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { 
					image.css('display','none').fadeIn(1000);
				}
				caption.css('display','none').fadeIn(1000);
				
				var _li = thumb.parents('li');
				
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				thumb.fadeTo('fast',1).addClass('selected');
				
				// adiciona um título para a imagem ampliada
				image.attr('title','Próxima imagem >>');
			},
			onThumb : function(thumb) {				
				var _li = thumb.parents('li');				
				var _fadeTo = _li.is('.active') ? '1' : '0.3';				
				// efeito ao carregar os thumbs
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);				
				// efeito ao colocar o mouse em cima do thumb
				thumb.hover(
					function() {thumb.fadeTo('fast',1);},
					function() {_li.not('.active').children('img').fadeTo('fast',0.3);} 
				)
			}
		});
	});
	var width = ($("#GALERIA_CLUBE > ul > li").size() * 95) + "px";
	$("#GALERIA_CLUBE").css({'width':width,'margin-left':'-5px'});
}


jQuery(document).ready(function($){
    if($("#tv-home").size() > 0){
        TV.init();
    }

    if($("#MENU").size() > 0){
        $("#MENU .menu_item:lt(2)").hover(
            function(){
                $(".sub-menu", $(this)).show();
            },
            function(){
                $(".sub-menu", $(this)).hide();
            }
        );
    }
    
    if($("#BANNER_EXP").size() > 0){
        var bannerRunning = false;
        
        $("#BANNER_EXP .banner-small").mouseup(function(){
            if(bannerRunning) return;
            
            bannerRunning = true;
            
            $(this).animate(
                {'top':'-50px'},
                {duration:300, complete: function(){ }
            });
            
            $("#BANNER_EXP").animate(
                {'height':'300px'},
                {duration:500, complete: function(){ }
            });
            
            $("#BANNER_EXP .banner-full").animate(
                {'top':'0'},
                {duration:500, complete: function(){ bannerRunning = false; }
            });
        });
        
        $("#BANNER_EXP .bt-close").mouseup(function(){
            if(bannerRunning) return;
            
            bannerRunning = true;
            
            $("#BANNER_EXP .banner-small").animate(
                {'top':'0'},
                {duration:300, complete: function(){ }
            });
            
            $("#BANNER_EXP").animate(
                {'height':'50px'},
                {duration:300, complete: function(){ }
            });
            
            $("#BANNER_EXP .banner-full").animate(
                {'top':'-250px'},
                {duration:300, complete: function(){ bannerRunning = false; }
            });
        });
    }

	if($("#sliderJPR").length > 0){
        sliderJPRrunning = false;
		$(".sliderNav").bind("mouseup",function(e){
            if(sliderJPRrunning) {return;}
            sliderJPRrunning = true;

			i = $(".sliderNav").index($(this));
			j = $("#sliderIMGs").find("a").index($(".sliderSelected"));
			marginChange = 180;
			tempo = 200;

            if(i == 0){
				change = -1;
				margin = parseInt($("#sliderIMGs").css("margin-left").replace("px",""));
				margin += marginChange;
			}else{
				change = 1;
				margin = (parseInt($("#sliderIMGs").css("margin-left").replace("px","")) - marginChange);
			}
			

			$("#sliderIMGs").stop().animate({ 
					marginLeft:(margin)+"px"
				},
				{
					duration: tempo, complete:function(p){}
			});
			
			//************************************************************normal
			$(".sliderSelected").stop().animate({ 
					marginTop:"40px",
					opacity:0.5
				},
				{
					duration: tempo, complete:function(p){}
			});
			$(".sliderSelected").find("img").stop().animate({ 
					width:"160px",
					height:"226px"
				},
				{
					duration: tempo, complete:function(p){}
			});
			
			//************************************************************changed
			$("#sliderIMGs").find("a:eq("+((j) + change)+")").stop().animate({ 
					marginTop:"0px",
					opacity:1
				},
				{
					duration: tempo, complete:function(p){}
			});
			$("#sliderIMGs").find("img:eq("+((j) + change)+")").stop().animate({ 
					width:"234px" ,
					height:"309px"
				},
				{
					duration: tempo, complete:function(p){
						$(".sliderSelected").removeClass("sliderSelected");	
						$("#sliderIMGs").find("a:eq("+((j) + change)+")").addClass("sliderSelected");		
						
						if(i == 0){
							$("#sliderIMGs").css("margin-left","-200px")
							$div = $("#sliderIMGs").find("a:last");	
							$("#sliderIMGs").prepend($div);
						}else{
							$("#sliderIMGs").css("margin-left","-200px")
							$div = $("#sliderIMGs").find("a:first");	
							$("#sliderIMGs").append($div);
						}

                        sliderJPRrunning = false;
					}
			});
		});
	}
});

var TV = {
    obj : null,
    interval : null,
    running : false,

    init : function(){
        TV.obj      = $("#tv-home");
        TV.width    = 320;
        TV.delay    = 5000;
        TV.duration = 280;

        //events
        TV.obj.find(".banner-info").click(function(){
            window.location.href = TV.obj.find(".banner-img:first").attr("href");
        });

        TV.obj.find(".arrow").click(function(){
            if(TV.running){ return; }

            if($(this).hasClass('left')){
                TV.move(0);
            }else{
                TV.move(TV.width);
            }

            TV.reset();
        });
        
        
        TV.reset();
    },

    reset : function(){
        clearInterval(TV.interval);
        TV.interval = setInterval(
            function(){
                TV.move(TV.width);
            },
            TV.delay
        );
    },
    
    move : function(wid){
        TV.running = true;

        wid = (-1)*wid;
        
        if(wid == 0){
            TV.obj.find(".banner-imgs").prepend(TV.obj.find(".banner-img:last"));
            TV.obj.find(".banner-imgs").css("margin-left", (-TV.width)+"px");
        }
        
        TV.obj.find(".banner-imgs").stop().animate(
                {'marginLeft':wid},
                {duration:TV.duration, complete:function(){
                    if(wid != 0){
                        TV.obj.find(".banner-imgs").append(TV.obj.find(".banner-img:first"));
                    }
                    
                    TV.obj.find(".banner-info").html("<span>"+TV.obj.find(".banner-img:first").find("img").attr("alt")+"</span>");
                    TV.obj.find(".banner-imgs").css("margin-left", "0");

                    TV.running = false;
                }}
        );
    }
}
