$(document).ready(function(){
	$("#submitLoop").click(function() {
		$.post("/home/mailinglist", {"emailaddress":$("#inputLoop").val()}, function(data) {
			if(data.error) {
				alert(data.error);
				return;
			}
			
			$("#loopStatus").text("You have been signed up!");
		}, "json");
		return false;
	});
	
	$(".submit, .send").live("click", function() {
		$(this).closest("form").submit();
		return false;
	});
	
	$(".back_btn").click(function(e) {
		e.preventDefault();
		history.back();
	});
	
	$(".applyForm_submit").click(function() {
		var form = $(this).closest("form");
		$(".error").removeClass("error");
		
		var pass = true;
		
		if($("#a_name").val() == "") {
			$("label[for='a_name']").addClass("error");
			pass = false;
		}
		if(!is_valid_email($("#a_email").val())) {
			$("label[for='a_email']").addClass("error");
			pass = false;
		}
		if($("#a_resume").val() == '') {
			$("label[for='a_resume']").addClass("error");
			pass = false;
		}
		
		if(pass) {
			form.submit();
		} else {
			return false;
		}
	});
	
	$(".study_thumbs .unit:first-child a").click(function(){ return false; });
	$(".study_thumbs .unit:first-child a").lightBox({
		txtOf : "/",
		txtImage: "",
		imageLoading: '/images/loading.gif',
		imageBtnPrev: '/images/lightbox_prev.png',
		imageBtnNext: '/images/lightbox_next.png',
		imageBtnPrevNone: '/images/lightbox_prev_none.png',
		imageBtnNextNone: '/images/lightbox_next_none.png',
		imageBtnClose: '/images/lightbox_close.png',
		fixedNavigation: true
	});
	
	$(".jqtransform").jqTransform();
	
	$(".screenshots a").lightBox();
	
	$(".topNavLinks a").hover(function() { 
		$(this).animate({"color":"#cae3f8"}, "fast");
	}, function() {
		$(this).animate({"color":"#97bfe2"}, "fast");
	});
	
	$(".topNavLinks a").click(function() {
		if($(this).hasClass("activeLink"))
			return false;
		
		else {
			$(".activeLink").removeClass("activeLink");
			$(this).addClass("activeLink");
		}
		
		$(".topNavLinks p").fadeOut();
		
		if($("#contactForm").is(":visible"))
			$("#contactForm").animate({"height":"0px"});
			
		var href = $(this).attr("href").split("#");
		
		if(href[1]) {
			var top = $("#"+href[1]).offset();
			top = top.top ;
			$.scrollTo((top-90)+'px', 500, {'axis':'y'});
			return false;
		} else {
			if($("#applyForm").height()) {
				$("#applyForm").animate({height:"0px"}, "normal");
			}
			$("#contactForm").animate({"height":"300px"}, "normal");
			$.scrollTo('0px', 500, {'axis':'y', 'onAfter':show_contact_form() });
			return false;
		}
		
		return true;
	});
	
	$("#summerinternships").click(function() {
		var href = $(this).attr("href").split("#");
		
		var top = $("#"+href[1]).offset();
		top = top.top ;
		$.scrollTo((top-90)+'px', 500, {'axis':'y'});
		return false;
	
	});
	
	$(".applyforjob").click(function() {
		if($("#contactForm").height()) {
			$("#contactForm").animate({height:"0px"}, "normal");
		}
		if(!$("#applyForm").height())
			$("#applyForm").animate({"height":"300px"}, "normal");
		$("#applyForm_form .jqTransformSelectWrapper > div span").text("Summer Internship ("+$(this).attr("rel")+")");
		if($("#a_position_ul li a.selected").attr("index") != $(this).attr("index")) {
			$("#a_position_ul li a.selected").removeClass("selected");
			$("#a_position_ul li a[index='"+$(this).attr("index")+"']").addClass("selected");
			($("#a_position option")[$(this).attr("index")]).selected = true;
		}
		$.scrollTo('0px', 500, {'axis':'y', 'onAfter':function() { $("#applyForm").animate({"height":"300px"}, "normal"); } });
		return false;
	});
	
	$(".backToTop").click(function() {
		$('.activeLink').removeClass("activeLink");
		$.scrollTo('0px', 500, {});
		return false;
	});
	
	$(".contactForm_submit").click(function() {
		$(".error").removeClass("error");
		var form = $(this).closest("form");
		
		$.post(form.attr("action"), form.serialize(), function(data) {
			if(data.success) {
				$(".contactForm_submit").text("Sent!");
				setTimeout(function() { $(".contactForm_cancel").trigger("click"); }, 2000);
				setTimeout(function() { resetForm(form); $(".contactForm_submit").text("Submit"); }, 3000);
			} else {
				$.each(data.errors, function(k, v) {
					$("label[for='"+v+"']").addClass("error");
				});
			}
			
		}, "json");
		
	});
	
	if(window.location.hash != "") {
		var top = $(window.location.hash).offset();
		top = top.top;
		$.scrollTo((top-90)+'px', 500, {'axis':'y'});
	}
	
	$(".topNavTabs a").hover(function() { 
		$(this).animate({"top":"0px"}, "fast");
	}, function() {
		$(this).animate({"top":"-5px"}, "fast");
	});
	
	$("#quickContactForm").click(function() {
		$.scrollTo('0px', 500, {'axis':'y', 'onAfter':function() { $("#contactUsTabLink").trigger("click"); } });
		return false;
	});
	
	$(".contactForm_cancel").click(function() {
		var form = $(this).closest("form");
		
		if($("#contactForm").height()) {
			$(".topNavLinks a:last").removeClass("activeLink");
			$("#contactForm").animate({"height":"0px"}, function() { resetForm(form); });
			$("#toptab_contactus").fadeOut();
		} else {
			$("#applyForm").animate({"height":"0px"}, function() { resetForm(form); });
		}
	});
	
	$("select[id^='filter_']").change(function() { 
		$("#total").val(6); // reset total viewing amount
		
		if($("#viewmore").hasClass("disabled"))
			$("#viewmore").removeClass("disabled");
		
		$.get("/home/filter", 
		{ "type":$("#filter_type").val(), "keyword":$("#filter_keyword").val(), "most":$("#filter_most").val(), "total":$("#total").val() }, function(data) {
			$("#feed_incoming").html(data);
			var new_height = $("#feed_incoming").height()+5;
			$("#feed_incoming").hide();
			
			$("#feed_container").height($("#feed_container").height());
			$("#feed").fadeOut(300,function() {
				$("#feed").hide();
				$("#feed_container").animate({height:new_height}, 300);
				$("#feed_incoming").fadeIn(300, function() {
					$("#feed").html($("#feed_incoming").html()).show().height($("#feed_incoming").height());
					$("#feed_incoming").html("");
				});
			});
		},
		"html");
	});
	
	$("#feed_most a").click(function() {
		$("#feed_most a.active").removeClass("active");
		$(this).addClass("active");
		$("#filter_most").val(($(this).text() == "Most Recent") ? "recent" : "popular");
		$("#filter_type").trigger("change");
		return false;
	});
	
	$("#viewmore").click(function() {
		if($(this).hasClass("disabled"))
			return false;
			
		var total = parseInt($("#total").val())+6;
		
		$.get("/home/filter", 
		{ "type":$("#filter_type").val(), "keyword":$("#filter_keyword").val(), "most":$("#filter_most").val(), "total":total }, function(data) {
			$("#total").val(total);
			$("#feed").html("");
			$("#feed_incoming").html(data);
			var new_height = $("#feed_incoming").height()+5;
			$("#feed_container").animate({height:new_height},300,function() {
				$("#feed").html($("#feed_incoming").html());
				$("#feed_incoming").html("");
			});
		},
		"html");
		
		return false;
	});
	
	$("#share").change(function() {
		if($(this).val() != "") {
			var formfunc = "show_"+$(this).val()+"_popup_form()";
			if($(this).val() != "facebook" && $(this).val() != "twitter")
				_init_popup_form();
			eval(formfunc);
		} else {
			close_popup_form();
		}
	});
	
	/* == coda slider == */
	$(".scroll").easySlider({ nextText : "", prevText : "", continuous : true});
	
	// setInterval(function() {
	// 		$("#nextBtn a").trigger("click");
	// 	}, 60000);
});


