/******************************************************************************
 * Global
 ******************************************************************************/

var animateDuration = 200; // Milliseconds
var transitionTime = 5000; // Milliseconds
var loaderHTML = "<span class=\"loader\">Carregando...</span>";
var marginWheel = 100;




/******************************************************************************
 * jqDnR - Minimalistic Drag'n'Resize for jQuery.
 *
 * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * $Version: 2007.08.19 +r2
 * Adaptado por Terra Networks - Equipe Webdev
 *
 ******************************************************************************/

(function($){
	$.fn.jqDrag=function(h,fDrag,fStop){return i(this,h,'d',fDrag,fStop);};
	$.fn.jqResize=function(h){return i(this,h,'r');};
	$.jqDnR={dnr:{},e:0,
		drag:function(v,fDrag){
			if(M.k == 'd') E.css({left:Math.max(Math.min(M.X+v.pageX-M.pX,E.parent().width() - E.width()),0),top:Math.max(Math.min(M.Y+v.pageY-M.pY,E.parent().height() - E.height()),0)});
			else E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
			if (fDrag) fDrag();
			return false;
		},
		stop:function(fStop){E.css('opacity',M.o);$().unbind('mousemove').unbind('mouseup');if(fStop)fStop();}
	};
	var J=$.jqDnR,M=J.dnr,E=J.e,
	i=function(e,h,k,fDrag,fStop){
		return e.each(
			function(){h=(h)?$(h,e):e;
				h.bind('mousedown',{e:e,k:k},function(v){
					var d=v.data,p={};E=d.e;
					$("html").bind('dragstart', function(){return false;}).bind('selectstart', function(){return false;});

					// attempt utilization of dimensions plugin to fix IE issues
					if(E.css("position") != "absolute"){try{E.css("position","absolute");}catch(e){}
				}
				M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};
				E.css({opacity:100});$().mousemove(function(v) { $.jqDnR.drag(v,fDrag) }).mouseup(function() { $.jqDnR.stop(fStop);$("html").unbind("dragstart").unbind("selectstart"); });
				return false;
			});
		});
	},
	f=function(k){return parseInt(E.css(k))||false;};
})(jQuery);




/******************************************************************************
 * Combobox 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo dependente dos modulos Scrolling, Clickout e ElementPosition
 *
 * COMO UTILIZAR
 * 
 * Inserir no HTML um select envolvido por uma div com o atributo class="combobox"
 *
 *
 * PARAMETROS
 *
 * Para setar uma label inicial no combo o atributo title no select deve ser setado com este valor (Ex.: "Selecione um numero")
 * Para um option sair marcado deve ser adicionado os atributos selected="selected" e class="selected" na opcao
 *
 ******************************************************************************/

