//<![CDATA[
var max_page = 0;
var timeoutNavHover = null;
var timeoutThumbsSubHover = null;
var sJqNavLi = 'ul#nav > li';
var sJqNavLiAct = 'ul#nav > li.act';
var sJqNavArea = '#divNavArea';
var bShowDetails = true;

$(document).ready(function(){
	$(".nojs").removeClass("nojs");
	hover_ThumbsImg();
	hover_ThumbsSub();
	//max_page_f();
	//pagin_v();
	if($('#divOpenDetails').length > 0) text_cols_hide();
	$('#divThumbsImg a').click(function(e){
		e.preventDefault();
		$('#divThumbsImg a').removeClass('act');
		$(this).addClass('act');
		var d = $(this).attr('href');
		$('#content_slide').scrollTo(d, 800);
	});
	//$(sJqNavLi).find('ul').hide();
	$(sJqNavLi).hover(
		 function(){
			if(timeoutNavHover) clearTimeout(timeoutNavHover);
			closeNavSub(false);
			$(this).addClass("on");
			$(this).find('ul').show();
			if($(this).find('a').hasClass('MenuEntryBindedToThumbsPrj')) showThumbsPrj(true);
			else hideThumbsPrj(false);
			showThumbsSubAndImg($(this).hasClass('act') && !$(this).find('a').hasClass('MenuEntryBindedToThumbsPrj'));
		}
		,function(){
		}
	);
	$(sJqNavArea).hover(
		 function() {
		}
		,function() {
			showThumbsPrj(false);
			closeNavSub(true);
			showThumbsSubAndImg(true);
		}
	);
	oThumbsPrjSub = new Pags('#divThumbsSub');
	oThumbsPrjPag = new Pags('#divThumbsPrj');
	thumbsSubCenterMiddle();
	divColLinkRelativeIfInsideScroll();
	$('div#cont_content_slide').each( function() {
		new ArrowsScroll($(this), $(this).find('div#text_one_col_cont'));
	} );
});

function showThumbsPrj(bShow) {
	$('#divThumbsPrj').removeClass('off');
	if(bShow) {
		$('#divThumbsPrj').addClass('Show');
		thumbsSubCenterMiddle();
	} else {
		$('#divThumbsPrj').removeClass('Show');
	}
}
function hideThumbsPrj(bShow) {
	$('#divThumbsPrj').addClass('off');
}

function showThumbsSubAndImg(bShow) {
	if(bShow) {
		$('#divThumbsSub').removeClass('off');
		$('#divThumbsImg').removeClass('off');
	} else {
		$('#divThumbsSub').addClass('off');
		$('#divThumbsImg').addClass('off');
	}
}

function closeNavSub(bSelected) {
	$(sJqNavLi).removeClass("on");		
	$(sJqNavLi).find('ul').hide();
	if(bSelected) $(sJqNavLiAct).find('ul').show();
}

function hover_ThumbsImg(){
	var counter = 2;
	$("#divThumbsImg a").each(function(i){
		$(this).append("<div><\/div>");
		counter++;
	});
	$('#slide').css("width",counter+"00%");
	$('#divThumbsImg a').hover(
		function(){
			$(this).addClass("on");
		},
		function(){
			$(this).removeClass("on");
		}
	);
}

function hover_ThumbsSub(){
	$('.ThumbsSub a').hover(
		function(){
			$(this).addClass("on");
		},
		function(){
			$(this).removeClass("on");
		}
	);
}



function project_details(){
	var velocidad_trans = 300;
	$("#text_one_col").animate({'right':'0'},velocidad_trans, "", function(){});
}

function project_details_hide() {
	$("#text_one_col.ShowHide").css('right', -$("#text_one_col").innerWidth() );
	$("#text_two_cols.ShowHide").css('right', -$("#text_two_cols").innerWidth() );
}
function project_details_close(){
	var velocidad_trans = 300;
	$("#text_one_col").animate({'right':-$("#text_one_col").innerWidth() },velocidad_trans, "", function(){});
}
function text_two_cols() {
	var velocidad_trans = 300;
	$("#text_two_cols").animate({'right':'0'},velocidad_trans, "", function(){});
}
function text_two_cols_close(){
	var velocidad_trans = 300;
	$("#text_two_cols").animate({'right':'-669px'},velocidad_trans, "", function(){});
}
function text_two_cols_hide(){
	var velocidad_trans = 300;
	$("#text_two_cols").animate({'right':'-669px'},velocidad_trans, "", function(){});
}
function text_cols_open() {
	project_details();
	text_two_cols()
	bShowDetails = true;
	$('#divOpenDetails').hide();
	$('#divCloseDetails').show();
}
function text_cols_close() {
	project_details_close();
	text_two_cols_close();
	bShowDetails = false;
	$('#divOpenDetails').show();
	$('#divCloseDetails').hide();
}
function text_cols_hide() {
	text_two_cols_hide();
	project_details_hide();
	bShowDetails = false;
	$('#divOpenDetails').show();
	$('#divCloseDetails').hide();
}
function text_cols_toggle(){
	if(bShowDetails) {
		text_cols_close();
	} else {
		text_cols_open();
	}
}