function resetForm(form) {
	$(".error").removeClass("error");
	form.find("input, textarea").val("");
}


/*
 * 	Easy Slider 1.7 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#slider").easySlider();
 *	
 * 	<div id="slider">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			
			if(options.continuous){
				$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ w +"px"));
				$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
				$("ul", obj).css('width',(s+1)*w);
			};				
			
			if(!options.vertical) $("li", obj).css('float','left');
								
			if(options.controlsShow){
				var html = options.controlsBefore;				
				if(options.numeric){
					html += '<ol id="'+ options.numericId +'"></ol>';
				} else {
					if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
					html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
					html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
					if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';				
				};
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			if(options.numeric){									
				for(var i=0;i<s;i++){						
					$(document.createElement("li"))
						.attr('id',options.numericId + (i+1))
						.html('<a rel='+ i +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
						.appendTo($("#"+ options.numericId))
						.click(function(){							
							animate($("a",$(this)).attr('rel'),true);
						}); 												
				};							
			} else {
				$("a","#"+options.nextId).click(function(){		
					animate("next",true);
				});
				$("a","#"+options.prevId).click(function(){		
					animate("prev",true);				
				});	
				$("a","#"+options.firstId).click(function(){		
					animate("first",true);
				});				
				$("a","#"+options.lastId).click(function(){		
					animate("last",true);				
				});				
			};
			
			function setCurrent(i){
				i = parseInt(i)+1;
				$("li", "#" + options.numericId).removeClass("current");
				$("li#" + options.numericId + i).addClass("current");
			};
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				if(!options.vertical) {
					$("ul",obj).css("margin-left",(t*w*-1));
				} else {
					$("ul",obj).css("margin-left",(t*h*-1));
				}
				clickable = true;
				if(options.numeric) setCurrent(t);
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;						
					if(!options.vertical) {
						p = (t*w*-1);
						$("ul",obj).animate(
							{ marginLeft: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);				
					} else {
						p = (t*h*-1);
						$("ul",obj).animate(
							{ marginTop: p }, 
							{ queue:false, duration:speed, complete:adjust }
						);					
					};
					
					if(!options.continuous && options.controlsFade){					
						if(t==ts){
							$("a","#"+options.nextId).parent().addClass("noMore");//hide();
							$("a","#"+options.lastId).parent().addClass("noMore");//hide();
						} else {
							$("a","#"+options.nextId).parent().removeClass("noMore");//.show();
							$("a","#"+options.lastId).parent().removeClass("noMore");//show();					
						};
						if(t==0){
							$("a","#"+options.prevId).parent().addClass("noMore");//hide();
							$("a","#"+options.firstId).parent().addClass("noMore");//hide();
						} else {
							$("a","#"+options.prevId).parent().removeClass("noMore");//show();
							$("a","#"+options.firstId).parent().removeClass("noMore");//show();
						};					
					};				
					
					if(clicked) clearTimeout(timeout);
					if(options.auto && dir=="next" && !clicked){;
						timeout = setTimeout(function(){
							animate("next",false);
						},diff*options.speed+options.pause);
					};
			
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
			
			if(options.numeric) setCurrent(0);
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).parent().addClass("noMore");//hide();
				$("a","#"+options.firstId).parent().addClass("noMore");//hide();				
			};				
			
		});
	  
	};

})(jQuery);






/**
 * jQuery.ScrollTo
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 *
 * @projectDescription Easy element scrolling using jQuery.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
 *
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * @id jQuery.scrollTo
 * @id jQuery.fn.scrollTo
 * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
 *	  The different options for target are:
 *		- A number position (will be applied to all axes).
 *		- A string position ('44', '100px', '+=90', etc ) will be applied to all axes
 *		- A jQuery/DOM element ( logically, child of the element to scroll )
 *		- A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
 *		- A hash { top:x, left:y }, x and y can be any kind of number/string like above.
*		- A percentage of the container's dimension/s, for example: 50% to go to the middle.
 *		- The string 'max' for go-to-end. 
 * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
 * @param {Object,Function} settings Optional set of settings or the onAfter callback.
 *	 @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
 *	 @option {Number} duration The OVERALL length of the animation.
 *	 @option {String} easing The easing method for the animation.
 *	 @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
 *	 @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
 *	 @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
 *	 @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
 *	 @option {Function} onAfter Function to be called after the scrolling ends. 
 *	 @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @desc Scroll to a fixed position
 * @example $('div').scrollTo( 340 );
 *
 * @desc Scroll relatively to the actual position
 * @example $('div').scrollTo( '+=340px', { axis:'y' } );
 *
 * @dec Scroll using a selector (relative to the scrolled element)
 * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
 *
 * @ Scroll to a DOM element (same for jQuery object)
 * @example var second_child = document.getElementById('container').firstChild.nextSibling;
 *			$('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
 *				alert('scrolled!!');																   
 *			}});
 *
 * @desc Scroll on both axes, to different values
 * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
 */