(function($) {

	$.fn.extend({

		// Combobox
		combobox: function() {
			selector = this;
			$(selector).each(function(i) {

				var objCombo = $(this);
				var selectCombo = objCombo.find("select");

				if (selectCombo.size() > 0) {
					// List
					var listValues = "";
					selectCombo.find("option").each(function(i) {
						listValues += "<li><a href=\"#"+$(this).attr("value")+"\" onclick=\"window.location='http://en.terra.com/news/news/"+$(this).attr("value")+"'\">"+$(this).html()+"</a>";
					});

					// Attributes
					var nameField = selectCombo.attr("name");
					var idField = selectCombo.attr("id");

					// Label n' value
					var selectedOption = objCombo.find(".selected");
					var labelField = selectedOption.size() > 0 ? selectedOption.html() : ( selectCombo.attr("title") ? selectCombo.attr("title") : selectCombo.find("option:first").html() );
					var valueField = selectedOption.size() > 0 ? selectedOption.attr("value") : ( selectCombo.attr("title") ? "" : selectCombo.find("option:first").attr("value") );

					objCombo.html("<input type=\"hidden\" name=\""+nameField+"\" id=\""+idField+"\" value=\""+valueField+"\" />" +
						"<div class=\"cmb-value\">"+labelField+"</div>" +
						"<div class=\"scr-listvalues clickout\">" +
							"<div class=\"scrolling scr-vertical\">" +
								"<div class=\"scr-content\">" +
									"<div class=\"scr-innercontent\">" +
										"<ul>" +
											listValues +
										"</ul>" +
									"</div>" +
								"</div>" +
							"</div>" +
						"</div>");

					// Height
					var objListValues = objCombo.find(".scr-listvalues");
					var objInnerContent = objCombo.find(".scr-innercontent");

					objListValues.show();
					if (objCombo.find(".scr-content").height() > objInnerContent.height()) {
						objCombo.find(".scr-content, .scrolling").height(objInnerContent.height());
					}
					objListValues.hide();

				}



				/*
				 * Events
				 */

				// Show hide combo
				objCombo.find(".cmb-value").unbind("click").click(function() {
					toggleCombobox($(this).parent());
				});

				// Select a value
				objCombo.find(".scr-listvalues a").unbind("click").click(function() {
					selectComboValue($(this));
					return false;
				});

			});



			/*
			 * Functions
			 */
	
			// Show hide combo
			/*
			 * PARAMETERS
			 * - selector (.combobox)
			 */
			function toggleCombobox(selector) {
				var objCombo = $(selector);
				var objListValues = objCombo.find(".scr-listvalues");
				$(".combobox .scr-listvalues").not(objListValues).hide().parent().find(".cmb-value").removeClass("active");
				
				objListValues.toggle();
				
				// Reset position
				if (objCombo.find(".scr-bar").size() > 0) {
					objCombo.find(".scr-content").get(0).scrollTop = 0;
					objCombo.find(".scr-bar").css("top","0");
				}
			
				// toggle class
				if (objListValues.is(":visible")) {
					objCombo.find(".cmb-value").addClass("active");
					// Position
					elementPosition(objCombo.offset().top + objListValues.height() + objCombo.find(".cmb-value").height(), (objListValues.height()+objCombo.find(".cmb-value").height() + 10 /* padding + border */)*(-1), objListValues);
				} else {
					objCombo.find(".cmb-value").removeClass("active");
				}
			}

			// Select value
			/*
			 * PARAMETERS
			 * - selector (a)
			 */
			function selectComboValue(selector) {
				var objCombo = $(selector).parents(".combobox");
				var textValue = $(selector).html();

				// wrap
				var maxChars = Math.floor((objCombo.width()-36)/7);
				if (textValue.length > maxChars) {
					textValue = textValue.substring(0,maxChars-2)+"...";
				}

				toggleCombobox(objCombo.find("scr-listvalues").hide());
				objCombo.find(".cmb-value").removeClass("active");
				objCombo.find(".cmb-value").html(textValue);
				objCombo.find("input:hidden").val($(selector).attr("href").replace("#",""));
			}
		}
	});
})(jQuery);




/******************************************************************************
 * Clickout 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo independente
 *
 * COMO UTILIZAR
 * 
 * Adicione o atributo class="clickout" no elemento que deve tomar o comportamento de ocultar ao clicar fora de sua area
 *
 ******************************************************************************/

/*
 * Var
 */
var clickout = true;



/*
 * Events
 */

// Init
function initClickOut(selector) {
	$(selector).hover(
		function(e) {
			clickout = false;
		},
		function(e) {
			clickout = true;
		}
	);
}

$(document).click(function(e) {
	clickOut();
});



/*
 * Functions
 */

function clickOut() {
	if (clickout) {
		var objClickout = $(".clickout:visible");
		if (objClickout.size() > 0) {
			if ($(".clickout:visible").size() > 0) {
				$(".clickout:visible").hide();
				$(".combobox .cmb-value").removeClass("active");
			}
		}
	}
}




/******************************************************************************
 * Scrolling 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo independente
 *
 * COMO UTILIZAR
 * 
 * Para utilizar o scrolling deve ser utilizada uma div com a classe scrolling
 *
 ******************************************************************************/

