// +var
var favorites_works 	= new Image();
var works 				= new Image();
var experience			= new Image();
var about_us			= new Image();
var go_to_top			= new Image();
// end var

// +attributes
favorites_works.src		= root_url+"imgs/buttons/favorites_works_over.png" ;
works.src				= root_url+"imgs/buttons/works_over.png" ;
experience.src			= root_url+"imgs/buttons/experience_over.png" ;
about_us.src			= root_url+"imgs/buttons/about_us_over.png" ;
go_to_top.src			= root_url+"imgs/buttons/go_to_top.png" ;
// end attributes

$(document).ready
(
	function()
	{
		var page_size   	= pageSize();  
		var page_scroll 	= getPageScroll(); 
		
		// +links
		blank("externo","(Este link abre uma nova janela)");
		
		$('.selected a').click(
			function() {
				return false;
			}
		);
		// end links
		
		
		// + go to top
		$('.top').click(
			function() {
				$(window).scrollTo("#header",800);
			}
		);
		
		displayGoToTop();
		// end go to top
		
	}
);

$(window).scroll(
	function() {
		displayGoToTop();
		goToTopIeFixed();	
	}
);

$(window).resize(
	function() {
		displayGoToTop();
		goToTopIeFixed();
	}
);

// +functions
// todos os links com o atributo 'rel' igual a 'externo' abrirao uma nova janela( o documento XHTML ainda sera valido )
function blank(rel_value,anchor_title){
	$("a[rel='"+rel_value+"']").attr({ target:"_blank",title:anchor_title });
}

// exibira ou nao o botao "ir para o topo" conforme posicao do scroll (nao exibira se estiver na posicao 0)
function displayGoToTop() {
	var page_scroll = getPageScroll(); 
		
	if(page_scroll[1] != 0)
		$('.top').show();
	else
		$('.top').hide();
}

// dara o efeito de position "fixed" para o ie6 atraves do javascript
function goToTopIeFixed() {
	if (typeof document.body.style.maxHeight === "undefined") { // ie 6
		var page_size   	= pageSize();  
		var page_scroll 	= getPageScroll(); 
		
		$('.top').css({ top:((page_size[3] + page_scroll[1]) - $('.top').height()) + "px", left:((page_size[2] + page_scroll[0]) - $('.top').width()) + "px" });
	}
}

function pageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = $('#wrapper').height();
	}
	
	if($('#wrapper').width() >= $('body').width()) {
		pageWidth = $('#wrapper').width();
	} else {
		pageWidth = $('body').width();
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight,xScroll, yScroll) 
	return arrayPageSize;
}

function getPageScroll() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}
// end functions