;(function( $ ){
	
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'xy',
		duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1
	};

	// Returns the element that needs to be animated to scroll the window.
	// Kept for backwards compatibility (specially for localScroll & serialScroll)
	$scrollTo.window = function( scope ){
		return $(window)._scrollable();
	};

	// Hack, hack, hack :)
	// Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
	$.fn._scrollable = function(){
		return this.map(function(){
			var elem = this,
				isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;

				if( !isWin )
					return elem;

			var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
			
			return $.browser.safari || doc.compatMode == 'BackCompat' ?
				doc.body : 
				doc.documentElement;
		});
	};

	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
			
		if( target == 'max' )
			target = 9e9;
			
		settings = $.extend( {}, $scrollTo.defaults, settings );
		// Speed is still recognized for backwards compatibility
		duration = duration || settings.speed || settings.duration;
		// Make sure the settings are given right
		settings.queue = settings.queue && settings.axis.length > 1;
		
		if( settings.queue )
			// Let's keep the overall duration
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );

		return this._scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');

			switch( typeof targ ){
				// A number will pass the regex
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(targ) ){
						targ = both( targ );
						// We are done
						break;
					}
					// Relative selector, no break!
					targ = $(targ,this);
				case 'object':
					// DOMElement / jQuery
					if( targ.is || targ.style )
						// Get the real position of the target 
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					max = $scrollTo.max(elem, axis);

				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );

					// If it's a dom element, reduce the margin
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					
					attr[key] += settings.offset[pos] || 0;
					
					if( settings.over[pos] )
						// Scroll to a fraction of its width/height
						attr[key] += targ[axis=='x'?'width':'height']() * settings.over[pos];
				}else{ 
					var val = targ[pos];
					// Handle percentage values
					attr[key] = val.slice && val.slice(-1) == '%' ? 
						parseFloat(val) / 100 * max
						: val;
				}

				// Number or 'number'
				if( /^\d+$/.test(attr[key]) )
					// Check the limits
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );

				// Queueing axes
				if( !i && settings.queue ){
					// Don't waste time animating, if there's no need.
					if( old != attr[key] )
						// Intermediate animation
						animate( settings.onAfterFirst );
					// Don't animate this axis again in the next iteration.
					delete attr[key];
				}
			});

			animate( settings.onAfter );			

			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};

		}).end();
	};
	
	// Max scrolling position, works on quirks mode
	// It only fails (not too badly) on IE, quirks mode.
	$scrollTo.max = function( elem, axis ){
		var Dim = axis == 'x' ? 'Width' : 'Height',
			scroll = 'scroll'+Dim;
		
		if( !$(elem).is('html,body') )
			return elem[scroll] - $(elem)[Dim.toLowerCase()]();
		
		var size = 'client' + Dim,
			html = elem.ownerDocument.documentElement,
			body = elem.ownerDocument.body;

		return Math.max( html[scroll], body[scroll] ) 
			 - Math.min( html[size]  , body[size]   );
			
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})( jQuery );