(function($) {

	$.fn.extend({

		// scrolling
		scrolling: function() {

			$(this).each(function(i) {
				var objScrolling = $(this);

				// Show combobox
				var combobox = objScrolling.parents(".combobox");
				if (combobox.size() > 0) {
					combobox.find(".scr-listvalues").show();
				}

				// Unbind wheel
				objScrolling.unmousewheel();

				if (objScrolling.find(".scr-innercontent").height() > objScrolling.height() || objScrolling.find(".scr-innercontent").width() > objScrolling.width()) { // Scrolling
					if (objScrolling.find(".scr-scrollbar").size() == 0) {
						objScrolling.append("<div class=\"scr-scrollbar hide\">" +
												"<div class=\"scr-track\"><!-- --></div>" +
												"<div class=\"scr-bar\"><!-- --></div>" +
											"</div>" +
											"<div class=\"clear\"><!-- --></div>");
					}
		
					objScrolling.find(".scr-content").addClass("content-scroll");

					// Reset position
					$(document).ready(function() {
						objScrolling.find(".scr-content").get(0).scrollTop = 0;
						objScrolling.find(".scr-content").get(0).scrollLeft = 0;
					});

					// Track
					objScrolling.find(".scr-track").unbind("click").click(function(e) {
						if (objScrolling.hasClass("scr-horizontal")) { // Horizontal
							$(this).parents(".scrolling").scrollBarPosition(e.pageX, 0);
						} else { // Vertical
							$(this).parents(".scrolling").scrollBarPosition(e.pageY, 0);
						}
					});

					// Drag
					objScrolling.find(".scr-bar").jqDrag(null,
						function() {
							if (objScrolling.hasClass("scr-horizontal")) { // Horizontal
								objScrolling.scrollBarPosition(objScrolling.find(".scr-bar").css("left").replace("px",""), 1);
							} else { // Vertical
								objScrolling.scrollBarPosition(objScrolling.find(".scr-bar").css("top").replace("px",""), 1);
							}
						}
					);

					// Wheel
					objScrolling.mousewheel(function(event, delta){
						wheelScroll(delta, this);
						return false;
					});

				} else { // No scrolling
					objScrolling.find(".scr-content").removeClass("content-scroll");
					objScrolling.find(".scr-scrollbar").next().remove();
					objScrolling.find(".scr-scrollbar").remove();
				}

				// Hide combobox content
				if (combobox.size() > 0) {
					combobox.find(".scr-listvalues").hide();
				}
			});



			/*
			 * Functions
			 */
			/*
			
			 * PARAMETERS
			 * - selector (.scrolling)
			 */
			function getContentPosition(selector) {
				var objScrolling = $(selector);
				return objScrolling.hasClass("scr-horizontal") ? objScrolling.find(".scr-content").get(0).scrollLeft : objScrolling.find(".scr-content").get(0).scrollTop;
			}

			/*
			 * PARAMETERS
			 * - selector (.scrolling)
			 */
			function wheelScroll(delta, selector) {
				objScrolling = $(selector);

				objScrolling.scrollContentPosition(getContentPosition(selector) + (marginWheel*delta*(-1)));
			}
		},



		/*
		 * Functions
		 */

		/*
		 * PARAMETERS
		 * - position (numeric)
		 * - selector (.scrolling)
		 * - flgDrag (0 - No drag / 1 - Drag)
		 */
		scrollBarPosition: function(position, flgDrag) {
			var objScrolling = $(this);
			var objBar = objScrolling.find(".scr-bar");
			var objContent = objScrolling.find(".scr-content");
			
			if (objScrolling.hasClass("scr-horizontal")) { // Horizontal
				if (flgDrag == 0) { // No drag
					var posBarX = Math.min(Math.max(position - objScrolling.offset().left - objBar.width()/2,0),objBar.parent().width()-objBar.width());
					objBar.animate({left:posBarX+"px"},{ duration: animateDuration, queue: false });
				} else { // Drag
					var posBarX = position;
				}
				percentPosition = (100 * posBarX) / (objBar.prev().width() - objBar.width());
				var posContentX = ( (objContent.find(".scr-innercontent").width() - objContent.width()) * percentPosition ) / 100;
				if (flgDrag == 0) {
					objContent.animate({scrollLeft: posContentX},{ duration: animateDuration, queue: false });
				} else {
					objContent.get(0).scrollLeft = posContentX;
				}

			} else { // Vertical
				if (flgDrag == 0) {
					var posBarY = Math.min(Math.max(position - objScrolling.offset().top - objBar.height()/2,0),objBar.parent().height()-objBar.height());
					objBar.animate({top:posBarY+"px"},{ duration: animateDuration, queue: false });
				} else {
					var posBarY = position;
				}
				percentPosition = (100 * posBarY) / (objBar.prev().height() - objBar.height());
				var posContentY = ( (objContent.find(".scr-innercontent").height() - objContent.height()) * percentPosition ) / 100;
				if (flgDrag == 0) {
					objContent.animate({scrollTop: posContentY},{ duration: animateDuration, queue: false });
				} else {
					objContent.get(0).scrollTop = posContentY;
				}
			}
		},

		/*
		 * PARAMETERS
		 * - position (numeric)
		 * - selector (.scrolling)
		 */
		scrollContentPosition: function(position) {
			var objScrolling = $(this);
			var objBar = objScrolling.find(".scr-bar");
			var objContent = objScrolling.find(".scr-content");

			// Stop current animation
			objContent.stop();
			objBar.stop();

			if (objScrolling.hasClass("scr-horizontal")) { // Horizontal
				objContent.animate({scrollLeft: position},{ duration: animateDuration, queue: false });
				percentPosition = Math.min(100,Math.max(0,(position * 100) / (objContent.find(".scr-innercontent").width() - objContent.width())));
				posBarX = ( (objBar.parent().width()-objBar.width()) * percentPosition ) / 100;
				objBar.animate({left:posBarX+"px"},{ duration: animateDuration, queue: false });

			} else { // Vertical
				objContent.animate({scrollTop: position},{ duration: animateDuration, queue: false });
				percentPosition = Math.min(100,Math.max(0,(position * 100) / (objContent.find(".scr-innercontent").height() - objContent.height())));
				posBarY = ( (objBar.parent().height()-objBar.height()) * percentPosition ) / 100;
				objBar.animate({top:posBarY+"px"},{ duration: animateDuration, queue: false });
			}
		}
	});
})(jQuery);




