

var myrules = {
    'a.open-close' : function(el) {
        el.onclick = function() {
			updateScroll();
            basePath = "/store/images/curriculum/";
			var bodyWidth;
			if (window.Event)  //is NN4
				bodyWidth=Math.floor( (window.innerWidth) *0.70);
			else //is IE
				bodyWidth=Math.floor( (document.body.clientWidth ) *0.70 ) ;

        	var itemBody = this.parentNode.getElementsByTagName("div")[0];
			itemBody.style.width= bodyWidth+"px";
            var imagesInsideBody = itemBody.getElementsByTagName("img");
            var anchorsInsideBody = itemBody.getElementsByTagName("a");
            
            if(  this.style.backgroundImage == "" || this.style.backgroundImage.indexOf('plus.gif') > 0  ) {
                
                if(anchorsInsideBody) {
                    for ( var i=0; i < imagesInsideBody.length ; i++) {
                        if( imagesInsideBody[i].src.indexOf(basePath) == -1 ) {
                            imagesInsideBody[i].className = "sombra";
                            var imgPath = anchorsInsideBody[i].href.split("#")[1];
                            imgPath = imgPath.split(".jpg")[0];
                            imgPath = basePath + imgPath + "_small.jpg";
                            imagesInsideBody[i].src = imgPath;
                        }
                    }
                }
                
                this.style.background = "URL('/images/minus.gif') 0px no-repeat";
				itemBody.style.display = "inline";
                this.innerHTML = "Fechar";
            } else {
                
                this.style.background = "URL('/images/plus.gif') 0px no-repeat";
                itemBody.style.display = "none";
                this.innerHTML = "Abrir";
            }
			
			var parent = this.parentNode;
		
			var intervalID = setTimeout( function() {
												window.scrollTo(0,parent.offsetTop+parent.offsetHeight);
												clearTimeout(intervalID);
										  }, 1); 
        }
    } ,
    'a.body-item' :  function(el) {
        el.onclick = function() {

		    window.defaultStatus="Carregando...";
            basePath = "/store/images/curriculum/";
            var fileName = this.href.split("#")[1] ;
			
			var divObj=this.parentNode.parentNode.parentNode.parentNode.parentNode;
			var divObjOffsetTop = divObj.offsetTop;
			var imgOffsetLeft = this.parentNode.offsetLeft;
          //--
           var query = "/Scripts/showpress.asp?";
           query+= "file="+basePath+fileName;
		   query+= aspParams ;
            
            //-- Pre Load 
            var img  = new Image();
            img.src = basePath+fileName;
            
            var waitBox = document.getElementById("Wait");
            waitBox.style.left = Math.floor((document.body.offsetWidth/2)*.70);
            waitBox.style.top = Math.floor(divObj.offsetTop+divObj.offsetHeight*1.5);
            waitBox.style.display = "inline";
            
            var intervalId;
            
           intervalId = setInterval(  function() { if( img.complete ) {
                                                        
                                        waitBox.style.display = "none"; 
                                        
                                        //--
                                       query+= "&width="+img.width;
                                       query+= "&height="+img.height;
                                       
                                       //resize and center
                                       
                                       var screenWidth = screen.availWidth;
                                       var screenHeight = screen.availHeight;
                                     
                                       var newWindowWidth = img.width*1.09;
                                       var newWindowHeight = img.height;
                                        
                                        //center
                                        newPosX = Math.floor( (screenWidth-newWindowWidth)/2 );
                                        newPosY = Math.floor( (screenHeight-newWindowHeight)/2 );
                                        
                                       //-- 
                                       openW(  query ,'top='+0+',left='+newPosX+',width='+newWindowWidth+', height='+newWindowHeight+',location=no,status=no,resizable=yes,scrollbars=yes,menubar=no,titlebar=no'); 
                                        clearInterval(intervalId);  
                                  }} 
                                                      
                                , 200 ); //-- End setInterval()
    
        }}
    
}; //End myrules literal Object

function openW(query,params) {
         window.open(  query ,'',params,false); 
}

Behaviour.register(myrules);