function _init_popup_form() {
	$('body').append('<div id="popupform-overlay"></div><div id="jquery-popupform"><div id="popupform-container-image-box"><a href="#" id="popupform-secNav-btnClose"><img src="/images/lightbox_close.png"></a><div id="popupform-container-image"><img id="popupform-image"><div id="popupform-loading"></div></div></div>');	
	$("#popupform-secNav-btnClose, #popupform-overlay").bind("click", function() { close_popup_form(); return false; });
	$('#popupform-overlay').css({
		backgroundColor:	"#e7f3fc",
		opacity:			".9",
		width:				$(window).width(),
		height:				$(document).height()
	}).fadeIn();
}

function close_popup_form() {
	$('#jquery-popupform').remove();
	$('#popupform-overlay').fadeOut(function() { $('#popupform-overlay').remove(); });
}

function show_popup_form(f) {
	$("#popupform-container-image").html(f);
	$("#jquery-popupform").css({
		width: f.width()+63, 
		height: f.height()+63,
		top:	( $(window).height() - $("#jquery-popupform").height() ) / 2+$(window).scrollTop() + "px",
		left:	( $(window).width() - f.width() ) / 2+$(window).scrollLeft() + "px"
	}).fadeIn();
}

function show_phone_popup_form() {
	var f = $("#phone_form_template").clone().show();
	f.addClass("phone_form_box");
	f.find("form").bind("submit", function(e) {
		e.preventDefault();
		this_form_status = $(this).find(".form_send_status");
		this_form_status.show();
		$.post($(this).attr("action"), $(this).serialize(), function(data) {
			this_form_status.text("Sent!")
			setTimeout(function() { close_popup_form(); }, 2000);
		}, "html");
		return false;
	});
	
	show_popup_form(f);
}

function show_facebook_popup_form() {
	$("#facebook_post").trigger("onclick");
}

function show_email_popup_form() {
	var f = $("#email_form_template").clone().show();
	f.addClass("email_form_box");
	f.find("form").bind("submit", function(e) {
		e.preventDefault();
		this_form_status = $(this).find(".form_send_status");
		this_form_status.show();
		$.post($(this).attr("action"), $(this).serialize(), function(data) {
			this_form_status.text("Sent!")
			setTimeout(function() { close_popup_form(); }, 2000);
		}, "html");
		return false;
	});
	
	show_popup_form(f);
}

function show_twitter_popup_form() {
	window.open("http://www.twitter.com?status="+$("#tweet_text").val());
	return;
	
	if($("#oauth_token").val() == "") {
		var f = $("#twitter_form_template").clone().show();
		f.addClass("twitter_form_box");
		
		show_popup_form(f);
		
		window.location = "/home/init_twitter";
		return;
	}
	
	var f = $("#twitter_form_template").clone().show();
	f.addClass("twitter_form_box");
	f.find("textarea").bind("keyup", function() {
		if($(this).val().length <= 140)
			$(this).siblings("p").find(".tweet_count").text(140-$(this).val().length);
		else {
			$(this).val( $(this).val().substring(0, 140) );
		}
	});
	f.find("form").bind("submit", function(e) {
		e.preventDefault();
		this_form_status = $(this).find(".form_send_status");
		this_form_status.show();
		$.post($(this).attr("action"), $(this).serialize(), function(data) {
			this_form_status.text("Sent!")
			setTimeout(function() { close_popup_form(); }, 2000);
		}, "html");
		return false;
	});
	
	show_popup_form(f);
	
}

function show_contact_form() {
	$(".topNavLinks a:last").addClass("activeLink");
	$("#contactForm").animate({"height":"300px"}, "normal");
	$("#toptab_contactus").fadeIn();
}