/******************************************************************************
 * ElementPosition 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo independente
 *
 * COMO UTILIZAR
 * 
 * Chame a funcao elementPosition para posicionar layers de acordo com o espaco disponivel no eixo Y
 *
 *
 * PARAMETROS
 *
 * Na funcao elementPosition posY e a posicao mais baixa que a layer alcanca
 * e diffPosY e a diferenca de distancia que sera utilizada para passar a layer para cima utilizando margin-top
 *
 ******************************************************************************/

/*
 * Functions
 */

// Positioning elements
function elementPosition(posY,diffPosY,selector) {
	obj = $(selector);

	// Scroll position
	scrollY = scrollTopPosition();
	windowHeight = window.innerHeight ? window.innerHeight : $("html").height();

	if (posY-scrollY+5 > windowHeight) {
		obj.css("marginTop",diffPosY+"px");
	} else {
		obj.css("marginTop",0);
	}
}

// Return the scroll top position
function scrollTopPosition() {
	var scrollY;
	if (document.all) {
		if (!document.documentElement.scrollTop) {
			scrollY = document.body.scrollTop;
		} else {
			scrollY = document.documentElement.scrollTop;
		}
	} else {
		scrollY = window.pageYOffset;
	}
	return scrollY;
}




/******************************************************************************
 * Photo Gallery 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo dependente do modulo Scrolling
 *
 * COMO UTILIZAR
 * 
 * Usar como base o exemplo abaixo
 *
 *	<div class="photogallery">
 *		PARAMETROS OPCIONAIS
 *		<input type="hidden" name="hdn-ctn-caption" value="gal-caption" />
 *		<input type="hidden" name="hdn-ctn-caption2" value="gal-caption2" />
 *		<input type="hidden" name="hdn-ctn-caption3" value="gal-caption3" />
 *		<input type="hidden" name="hdn-play" value="1" />
 *		LISTA DE THUMBS
 *		<ul class="gal-thumbs" title="Clique na miniatura para ampliá-la">
 *			<li>
 *				LINK PARA A IMAGEM MEDIA
 *				<a target="_blank" href="http://vgn.img.terra.com/English/Photos/US/Sports/Olympics/82534698_10_cv572x400.jpg">
 *					<img src="http://vgn.img.terra.com/English/Photos/US/Sports/Olympics/82534698_10_cf110x76.jpg" alt="Closing Ceremonies 1" />
 *					ENDERECO DA IMAGEM MAIOR
 *					<input type="hidden" value="http://vgn.img.terra.com/English/Photos/US/Sports/Olympics/82534698_10_r800x800.jpg" name="hdn-zoomphoto"/>
 *				</a>
 *				OPCIONAL PARA QUANDO HOUVER LEGENDA, O CONTEUDO DESTA DIV ENTRARA NA DIV SETADA NO HIDDEN "hdn-ctn-caption"
 *				<div class="gal-contentcaption">
 *					<p>HTML caption</p>
 *				</div>
 *				<div class="gal-contentcaption2">IMAGEN 0 DE 0</div>
 *			</li>
 *		</ul>
 *
 *		<div class="gal-photo">
 *			<img alt="" src="img/blank.gif" class="img-photogallery" />
 *		</div>
 *	</div>
 *
 *
 * PARAMETROS
 *
 * O input com hidden citado no exemplo acima (hdn-ctn-caption) possue como valor a class do elemento que carregara a legenda
 * O input com hidden citado no exemplo acima (hdn-ctn-caption2) possue como valor a class do elemento que carregara o número da foto
 * O input com hidden citado no exemplo acima (hdn-play) define se a gallery vai iniciar com play - 0 = pause / 1 = play
 *
 ******************************************************************************/