function Pags(sJqDiv) {
	this.prev = function() {
		this.iSelected = (this.iSelected + this.iTotal - 1) % this.iTotal;
		this.update();
	}
	this.next = function() {
		this.iSelected = (this.iSelected + 1) % this.iTotal;
		this.update();
	}
	this.update = function() {
		$(this.sJqDiv + " .ThumbsNav").removeClass('off');
		$(this.sJqDiv + " .Pag").addClass('off');
		$(this.sJqDiv + " .Pag").eq(this.iSelected).removeClass('off');
		thumbsSubCenterMiddle();
	}
	this.iSelected = 0;
	this.iTotal = 0;
	this.sJqDiv = sJqDiv;
	if((this.iTotal = $(sJqDiv).find('.Pag').size()) > 1) {
		var oThis = this;
		$(this.sJqDiv + " a.ThumbsNavPrev").click( function() { oThis.prev(); } );
		$(this.sJqDiv + " a.ThumbsNavNext").click( function() { oThis.next(); } );
		this.update();
	}
}

function thumbsSubCenterMiddle() {
	var iPos, jqTxt;
	$('div.ThumbsSub .Pag a').each( function() {
		jqText = $(this).find('span.ThumbsTxt');
		if((iPos = ($(this).height() - jqText.height()) / 2 - 1) > 0 ) {
			jqText.css('top', iPos);
		}
	} );
}

function divColLinkRelativeIfInsideScroll() {
	if($('#divColLinks').parent('div').height() < 411) {
		$('#divColLinks').removeClass('InsideScroll');
	}
}

function ArrowsScroll(jqDivOut, jqDivIn) {
	this.onMouseOverUp = function() {
		this.iVel = -this.iYInc;
	}
	this.onMouseOverDown = function() {
		this.iVel = +this.iYInc;
	}
	this.onMovement = function() {
		var iYPosAct = this.jqDivOut.find('div.' + this.sDivWrapClass).scrollTop();
		this.iYPos += this.iVel;
		if(this.iYPos > this.iMaxScroll) this.iYPos = this.iMaxScroll;
		else if(this.iYPos < 0) this.iYPos = 0;
		this.jqDivOut.find('div.'+this.sDivWrapClass).scrollTo(iYPosAct + (this.iYPos - iYPosAct) * this.nEasingFactor, 0, { axis: 'y' } );
		var oThis = this;
		this.timeout = setTimeout(function() { oThis.onMovement(); }, this.iDelay);
	}
	this.onMouseOut = function() {
		this.iVel = 0;
		//clearTimeout(this.timeout);
	}
	this.onResize = function() {
		if(this.bFirstTime) {
			this.bFirstTime = false;
			this.jqDivOut.css('overflow', 'hidden');
			this.jqDivOut.find('div').css('overflow', 'hidden');
			this.jqDivIn.wrap('<div class="'+this.sDivWrapClass+'">');
			jqDivWrap = this.jqDivOut.find('div.' + this.sDivWrapClass);
			if(this.jqDivOut.css('position') != 'absolute') this.jqDivOut.css('position', 'relative');
			this.jqDivOut.append('<img class="ScrollArrowUp" src="images/scroll-arrow-up.png" alt="up" /><img class="ScrollArrowDown" src="images/scroll-arrow-down.png" alt="down" />');
			this.jqDivIn.append('<div style="height: '+this.iMarginBottom+'px; background: none;"></div>');
			jqDivWrap.css('position', 'absolute');
			jqDivWrap.css('width', '100%');
			jqDivWrap.css('height', this.jqDivOut.height() + 'px');
			jqDivWrap.css('overflow', 'hidden');
		}
		this.jqDivOut.find('div.' + this.sDivWrapClass).scrollTo(0, { axis: 'y' } );
		this.iYPos = 0;
		this.iMaxScroll = this.jqDivIn.height() - this.jqDivOut.height();
		if(this.iMaxScroll > 0) {
			var oThis = this;
			this.jqDivOut.find('img.ScrollArrowUp, img.ScrollArrowDown').show();
			this.jqDivOut.find('img.ScrollArrowUp').mouseover( function() {
				oThis.onMouseOverUp();
			} );
			this.jqDivOut.find('img.ScrollArrowDown').mouseover( function() {
				oThis.onMouseOverDown();
			} );
			this.jqDivOut.find('img.ScrollArrowUp,img.ScrollArrowDown').mouseout( function() {
				oThis.onMouseOut();
			} );
			if(this.timeout) clearTimeout(this.timeout);
			this.onMovement();
		} else {
			this.jqDivOut.find('img.ScrollArrowUp, img.ScrollArrowDown').hide();
		}
	}
	this.iDelay = 50;
	this.iYInc = 10;
	this.nEasingFactor = 0.4;
	this.iMarginBottom = 6;
	this.sDivWrapClass = 'text_one_col_cont_wrap';
	this.bFirstTime = true;
	this.iVel = 0;
	this.iYPos = 0;
	this.jqDivOut = jqDivOut;
	this.jqDivIn = jqDivIn;
	if(this.jqDivIn.length > 0) this.onResize();
}
//]]>