function is_valid_email(email) {
    return /^([a-zA-Z0-9_.\-])+@(([a-zA-Z0-9\-])+.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}

/* coda slider */


/* jqtransform */
$(document).ready(function(){$(".jqtransform").jqTransform();});(function($){var defaultOptions={preloadImg:true};var jqTransformImgPreloaded=false;var jqTransformPreloadHoverFocusImg=function(strImgUrl){strImgUrl=strImgUrl.replace(/^url\((.*)\)/,'$1').replace(/^\"(.*)\"$/,'$1');var imgHover=new Image();imgHover.src=strImgUrl.replace(/\.([a-zA-Z]*)$/,'-hover.$1');var imgFocus=new Image();imgFocus.src=strImgUrl.replace(/\.([a-zA-Z]*)$/,'-focus.$1');};var jqTransformGetLabel=function(objfield){var selfForm=$(objfield.get(0).form);var oLabel=objfield.next();if(!oLabel.is('label')){oLabel=objfield.prev();if(oLabel.is('label')){var inputname=objfield.attr('id');if(inputname){oLabel=selfForm.find('label[for="'+inputname+'"]');}}}if(oLabel.is('label')){return oLabel.css('cursor','pointer');}return false;};var jqTransformHideSelect=function(oTarget){var ulVisible=$('.jqTransformSelectWrapper ul:visible');ulVisible.each(function(){var oSelect=$(this).parents(".jqTransformSelectWrapper:first").find("select").get(0);if(!(oTarget&&oSelect.oLabel&&oSelect.oLabel.get(0)==oTarget.get(0))){$(this).hide();}});};var jqTransformCheckExternalClick=function(event){if($(event.target).parents('.jqTransformSelectWrapper').length===0){jqTransformHideSelect($(event.target));}};var jqTransformAddDocumentListener=function(){$(document).mousedown(jqTransformCheckExternalClick);};var jqTransformReset=function(f){var sel;$('.jqTransformSelectWrapper select',f).each(function(){sel=(this.selectedIndex<0)?0:this.selectedIndex;$('ul',$(this).parent()).each(function(){$('a:eq('+sel+')',this).click();});});$('a.jqTransformCheckbox, a.jqTransformRadio',f).removeClass('jqTransformChecked');$('input:checkbox, input:radio',f).each(function(){if(this.checked){$('a',$(this).parent()).addClass('jqTransformChecked');}});};$.fn.jqTransInputButton=function(){return this.each(function(){var newBtn=$('<button id="'+this.id+'" name="'+this.name+'" type="'+this.type+'" class="'+this.className+' jqTransformButton"><span><span>'+$(this).attr('value')+'</span></span>').hover(function(){newBtn.addClass('jqTransformButton_hover');},function(){newBtn.removeClass('jqTransformButton_hover')}).mousedown(function(){newBtn.addClass('jqTransformButton_click')}).mouseup(function(){newBtn.removeClass('jqTransformButton_click')});$(this).replaceWith(newBtn);});};$.fn.jqTransInputText=function(){return this.each(function(){var $input=$(this);if($input.hasClass('jqtranformdone')||!$input.is('input')){return;}$input.addClass('jqtranformdone');var oLabel=jqTransformGetLabel($(this));oLabel&&oLabel.bind('click',function(){$input.focus();});var inputSize=$input.width();if($input.attr('size')){inputSize=$input.attr('size')*10;$input.css('width',inputSize);}$input.addClass("jqTransformInput").wrap('<div class="jqTransformInputWrapper"><div class="jqTransformInputInner"><div></div></div></div>');var $wrapper=$input.parent().parent().parent();$wrapper.css("width",inputSize+10);$input.focus(function(){$wrapper.addClass("jqTransformInputWrapper_focus");}).blur(function(){$wrapper.removeClass("jqTransformInputWrapper_focus");}).hover(function(){$wrapper.addClass("jqTransformInputWrapper_hover");},function(){$wrapper.removeClass("jqTransformInputWrapper_hover");});$.browser.safari&&$wrapper.addClass('jqTransformSafari');$.browser.safari&&$input.css('width',$wrapper.width()+16);this.wrapper=$wrapper;});};$.fn.jqTransCheckBox=function(){return this.each(function(){if($(this).hasClass('jqTransformHidden')){return;}var $input=$(this);var inputSelf=this;var oLabel=jqTransformGetLabel($input);oLabel&&oLabel.click(function(){aLink.trigger('click');});var aLink=$('<a href="#" class="jqTransformCheckbox"></a>');$input.addClass('jqTransformHidden').wrap('<span class="jqTransformCheckboxWrapper"></span>').parent().prepend(aLink);$input.change(function(){this.checked&&aLink.addClass('jqTransformChecked')||aLink.removeClass('jqTransformChecked');return true;});aLink.click(function(){if($input.attr('disabled')){return false;}$input.trigger('click').trigger("change");return false;});this.checked&&aLink.addClass('jqTransformChecked');});};$.fn.jqTransRadio=function(){return this.each(function(){if($(this).hasClass('jqTransformHidden')){return;}var $input=$(this);var inputSelf=this;oLabel=jqTransformGetLabel($input);oLabel&&oLabel.click(function(){aLink.trigger('click');});var aLink=$('<a href="#" class="jqTransformRadio" rel="'+this.name+'"></a>');$input.addClass('jqTransformHidden').wrap('<span class="jqTransformRadioWrapper"></span>').parent().prepend(aLink);$input.change(function(){inputSelf.checked&&aLink.addClass('jqTransformChecked')||aLink.removeClass('jqTransformChecked');return true;});aLink.click(function(){if($input.attr('disabled')){return false;}$input.trigger('click').trigger('change');$('input[name="'+$input.attr('name')+'"]',inputSelf.form).not($input).each(function(){$(this).attr('type')=='radio'&&$(this).trigger('change');});return false;});inputSelf.checked&&aLink.addClass('jqTransformChecked');});};$.fn.jqTransTextarea=function(){return this.each(function(){var textarea=$(this);if(textarea.hasClass('jqtransformdone')){return;}textarea.addClass('jqtransformdone');oLabel=jqTransformGetLabel(textarea);oLabel&&oLabel.click(function(){textarea.focus();});var strTable='<table cellspacing="0" cellpadding="0" border="0" class="jqTransformTextarea">';strTable+='<tr><td id="jqTransformTextarea-tl"></td><td id="jqTransformTextarea-tm"></td><td id="jqTransformTextarea-tr"></td></tr>';strTable+='<tr><td id="jqTransformTextarea-ml">&nbsp;</td><td id="jqTransformTextarea-mm"><div></div></td><td id="jqTransformTextarea-mr">&nbsp;</td></tr>';strTable+='<tr><td id="jqTransformTextarea-bl"></td><td id="jqTransformTextarea-bm"></td><td id="jqTransformTextarea-br"></td></tr>';strTable+='</table>';var oTable=$(strTable).insertAfter(textarea).hover(function(){!oTable.hasClass('jqTransformTextarea-focus')&&oTable.addClass('jqTransformTextarea-hover');},function(){oTable.removeClass('jqTransformTextarea-hover');});textarea.focus(function(){oTable.removeClass('jqTransformTextarea-hover').addClass('jqTransformTextarea-focus');}).blur(function(){oTable.removeClass('jqTransformTextarea-focus');}).appendTo($('#jqTransformTextarea-mm div',oTable));this.oTable=oTable;if($.browser.safari){$('#jqTransformTextarea-mm',oTable).addClass('jqTransformSafariTextarea').find('div').css('height',textarea.height()).css('width',textarea.width());}});};$.fn.jqTransSelect=function(){return this.each(function(index){var $select=$(this);if($select.hasClass('jqTransformHidden')){return;}if($select.attr('multiple')){return;}var oLabel=jqTransformGetLabel($select);var $wrapper=$select.addClass('jqTransformHidden').wrap('<div class="jqTransformSelectWrapper jqTransformSelect'+($(this).attr("disabled")?'Disabled':'Active')+'"></div>').parent();$wrapper.prepend('<div><span></span><a href="#" class="jqTransformSelectOpen"></a></div><ul id="'+$select.attr("id")+'_ul"></ul>');var $ul=$('ul',$wrapper).css('width',$select.width()).hide();$('option',this).each(function(i){var oLi=$('<li><a href="#" index="'+i+'">'+$(this).html()+'</a></li>');$ul.append(oLi);});$ul.find('a').click(function(){$('a.selected',$wrapper).removeClass('selected');$(this).addClass('selected');if($select[0].selectedIndex!=$(this).attr('index')){$select[0].selectedIndex=$(this).attr('index');$($select[0]).change();}$select[0].selectedIndex=$(this).attr('index');$('span:eq(0)',$wrapper).html($(this).html());$ul.hide();return false;});$('a:eq('+this.selectedIndex+')',$ul).click();$('span:first',$wrapper).click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger('click');});oLabel&&oLabel.click(function(){$("a.jqTransformSelectOpen",$wrapper).trigger('click');});this.oLabel=oLabel;var oLinkOpen=$('a.jqTransformSelectOpen',$wrapper).click(function(){if($ul.css('display')=='none'){jqTransformHideSelect();}if($select.attr('disabled')){return false;}$ul.slideToggle('fast',function(){var offSet=($('a.selected',$ul).offset().top-$ul.offset().top);$ul.animate({scrollTop:offSet});});if($(this).closest(".half").hasClass("faded")){$(this).closest(".half").siblings(".half").addClass("faded");$(this).closest(".faded").removeClass("faded");}return false;});var iSelectWidth=$select.outerWidth();var oSpan=$('span:first',$wrapper);var newWidth=(iSelectWidth>oSpan.innerWidth())?iSelectWidth+oLinkOpen.outerWidth():$wrapper.width();$wrapper.css('width',newWidth);$.browser.msie&&$wrapper.addClass('jqTransformMsie'+$.browser.version.substr(0,1));$ul.css('width',newWidth-2);oSpan.css({width:iSelectWidth});$ul.css({display:'block',visibility:'hidden'});var iSelectHeight=($('li',$ul).length)*($('li:first',$ul).height());(iSelectHeight<$ul.height())&&$ul.css({height:iSelectHeight,'overflow':'hidden'});$ul.css({display:'none',visibility:'visible'});});};$.fn.jqTransform=function(options){var opt=$.extend({},defaultOptions,options);return this.each(function(){var selfForm=$(this);if(selfForm.hasClass('jqtransformdone')){return;}selfForm.addClass('jqtransformdone');$('input:submit, input:reset, input[type="button"]',this).jqTransInputButton();$('input:text, input:password',this).jqTransInputText();$('input:checkbox',this).jqTransCheckBox();$('input:radio',this).jqTransRadio();$('textarea',this).jqTransTextarea();if($('select',this).jqTransSelect().length>0){jqTransformAddDocumentListener();}$("select",this).bind("click",function(){$("select",this).jqTransSelect();});selfForm.bind('reset',function(){var action=function(){jqTransformReset(this);};window.setTimeout(action,10);});});};})(jQuery);


/* lightbox */
/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */

// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function($) {
	/**
	 * $ is an alias to jQuery object
	 *
	 */
	$.fn.lightBox = function(settings) {
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			// Configuration related to overlay
			overlayBgColor: 		'#000',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
			// Configuration related to navigation
			fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			// Configuration related to images
			imageLoading:			'images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			'images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			'images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBtnPrevNone: 		'', 
			imageBtnNextNone: 		'', 
			imageBlank:				'images/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
			// Configuration related to container image box
			containerBorderSize:	10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
			// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
			txtImage:				'Image',	// (string) Specify text "Image"
			txtOf:					'of',		// (string) Specify text "of"
			// Configuration related to keyboard navigation
			keyToClose:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
			keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
			keyToNext:				'n',		// (string) (n = next) Letter to show the next image.
			// Don´t alter these variables in any way
			imageArray:				[],
			activeImage:			0
		},settings);
		// Caching the jQuery object with all elements matched
		var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		function _initialize() {
			_start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
			return false; // Avoid the browser following the link
		}
		/**
		 * Start the jQuery lightBox plugin
		 *
		 * @param object objClicked The object (link) whick the user have clicked
		 * @param object jQueryMatchedObj The jQuery object with all elements matched
		 */
		function _start(objClicked,jQueryMatchedObj) { 
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'hidden' });
			// Call the function to create the markup structure; style some elements; assign events in some elements.
			_set_interface();
			// Unset total images in imageArray
			settings.imageArray.length = 0;
			// Unset image active information
			settings.activeImage = 0;
			// We have an image set? Or just an image? Let´s see it.
			if ( jQueryMatchedObj.length == 1 ) {
				settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
			} else {
				// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references		
				for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
					settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
				}
			} 
			while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
				settings.activeImage++;
			}
			// Call the function that prepares image exibition
			_set_image_to_view();
		}
		/**
		 * Create the jQuery lightBox plugin interface
		 *
		 * The HTML markup will be like that:
			<div id="jquery-overlay"></div>
			<div id="jquery-lightbox">
				<div id="lightbox-container-image-box">
					<div id="lightbox-container-image">
						<img src="../fotos/XX.jpg" id="lightbox-image">
						<div id="lightbox-nav">
							<a href="#" id="lightbox-nav-btnPrev"></a>
							<a href="#" id="lightbox-nav-btnNext"></a>
						</div>
						<div id="lightbox-loading">
							<a href="#" id="lightbox-loading-link">
								<img src="../images/lightbox-ico-loading.gif">
							</a>
						</div>
					</div>
				</div>
				<div id="lightbox-container-image-data-box">
					<div id="lightbox-container-image-data">
						<div id="lightbox-image-details">
							<span id="lightbox-image-details-caption"></span>
							<span id="lightbox-image-details-currentNumber"></span>
						</div>
						<div id="lightbox-secNav">
							<a href="#" id="lightbox-secNav-btnClose">
								<img src="../images/lightbox-btn-close.gif">
							</a>
						</div>
					</div>
				</div>
			</div>
		 *
		 */
		function _set_interface() {
			// Apply the HTML markup into body tag
			$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div>');	
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			$('#jquery-overlay').css({
				backgroundColor:	settings.overlayBgColor,
				opacity:			settings.overlayOpacity,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			$('#jquery-lightbox').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			}).show();
			// Assigning click events in elements to close overlay
			$('#jquery-overlay,#jquery-lightbox').click(function() {
				_finish();									
			});
			// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
			$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
				_finish();
				return false;
			});
			// If window was resized, calculate the new overlay dimensions
			$(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				$('#jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				// Get page scroll
				var arrPageScroll = ___getPageScroll();
				// Calculate top and left offset for the jquery-lightbox div object and show it
				$('#jquery-lightbox').css({
					top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
					left:	arrPageScroll[0]
				});
			});
		}
		/**
		 * Prepares image exibition; doing a image´s preloader to calculate it´s size
		 *
		 */
		function _set_image_to_view() { // show the loading
			// Show the loading
			$('#lightbox-loading').show();
			if ( settings.fixedNavigation ) {
				$('#lightbox-image').hide();
				//,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber
			} else {
				// Hide some elements
				$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
			}
			// Image preload process
			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {
				$('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
				// Perfomance an effect in the image container resizing it
				_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
				//	clear onLoad, IE behaves irratically with animated gifs otherwise
				objImagePreloader.onload=function(){};
			};
			objImagePreloader.src = settings.imageArray[settings.activeImage][0];
		};
		/**
		 * Perfomance an effect in the image container resizing it
		 *
		 * @param integer intImageWidth The image´s width that will be showed
		 * @param integer intImageHeight The image´s height that will be showed
		 */
		function _resize_container_image_box(intImageWidth,intImageHeight) {
			// Get current width and height
			var intCurrentWidth = $('#lightbox-container-image-box').width();
			var intCurrentHeight = $('#lightbox-container-image-box').height();
			// Get the width and height of the selected image plus the padding
			var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image´s width and the left and right padding value
			var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image´s height and the left and right padding value
			// Diferences
			var intDiffW = intCurrentWidth - intWidth;
			var intDiffH = intCurrentHeight - intHeight;

			// Perfomance the effect
//			$('#lightbox-container-image-box').fadeIn(settings.containerResizeSpeed, function() { _show_image(); }); // was lightbox-container-image-box
				
				$("#lightbox-container-image-data-box").animate({ width: intWidth });
				$("#lightbox-container-image-data").animate({ width: intWidth-46 });
				$("#lightbox-container-image-box").animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
			if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
				if ( $.browser.msie ) {
					___pause(250);
				} else {
					___pause(100);	
				}
			} 
			//$('#lightbox-container-image-data-box').css({ width: intImageWidth });
			//$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
		};
		/**
		 * Show the prepared image
		 *
		 */
		function _show_image() {
			$('#lightbox-loading').hide();
			$('#lightbox-image').fadeIn(function() {
				_show_image_data();
				_set_navigation();
			});
			_preload_neighbor_images();
		};
		/**
		 * Show the image information
		 *
		 */
		function _show_image_data() {
			$('#lightbox-container-image-data-box').slideDown('fast');
			$('#lightbox-image-details-caption').hide();
			if ( settings.imageArray[settings.activeImage][1] ) {
				$('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
			}
			// If we have a image set, display 'Image X of X'
			if ( settings.imageArray.length > 1 || true) {
				$('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
			}		
		}
		/**
		 * Display the button navigations
		 *
		 */
		function _set_navigation() {
			$('#lightbox-nav').show();

			// Instead to define this configuration in CSS file, we define here. And it´s need to IE. Just.
			$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
			
			// Show the prev button, if not the first image in set
			if ( settings.activeImage != 0 ) {
				if ( settings.fixedNavigation ) {
					$('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage - 1;
							_set_image_to_view();
							return false;
						});
				} else {
					// Show the images button for Next buttons
					$('#lightbox-nav-btnPrev').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
					},function() {
						$(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage - 1;
						_set_image_to_view();
						return false;
					});
				}
			} else { 
				$('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrevNone + ') left 15% no-repeat' })
					.unbind()
					.bind('click',function() {
						return false;
					});
			}
			
			// Show the next button, if not the last image in set
			if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
				if ( settings.fixedNavigation ) {
					$('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage + 1;
							_set_image_to_view();
							return false;
						});
				} else { 
					// Show the images button for Next buttons
					$('#lightbox-nav-btnNext').unbind().hover(function() {
						$(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
					},function() {
						$(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage + 1;
						_set_image_to_view();
						return false;
					});
				}
			} else {
				$('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNextNone + ') right 15% no-repeat' })
					.unbind()
					.bind('click',function() {
						return false;
					});
			}
			// Enable keyboard navigation
			_enable_keyboard_navigation();
		}
		/**
		 * Enable a support to keyboard navigation
		 *
		 */
		function _enable_keyboard_navigation() {
			$(document).keydown(function(objEvent) {
				_keyboard_action(objEvent);
			});
		}
		/**
		 * Disable the support to keyboard navigation
		 *
		 */
		function _disable_keyboard_navigation() {
			$(document).unbind();
		}
		/**
		 * Perform the keyboard actions
		 *
		 */
		function _keyboard_action(objEvent) {
			// To ie
			if ( objEvent == null ) {
				keycode = event.keyCode;
				escapeKey = 27;
			// To Mozilla
			} else {
				keycode = objEvent.keyCode;
				escapeKey = objEvent.DOM_VK_ESCAPE;
			}
			// Get the key in lower case form
			key = String.fromCharCode(keycode).toLowerCase();
			// Verify the keys to close the ligthBox
			if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
				_finish();
			}
			// Verify the key to show the previous image
			if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
				// If we´re not showing the first image, call the previous
				if ( settings.activeImage != 0 ) {
					settings.activeImage = settings.activeImage - 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
			// Verify the key to show the next image
			if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
				// If we´re not showing the last image, call the next
				if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {
					settings.activeImage = settings.activeImage + 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
		}
		/**
		 * Preload prev and next images being showed
		 *
		 */
		function _preload_neighbor_images() {
			if ( (settings.imageArray.length -1) > settings.activeImage ) {
				objNext = new Image();
				objNext.src = settings.imageArray[settings.activeImage + 1][0];
			}
			if ( settings.activeImage > 0 ) {
				objPrev = new Image();
				objPrev.src = settings.imageArray[settings.activeImage -1][0];
			}
		}
		/**
		 * Remove jQuery lightBox plugin HTML markup
		 *
		 */
		function _finish() {
			$('#jquery-lightbox').remove();
			$('#jquery-overlay').fadeOut(function() { $('#jquery-overlay').remove(); });
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			$('embed, object, select').css({ 'visibility' : 'visible' });
		}
		/**
		 / THIRD FUNCTION
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
		 /**
		  * Stop the code execution from a escified time in milisecond
		  *
		  */
		 function ___pause(ms) {
			var date = new Date(); 
			curDate = null;
			do { var curDate = new Date(); }
			while ( curDate - date < ms);
		 };
		// Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
		return this.unbind('click').click(_initialize);
	};
})(jQuery); // Call and execute the function immediately passing the jQuery object