(function($) {

	$.fn.extend({

		// Photo gallery
		photoGallery: function() {

			$(this).each(function(i) {
				var objGallery = $(this);
				var objListThumbs = objGallery.find(".gal-thumbs");
				var anterior = objGallery.find(".gal-go-previous");
				var anterior2 = objGallery.find(".gal-go-previous2");
				var proximo = objGallery.find(".gal-go-next");
				var proximo2 = objGallery.find(".gal-go-next2");
				var objPlay = objGallery.find("input:hidden[name='hdn-play']");
				var objPhoto = objGallery.find(".img-photogallery");
								
				if (!objPhoto.next().is("span")) {
					objPhoto.before("<span>&nbsp;</span>");
				}

				
				/*
				 * Events
				 */
				 
				// Thumb click
				objListThumbs.find("li>a").unbind("click").click(function() {
					objGallery.find(".gal-pause").trigger("click"); // pause
					openPhoto($(this), objGallery);
					return false;
				});

				// Previous
				objGallery.find(".gal-go-previous").unbind("click").click(function() {
					objGallery.find(".gal-pause").trigger("click"); // pause
					nextPrevPhoto(objGallery,0);
					return false;
				});

				// Next
				objGallery.find(".gal-go-next").unbind("click").click(function() {
					objGallery.find(".gal-pause").trigger("click"); // pause
					nextPrevPhoto(objGallery,1);
					return false;

				});

				objGallery.find(".gal-photo").unmousewheel().mousewheel(function(event, delta) {
					if (delta > 0) {
						objGallery.find(".gal-go-previous").click();
					} else if (delta < 0) {
						objGallery.find(".gal-go-next").click();
					}
					return false;
				});

				// First
				objGallery.find(".gal-go-first").unbind("click").click(function() {
					objListThumbs.find("li:first a").trigger("click");
					return false;
				});

				// Last
				objGallery.find(".gal-go-last").unbind("click").click(function() {
					objListThumbs.find("li:last a").trigger("click");
					return false;
				});

				// Play
				objGallery.find(".gal-play").unbind("click").click(function() {
					$(this).hide();
		
					objGallery.find(".gal-pause").show();
					objPlay.val(1);
					
					nextPrevPhoto(objGallery,1);
					return false;
				});

				// Pause
				objGallery.find(".gal-pause").unbind("click").click(function() {
					$(this).hide();
					objGallery.find(".gal-play").show();
		
					clearTimeout(objPlay.val());
					objPlay.val(0);
					return false;
				});

				// Enlarge
				objGallery.find(".gal-enlarge").unbind("click").click(function() {
					objGallery.find(".gal-pause").trigger("click"); // pause
				});
				
				
				// Init
				
				openPhoto(objListThumbs.find("a:first"), this);
				
				
				//Visibilidade Setas
				anterior.show();
				anterior2.hide();
				proximo.show();
				proximo2.hide();
				
				

			});



			/*
			 * Functions
			 */

			/*
			 * PARAMETERS
			 * - e (object a)
			 * - selector (.photogallery)
			 */
			function openPhoto(e, selector) {
				
		
				var objGallery = $(selector);
				var objListThumbs = objGallery.find(".gal-thumbs");
				var objThumb2 = null;
				var objThumb3 = null;
				
				/*Visibilidade Setas
				var anterior = objGallery.find(".gal-go-previous");
				var anterior2 = objGallery.find(".gal-go-previous2");
				var proximo = objGallery.find(".gal-go-next");
				var proximo2 = objGallery.find(".gal-go-next2");
				anterior.show();
				anterior2.hide();
				proximo.show();
				proximo2.hide();*/

			
				if (!e.parent().hasClass("active")) {

					var objGallery = $(selector);
					var objListThumbs = objGallery.find(".gal-thumbs");
					var objPhoto = objGallery.find(".img-photogallery");
					var objSee = objGallery.find(".see");
					var objSee2 = objGallery.find(".SeeLink");
					var objSee3 = objGallery.find(".SeeLink2");
					var objPlay = objGallery.find("input:hidden[name='hdn-play']");
					var objCaption = $("."+objGallery.find("input:hidden[name='hdn-ctn-caption']").val());
					var objCaption2 = $("."+objGallery.find("input:hidden[name='hdn-ctn-caption2']").val());
					var objCaption3 = $("."+objGallery.find("input:hidden[name='hdn-ctn-caption3']").val());
					var objCaption4 = $("."+objGallery.find("input:hidden[name='hdn-ctn-caption4']").val());
					var objScrolling = objGallery.find(".scrolling");
					var indexThumb = e.parent().parent().find("li").index(e.parent().get(0));

					// Position thumbs
					tmbMargin = parseInt(e.parent().css("margin-right").replace("px",""));
					tmbWidth = e.parent().width() + tmbMargin;
					if ( (e.parent().offset().left > objScrolling.width() - tmbWidth - tmbMargin + 5) || (e.parent().offset().left < 5) ) {
						objScrolling.scrollContentPosition((indexThumb*tmbWidth-objScrolling.width()/2)+tmbWidth/2);
					}

					// Caption
					if (objCaption.size() > 0) {
						objCaption.fadeOut(animateDuration);
					}
					
					// Select thumb
					objListThumbs.find(">li.active").removeClass("active");
					e.parent().addClass("active");
					
					// Caption
					if (objCaption2.size() > 0) {
						objCaption2.fadeOut(animateDuration);
					}
					
					// Caption
					if (objCaption3.size() > 0) {
						objCaption3.fadeOut(animateDuration);
					}
					
					// Caption
					if (objCaption4.size() > 0) {
						objCaption4.fadeOut(animateDuration);
					}
					

					// Enlarge
					if (objGallery.find(".gal-enlarge").size() > 0)  {
						objGallery.find(".gal-enlarge").attr("href",e.parent().find("input:hidden[name='hdn-zoomphoto']").val());
					}
					
					objPhoto.fadeOut(animateDuration, function() {
															   

						$(this).attr("src",e.attr("href")).unbind("load").load(function() {
																						
							$(this).attr("alt",e.attr("title")).unbind("load").load;
							tempSee = e.parent().find(".gal-contentcaption2").html();
							objSee.attr("href",tempSee).unbind("load").load;
							objSee2.attr("href",tempSee).unbind("load").load;
							objSee3.attr("href",tempSee).unbind("load").load;
							

							// Play					
							if (objPlay.val() != "0") {
								objGallery.find(".gal-play").hide();
								objGallery.find(".gal-pause").show();
								clearTimeout(objPlay.val());
								objPlay.val(setTimeout(function() {
									nextPrevPhoto(objGallery,1);
								},transitionTime));
							} else {
								objGallery.find(".gal-play").show();
								objGallery.find(".gal-pause").hide();
							}

							$(this).fadeIn(animateDuration);

							// Caption
							if (objCaption.size() > 0) {
								objCaption.html(e.parent().find(".gal-contentcaption").html()).fadeIn(animateDuration);
							}
							
							// Caption
							if (objCaption2.size() > 0) {
								objCaption2.html(e.parent().find(".gal-contentcaption2").html()).fadeIn(animateDuration);
							}
							
							// Caption
							if (objCaption3.size() > 0) {
								objCaption3.html(e.parent().find(".gal-contentcaption3").html()).fadeIn(animateDuration);
							}
							
							// Caption
							if (objCaption4.size() > 0) {
								objCaption4.html(e.parent().find(".gal-contentcaption4").html()).fadeIn(animateDuration);
							}
							
							

						});
					});
					

					
					
					
				}
			}

			/*
			 * PARAMETERS
			 * - selector (.photogallery)
			 * - action (0 - Prev / 1 - Next)
			 */
			function nextPrevPhoto(selector,action) {
				var objGallery = $(selector);
				var objListThumbs = objGallery.find(".gal-thumbs");
				var objThumb = null;
				var objThumb2 = null;
				var anterior = objGallery.find(".gal-go-previous");
				var anterior2 = objGallery.find(".gal-go-previous2");
				var proximo = objGallery.find(".gal-go-next");
				var proximo2 = objGallery.find(".gal-go-next2");
				
				/* Visibilidade Setas
				objThumb2 = objListThumbs.find(".active").next();
				objThumb3 = objListThumbs.find(".active").next().next();
				if (objThumb2.size() == 0) {
					anterior.hide();
					anterior2.show();
					proximo.show();
					proximo2.hide();
				} else {
					if (objThumb3.size() == 0) { 
					anterior.show();
					anterior2.hide();
					proximo.hide();
					proximo2.show();						
					} else {
					anterior.show();
					anterior2.hide();
					proximo.show();
					proximo2.hide();
					}
				}*/
			
				if (action == 0) { // Prev
					var objThumb = objListThumbs.find(".active").prev();

					if (objThumb.size() == 0) { // Loop
						objThumb = objListThumbs.find("li:last");

					}
					
				} else { // Next

					objThumb = objListThumbs.find(".active").next();

					if (objThumb.size() == 0) { // Loop
						objThumb = objListThumbs.find("li:first");
					}

				}
				openPhoto(objThumb.find("a"), selector);

			}
		}
	});
})(jQuery);




/******************************************************************************
 * Tabs 2.0 - Terra Networks - Equipe Webdev
 * 2008
 * Modulo independente
 *
 * COMO UTILIZAR
 * 
 * Usar como base o exemplo abaixo
 *
 *	<div class="tabs">
 *		<ul class="tab-list">
 *			<li><a href="#tab-content1" class="anchor"><span>Aba 1</span></a></li>
 *			<li><a href="#tab-content2" class="anchor"><span>Aba 2</span></a></li>
 *		</ul>
 *
 *		<div id="tab-content1" class="tab-content">
 *			Conteúdo da aba 1
 *		</div>
 *
 *		<div id="tab-content2" class="tab-content">
 *			Conteúdo da aba 2
 *		</div>
 *	</div>
 *
 * PARAMETROS
 *
 * Ao adicionar a classe "anchor" nos links das abas passamos a ter a funcionalidade de historico, esta classe é opcional
 *
 ******************************************************************************/

(function($) {

	$.fn.extend({

		// Tabs
		tabs: function() {

			$(this).each(function() {
				var objTabs = $(this);

				objTabs.find(".tab-content").hide();

				var initTab = (/#.*$/).exec(window.location.href);
				if (objTabs.find("a[href='"+initTab+"']").size() > 0) {
					changeTab(objTabs.find("a[href='"+initTab+"']"));
					objTabs.find("a[href='"+initTab+"']").addClass("selected");
					window.scrollTo(0,0);
				}



				/*
				 * Events
				 */
				$(".tab-list a").unbind("click").click(function() {
					changeTab(this);
					if (!$(this).hasClass("anchor"))
						return false;

				});
			});



			/*
			 * Functions
			 */

			/*
			 * PARAMETERS
			 * - selector (a)
			 */
			function changeTab(selector) {
				obj = $(selector);
				var tabsContainer = obj.parents(".tab-list");
				var tabsContentContainer = obj.parents(".tabs:first");
				var tabContentName = obj.attr("href");

				// Tab
				tabsContainer.find("li.selected").removeClass("selected");
				obj.parent().addClass("selected");

				// Tab content
				tabsContentContainer.find(".tab-content:first").parent().find(">.tab-content:visible:not("+tabContentName+")").hide();
				tabsContentContainer.find(tabContentName).show();
			}
		}
	});

})(jQuery);





/******************************************************************************
 * Initialization
 ******************************************************************************/

$(".combobox").combobox();
initClickOut(".clickout, .cmb-value");
$(".scrolling").scrolling();
$(".photogallery").photoGallery();
$(".tabs").tabs();


/******************************************************************************
 * mouse over
 ******************************************************************************/


function overSee() {
	document.getElementById("seeid").className= 'seeover';
	document.getElementById("seeid2").className= 'SeeLinkover';
}

function outSee() {
	document.getElementById("seeid").className = 'see';
	document.getElementById("seeid2").className= 'SeeLink';
}

